mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
* fixes #10703 * emit frame defines once
This commit is contained in:
@@ -21,6 +21,7 @@ const
|
||||
CFileSectionNames: array[TCFileSection, string] = [
|
||||
cfsMergeInfo: "",
|
||||
cfsHeaders: "NIM_merge_HEADERS",
|
||||
cfsFrameDefines: "NIM_merge_FRAME_DEFINES",
|
||||
cfsForwardTypes: "NIM_merge_FORWARD_TYPES",
|
||||
cfsTypes: "NIM_merge_TYPES",
|
||||
cfsSeqTypes: "NIM_merge_SEQ_TYPES",
|
||||
|
||||
@@ -539,7 +539,22 @@ proc initLocExprSingleUse(p: BProc, e: PNode, result: var TLoc) =
|
||||
|
||||
include ccgcalls, "ccgstmts.nim"
|
||||
|
||||
proc initFrame(p: BProc, procname, filename: Rope): Rope =
|
||||
proc initFrame(p: BProc, procname, filename: Rope): Rope =
|
||||
const frameDefines = """
|
||||
$1 define nimfr_(proc, file) \
|
||||
TFrame FR_; \
|
||||
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; #nimFrame(&FR_);
|
||||
|
||||
$1 define nimfrs_(proc, file, slots, length) \
|
||||
struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
|
||||
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; #nimFrame((TFrame*)&FR_);
|
||||
|
||||
$1 define nimln_(n, file) \
|
||||
FR_.line = n; FR_.filename = file;
|
||||
"""
|
||||
if p.module.s[cfsFrameDefines].len == 0:
|
||||
appcg(p.module, p.module.s[cfsFrameDefines], frameDefines, [rope("#")])
|
||||
|
||||
discard cgsym(p.module, "nimFrame")
|
||||
if p.maxFrameLen > 0:
|
||||
discard cgsym(p.module, "VarSlot")
|
||||
@@ -1123,20 +1138,6 @@ proc genVarPrototype(m: BModule, n: PNode) =
|
||||
"\t$1 = ($2*)hcrGetGlobal($3, \"$1\");$n", [sym.loc.r,
|
||||
getTypeDesc(m, sym.loc.t), getModuleDllPath(m, sym)])
|
||||
|
||||
const
|
||||
frameDefines = """
|
||||
$1 define nimfr_(proc, file) \
|
||||
TFrame FR_; \
|
||||
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; #nimFrame(&FR_);
|
||||
|
||||
$1 define nimfrs_(proc, file, slots, length) \
|
||||
struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
|
||||
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; #nimFrame((TFrame*)&FR_);
|
||||
|
||||
$1 define nimln_(n, file) \
|
||||
FR_.line = n; FR_.filename = file;
|
||||
"""
|
||||
|
||||
proc addIntTypes(result: var Rope; conf: ConfigRef) {.inline.} =
|
||||
addf(result, "#define NIM_INTBITS $1\L", [
|
||||
platform.CPU[conf.target.targetCPU].intSize.rope])
|
||||
@@ -1477,8 +1478,6 @@ proc genInitCode(m: BModule) =
|
||||
## this function is called in cgenWriteModules after all modules are closed,
|
||||
## it means raising dependency on the symbols is too late as it will not propogate
|
||||
## into other modules, only simple rope manipulations are allowed
|
||||
appcg(m, m.s[cfsForwardTypes], frameDefines, [rope("#")])
|
||||
|
||||
var moduleInitRequired = m.hcrOn
|
||||
let initname = getInitName(m)
|
||||
var prc = "$1 N_NIMCALL(void, $2)(void) {$N" %
|
||||
@@ -1608,6 +1607,9 @@ proc genModule(m: BModule, cfile: Cfile): Rope =
|
||||
add(result, genSectionStart(cfsHeaders, m.config))
|
||||
add(result, m.s[cfsHeaders])
|
||||
add(result, genSectionEnd(cfsHeaders, m.config))
|
||||
add(result, genSectionStart(cfsFrameDefines, m.config))
|
||||
add(result, m.s[cfsFrameDefines])
|
||||
add(result, genSectionEnd(cfsFrameDefines, m.config))
|
||||
|
||||
for i in countup(cfsForwardTypes, cfsProcs):
|
||||
if m.s[i].len > 0:
|
||||
|
||||
@@ -20,6 +20,7 @@ type
|
||||
TCFileSection* = enum # the sections a generated C file consists of
|
||||
cfsMergeInfo, # section containing merge information
|
||||
cfsHeaders, # section for C include file headers
|
||||
cfsFrameDefines # section for nim frame macros
|
||||
cfsForwardTypes, # section for C forward typedefs
|
||||
cfsTypes, # section for C typedefs
|
||||
cfsSeqTypes, # section for sequence types only
|
||||
|
||||
Reference in New Issue
Block a user