* fixes #10703 * emit frame defines once
This commit is contained in:
parent
3e04afda9f
commit
ea3e18bc6c
3 changed files with 21 additions and 17 deletions
|
|
@ -21,6 +21,7 @@ const
|
||||||
CFileSectionNames: array[TCFileSection, string] = [
|
CFileSectionNames: array[TCFileSection, string] = [
|
||||||
cfsMergeInfo: "",
|
cfsMergeInfo: "",
|
||||||
cfsHeaders: "NIM_merge_HEADERS",
|
cfsHeaders: "NIM_merge_HEADERS",
|
||||||
|
cfsFrameDefines: "NIM_merge_FRAME_DEFINES",
|
||||||
cfsForwardTypes: "NIM_merge_FORWARD_TYPES",
|
cfsForwardTypes: "NIM_merge_FORWARD_TYPES",
|
||||||
cfsTypes: "NIM_merge_TYPES",
|
cfsTypes: "NIM_merge_TYPES",
|
||||||
cfsSeqTypes: "NIM_merge_SEQ_TYPES",
|
cfsSeqTypes: "NIM_merge_SEQ_TYPES",
|
||||||
|
|
|
||||||
|
|
@ -539,7 +539,22 @@ proc initLocExprSingleUse(p: BProc, e: PNode, result: var TLoc) =
|
||||||
|
|
||||||
include ccgcalls, "ccgstmts.nim"
|
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")
|
discard cgsym(p.module, "nimFrame")
|
||||||
if p.maxFrameLen > 0:
|
if p.maxFrameLen > 0:
|
||||||
discard cgsym(p.module, "VarSlot")
|
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,
|
"\t$1 = ($2*)hcrGetGlobal($3, \"$1\");$n", [sym.loc.r,
|
||||||
getTypeDesc(m, sym.loc.t), getModuleDllPath(m, sym)])
|
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.} =
|
proc addIntTypes(result: var Rope; conf: ConfigRef) {.inline.} =
|
||||||
addf(result, "#define NIM_INTBITS $1\L", [
|
addf(result, "#define NIM_INTBITS $1\L", [
|
||||||
platform.CPU[conf.target.targetCPU].intSize.rope])
|
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,
|
## 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
|
## it means raising dependency on the symbols is too late as it will not propogate
|
||||||
## into other modules, only simple rope manipulations are allowed
|
## into other modules, only simple rope manipulations are allowed
|
||||||
appcg(m, m.s[cfsForwardTypes], frameDefines, [rope("#")])
|
|
||||||
|
|
||||||
var moduleInitRequired = m.hcrOn
|
var moduleInitRequired = m.hcrOn
|
||||||
let initname = getInitName(m)
|
let initname = getInitName(m)
|
||||||
var prc = "$1 N_NIMCALL(void, $2)(void) {$N" %
|
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, genSectionStart(cfsHeaders, m.config))
|
||||||
add(result, m.s[cfsHeaders])
|
add(result, m.s[cfsHeaders])
|
||||||
add(result, genSectionEnd(cfsHeaders, m.config))
|
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):
|
for i in countup(cfsForwardTypes, cfsProcs):
|
||||||
if m.s[i].len > 0:
|
if m.s[i].len > 0:
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ type
|
||||||
TCFileSection* = enum # the sections a generated C file consists of
|
TCFileSection* = enum # the sections a generated C file consists of
|
||||||
cfsMergeInfo, # section containing merge information
|
cfsMergeInfo, # section containing merge information
|
||||||
cfsHeaders, # section for C include file headers
|
cfsHeaders, # section for C include file headers
|
||||||
|
cfsFrameDefines # section for nim frame macros
|
||||||
cfsForwardTypes, # section for C forward typedefs
|
cfsForwardTypes, # section for C forward typedefs
|
||||||
cfsTypes, # section for C typedefs
|
cfsTypes, # section for C typedefs
|
||||||
cfsSeqTypes, # section for sequence types only
|
cfsSeqTypes, # section for sequence types only
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue