C++ codegen: emit 'extern C' for importc'ed functions that we declare a prototype for
This commit is contained in:
parent
f0aef9f4e2
commit
57874ed9b8
2 changed files with 9 additions and 6 deletions
|
|
@ -57,8 +57,8 @@ proc generateThreadLocalStorage(m: BModule) =
|
||||||
|
|
||||||
proc generateThreadVarsSize(m: BModule) =
|
proc generateThreadVarsSize(m: BModule) =
|
||||||
if nimtv != nil:
|
if nimtv != nil:
|
||||||
let externc = if gCmd != cmdCompileToCpp and
|
let externc = if gCmd == cmdCompileToCpp or
|
||||||
sfCompileToCpp in m.module.flags: "extern \"C\""
|
sfCompileToCpp in m.module.flags: "extern \"C\" "
|
||||||
else: ""
|
else: ""
|
||||||
addf(m.s[cfsProcs],
|
addf(m.s[cfsProcs],
|
||||||
"$#NI NimThreadVarsSize(){return (NI)sizeof(NimThreadVars);}$n",
|
"$#NI NimThreadVarsSize(){return (NI)sizeof(NimThreadVars);}$n",
|
||||||
|
|
|
||||||
|
|
@ -715,10 +715,13 @@ proc genProcAux(m: BModule, prc: PSym) =
|
||||||
add(generatedProc, ~"}$N")
|
add(generatedProc, ~"}$N")
|
||||||
add(m.s[cfsProcs], generatedProc)
|
add(m.s[cfsProcs], generatedProc)
|
||||||
|
|
||||||
proc crossesCppBoundary(m: BModule; sym: PSym): bool {.inline.} =
|
proc requiresExternC(m: BModule; sym: PSym): bool {.inline.} =
|
||||||
result = sfCompileToCpp in m.module.flags and
|
result = (sfCompileToCpp in m.module.flags and
|
||||||
sfCompileToCpp notin sym.getModule().flags and
|
sfCompileToCpp notin sym.getModule().flags and
|
||||||
gCmd != cmdCompileToCpp
|
gCmd != cmdCompileToCpp) or (
|
||||||
|
sym.flags * {sfImportc, sfInfixCall, sfCompilerProc} == {sfImportc} and
|
||||||
|
sym.magic == mNone and
|
||||||
|
gCmd == cmdCompileToCpp)
|
||||||
|
|
||||||
proc genProcPrototype(m: BModule, sym: PSym) =
|
proc genProcPrototype(m: BModule, sym: PSym) =
|
||||||
useHeader(m, sym)
|
useHeader(m, sym)
|
||||||
|
|
@ -732,7 +735,7 @@ proc genProcPrototype(m: BModule, sym: PSym) =
|
||||||
var header = genProcHeader(m, sym)
|
var header = genProcHeader(m, sym)
|
||||||
if sfNoReturn in sym.flags and hasDeclspec in extccomp.CC[cCompiler].props:
|
if sfNoReturn in sym.flags and hasDeclspec in extccomp.CC[cCompiler].props:
|
||||||
header = "__declspec(noreturn) " & header
|
header = "__declspec(noreturn) " & header
|
||||||
if sym.typ.callConv != ccInline and crossesCppBoundary(m, sym):
|
if sym.typ.callConv != ccInline and requiresExternC(m, sym):
|
||||||
header = "extern \"C\" " & header
|
header = "extern \"C\" " & header
|
||||||
if sfPure in sym.flags and hasAttribute in CC[cCompiler].props:
|
if sfPure in sym.flags and hasAttribute in CC[cCompiler].props:
|
||||||
header.add(" __attribute__((naked))")
|
header.add(" __attribute__((naked))")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue