mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-14 23:33:28 +00:00
add static assertions in the generated code about platform-related assumptions
This commit is contained in:
@@ -40,15 +40,7 @@ proc addForwardedProc(m: BModule, prc: PSym) =
|
||||
|
||||
proc findPendingModule(m: BModule, s: PSym): BModule =
|
||||
var ms = getModule(s)
|
||||
if ms.id == m.module.id: return m
|
||||
for i in countup(0, high(gModules)):
|
||||
result = gModules[i]
|
||||
if result.module.id == ms.id: return
|
||||
# else we found no pending module: This can happen for procs that are in
|
||||
# a module that is already closed. This is fine, don't generate code for
|
||||
# it then:
|
||||
result = nil
|
||||
#InternalError(s.info, "no pending module found for: " & s.name.s)
|
||||
result = gModules[ms.position]
|
||||
|
||||
proc emitLazily(s: PSym): bool {.inline.} =
|
||||
result = optDeadCodeElim in gGlobalOptions or
|
||||
@@ -1139,6 +1131,11 @@ proc writeModule(m: BModule, pending: bool) =
|
||||
addFileToCompile(cfilenoext)
|
||||
addFileToLink(cfilenoext)
|
||||
|
||||
proc genPlatformAsserts(m: BModule) =
|
||||
appf(m.s[cfsForwardTypes],
|
||||
"typedef assert_numbits[sizeof(NI) == sizeof(void*) &&" &
|
||||
"NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];$N")
|
||||
|
||||
proc myClose(b: PPassContext, n: PNode): PNode =
|
||||
result = n
|
||||
if b == nil or passes.skipCodegen(n): return
|
||||
@@ -1152,6 +1149,7 @@ proc myClose(b: PPassContext, n: PNode): PNode =
|
||||
if sfMainModule in m.module.flags:
|
||||
var disp = generateMethodDispatchers()
|
||||
for i in 0..sonsLen(disp)-1: genProcAux(m, disp.sons[i].sym)
|
||||
genPlatformAsserts(m)
|
||||
genMainProc(m)
|
||||
# we need to process the transitive closure because recursive module
|
||||
# deps are allowed (and the system module is processed in the wrong
|
||||
|
||||
Reference in New Issue
Block a user