Make main functions static so they are visible only within main module
This commit is contained in:
parent
eec239e851
commit
2c904039fa
1 changed files with 14 additions and 7 deletions
|
|
@ -953,13 +953,13 @@ proc genMainProc(m: BModule) =
|
||||||
# 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.
|
||||||
PreMainBody =
|
PreMainBody =
|
||||||
"void PreMainInner(void) {$N" &
|
"static void PreMainInner(void) {$N" &
|
||||||
"\tsystemInit000();$N" &
|
"\tsystemInit000();$N" &
|
||||||
"$1" &
|
"$1" &
|
||||||
"$2" &
|
"$2" &
|
||||||
"$3" &
|
"$3" &
|
||||||
"}$N$N" &
|
"}$N$N" &
|
||||||
"void PreMain(void) {$N" &
|
"static void PreMain(void) {$N" &
|
||||||
"\tvoid (*volatile inner)(void);$N" &
|
"\tvoid (*volatile inner)(void);$N" &
|
||||||
"\tsystemDatInit000();$N" &
|
"\tsystemDatInit000();$N" &
|
||||||
"\tinner = PreMainInner;$N" &
|
"\tinner = PreMainInner;$N" &
|
||||||
|
|
@ -973,12 +973,12 @@ proc genMainProc(m: BModule) =
|
||||||
MainProcsWithResult =
|
MainProcsWithResult =
|
||||||
MainProcs & "\treturn nim_program_result;$N"
|
MainProcs & "\treturn nim_program_result;$N"
|
||||||
|
|
||||||
NimMainInner = "N_CDECL(void, NimMainInner)(void) {$N" &
|
NimMainInner = "N_CDECL(static void, NimMainInner)(void) {$N" &
|
||||||
"$1" &
|
"$1" &
|
||||||
"}$N$N"
|
"}$N$N"
|
||||||
|
|
||||||
NimMainProc =
|
NimMainProc =
|
||||||
"N_CDECL(void, NimMain)(void) {$N" &
|
"N_CDECL(static void, NimMain)(void) {$N" &
|
||||||
"\tvoid (*volatile inner)(void);$N" &
|
"\tvoid (*volatile inner)(void);$N" &
|
||||||
"\tPreMain();$N" &
|
"\tPreMain();$N" &
|
||||||
"\tinner = NimMainInner;$N" &
|
"\tinner = NimMainInner;$N" &
|
||||||
|
|
@ -1026,7 +1026,7 @@ proc genMainProc(m: BModule) =
|
||||||
PosixNimDllMain = WinNimDllMain
|
PosixNimDllMain = WinNimDllMain
|
||||||
|
|
||||||
PosixCDllMain =
|
PosixCDllMain =
|
||||||
"void NIM_POSIX_INIT NimMainInit(void) {$N" &
|
"static void NIM_POSIX_INIT NimMainInit(void) {$N" &
|
||||||
MainProcs &
|
MainProcs &
|
||||||
"}$N$N"
|
"}$N$N"
|
||||||
|
|
||||||
|
|
@ -1117,6 +1117,9 @@ proc registerModuleToMain(g: BModuleList; m: PSym) =
|
||||||
var
|
var
|
||||||
init = m.getInitName
|
init = m.getInitName
|
||||||
datInit = m.getDatInitName
|
datInit = m.getDatInitName
|
||||||
|
if sfMainModule in m.flags:
|
||||||
|
addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(static void, $1)(void);$N", [init])
|
||||||
|
else:
|
||||||
addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [init])
|
addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [init])
|
||||||
addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [datInit])
|
addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [datInit])
|
||||||
if sfSystemModule notin m.flags:
|
if sfSystemModule notin m.flags:
|
||||||
|
|
@ -1129,7 +1132,11 @@ proc registerModuleToMain(g: BModuleList; m: PSym) =
|
||||||
|
|
||||||
proc genInitCode(m: BModule) =
|
proc genInitCode(m: BModule) =
|
||||||
var initname = getInitName(m.module)
|
var initname = getInitName(m.module)
|
||||||
var prc = "N_LIB_PRIVATE N_NIMCALL(void, $1)(void) {$N" % [initname]
|
var prc: Rope
|
||||||
|
if sfMainModule in m.module.flags:
|
||||||
|
prc = "N_LIB_PRIVATE N_NIMCALL(static void, $1)(void) {$N" % [initname]
|
||||||
|
else:
|
||||||
|
prc = "N_LIB_PRIVATE N_NIMCALL(void, $1)(void) {$N" % [initname]
|
||||||
if m.typeNodes > 0:
|
if m.typeNodes > 0:
|
||||||
appcg(m, m.s[cfsTypeInit1], "static #TNimNode $1[$2];$n",
|
appcg(m, m.s[cfsTypeInit1], "static #TNimNode $1[$2];$n",
|
||||||
[m.typeNodesName, rope(m.typeNodes)])
|
[m.typeNodesName, rope(m.typeNodes)])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue