nest PreMain inside NimMain for easier consumption of static libraries developed in Nimrod
fixes many uses of $N instead of $n for new lines that don't affect #line directives
This commit is contained in:
parent
85a5bfe605
commit
9dec669b94
1 changed files with 67 additions and 57 deletions
|
|
@ -913,21 +913,21 @@ proc addIntTypes(result: var PRope) {.inline.} =
|
||||||
|
|
||||||
proc getCopyright(cfilenoext: string): PRope =
|
proc getCopyright(cfilenoext: string): PRope =
|
||||||
if optCompileOnly in gGlobalOptions:
|
if optCompileOnly in gGlobalOptions:
|
||||||
result = ropeff("/* Generated by Nimrod Compiler v$1 */$n" &
|
result = ropeff("/* Generated by Nimrod Compiler v$1 */$N" &
|
||||||
"/* (c) 2014 Andreas Rumpf */$n" &
|
"/* (c) 2014 Andreas Rumpf */$N" &
|
||||||
"/* The generated code is subject to the original license. */$n",
|
"/* The generated code is subject to the original license. */$N",
|
||||||
"; Generated by Nimrod Compiler v$1$n" &
|
"; Generated by Nimrod Compiler v$1$N" &
|
||||||
"; (c) 2012 Andreas Rumpf$n", [toRope(VersionAsString)])
|
"; (c) 2012 Andreas Rumpf$N", [toRope(VersionAsString)])
|
||||||
else:
|
else:
|
||||||
result = ropeff("/* Generated by Nimrod Compiler v$1 */$n" &
|
result = ropeff("/* Generated by Nimrod Compiler v$1 */$N" &
|
||||||
"/* (c) 2014 Andreas Rumpf */$n" &
|
"/* (c) 2014 Andreas Rumpf */$N" &
|
||||||
"/* The generated code is subject to the original license. */$n" &
|
"/* The generated code is subject to the original license. */$N" &
|
||||||
"/* Compiled for: $2, $3, $4 */$n" &
|
"/* Compiled for: $2, $3, $4 */$N" &
|
||||||
"/* Command for C compiler:$n $5 */$n",
|
"/* Command for C compiler:$n $5 */$N",
|
||||||
"; Generated by Nimrod Compiler v$1$n" &
|
"; Generated by Nimrod Compiler v$1$N" &
|
||||||
"; (c) 2014 Andreas Rumpf$n" &
|
"; (c) 2014 Andreas Rumpf$N" &
|
||||||
"; Compiled for: $2, $3, $4$n" &
|
"; Compiled for: $2, $3, $4$N" &
|
||||||
"; Command for LLVM compiler:$n $5$n", [toRope(VersionAsString),
|
"; Command for LLVM compiler:$N $5$N", [toRope(VersionAsString),
|
||||||
toRope(platform.OS[targetOS].name),
|
toRope(platform.OS[targetOS].name),
|
||||||
toRope(platform.CPU[targetCPU].name),
|
toRope(platform.CPU[targetCPU].name),
|
||||||
toRope(extccomp.CC[extccomp.cCompiler].name),
|
toRope(extccomp.CC[extccomp.cCompiler].name),
|
||||||
|
|
@ -941,61 +941,71 @@ proc genFilenames(m: BModule): PRope =
|
||||||
discard cgsym(m, "dbgRegisterFilename")
|
discard cgsym(m, "dbgRegisterFilename")
|
||||||
result = nil
|
result = nil
|
||||||
for i in 0.. <fileInfos.len:
|
for i in 0.. <fileInfos.len:
|
||||||
result.appf("dbgRegisterFilename($1);$n", fileInfos[i].projPath.makeCString)
|
result.appf("dbgRegisterFilename($1);$N", fileInfos[i].projPath.makeCString)
|
||||||
|
|
||||||
proc genMainProc(m: BModule) =
|
proc genMainProc(m: BModule) =
|
||||||
const
|
const
|
||||||
PreMainBody =
|
PreMainBody =
|
||||||
"\tsystemDatInit();$n" &
|
"\tsystemDatInit();$N" &
|
||||||
"\tsystemInit();$n" &
|
"\tsystemInit();$N" &
|
||||||
"$1" &
|
"$1" &
|
||||||
"$2" &
|
"$2" &
|
||||||
"$3" &
|
"$3" &
|
||||||
"$4"
|
"$4"
|
||||||
|
|
||||||
MainProcs =
|
MainProcs =
|
||||||
"\tPreMain();$n" &
|
"\tNimMain();$N"
|
||||||
"\tNimMain();$n"
|
|
||||||
|
|
||||||
MainProcsWithResult =
|
MainProcsWithResult =
|
||||||
MainProcs & "\treturn nim_program_result;$n"
|
MainProcs & "\treturn nim_program_result;$N"
|
||||||
|
|
||||||
|
NimMainBody =
|
||||||
|
"N_CDECL(void, NimMain)(void) {$N" &
|
||||||
|
"\tPreMain();$N" &
|
||||||
|
"$1$N" &
|
||||||
|
"}$N"
|
||||||
|
|
||||||
PosixNimMain =
|
PosixNimMain =
|
||||||
"int cmdCount;$n" &
|
"int cmdCount;$N" &
|
||||||
"char** cmdLine;$n" &
|
"char** cmdLine;$N" &
|
||||||
"char** gEnv;$n" &
|
"char** gEnv;$N" &
|
||||||
"N_CDECL(void, NimMain)(void) {$n$1}$n"
|
NimMainBody
|
||||||
|
|
||||||
PosixCMain = "int main(int argc, char** args, char** env) {$n" &
|
PosixCMain =
|
||||||
"\tcmdLine = args;$n" & "\tcmdCount = argc;$n" & "\tgEnv = env;$n" &
|
"int main(int argc, char** args, char** env) {$N" &
|
||||||
|
"\tcmdLine = args;$N" &
|
||||||
|
"\tcmdCount = argc;$N" &
|
||||||
|
"\tgEnv = env;$N" &
|
||||||
MainProcsWithResult &
|
MainProcsWithResult &
|
||||||
"}$n"
|
"}$N"
|
||||||
|
|
||||||
StandaloneCMain = "int main(void) {$n" &
|
StandaloneCMain =
|
||||||
|
"int main(void) {$N" &
|
||||||
MainProcs &
|
MainProcs &
|
||||||
"\treturn 0;$n" & "}$n"
|
"\treturn 0;$N" &
|
||||||
|
"}$N"
|
||||||
|
|
||||||
WinNimMain = "N_CDECL(void, NimMain)(void) {$n$1}$n"
|
WinNimMain = NimMainBody
|
||||||
|
|
||||||
WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $n" &
|
WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $N" &
|
||||||
" HINSTANCE hPrevInstance, $n" &
|
" HINSTANCE hPrevInstance, $N" &
|
||||||
" LPSTR lpCmdLine, int nCmdShow) {$n" &
|
" LPSTR lpCmdLine, int nCmdShow) {$N" &
|
||||||
MainProcsWithResult & "}$n"
|
MainProcsWithResult & "}$N"
|
||||||
|
|
||||||
WinNimDllMain = "N_LIB_EXPORT N_CDECL(void, NimMain)(void) {$n$1}$n"
|
WinNimDllMain = "N_LIB_EXPORT " & NimMainBody
|
||||||
|
|
||||||
WinCDllMain =
|
WinCDllMain =
|
||||||
"BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, $n" &
|
"BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, $N" &
|
||||||
" LPVOID lpvReserved) {$n" &
|
" LPVOID lpvReserved) {$N" &
|
||||||
"\tif(fwdreason == DLL_PROCESS_ATTACH) {" & MainProcs & "}$n" &
|
"\tif(fwdreason == DLL_PROCESS_ATTACH) {$N" & MainProcs & "}$N" &
|
||||||
"\treturn 1;$n}$n"
|
"\treturn 1;$N}$N"
|
||||||
|
|
||||||
PosixNimDllMain = WinNimDllMain
|
PosixNimDllMain = WinNimDllMain
|
||||||
|
|
||||||
PosixCDllMain =
|
PosixCDllMain =
|
||||||
"void NIM_POSIX_INIT NimMainInit(void) {$n" &
|
"void NIM_POSIX_INIT NimMainInit(void) {$N" &
|
||||||
MainProcs &
|
MainProcs &
|
||||||
"}$n"
|
"}$N"
|
||||||
|
|
||||||
var nimMain, otherMain: TFormatStr
|
var nimMain, otherMain: TFormatStr
|
||||||
if platform.targetOS == osWindows and
|
if platform.targetOS == osWindows and
|
||||||
|
|
@ -1022,9 +1032,9 @@ proc genMainProc(m: BModule) =
|
||||||
|
|
||||||
let initStackBottomCall = if emulatedThreadVars() or
|
let initStackBottomCall = if emulatedThreadVars() or
|
||||||
platform.targetOS == osStandalone: "".toRope
|
platform.targetOS == osStandalone: "".toRope
|
||||||
else: ropecg(m, "\t#initStackBottom();$n")
|
else: ropecg(m, "\t#initStackBottom();$N")
|
||||||
inc(m.labels)
|
inc(m.labels)
|
||||||
appcg(m, m.s[cfsProcs], "void PreMain() {$n" & PreMainBody & "}$n", [
|
appcg(m, m.s[cfsProcs], "void PreMain() {$N" & PreMainBody & "}$N", [
|
||||||
mainDatInit, initStackBottomCall, gBreakpoints, otherModsInit])
|
mainDatInit, initStackBottomCall, gBreakpoints, otherModsInit])
|
||||||
|
|
||||||
appcg(m, m.s[cfsProcs], nimMain, [mainModInit, toRope(m.labels)])
|
appcg(m, m.s[cfsProcs], nimMain, [mainModInit, toRope(m.labels)])
|
||||||
|
|
@ -1049,8 +1059,8 @@ proc registerModuleToMain(m: PSym) =
|
||||||
appff(mainModProcs, "N_NOINLINE(void, $1)(void);$N",
|
appff(mainModProcs, "N_NOINLINE(void, $1)(void);$N",
|
||||||
"declare void $1() noinline$N", [datInit])
|
"declare void $1() noinline$N", [datInit])
|
||||||
if sfSystemModule notin m.flags:
|
if sfSystemModule notin m.flags:
|
||||||
appff(mainDatInit, "\t$1();$n", "call void ()* $1$n", [datInit])
|
appff(mainDatInit, "\t$1();$N", "call void ()* $1$n", [datInit])
|
||||||
let initCall = ropeff("\t$1();$n", "call void ()* $1$n", [init])
|
let initCall = ropeff("\t$1();$N", "call void ()* $1$n", [init])
|
||||||
if sfMainModule in m.flags:
|
if sfMainModule in m.flags:
|
||||||
app(mainModInit, initCall)
|
app(mainModInit, initCall)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1058,7 +1068,7 @@ proc registerModuleToMain(m: PSym) =
|
||||||
|
|
||||||
proc genInitCode(m: BModule) =
|
proc genInitCode(m: BModule) =
|
||||||
var initname = getInitName(m.module)
|
var initname = getInitName(m.module)
|
||||||
var prc = ropeff("N_NOINLINE(void, $1)(void) {$n",
|
var prc = ropeff("N_NOINLINE(void, $1)(void) {$N",
|
||||||
"define void $1() noinline {$n", [initname])
|
"define void $1() noinline {$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",
|
||||||
|
|
@ -1101,7 +1111,7 @@ proc genInitCode(m: BModule) =
|
||||||
app(prc, deinitGCFrame(m.initProc))
|
app(prc, deinitGCFrame(m.initProc))
|
||||||
appf(prc, "}$N$N")
|
appf(prc, "}$N$N")
|
||||||
|
|
||||||
prc.appff("N_NOINLINE(void, $1)(void) {$n",
|
prc.appff("N_NOINLINE(void, $1)(void) {$N",
|
||||||
"define void $1() noinline {$n", [getDatInitName(m.module)])
|
"define void $1() noinline {$n", [getDatInitName(m.module)])
|
||||||
|
|
||||||
for i in cfsTypeInit1..cfsDynLibInit:
|
for i in cfsTypeInit1..cfsDynLibInit:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue