summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2019-03-12 07:24:17 +0000
committerAndreas Rumpf <rumpf_a@web.de>2019-03-12 08:24:17 +0100
commitea3e18bc6cd6f37581d65fb13512fdde35bed95c (patch)
tree53a139cfd44e4abfdc052e552346424388f4b4ce
parent3e04afda9f8d1797e63a70f90a969fa8f98823b3 (diff)
downloadNim-ea3e18bc6cd6f37581d65fb13512fdde35bed95c.tar.gz
fixes dce regression #10703 (#10820)
* fixes #10703

* emit frame defines once
-rw-r--r--compiler/ccgmerge.nim1
-rw-r--r--compiler/cgen.nim36
-rw-r--r--compiler/cgendata.nim1
3 files changed, 21 insertions, 17 deletions
diff --git a/compiler/ccgmerge.nim b/compiler/ccgmerge.nim
index 56b17440e..3aca741cc 100644
--- a/compiler/ccgmerge.nim
+++ b/compiler/ccgmerge.nim
@@ -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",
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 09076c520..4a10a4d2b 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -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:
diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim
index 7b1e7c123..6c38ae1c4 100644
--- a/compiler/cgendata.nim
+++ b/compiler/cgendata.nim
@@ -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