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
|
||||
|
|
@ -77,7 +77,8 @@
|
|||
|
||||
- JS target indent is all spaces, instead of mixed spaces and tabs, for
|
||||
generated JavaScript.
|
||||
|
||||
- The Nim compiler now supports the ``--asm`` command option for easier
|
||||
inspection of the produced assembler code.
|
||||
|
||||
|
||||
## Bugfixes
|
||||
|
|
|
|||
|
|
@ -626,6 +626,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
|||
conf.implicitIncludes.add findModule(conf, arg, toFullPath(conf, info)).string
|
||||
of "listcmd":
|
||||
processOnOffSwitchG(conf, {optListCmd}, arg, pass, info)
|
||||
of "asm":
|
||||
processOnOffSwitchG(conf, {optProduceAsm}, arg, pass, info)
|
||||
of "genmapping":
|
||||
processOnOffSwitchG(conf, {optGenMapping}, arg, pass, info)
|
||||
of "os":
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ type
|
|||
# used on some platforms
|
||||
asmStmtFrmt: string, # format of ASM statement
|
||||
structStmtFmt: string, # Format for struct statement
|
||||
produceAsm: string, # Format how to produce assembler listings
|
||||
props: TInfoCCProps] # properties of the C compiler
|
||||
|
||||
|
||||
|
|
@ -58,6 +59,9 @@ type
|
|||
template compiler(name, settings: untyped): untyped =
|
||||
proc name: TInfoCC {.compileTime.} = settings
|
||||
|
||||
const
|
||||
gnuAsmListing = "-Wa,-acdl=$asmfile -g -fverbose-asm -masm=intel"
|
||||
|
||||
# GNU C and C++ Compiler
|
||||
compiler gcc:
|
||||
result = (
|
||||
|
|
@ -80,6 +84,7 @@ compiler gcc:
|
|||
pic: "-fPIC",
|
||||
asmStmtFrmt: "asm($1);$n",
|
||||
structStmtFmt: "$1 $3 $2 ", # struct|union [packed] $name
|
||||
produceAsm: gnuAsmListing,
|
||||
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm,
|
||||
hasAttribute})
|
||||
|
||||
|
|
@ -105,6 +110,7 @@ compiler nintendoSwitchGCC:
|
|||
pic: "-fPIE",
|
||||
asmStmtFrmt: "asm($1);$n",
|
||||
structStmtFmt: "$1 $3 $2 ", # struct|union [packed] $name
|
||||
produceAsm: gnuAsmListing,
|
||||
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm,
|
||||
hasAttribute})
|
||||
|
||||
|
|
@ -151,6 +157,7 @@ compiler vcc:
|
|||
pic: "",
|
||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||
structStmtFmt: "$3$n$1 $2",
|
||||
produceAsm: "/Fa$asmfile",
|
||||
props: {hasCpp, hasAssume, hasDeclspec})
|
||||
|
||||
compiler clangcl:
|
||||
|
|
@ -196,6 +203,7 @@ compiler lcc:
|
|||
pic: "",
|
||||
asmStmtFrmt: "_asm{$n$1$n}$n",
|
||||
structStmtFmt: "$1 $2",
|
||||
produceAsm: "",
|
||||
props: {})
|
||||
|
||||
# Borland C Compiler
|
||||
|
|
@ -220,6 +228,7 @@ compiler bcc:
|
|||
pic: "",
|
||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||
structStmtFmt: "$1 $2",
|
||||
produceAsm: "",
|
||||
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard,
|
||||
hasAttribute})
|
||||
|
||||
|
|
@ -245,6 +254,7 @@ compiler dmc:
|
|||
pic: "",
|
||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||
structStmtFmt: "$3$n$1 $2",
|
||||
produceAsm: "",
|
||||
props: {hasCpp})
|
||||
|
||||
# Watcom C Compiler
|
||||
|
|
@ -269,6 +279,7 @@ compiler wcc:
|
|||
pic: "",
|
||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||
structStmtFmt: "$1 $2",
|
||||
produceAsm: "",
|
||||
props: {hasCpp})
|
||||
|
||||
# Tiny C Compiler
|
||||
|
|
@ -293,6 +304,7 @@ compiler tcc:
|
|||
pic: "",
|
||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||
structStmtFmt: "$1 $2",
|
||||
produceAsm: "",
|
||||
props: {hasSwitchRange, hasComputedGoto})
|
||||
|
||||
# Pelles C Compiler
|
||||
|
|
@ -318,6 +330,7 @@ compiler pcc:
|
|||
pic: "",
|
||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||
structStmtFmt: "$1 $2",
|
||||
produceAsm: "",
|
||||
props: {})
|
||||
|
||||
# Your C Compiler
|
||||
|
|
@ -342,6 +355,7 @@ compiler ucc:
|
|||
pic: "",
|
||||
asmStmtFrmt: "__asm{$n$1$n}$n",
|
||||
structStmtFmt: "$1 $2",
|
||||
produceAsm: "",
|
||||
props: {})
|
||||
|
||||
const
|
||||
|
|
@ -572,7 +586,8 @@ proc getLinkerExe(conf: ConfigRef; compiler: TSystemCC): string =
|
|||
elif optMixedMode in conf.globalOptions and conf.cmd != cmdCompileToCpp: CC[compiler].cppCompiler
|
||||
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 options = cFileSpecificOptions(conf, cfile.nimname)
|
||||
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
|
||||
# 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)
|
||||
result = quoteShell(compilePattern % [
|
||||
"dfile", dfile,
|
||||
"file", cfsh, "objfile", objfile, "options", options,
|
||||
"file", cfsh, "objfile", quoteShell(objfile), "options", options,
|
||||
"include", includeCmd, "nim", getPrefixDir(conf).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, ' ')
|
||||
addf(result, CC[c].compileTmpl, [
|
||||
"dfile", dfile,
|
||||
"file", cfsh, "objfile", objfile,
|
||||
"file", cfsh, "objfile", quoteShell(objfile),
|
||||
"options", options, "include", includeCmd,
|
||||
"nim", quoteShell(getPrefixDir(conf)),
|
||||
"lib", quoteShell(conf.libpath),
|
||||
|
|
@ -680,7 +706,7 @@ proc compileCFiles(conf: ConfigRef; list: CfileList, script: var Rope, cmds: var
|
|||
for it in list:
|
||||
# call the C compiler for the .c file:
|
||||
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
|
||||
if optCompileOnly notin conf.globalOptions:
|
||||
add(cmds, compileCmd)
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ type # please make sure we have under 32 options
|
|||
optMultiMethods
|
||||
optNimV019
|
||||
optBenchmarkVM # Enables cpuTime() in the VM
|
||||
optProduceAsm # produce assembler code
|
||||
|
||||
TGlobalOptions* = set[TGlobalOption]
|
||||
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ Advanced options:
|
|||
--dynlibOverrideAll
|
||||
disables the effects of the dynlib pragma
|
||||
--listCmd list the commands used to execute external programs
|
||||
--asm produce assembler code
|
||||
--parallelBuild:0|1|... perform a parallel build
|
||||
value = number of processors (0 for auto-detect)
|
||||
--incremental:on|off only recompile the changed modules (experimental!)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue