summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/cgen.nim13
-rw-r--r--compiler/extccomp.nim17
-rw-r--r--compiler/options.nim1
-rw-r--r--compiler/pragmas.nim3
-rw-r--r--compiler/rodimpl.nim4
5 files changed, 22 insertions, 16 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 10dfef6d9..1f4980385 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -1898,7 +1898,6 @@ proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
 # it would generate multiple 'main' procs, for instance.
 
 proc writeModule(m: BModule, pending: bool) =
-  # generate code for the init statements of the module:
   let cfile = getCFile(m)
 
   if true or optForceFullMake in m.config.globalOptions:
@@ -1910,7 +1909,8 @@ proc writeModule(m: BModule, pending: bool) =
       add(m.s[cfsProcHeaders], m.g.mainModProcs)
       generateThreadVarsSize(m)
 
-    var cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
+    var cf = Cfile(nimname: m.module.name.s, cname: cfile,
+                   obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
     var code = genModule(m, cf)
     if code != nil:
       when hasTinyCBackend:
@@ -1921,7 +1921,8 @@ proc writeModule(m: BModule, pending: bool) =
       if not shouldRecompile(m, code, cf): cf.flags = {CfileFlag.Cached}
       addFileToCompile(m.config, cf)
   elif pending and mergeRequired(m) and sfMainModule notin m.module.flags:
-    let cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
+    let cf = Cfile(nimname: m.module.name.s, cname: cfile,
+                   obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
     mergeFiles(cfile, m)
     genInitCode(m)
     finishTypeDescriptions(m)
@@ -1934,14 +1935,16 @@ proc writeModule(m: BModule, pending: bool) =
     # Consider: first compilation compiles ``system.nim`` and produces
     # ``system.c`` but then compilation fails due to an error. This means
     # that ``system.o`` is missing, so we need to call the C compiler for it:
-    var cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
+    var cf = Cfile(nimname: m.module.name.s, cname: cfile,
+                   obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
     if not fileExists(cf.obj): cf.flags = {CfileFlag.Cached}
     addFileToCompile(m.config, cf)
   close(m.ndi)
 
 proc updateCachedModule(m: BModule) =
   let cfile = getCFile(m)
-  var cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
+  var cf = Cfile(nimname: m.module.name.s, cname: cfile,
+                 obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
 
   if mergeRequired(m) and sfMainModule notin m.module.flags:
     mergeFiles(cfile, m)
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim
index 530fba7b0..ae2971b65 100644
--- a/compiler/extccomp.nim
+++ b/compiler/extccomp.nim
@@ -504,30 +504,29 @@ proc noAbsolutePaths(conf: ConfigRef): bool {.inline.} =
   # `optGenMapping` is included here for niminst.
   result = conf.globalOptions * {optGenScript, optGenMapping} != {}
 
-proc cFileSpecificOptions(conf: ConfigRef; cfilename: AbsoluteFile): string =
+proc cFileSpecificOptions(conf: ConfigRef; nimname: string): string =
   result = conf.compileOptions
   for option in conf.compileOptionsCmd:
     if strutils.find(result, option, 0) < 0:
       addOpt(result, option)
 
-  let trunk = splitFile(cfilename).name
   if optCDebug in conf.globalOptions:
-    let key = trunk & ".debug"
+    let key = nimname & ".debug"
     if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key))
     else: addOpt(result, getDebug(conf, conf.cCompiler))
   if optOptimizeSpeed in conf.options:
-    let key = trunk & ".speed"
+    let key = nimname & ".speed"
     if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key))
     else: addOpt(result, getOptSpeed(conf, conf.cCompiler))
   elif optOptimizeSize in conf.options:
-    let key = trunk & ".size"
+    let key = nimname & ".size"
     if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key))
     else: addOpt(result, getOptSize(conf, conf.cCompiler))
-  let key = trunk & ".always"
+  let key = nimname & ".always"
   if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key))
 
 proc getCompileOptions(conf: ConfigRef): string =
-  result = cFileSpecificOptions(conf, AbsoluteFile"__dummy__")
+  result = cFileSpecificOptions(conf, "__dummy__")
 
 proc getLinkOptions(conf: ConfigRef): string =
   result = conf.linkOptions & " " & conf.linkOptionsCmd & " "
@@ -557,7 +556,7 @@ proc getLinkerExe(conf: ConfigRef; compiler: TSystemCC): string =
 
 proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile, isMainFile = false): string =
   var c = conf.cCompiler
-  var options = cFileSpecificOptions(conf, cfile.cname)
+  var options = cFileSpecificOptions(conf, cfile.nimname)
   var exe = getConfigVar(conf, c, ".exe")
   if exe.len == 0: exe = getCompilerExe(conf, c, cfile.cname)
 
@@ -647,7 +646,7 @@ proc addExternalFileToCompile*(conf: ConfigRef; c: var Cfile) =
   conf.toCompile.add(c)
 
 proc addExternalFileToCompile*(conf: ConfigRef; filename: AbsoluteFile) =
-  var c = Cfile(cname: filename,
+  var c = Cfile(nimname: splitFile(filename).name, cname: filename,
     obj: toObjFile(conf, completeCFilePath(conf, filename, false)),
     flags: {CfileFlag.External})
   addExternalFileToCompile(conf, c)
diff --git a/compiler/options.nim b/compiler/options.nim
index 2ab5309bf..bacef5b4a 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -147,6 +147,7 @@ type
     External   ## file was introduced via .compile pragma
 
   Cfile* = object
+    nimname*: string
     cname*, obj*: AbsoluteFile
     flags*: set[CFileFlag]
   CfileList* = seq[Cfile]
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index e49461eea..77c037e51 100644
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -471,7 +471,8 @@ proc relativeFile(c: PContext; n: PNode; ext=""): AbsoluteFile =
 
 proc processCompile(c: PContext, n: PNode) =
   proc docompile(c: PContext; it: PNode; src, dest: AbsoluteFile) =
-    var cf = Cfile(cname: src, obj: dest, flags: {CfileFlag.External})
+    var cf = Cfile(nimname: splitFile(src).name,
+                   cname: src, obj: dest, flags: {CfileFlag.External})
     extccomp.addExternalFileToCompile(c.config, cf)
     recordPragma(c, it, "compile", src.string, dest.string)
 
diff --git a/compiler/rodimpl.nim b/compiler/rodimpl.nim
index 7a2453caf..c6f09d795 100644
--- a/compiler/rodimpl.nim
+++ b/compiler/rodimpl.nim
@@ -846,7 +846,9 @@ proc replay(g: ModuleGraph; module: PSym; n: PNode) =
       of "error": localError(g.config, n.info, errUser, n[1].strVal)
       of "compile":
         internalAssert g.config, n.len == 3 and n[2].kind == nkStrLit
-        var cf = Cfile(cname: AbsoluteFile n[1].strVal, obj: AbsoluteFile n[2].strVal,
+        let cname = AbsoluteFile n[1].strVal,
+        var cf = Cfile(nimname: splitFile(cname).name, cname: cname,
+                       obj: AbsoluteFile n[2].strVal,
                        flags: {CfileFlag.External})
         extccomp.addExternalFileToCompile(g.config, cf)
       of "link":