added the --asm command line option for inspection of the produced assember code (#12699)
This commit is contained in:
parent
135774d92b
commit
f7ba7c711a
5 changed files with 39 additions and 8 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
# x.x - xxxx-xx-xx
|
# 1.2 - xxxx-xx-xx
|
||||||
|
|
||||||
|
|
||||||
## Changes affecting backwards compatibility
|
## Changes affecting backwards compatibility
|
||||||
|
|
@ -77,7 +77,8 @@
|
||||||
|
|
||||||
- JS target indent is all spaces, instead of mixed spaces and tabs, for
|
- JS target indent is all spaces, instead of mixed spaces and tabs, for
|
||||||
generated JavaScript.
|
generated JavaScript.
|
||||||
|
- The Nim compiler now supports the ``--asm`` command option for easier
|
||||||
|
inspection of the produced assembler code.
|
||||||
|
|
||||||
|
|
||||||
## Bugfixes
|
## Bugfixes
|
||||||
|
|
|
||||||
|
|
@ -626,6 +626,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
conf.implicitIncludes.add findModule(conf, arg, toFullPath(conf, info)).string
|
conf.implicitIncludes.add findModule(conf, arg, toFullPath(conf, info)).string
|
||||||
of "listcmd":
|
of "listcmd":
|
||||||
processOnOffSwitchG(conf, {optListCmd}, arg, pass, info)
|
processOnOffSwitchG(conf, {optListCmd}, arg, pass, info)
|
||||||
|
of "asm":
|
||||||
|
processOnOffSwitchG(conf, {optProduceAsm}, arg, pass, info)
|
||||||
of "genmapping":
|
of "genmapping":
|
||||||
processOnOffSwitchG(conf, {optGenMapping}, arg, pass, info)
|
processOnOffSwitchG(conf, {optGenMapping}, arg, pass, info)
|
||||||
of "os":
|
of "os":
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ type
|
||||||
# used on some platforms
|
# used on some platforms
|
||||||
asmStmtFrmt: string, # format of ASM statement
|
asmStmtFrmt: string, # format of ASM statement
|
||||||
structStmtFmt: string, # Format for struct statement
|
structStmtFmt: string, # Format for struct statement
|
||||||
|
produceAsm: string, # Format how to produce assembler listings
|
||||||
props: TInfoCCProps] # properties of the C compiler
|
props: TInfoCCProps] # properties of the C compiler
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -58,6 +59,9 @@ type
|
||||||
template compiler(name, settings: untyped): untyped =
|
template compiler(name, settings: untyped): untyped =
|
||||||
proc name: TInfoCC {.compileTime.} = settings
|
proc name: TInfoCC {.compileTime.} = settings
|
||||||
|
|
||||||
|
const
|
||||||
|
gnuAsmListing = "-Wa,-acdl=$asmfile -g -fverbose-asm -masm=intel"
|
||||||
|
|
||||||
# GNU C and C++ Compiler
|
# GNU C and C++ Compiler
|
||||||
compiler gcc:
|
compiler gcc:
|
||||||
result = (
|
result = (
|
||||||
|
|
@ -80,6 +84,7 @@ compiler gcc:
|
||||||
pic: "-fPIC",
|
pic: "-fPIC",
|
||||||
asmStmtFrmt: "asm($1);$n",
|
asmStmtFrmt: "asm($1);$n",
|
||||||
structStmtFmt: "$1 $3 $2 ", # struct|union [packed] $name
|
structStmtFmt: "$1 $3 $2 ", # struct|union [packed] $name
|
||||||
|
produceAsm: gnuAsmListing,
|
||||||
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm,
|
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm,
|
||||||
hasAttribute})
|
hasAttribute})
|
||||||
|
|
||||||
|
|
@ -105,6 +110,7 @@ compiler nintendoSwitchGCC:
|
||||||
pic: "-fPIE",
|
pic: "-fPIE",
|
||||||
asmStmtFrmt: "asm($1);$n",
|
asmStmtFrmt: "asm($1);$n",
|
||||||
structStmtFmt: "$1 $3 $2 ", # struct|union [packed] $name
|
structStmtFmt: "$1 $3 $2 ", # struct|union [packed] $name
|
||||||
|
produceAsm: gnuAsmListing,
|
||||||
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm,
|
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm,
|
||||||
hasAttribute})
|
hasAttribute})
|
||||||
|
|
||||||
|
|
@ -151,6 +157,7 @@ compiler vcc:
|
||||||
pic: "",
|
pic: "",
|
||||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||||
structStmtFmt: "$3$n$1 $2",
|
structStmtFmt: "$3$n$1 $2",
|
||||||
|
produceAsm: "/Fa$asmfile",
|
||||||
props: {hasCpp, hasAssume, hasDeclspec})
|
props: {hasCpp, hasAssume, hasDeclspec})
|
||||||
|
|
||||||
compiler clangcl:
|
compiler clangcl:
|
||||||
|
|
@ -196,6 +203,7 @@ compiler lcc:
|
||||||
pic: "",
|
pic: "",
|
||||||
asmStmtFrmt: "_asm{$n$1$n}$n",
|
asmStmtFrmt: "_asm{$n$1$n}$n",
|
||||||
structStmtFmt: "$1 $2",
|
structStmtFmt: "$1 $2",
|
||||||
|
produceAsm: "",
|
||||||
props: {})
|
props: {})
|
||||||
|
|
||||||
# Borland C Compiler
|
# Borland C Compiler
|
||||||
|
|
@ -220,6 +228,7 @@ compiler bcc:
|
||||||
pic: "",
|
pic: "",
|
||||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||||
structStmtFmt: "$1 $2",
|
structStmtFmt: "$1 $2",
|
||||||
|
produceAsm: "",
|
||||||
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard,
|
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard,
|
||||||
hasAttribute})
|
hasAttribute})
|
||||||
|
|
||||||
|
|
@ -245,6 +254,7 @@ compiler dmc:
|
||||||
pic: "",
|
pic: "",
|
||||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||||
structStmtFmt: "$3$n$1 $2",
|
structStmtFmt: "$3$n$1 $2",
|
||||||
|
produceAsm: "",
|
||||||
props: {hasCpp})
|
props: {hasCpp})
|
||||||
|
|
||||||
# Watcom C Compiler
|
# Watcom C Compiler
|
||||||
|
|
@ -269,6 +279,7 @@ compiler wcc:
|
||||||
pic: "",
|
pic: "",
|
||||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||||
structStmtFmt: "$1 $2",
|
structStmtFmt: "$1 $2",
|
||||||
|
produceAsm: "",
|
||||||
props: {hasCpp})
|
props: {hasCpp})
|
||||||
|
|
||||||
# Tiny C Compiler
|
# Tiny C Compiler
|
||||||
|
|
@ -293,6 +304,7 @@ compiler tcc:
|
||||||
pic: "",
|
pic: "",
|
||||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||||
structStmtFmt: "$1 $2",
|
structStmtFmt: "$1 $2",
|
||||||
|
produceAsm: "",
|
||||||
props: {hasSwitchRange, hasComputedGoto})
|
props: {hasSwitchRange, hasComputedGoto})
|
||||||
|
|
||||||
# Pelles C Compiler
|
# Pelles C Compiler
|
||||||
|
|
@ -318,6 +330,7 @@ compiler pcc:
|
||||||
pic: "",
|
pic: "",
|
||||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||||
structStmtFmt: "$1 $2",
|
structStmtFmt: "$1 $2",
|
||||||
|
produceAsm: "",
|
||||||
props: {})
|
props: {})
|
||||||
|
|
||||||
# Your C Compiler
|
# Your C Compiler
|
||||||
|
|
@ -342,6 +355,7 @@ compiler ucc:
|
||||||
pic: "",
|
pic: "",
|
||||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||||
structStmtFmt: "$1 $2",
|
structStmtFmt: "$1 $2",
|
||||||
|
produceAsm: "",
|
||||||
props: {})
|
props: {})
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
@ -572,7 +586,8 @@ proc getLinkerExe(conf: ConfigRef; compiler: TSystemCC): string =
|
||||||
elif optMixedMode in conf.globalOptions and conf.cmd != cmdCompileToCpp: CC[compiler].cppCompiler
|
elif optMixedMode in conf.globalOptions and conf.cmd != cmdCompileToCpp: CC[compiler].cppCompiler
|
||||||
else: getCompilerExe(conf, compiler, AbsoluteFile"")
|
else: getCompilerExe(conf, compiler, AbsoluteFile"")
|
||||||
|
|
||||||
proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile, isMainFile = false): string =
|
proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile,
|
||||||
|
isMainFile = false; produceOutput = false): string =
|
||||||
var c = conf.cCompiler
|
var c = conf.cCompiler
|
||||||
var options = cFileSpecificOptions(conf, cfile.nimname)
|
var options = cFileSpecificOptions(conf, cfile.nimname)
|
||||||
var exe = getConfigVar(conf, c, ".exe")
|
var exe = getConfigVar(conf, c, ".exe")
|
||||||
|
|
@ -614,19 +629,30 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile, isMainFile = false): str
|
||||||
|
|
||||||
# D files are required by nintendo switch libs for
|
# D files are required by nintendo switch libs for
|
||||||
# compilation. They are basically a list of all includes.
|
# compilation. They are basically a list of all includes.
|
||||||
let dfile = objfile.changeFileExt(".d").quoteShell()
|
let dfile = objfile.changeFileExt(".d").quoteShell
|
||||||
|
|
||||||
objfile = quoteShell(objfile)
|
|
||||||
let cfsh = quoteShell(cf)
|
let cfsh = quoteShell(cf)
|
||||||
result = quoteShell(compilePattern % [
|
result = quoteShell(compilePattern % [
|
||||||
"dfile", dfile,
|
"dfile", dfile,
|
||||||
"file", cfsh, "objfile", objfile, "options", options,
|
"file", cfsh, "objfile", quoteShell(objfile), "options", options,
|
||||||
"include", includeCmd, "nim", getPrefixDir(conf).string,
|
"include", includeCmd, "nim", getPrefixDir(conf).string,
|
||||||
"lib", conf.libpath.string])
|
"lib", conf.libpath.string])
|
||||||
|
|
||||||
|
if optProduceAsm in conf.globalOptions:
|
||||||
|
if CC[conf.cCompiler].produceAsm.len > 0:
|
||||||
|
let asmfile = objfile.changeFileExt(".asm").quoteShell
|
||||||
|
addOpt(result, CC[conf.cCompiler].produceAsm % ["asmfile", asmfile])
|
||||||
|
if produceOutput:
|
||||||
|
rawMessage(conf, hintUserRaw, "Produced assembler here: " & asmfile)
|
||||||
|
else:
|
||||||
|
if produceOutput:
|
||||||
|
rawMessage(conf, hintUserRaw, "Couldn't produce assembler listing " &
|
||||||
|
"for the selected C compiler: " & CC[conf.cCompiler].name)
|
||||||
|
|
||||||
add(result, ' ')
|
add(result, ' ')
|
||||||
addf(result, CC[c].compileTmpl, [
|
addf(result, CC[c].compileTmpl, [
|
||||||
"dfile", dfile,
|
"dfile", dfile,
|
||||||
"file", cfsh, "objfile", objfile,
|
"file", cfsh, "objfile", quoteShell(objfile),
|
||||||
"options", options, "include", includeCmd,
|
"options", options, "include", includeCmd,
|
||||||
"nim", quoteShell(getPrefixDir(conf)),
|
"nim", quoteShell(getPrefixDir(conf)),
|
||||||
"lib", quoteShell(conf.libpath),
|
"lib", quoteShell(conf.libpath),
|
||||||
|
|
@ -680,7 +706,7 @@ proc compileCFiles(conf: ConfigRef; list: CfileList, script: var Rope, cmds: var
|
||||||
for it in list:
|
for it in list:
|
||||||
# call the C compiler for the .c file:
|
# call the C compiler for the .c file:
|
||||||
if it.flags.contains(CfileFlag.Cached): continue
|
if it.flags.contains(CfileFlag.Cached): continue
|
||||||
var compileCmd = getCompileCFileCmd(conf, it, currIdx == list.len - 1)
|
var compileCmd = getCompileCFileCmd(conf, it, currIdx == list.len - 1, produceOutput=true)
|
||||||
inc currIdx
|
inc currIdx
|
||||||
if optCompileOnly notin conf.globalOptions:
|
if optCompileOnly notin conf.globalOptions:
|
||||||
add(cmds, compileCmd)
|
add(cmds, compileCmd)
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ type # please make sure we have under 32 options
|
||||||
optMultiMethods
|
optMultiMethods
|
||||||
optNimV019
|
optNimV019
|
||||||
optBenchmarkVM # Enables cpuTime() in the VM
|
optBenchmarkVM # Enables cpuTime() in the VM
|
||||||
|
optProduceAsm # produce assembler code
|
||||||
|
|
||||||
TGlobalOptions* = set[TGlobalOption]
|
TGlobalOptions* = set[TGlobalOption]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ Advanced options:
|
||||||
--dynlibOverrideAll
|
--dynlibOverrideAll
|
||||||
disables the effects of the dynlib pragma
|
disables the effects of the dynlib pragma
|
||||||
--listCmd list the commands used to execute external programs
|
--listCmd list the commands used to execute external programs
|
||||||
|
--asm produce assembler code
|
||||||
--parallelBuild:0|1|... perform a parallel build
|
--parallelBuild:0|1|... perform a parallel build
|
||||||
value = number of processors (0 for auto-detect)
|
value = number of processors (0 for auto-detect)
|
||||||
--incremental:on|off only recompile the changed modules (experimental!)
|
--incremental:on|off only recompile the changed modules (experimental!)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue