Add compiler flag that makes NimMain function unique.
This commit is contained in:
parent
2c904039fa
commit
13c6491b10
3 changed files with 16 additions and 3 deletions
|
|
@ -947,8 +947,16 @@ proc genFilenames(m: BModule): Rope =
|
||||||
for i in 0..<m.config.m.fileInfos.len:
|
for i in 0..<m.config.m.fileInfos.len:
|
||||||
result.addf("dbgRegisterFilename($1);$N", [m.config.m.fileInfos[i].projPath.makeCString])
|
result.addf("dbgRegisterFilename($1);$N", [m.config.m.fileInfos[i].projPath.makeCString])
|
||||||
|
|
||||||
|
proc genHashName(m: PSym, name: string): string =
|
||||||
|
name & $hashProc(m)
|
||||||
|
|
||||||
|
proc maybeHashMain(m: BModule, name: string): string =
|
||||||
|
result = name
|
||||||
|
if optUniqueMain in m.config.globalOptions:
|
||||||
|
result = m.module.genHashName(name)
|
||||||
|
|
||||||
proc genMainProc(m: BModule) =
|
proc genMainProc(m: BModule) =
|
||||||
const
|
let
|
||||||
# The use of a volatile function pointer to call Pre/NimMainInner
|
# The use of a volatile function pointer to call Pre/NimMainInner
|
||||||
# prevents inlining of the NimMainInner function and dependent
|
# prevents inlining of the NimMainInner function and dependent
|
||||||
# functions, which might otherwise merge their stack frames.
|
# functions, which might otherwise merge their stack frames.
|
||||||
|
|
@ -968,7 +976,7 @@ proc genMainProc(m: BModule) =
|
||||||
"}$N$N"
|
"}$N$N"
|
||||||
|
|
||||||
MainProcs =
|
MainProcs =
|
||||||
"\tNimMain();$N"
|
"\t" & m.maybeHashMain("NimMain") & "();$N"
|
||||||
|
|
||||||
MainProcsWithResult =
|
MainProcsWithResult =
|
||||||
MainProcs & "\treturn nim_program_result;$N"
|
MainProcs & "\treturn nim_program_result;$N"
|
||||||
|
|
@ -978,7 +986,7 @@ proc genMainProc(m: BModule) =
|
||||||
"}$N$N"
|
"}$N$N"
|
||||||
|
|
||||||
NimMainProc =
|
NimMainProc =
|
||||||
"N_CDECL(static void, NimMain)(void) {$N" &
|
"N_CDECL(void, " & m.maybeHashMain("NimMain") & ")(void) {$N" &
|
||||||
"\tvoid (*volatile inner)(void);$N" &
|
"\tvoid (*volatile inner)(void);$N" &
|
||||||
"\tPreMain();$N" &
|
"\tPreMain();$N" &
|
||||||
"\tinner = NimMainInner;$N" &
|
"\tinner = NimMainInner;$N" &
|
||||||
|
|
|
||||||
|
|
@ -246,6 +246,7 @@ proc testCompileOption*(conf: ConfigRef; switch: string, info: TLineInfo): bool
|
||||||
of "compileonly", "c": result = contains(conf.globalOptions, optCompileOnly)
|
of "compileonly", "c": result = contains(conf.globalOptions, optCompileOnly)
|
||||||
of "nolinking": result = contains(conf.globalOptions, optNoLinking)
|
of "nolinking": result = contains(conf.globalOptions, optNoLinking)
|
||||||
of "nomain": result = contains(conf.globalOptions, optNoMain)
|
of "nomain": result = contains(conf.globalOptions, optNoMain)
|
||||||
|
of "uniquemain": result = contains(conf.globalOptions, optUniqueMain)
|
||||||
of "forcebuild", "f": result = contains(conf.globalOptions, optForceFullMake)
|
of "forcebuild", "f": result = contains(conf.globalOptions, optForceFullMake)
|
||||||
of "warnings", "w": result = contains(conf.options, optWarns)
|
of "warnings", "w": result = contains(conf.options, optWarns)
|
||||||
of "hints": result = contains(conf.options, optHints)
|
of "hints": result = contains(conf.options, optHints)
|
||||||
|
|
@ -416,6 +417,9 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
of "nomain":
|
of "nomain":
|
||||||
expectNoArg(conf, switch, arg, pass, info)
|
expectNoArg(conf, switch, arg, pass, info)
|
||||||
incl(conf.globalOptions, optNoMain)
|
incl(conf.globalOptions, optNoMain)
|
||||||
|
of "uniquemain":
|
||||||
|
expectNoArg(conf, switch, arg, pass, info)
|
||||||
|
incl(conf.globalOptions, optUniqueMain)
|
||||||
of "forcebuild", "f":
|
of "forcebuild", "f":
|
||||||
expectNoArg(conf, switch, arg, pass, info)
|
expectNoArg(conf, switch, arg, pass, info)
|
||||||
incl(conf.globalOptions, optForceFullMake)
|
incl(conf.globalOptions, optForceFullMake)
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ type # please make sure we have under 32 options
|
||||||
optSkipUserConfigFile, # skip the users's config file
|
optSkipUserConfigFile, # skip the users's config file
|
||||||
optSkipParentConfigFiles, # skip parent dir's config files
|
optSkipParentConfigFiles, # skip parent dir's config files
|
||||||
optNoMain, # do not generate a "main" proc
|
optNoMain, # do not generate a "main" proc
|
||||||
|
optUniqueMain, # generate a unique name for the NimMain function
|
||||||
optUseColors, # use colors for hints, warnings, and errors
|
optUseColors, # use colors for hints, warnings, and errors
|
||||||
optThreads, # support for multi-threading
|
optThreads, # support for multi-threading
|
||||||
optStdout, # output to stdout
|
optStdout, # output to stdout
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue