Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
commit
150e733a40
1 changed files with 34 additions and 27 deletions
|
|
@ -491,34 +491,35 @@ proc libCandidates(s: string, dest: var TStringSeq) =
|
||||||
else:
|
else:
|
||||||
add(dest, s)
|
add(dest, s)
|
||||||
|
|
||||||
proc loadDynamicLib(m: BModule, lib: PLib) =
|
proc loadDynamicLib(m: BModule, lib: PLib) =
|
||||||
|
let g = gNimDat
|
||||||
assert(lib != nil)
|
assert(lib != nil)
|
||||||
if not lib.generated:
|
if not lib.generated:
|
||||||
lib.generated = true
|
lib.generated = true
|
||||||
var tmp = getGlobalTempName()
|
var tmp = getGlobalTempName()
|
||||||
assert(lib.name == nil)
|
assert(lib.name == nil)
|
||||||
lib.name = tmp # BUGFIX: cgsym has awful side-effects
|
lib.name = tmp # BUGFIX: cgsym has awful side-effects
|
||||||
appf(m.s[cfsVars], "static void* $1;$n", [tmp])
|
appf(g.s[cfsVars], "static void* $1;$n", [tmp])
|
||||||
if lib.path.kind in {nkStrLit..nkTripleStrLit}:
|
if lib.path.kind in {nkStrLit..nkTripleStrLit}:
|
||||||
var s: TStringSeq = @[]
|
var s: TStringSeq = @[]
|
||||||
libCandidates(lib.path.strVal, s)
|
libCandidates(lib.path.strVal, s)
|
||||||
var loadlib: PRope = nil
|
var loadlib: PRope = nil
|
||||||
for i in countup(0, high(s)):
|
for i in countup(0, high(s)):
|
||||||
inc(m.labels)
|
inc(g.labels)
|
||||||
if i > 0: app(loadlib, "||")
|
if i > 0: app(loadlib, "||")
|
||||||
appcg(m, loadlib, "($1 = #nimLoadLibrary((#NimStringDesc*) &$2))$n",
|
appcg(g, loadlib, "($1 = #nimLoadLibrary((#NimStringDesc*) &$2))$n",
|
||||||
[tmp, getStrLit(m, s[i])])
|
[tmp, getStrLit(g, s[i])])
|
||||||
appcg(m, m.s[cfsDynLibInit],
|
appcg(g, g.s[cfsDynLibInit],
|
||||||
"if (!($1)) #nimLoadLibraryError((#NimStringDesc*) &$2);$n",
|
"if (!($1)) #nimLoadLibraryError((#NimStringDesc*) &$2);$n",
|
||||||
[loadlib, getStrLit(m, lib.path.strVal)])
|
[loadlib, getStrLit(g, lib.path.strVal)])
|
||||||
else:
|
else:
|
||||||
var p = newProc(nil, m)
|
var p = newProc(nil, g)
|
||||||
var dest: TLoc
|
var dest: TLoc
|
||||||
initLocExpr(p, lib.path, dest)
|
initLocExpr(p, lib.path, dest)
|
||||||
app(m.s[cfsVars], p.s(cpsLocals))
|
app(g.s[cfsVars], p.s(cpsLocals))
|
||||||
app(m.s[cfsDynLibInit], p.s(cpsInit))
|
app(g.s[cfsDynLibInit], p.s(cpsInit))
|
||||||
app(m.s[cfsDynLibInit], p.s(cpsStmts))
|
app(g.s[cfsDynLibInit], p.s(cpsStmts))
|
||||||
appcg(m, m.s[cfsDynLibInit],
|
appcg(g, g.s[cfsDynLibInit],
|
||||||
"if (!($1 = #nimLoadLibrary($2))) #nimLoadLibraryError($2);$n",
|
"if (!($1 = #nimLoadLibrary($2))) #nimLoadLibraryError($2);$n",
|
||||||
[tmp, rdLoc(dest)])
|
[tmp, rdLoc(dest)])
|
||||||
|
|
||||||
|
|
@ -531,7 +532,8 @@ proc mangleDynLibProc(sym: PSym): PRope =
|
||||||
else:
|
else:
|
||||||
result = ropef("Dl_$1", [toRope(sym.id)])
|
result = ropef("Dl_$1", [toRope(sym.id)])
|
||||||
|
|
||||||
proc SymInDynamicLib(m: BModule, sym: PSym) =
|
proc SymInDynamicLib(m: BModule, sym: PSym) =
|
||||||
|
let g = gNimDat
|
||||||
var lib = sym.annex
|
var lib = sym.annex
|
||||||
var extname = sym.loc.r
|
var extname = sym.loc.r
|
||||||
loadDynamicLib(m, lib)
|
loadDynamicLib(m, lib)
|
||||||
|
|
@ -539,28 +541,33 @@ proc SymInDynamicLib(m: BModule, sym: PSym) =
|
||||||
var tmp = mangleDynLibProc(sym)
|
var tmp = mangleDynLibProc(sym)
|
||||||
sym.loc.r = tmp # from now on we only need the internal name
|
sym.loc.r = tmp # from now on we only need the internal name
|
||||||
sym.typ.sym = nil # generate a new name
|
sym.typ.sym = nil # generate a new name
|
||||||
inc(m.labels, 2)
|
inc(g.labels, 2)
|
||||||
appcg(m, m.s[cfsDynLibInit],
|
appcg(g, g.s[cfsDynLibInit],
|
||||||
"$1 = ($2) #nimGetProcAddr($3, $4);$n",
|
"$1 = ($2) #nimGetProcAddr($3, $4);$n",
|
||||||
[tmp, getTypeDesc(m, sym.typ),
|
[tmp, getTypeDesc(g, sym.typ),
|
||||||
lib.name, cstringLit(m, m.s[cfsDynLibInit], ropeToStr(extname))])
|
lib.name, cstringLit(g, g.s[cfsDynLibInit], ropeToStr(extname))])
|
||||||
appff(m.s[cfsVars], "$2 $1;$n",
|
appff(g.s[cfsVars], "$2 $1;$n",
|
||||||
"$1 = linkonce global $2 zeroinitializer$n",
|
"$1 = linkonce global $2 zeroinitializer$n",
|
||||||
|
[sym.loc.r, getTypeDesc(g, sym.loc.t)])
|
||||||
|
appf(m.s[cfsVars], "extern $2 $1;$n",
|
||||||
[sym.loc.r, getTypeDesc(m, sym.loc.t)])
|
[sym.loc.r, getTypeDesc(m, sym.loc.t)])
|
||||||
|
|
||||||
proc VarInDynamicLib(m: BModule, sym: PSym) =
|
proc VarInDynamicLib(m: BModule, sym: PSym) =
|
||||||
|
let g = gNimDat
|
||||||
var lib = sym.annex
|
var lib = sym.annex
|
||||||
var extname = sym.loc.r
|
var extname = sym.loc.r
|
||||||
loadDynamicLib(m, lib)
|
loadDynamicLib(m, lib)
|
||||||
incl(sym.loc.flags, lfIndirect)
|
incl(sym.loc.flags, lfIndirect)
|
||||||
var tmp = mangleDynLibProc(sym)
|
var tmp = mangleDynLibProc(sym)
|
||||||
sym.loc.r = tmp # from now on we only need the internal name
|
sym.loc.r = tmp # from now on we only need the internal name
|
||||||
inc(m.labels, 2)
|
inc(g.labels, 2)
|
||||||
appcg(m, m.s[cfsDynLibInit],
|
appcg(g, g.s[cfsDynLibInit],
|
||||||
"$1 = ($2*) #nimGetProcAddr($3, $4);$n",
|
"$1 = ($2*) #nimGetProcAddr($3, $4);$n",
|
||||||
[tmp, getTypeDesc(m, sym.typ),
|
[tmp, getTypeDesc(g, sym.typ),
|
||||||
lib.name, cstringLit(m, m.s[cfsDynLibInit], ropeToStr(extname))])
|
lib.name, cstringLit(g, g.s[cfsDynLibInit], ropeToStr(extname))])
|
||||||
appf(m.s[cfsVars], "$2* $1;$n",
|
appf(g.s[cfsVars], "$2* $1;$n",
|
||||||
|
[sym.loc.r, getTypeDesc(g, sym.loc.t)])
|
||||||
|
appf(m.s[cfsVars], "extern $2* $1;$n",
|
||||||
[sym.loc.r, getTypeDesc(m, sym.loc.t)])
|
[sym.loc.r, getTypeDesc(m, sym.loc.t)])
|
||||||
|
|
||||||
proc SymInDynamicLibPartial(m: BModule, sym: PSym) =
|
proc SymInDynamicLibPartial(m: BModule, sym: PSym) =
|
||||||
|
|
@ -820,8 +827,8 @@ proc genMainProc(m: BModule) =
|
||||||
const
|
const
|
||||||
CommonMainBody =
|
CommonMainBody =
|
||||||
"\tnim__datInit();$n" &
|
"\tnim__datInit();$n" &
|
||||||
"\tsystemInit();$n" &
|
|
||||||
"$1" &
|
"$1" &
|
||||||
|
"\tsystemInit();$n" &
|
||||||
"$2" &
|
"$2" &
|
||||||
"$3"
|
"$3"
|
||||||
PosixNimMain =
|
PosixNimMain =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue