small steps for making --symbolFiles:on work again
This commit is contained in:
parent
caf7717cb8
commit
d3255f708c
3 changed files with 108 additions and 106 deletions
|
|
@ -276,7 +276,8 @@ proc processNote(c: PContext, n: PNode) =
|
||||||
if (n.kind == nkExprColonExpr) and (sonsLen(n) == 2) and
|
if (n.kind == nkExprColonExpr) and (sonsLen(n) == 2) and
|
||||||
(n.sons[0].kind == nkBracketExpr) and
|
(n.sons[0].kind == nkBracketExpr) and
|
||||||
(n.sons[0].sons[1].kind == nkIdent) and
|
(n.sons[0].sons[1].kind == nkIdent) and
|
||||||
(n.sons[0].sons[0].kind == nkIdent) and (n.sons[1].kind == nkIdent):
|
(n.sons[0].sons[0].kind == nkIdent):
|
||||||
|
#and (n.sons[1].kind == nkIdent):
|
||||||
var nk: TNoteKind
|
var nk: TNoteKind
|
||||||
case whichKeyword(n.sons[0].sons[0].ident)
|
case whichKeyword(n.sons[0].sons[0].ident)
|
||||||
of wHint:
|
of wHint:
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
os, options, strutils, nversion, ast, astalgo, msgs, platform, condsyms,
|
os, options, strutils, nversion, ast, astalgo, msgs, platform, condsyms,
|
||||||
ropes, idents, securehash, idgen, types, rodutils, memfiles
|
ropes, idents, securehash, idgen, types, rodutils, memfiles, tables
|
||||||
|
|
||||||
type
|
type
|
||||||
TReasonForRecompile* = enum ## all the reasons that can trigger recompilation
|
TReasonForRecompile* = enum ## all the reasons that can trigger recompilation
|
||||||
|
|
@ -136,7 +136,7 @@ type
|
||||||
readerIndex: int
|
readerIndex: int
|
||||||
line: int # only used for debugging, but is always in the code
|
line: int # only used for debugging, but is always in the code
|
||||||
moduleID: int
|
moduleID: int
|
||||||
syms: TIdTable # already processed symbols
|
syms: Table[int, PSym] # already processed symbols
|
||||||
memfile: MemFile # unfortunately there is no point in time where we
|
memfile: MemFile # unfortunately there is no point in time where we
|
||||||
# can close this! XXX
|
# can close this! XXX
|
||||||
methods*: TSymSeq
|
methods*: TSymSeq
|
||||||
|
|
@ -372,11 +372,11 @@ proc decodeSym(r: PRodReader, info: TLineInfo): PSym =
|
||||||
else:
|
else:
|
||||||
internalError(info, "decodeSym: no ident")
|
internalError(info, "decodeSym: no ident")
|
||||||
#echo "decoding: {", ident.s
|
#echo "decoding: {", ident.s
|
||||||
result = PSym(idTableGet(r.syms, id))
|
result = r.syms[id]
|
||||||
if result == nil:
|
if result == nil:
|
||||||
new(result)
|
new(result)
|
||||||
result.id = id
|
result.id = id
|
||||||
idTablePut(r.syms, result, result)
|
r.syms[result.id] = result
|
||||||
if debugIds: registerID(result)
|
if debugIds: registerID(result)
|
||||||
elif result.id != id:
|
elif result.id != id:
|
||||||
internalError(info, "decodeSym: wrong id")
|
internalError(info, "decodeSym: wrong id")
|
||||||
|
|
@ -481,7 +481,7 @@ proc processInterf(r: PRodReader, module: PSym) =
|
||||||
var s = newStub(r, w, key)
|
var s = newStub(r, w, key)
|
||||||
s.owner = module
|
s.owner = module
|
||||||
strTableAdd(module.tab, s)
|
strTableAdd(module.tab, s)
|
||||||
idTablePut(r.syms, s, s)
|
r.syms[s.id] = s
|
||||||
|
|
||||||
proc processCompilerProcs(r: PRodReader, module: PSym) =
|
proc processCompilerProcs(r: PRodReader, module: PSym) =
|
||||||
if r.compilerProcsIdx == 0: internalError("processCompilerProcs")
|
if r.compilerProcsIdx == 0: internalError("processCompilerProcs")
|
||||||
|
|
@ -491,11 +491,11 @@ proc processCompilerProcs(r: PRodReader, module: PSym) =
|
||||||
inc(r.pos)
|
inc(r.pos)
|
||||||
var key = decodeVInt(r.s, r.pos)
|
var key = decodeVInt(r.s, r.pos)
|
||||||
inc(r.pos) # #10
|
inc(r.pos) # #10
|
||||||
var s = PSym(idTableGet(r.syms, key))
|
var s = r.syms[key]
|
||||||
if s == nil:
|
if s == nil:
|
||||||
s = newStub(r, w, key)
|
s = newStub(r, w, key)
|
||||||
s.owner = module
|
s.owner = module
|
||||||
idTablePut(r.syms, s, s)
|
r.syms[s.id] = s
|
||||||
strTableAdd(rodCompilerprocs, s)
|
strTableAdd(rodCompilerprocs, s)
|
||||||
|
|
||||||
proc processIndex(r: PRodReader; idx: var TIndex; outf: File = nil) =
|
proc processIndex(r: PRodReader; idx: var TIndex; outf: File = nil) =
|
||||||
|
|
@ -667,7 +667,7 @@ proc newRodReader(modfilename: string, hash: SecureHash,
|
||||||
r.line = 1
|
r.line = 1
|
||||||
r.readerIndex = readerIndex
|
r.readerIndex = readerIndex
|
||||||
r.filename = modfilename
|
r.filename = modfilename
|
||||||
initIdTable(r.syms)
|
r.syms = initTable[int, PSym]()
|
||||||
# we terminate the file explicitly with ``\0``, so the cast to `cstring`
|
# we terminate the file explicitly with ``\0``, so the cast to `cstring`
|
||||||
# is safe:
|
# is safe:
|
||||||
r.s = cast[cstring](r.memfile.mem)
|
r.s = cast[cstring](r.memfile.mem)
|
||||||
|
|
@ -737,7 +737,7 @@ proc getReader(moduleId: int): PRodReader =
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym =
|
proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym =
|
||||||
result = PSym(idTableGet(r.syms, id))
|
result = r.syms[id]
|
||||||
if result == nil:
|
if result == nil:
|
||||||
# load the symbol:
|
# load the symbol:
|
||||||
var d = iiTableGet(r.index.tab, id)
|
var d = iiTableGet(r.index.tab, id)
|
||||||
|
|
@ -802,7 +802,7 @@ proc getHash*(fileIdx: int32): SecureHash =
|
||||||
if gMods[fileIdx].hashDone:
|
if gMods[fileIdx].hashDone:
|
||||||
return gMods[fileIdx].hash
|
return gMods[fileIdx].hash
|
||||||
|
|
||||||
result = secureHashFile(fileIdx.toFilename)
|
result = secureHashFile(fileIdx.toFullPath)
|
||||||
gMods[fileIdx].hash = result
|
gMods[fileIdx].hash = result
|
||||||
|
|
||||||
template growCache*(cache, pos) =
|
template growCache*(cache, pos) =
|
||||||
|
|
@ -859,7 +859,7 @@ proc handleSymbolFile(module: PSym): PRodReader =
|
||||||
result = gMods[fileIdx].rd
|
result = gMods[fileIdx].rd
|
||||||
if result != nil:
|
if result != nil:
|
||||||
module.id = result.moduleID
|
module.id = result.moduleID
|
||||||
idTablePut(result.syms, module, module)
|
result.syms[module.id] = module
|
||||||
processInterf(result, module)
|
processInterf(result, module)
|
||||||
processCompilerProcs(result, module)
|
processCompilerProcs(result, module)
|
||||||
loadConverters(result)
|
loadConverters(result)
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@
|
||||||
# rod files is a pass, reading of rod files is not! This is why reading and
|
# rod files is a pass, reading of rod files is not! This is why reading and
|
||||||
# writing of rod files is split into two different modules.
|
# writing of rod files is split into two different modules.
|
||||||
|
|
||||||
import
|
import
|
||||||
intsets, os, options, strutils, nversion, ast, astalgo, msgs, platform,
|
intsets, os, options, strutils, nversion, ast, astalgo, msgs, platform,
|
||||||
condsyms, ropes, idents, securehash, rodread, passes, importer, idgen,
|
condsyms, ropes, idents, securehash, rodread, passes, importer, idgen,
|
||||||
rodutils
|
rodutils
|
||||||
|
|
||||||
# implementation
|
# implementation
|
||||||
|
|
||||||
type
|
type
|
||||||
TRodWriter = object of TPassContext
|
TRodWriter = object of TPassContext
|
||||||
module: PSym
|
module: PSym
|
||||||
hash: SecureHash
|
hash: SecureHash
|
||||||
|
|
@ -46,15 +46,15 @@ proc addInterfaceSym(w: PRodWriter, s: PSym)
|
||||||
proc addStmt(w: PRodWriter, n: PNode)
|
proc addStmt(w: PRodWriter, n: PNode)
|
||||||
proc writeRod(w: PRodWriter)
|
proc writeRod(w: PRodWriter)
|
||||||
|
|
||||||
proc getDefines(): string =
|
proc getDefines(): string =
|
||||||
result = ""
|
result = ""
|
||||||
for d in definedSymbolNames():
|
for d in definedSymbolNames():
|
||||||
if result.len != 0: add(result, " ")
|
if result.len != 0: add(result, " ")
|
||||||
add(result, d)
|
add(result, d)
|
||||||
|
|
||||||
proc fileIdx(w: PRodWriter, filename: string): int =
|
proc fileIdx(w: PRodWriter, filename: string): int =
|
||||||
for i in countup(0, high(w.files)):
|
for i in countup(0, high(w.files)):
|
||||||
if w.files[i] == filename:
|
if w.files[i] == filename:
|
||||||
return i
|
return i
|
||||||
result = len(w.files)
|
result = len(w.files)
|
||||||
setLen(w.files, result + 1)
|
setLen(w.files, result + 1)
|
||||||
|
|
@ -63,7 +63,7 @@ proc fileIdx(w: PRodWriter, filename: string): int =
|
||||||
template filename*(w: PRodWriter): string =
|
template filename*(w: PRodWriter): string =
|
||||||
w.module.filename
|
w.module.filename
|
||||||
|
|
||||||
proc newRodWriter(hash: SecureHash, module: PSym): PRodWriter =
|
proc newRodWriter(hash: SecureHash, module: PSym): PRodWriter =
|
||||||
new(result)
|
new(result)
|
||||||
result.sstack = @[]
|
result.sstack = @[]
|
||||||
result.tstack = @[]
|
result.tstack = @[]
|
||||||
|
|
@ -85,12 +85,12 @@ proc newRodWriter(hash: SecureHash, module: PSym): PRodWriter =
|
||||||
result.init = ""
|
result.init = ""
|
||||||
result.origFile = module.info.toFilename
|
result.origFile = module.info.toFilename
|
||||||
result.data = newStringOfCap(12_000)
|
result.data = newStringOfCap(12_000)
|
||||||
|
|
||||||
proc addModDep(w: PRodWriter, dep: string) =
|
proc addModDep(w: PRodWriter, dep: string) =
|
||||||
if w.modDeps.len != 0: add(w.modDeps, ' ')
|
if w.modDeps.len != 0: add(w.modDeps, ' ')
|
||||||
encodeVInt(fileIdx(w, dep), w.modDeps)
|
encodeVInt(fileIdx(w, dep), w.modDeps)
|
||||||
|
|
||||||
const
|
const
|
||||||
rodNL = "\x0A"
|
rodNL = "\x0A"
|
||||||
|
|
||||||
proc addInclDep(w: PRodWriter, dep: string) =
|
proc addInclDep(w: PRodWriter, dep: string) =
|
||||||
|
|
@ -110,18 +110,18 @@ proc pushSym(w: PRodWriter, s: PSym) =
|
||||||
if iiTableGet(w.index.tab, s.id) == InvalidKey:
|
if iiTableGet(w.index.tab, s.id) == InvalidKey:
|
||||||
w.sstack.add(s)
|
w.sstack.add(s)
|
||||||
|
|
||||||
proc encodeNode(w: PRodWriter, fInfo: TLineInfo, n: PNode,
|
proc encodeNode(w: PRodWriter, fInfo: TLineInfo, n: PNode,
|
||||||
result: var string) =
|
result: var string) =
|
||||||
if n == nil:
|
if n == nil:
|
||||||
# nil nodes have to be stored too:
|
# nil nodes have to be stored too:
|
||||||
result.add("()")
|
result.add("()")
|
||||||
return
|
return
|
||||||
result.add('(')
|
result.add('(')
|
||||||
encodeVInt(ord(n.kind), result)
|
encodeVInt(ord(n.kind), result)
|
||||||
# we do not write comments for now
|
# we do not write comments for now
|
||||||
# Line information takes easily 20% or more of the filesize! Therefore we
|
# Line information takes easily 20% or more of the filesize! Therefore we
|
||||||
# omit line information if it is the same as the father's line information:
|
# omit line information if it is the same as the father's line information:
|
||||||
if fInfo.fileIndex != n.info.fileIndex:
|
if fInfo.fileIndex != n.info.fileIndex:
|
||||||
result.add('?')
|
result.add('?')
|
||||||
encodeVInt(n.info.col, result)
|
encodeVInt(n.info.col, result)
|
||||||
result.add(',')
|
result.add(',')
|
||||||
|
|
@ -139,7 +139,7 @@ proc encodeNode(w: PRodWriter, fInfo: TLineInfo, n: PNode,
|
||||||
# No need to output the file index, as this is the serialization of one
|
# No need to output the file index, as this is the serialization of one
|
||||||
# file.
|
# file.
|
||||||
var f = n.flags * PersistentNodeFlags
|
var f = n.flags * PersistentNodeFlags
|
||||||
if f != {}:
|
if f != {}:
|
||||||
result.add('$')
|
result.add('$')
|
||||||
encodeVInt(cast[int32](f), result)
|
encodeVInt(cast[int32](f), result)
|
||||||
if n.typ != nil:
|
if n.typ != nil:
|
||||||
|
|
@ -147,16 +147,16 @@ proc encodeNode(w: PRodWriter, fInfo: TLineInfo, n: PNode,
|
||||||
encodeVInt(n.typ.id, result)
|
encodeVInt(n.typ.id, result)
|
||||||
pushType(w, n.typ)
|
pushType(w, n.typ)
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkCharLit..nkInt64Lit:
|
of nkCharLit..nkInt64Lit:
|
||||||
if n.intVal != 0:
|
if n.intVal != 0:
|
||||||
result.add('!')
|
result.add('!')
|
||||||
encodeVBiggestInt(n.intVal, result)
|
encodeVBiggestInt(n.intVal, result)
|
||||||
of nkFloatLit..nkFloat64Lit:
|
of nkFloatLit..nkFloat64Lit:
|
||||||
if n.floatVal != 0.0:
|
if n.floatVal != 0.0:
|
||||||
result.add('!')
|
result.add('!')
|
||||||
encodeStr($n.floatVal, result)
|
encodeStr($n.floatVal, result)
|
||||||
of nkStrLit..nkTripleStrLit:
|
of nkStrLit..nkTripleStrLit:
|
||||||
if n.strVal != "":
|
if n.strVal != "":
|
||||||
result.add('!')
|
result.add('!')
|
||||||
encodeStr(n.strVal, result)
|
encodeStr(n.strVal, result)
|
||||||
of nkIdent:
|
of nkIdent:
|
||||||
|
|
@ -167,25 +167,25 @@ proc encodeNode(w: PRodWriter, fInfo: TLineInfo, n: PNode,
|
||||||
encodeVInt(n.sym.id, result)
|
encodeVInt(n.sym.id, result)
|
||||||
pushSym(w, n.sym)
|
pushSym(w, n.sym)
|
||||||
else:
|
else:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
encodeNode(w, n.info, n.sons[i], result)
|
encodeNode(w, n.info, n.sons[i], result)
|
||||||
add(result, ')')
|
add(result, ')')
|
||||||
|
|
||||||
proc encodeLoc(w: PRodWriter, loc: TLoc, result: var string) =
|
proc encodeLoc(w: PRodWriter, loc: TLoc, result: var string) =
|
||||||
var oldLen = result.len
|
var oldLen = result.len
|
||||||
result.add('<')
|
result.add('<')
|
||||||
if loc.k != low(loc.k): encodeVInt(ord(loc.k), result)
|
if loc.k != low(loc.k): encodeVInt(ord(loc.k), result)
|
||||||
if loc.s != low(loc.s):
|
if loc.s != low(loc.s):
|
||||||
add(result, '*')
|
add(result, '*')
|
||||||
encodeVInt(ord(loc.s), result)
|
encodeVInt(ord(loc.s), result)
|
||||||
if loc.flags != {}:
|
if loc.flags != {}:
|
||||||
add(result, '$')
|
add(result, '$')
|
||||||
encodeVInt(cast[int32](loc.flags), result)
|
encodeVInt(cast[int32](loc.flags), result)
|
||||||
if loc.t != nil:
|
if loc.t != nil:
|
||||||
add(result, '^')
|
add(result, '^')
|
||||||
encodeVInt(cast[int32](loc.t.id), result)
|
encodeVInt(cast[int32](loc.t.id), result)
|
||||||
pushType(w, loc.t)
|
pushType(w, loc.t)
|
||||||
if loc.r != nil:
|
if loc.r != nil:
|
||||||
add(result, '!')
|
add(result, '!')
|
||||||
encodeStr($loc.r, result)
|
encodeStr($loc.r, result)
|
||||||
if oldLen + 1 == result.len:
|
if oldLen + 1 == result.len:
|
||||||
|
|
@ -193,9 +193,9 @@ proc encodeLoc(w: PRodWriter, loc: TLoc, result: var string) =
|
||||||
setLen(result, oldLen)
|
setLen(result, oldLen)
|
||||||
else:
|
else:
|
||||||
add(result, '>')
|
add(result, '>')
|
||||||
|
|
||||||
proc encodeType(w: PRodWriter, t: PType, result: var string) =
|
proc encodeType(w: PRodWriter, t: PType, result: var string) =
|
||||||
if t == nil:
|
if t == nil:
|
||||||
# nil nodes have to be stored too:
|
# nil nodes have to be stored too:
|
||||||
result.add("[]")
|
result.add("[]")
|
||||||
return
|
return
|
||||||
|
|
@ -207,38 +207,38 @@ proc encodeType(w: PRodWriter, t: PType, result: var string) =
|
||||||
encodeVInt(ord(t.kind), result)
|
encodeVInt(ord(t.kind), result)
|
||||||
add(result, '+')
|
add(result, '+')
|
||||||
encodeVInt(t.id, result)
|
encodeVInt(t.id, result)
|
||||||
if t.n != nil:
|
if t.n != nil:
|
||||||
encodeNode(w, unknownLineInfo(), t.n, result)
|
encodeNode(w, unknownLineInfo(), t.n, result)
|
||||||
if t.flags != {}:
|
if t.flags != {}:
|
||||||
add(result, '$')
|
add(result, '$')
|
||||||
encodeVInt(cast[int32](t.flags), result)
|
encodeVInt(cast[int32](t.flags), result)
|
||||||
if t.callConv != low(t.callConv):
|
if t.callConv != low(t.callConv):
|
||||||
add(result, '?')
|
add(result, '?')
|
||||||
encodeVInt(ord(t.callConv), result)
|
encodeVInt(ord(t.callConv), result)
|
||||||
if t.owner != nil:
|
if t.owner != nil:
|
||||||
add(result, '*')
|
add(result, '*')
|
||||||
encodeVInt(t.owner.id, result)
|
encodeVInt(t.owner.id, result)
|
||||||
pushSym(w, t.owner)
|
pushSym(w, t.owner)
|
||||||
if t.sym != nil:
|
if t.sym != nil:
|
||||||
add(result, '&')
|
add(result, '&')
|
||||||
encodeVInt(t.sym.id, result)
|
encodeVInt(t.sym.id, result)
|
||||||
pushSym(w, t.sym)
|
pushSym(w, t.sym)
|
||||||
if t.size != - 1:
|
if t.size != - 1:
|
||||||
add(result, '/')
|
add(result, '/')
|
||||||
encodeVBiggestInt(t.size, result)
|
encodeVBiggestInt(t.size, result)
|
||||||
if t.align != 2:
|
if t.align != 2:
|
||||||
add(result, '=')
|
add(result, '=')
|
||||||
encodeVInt(t.align, result)
|
encodeVInt(t.align, result)
|
||||||
encodeLoc(w, t.loc, result)
|
encodeLoc(w, t.loc, result)
|
||||||
for i in countup(0, sonsLen(t) - 1):
|
for i in countup(0, sonsLen(t) - 1):
|
||||||
if t.sons[i] == nil:
|
if t.sons[i] == nil:
|
||||||
add(result, "^()")
|
add(result, "^()")
|
||||||
else:
|
else:
|
||||||
add(result, '^')
|
add(result, '^')
|
||||||
encodeVInt(t.sons[i].id, result)
|
encodeVInt(t.sons[i].id, result)
|
||||||
pushType(w, t.sons[i])
|
pushType(w, t.sons[i])
|
||||||
|
|
||||||
proc encodeLib(w: PRodWriter, lib: PLib, info: TLineInfo, result: var string) =
|
proc encodeLib(w: PRodWriter, lib: PLib, info: TLineInfo, result: var string) =
|
||||||
add(result, '|')
|
add(result, '|')
|
||||||
encodeVInt(ord(lib.kind), result)
|
encodeVInt(ord(lib.kind), result)
|
||||||
add(result, '|')
|
add(result, '|')
|
||||||
|
|
@ -277,10 +277,10 @@ proc encodeSym(w: PRodWriter, s: PSym, result: var string) =
|
||||||
if s.magic != mNone:
|
if s.magic != mNone:
|
||||||
result.add('@')
|
result.add('@')
|
||||||
encodeVInt(ord(s.magic), result)
|
encodeVInt(ord(s.magic), result)
|
||||||
if s.options != w.options:
|
if s.options != w.options:
|
||||||
result.add('!')
|
result.add('!')
|
||||||
encodeVInt(cast[int32](s.options), result)
|
encodeVInt(cast[int32](s.options), result)
|
||||||
if s.position != 0:
|
if s.position != 0:
|
||||||
result.add('%')
|
result.add('%')
|
||||||
encodeVInt(s.position, result)
|
encodeVInt(s.position, result)
|
||||||
if s.offset != - 1:
|
if s.offset != - 1:
|
||||||
|
|
@ -308,7 +308,7 @@ proc encodeSym(w: PRodWriter, s: PSym, result: var string) =
|
||||||
if codeAst != nil:
|
if codeAst != nil:
|
||||||
# resore the AST:
|
# resore the AST:
|
||||||
s.ast.sons[codePos] = codeAst
|
s.ast.sons[codePos] = codeAst
|
||||||
|
|
||||||
proc addToIndex(w: var TIndex, key, val: int) =
|
proc addToIndex(w: var TIndex, key, val: int) =
|
||||||
if key - w.lastIdxKey == 1:
|
if key - w.lastIdxKey == 1:
|
||||||
# we do not store a key-diff of 1 to safe space
|
# we do not store a key-diff of 1 to safe space
|
||||||
|
|
@ -329,24 +329,25 @@ when debugWrittenIds:
|
||||||
|
|
||||||
proc symStack(w: PRodWriter): int =
|
proc symStack(w: PRodWriter): int =
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < len(w.sstack):
|
while i < len(w.sstack):
|
||||||
var s = w.sstack[i]
|
var s = w.sstack[i]
|
||||||
if sfForward in s.flags:
|
if sfForward in s.flags:
|
||||||
w.sstack[result] = s
|
w.sstack[result] = s
|
||||||
inc result
|
inc result
|
||||||
elif iiTableGet(w.index.tab, s.id) == InvalidKey:
|
elif iiTableGet(w.index.tab, s.id) == InvalidKey:
|
||||||
var m = getModule(s)
|
var m = getModule(s)
|
||||||
if m == nil: internalError("symStack: module nil: " & s.name.s)
|
if m == nil and s.kind != skPackage:
|
||||||
if (m.id == w.module.id) or (sfFromGeneric in s.flags):
|
internalError("symStack: module nil: " & s.name.s)
|
||||||
|
if s.kind == skPackage or m.id == w.module.id or sfFromGeneric in s.flags:
|
||||||
# put definition in here
|
# put definition in here
|
||||||
var L = w.data.len
|
var L = w.data.len
|
||||||
addToIndex(w.index, s.id, L)
|
addToIndex(w.index, s.id, L)
|
||||||
when debugWrittenIds: incl(debugWritten, s.id)
|
when debugWrittenIds: incl(debugWritten, s.id)
|
||||||
encodeSym(w, s, w.data)
|
encodeSym(w, s, w.data)
|
||||||
add(w.data, rodNL)
|
add(w.data, rodNL)
|
||||||
# put into interface section if appropriate:
|
# put into interface section if appropriate:
|
||||||
if {sfExported, sfFromGeneric} * s.flags == {sfExported} and
|
if {sfExported, sfFromGeneric} * s.flags == {sfExported} and
|
||||||
s.kind in ExportableSymKinds:
|
s.kind in ExportableSymKinds:
|
||||||
encodeStr(s.name.s, w.interf)
|
encodeStr(s.name.s, w.interf)
|
||||||
add(w.interf, ' ')
|
add(w.interf, ' ')
|
||||||
encodeVInt(s.id, w.interf)
|
encodeVInt(s.id, w.interf)
|
||||||
|
|
@ -362,26 +363,26 @@ proc symStack(w: PRodWriter): int =
|
||||||
if s.kind == skMethod and sfDispatcher notin s.flags:
|
if s.kind == skMethod and sfDispatcher notin s.flags:
|
||||||
if w.methods.len != 0: add(w.methods, ' ')
|
if w.methods.len != 0: add(w.methods, ' ')
|
||||||
encodeVInt(s.id, w.methods)
|
encodeVInt(s.id, w.methods)
|
||||||
elif iiTableGet(w.imports.tab, s.id) == InvalidKey:
|
elif iiTableGet(w.imports.tab, s.id) == InvalidKey:
|
||||||
addToIndex(w.imports, s.id, m.id)
|
addToIndex(w.imports, s.id, m.id)
|
||||||
when debugWrittenIds:
|
when debugWrittenIds:
|
||||||
if not Contains(debugWritten, s.id):
|
if not contains(debugWritten, s.id):
|
||||||
echo(w.filename)
|
echo(w.filename)
|
||||||
debug(s)
|
debug(s)
|
||||||
debug(s.owner)
|
debug(s.owner)
|
||||||
debug(m)
|
debug(m)
|
||||||
InternalError("Symbol referred to but never written")
|
internalError("Symbol referred to but never written")
|
||||||
inc(i)
|
inc(i)
|
||||||
setLen(w.sstack, result)
|
setLen(w.sstack, result)
|
||||||
|
|
||||||
proc typeStack(w: PRodWriter): int =
|
proc typeStack(w: PRodWriter): int =
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < len(w.tstack):
|
while i < len(w.tstack):
|
||||||
var t = w.tstack[i]
|
var t = w.tstack[i]
|
||||||
if t.kind == tyForward:
|
if t.kind == tyForward:
|
||||||
w.tstack[result] = t
|
w.tstack[result] = t
|
||||||
inc result
|
inc result
|
||||||
elif iiTableGet(w.index.tab, t.id) == InvalidKey:
|
elif iiTableGet(w.index.tab, t.id) == InvalidKey:
|
||||||
var L = w.data.len
|
var L = w.data.len
|
||||||
addToIndex(w.index, t.id, L)
|
addToIndex(w.index, t.id, L)
|
||||||
encodeType(w, t, w.data)
|
encodeType(w, t, w.data)
|
||||||
|
|
@ -401,24 +402,24 @@ proc processStacks(w: PRodWriter, finalPass: bool) =
|
||||||
if finalPass and (oldS != 0 or oldT != 0):
|
if finalPass and (oldS != 0 or oldT != 0):
|
||||||
internalError("could not serialize some forwarded symbols/types")
|
internalError("could not serialize some forwarded symbols/types")
|
||||||
|
|
||||||
proc rawAddInterfaceSym(w: PRodWriter, s: PSym) =
|
proc rawAddInterfaceSym(w: PRodWriter, s: PSym) =
|
||||||
pushSym(w, s)
|
pushSym(w, s)
|
||||||
processStacks(w, false)
|
processStacks(w, false)
|
||||||
|
|
||||||
proc addInterfaceSym(w: PRodWriter, s: PSym) =
|
proc addInterfaceSym(w: PRodWriter, s: PSym) =
|
||||||
if w == nil: return
|
if w == nil: return
|
||||||
if s.kind in ExportableSymKinds and
|
if s.kind in ExportableSymKinds and
|
||||||
{sfExported, sfCompilerProc} * s.flags != {}:
|
{sfExported, sfCompilerProc} * s.flags != {}:
|
||||||
rawAddInterfaceSym(w, s)
|
rawAddInterfaceSym(w, s)
|
||||||
|
|
||||||
proc addStmt(w: PRodWriter, n: PNode) =
|
proc addStmt(w: PRodWriter, n: PNode) =
|
||||||
encodeVInt(w.data.len, w.init)
|
encodeVInt(w.data.len, w.init)
|
||||||
add(w.init, rodNL)
|
add(w.init, rodNL)
|
||||||
encodeNode(w, unknownLineInfo(), n, w.data)
|
encodeNode(w, unknownLineInfo(), n, w.data)
|
||||||
add(w.data, rodNL)
|
add(w.data, rodNL)
|
||||||
processStacks(w, false)
|
processStacks(w, false)
|
||||||
|
|
||||||
proc writeRod(w: PRodWriter) =
|
proc writeRod(w: PRodWriter) =
|
||||||
processStacks(w, true)
|
processStacks(w, true)
|
||||||
var f: File
|
var f: File
|
||||||
if not open(f, completeGeneratedFilePath(changeFileExt(
|
if not open(f, completeGeneratedFilePath(changeFileExt(
|
||||||
|
|
@ -439,12 +440,12 @@ proc writeRod(w: PRodWriter) =
|
||||||
encodeStr(w.origFile, orig)
|
encodeStr(w.origFile, orig)
|
||||||
f.write(orig)
|
f.write(orig)
|
||||||
f.write(rodNL)
|
f.write(rodNL)
|
||||||
|
|
||||||
var hash = "HASH:"
|
var hash = "HASH:"
|
||||||
encodeStr($w.hash, hash)
|
encodeStr($w.hash, hash)
|
||||||
f.write(hash)
|
f.write(hash)
|
||||||
f.write(rodNL)
|
f.write(rodNL)
|
||||||
|
|
||||||
var options = "OPTIONS:"
|
var options = "OPTIONS:"
|
||||||
encodeVInt(cast[int32](w.options), options)
|
encodeVInt(cast[int32](w.options), options)
|
||||||
f.write(options)
|
f.write(options)
|
||||||
|
|
@ -458,31 +459,31 @@ proc writeRod(w: PRodWriter) =
|
||||||
var cmd = "CMD:"
|
var cmd = "CMD:"
|
||||||
encodeVInt(cast[int32](gCmd), cmd)
|
encodeVInt(cast[int32](gCmd), cmd)
|
||||||
f.write(cmd)
|
f.write(cmd)
|
||||||
f.write(rodNL)
|
f.write(rodNL)
|
||||||
|
|
||||||
f.write("DEFINES:")
|
f.write("DEFINES:")
|
||||||
f.write(w.defines)
|
f.write(w.defines)
|
||||||
f.write(rodNL)
|
f.write(rodNL)
|
||||||
|
|
||||||
var files = "FILES(" & rodNL
|
var files = "FILES(" & rodNL
|
||||||
for i in countup(0, high(w.files)):
|
for i in countup(0, high(w.files)):
|
||||||
encodeStr(w.files[i], files)
|
encodeStr(w.files[i], files)
|
||||||
files.add(rodNL)
|
files.add(rodNL)
|
||||||
f.write(files)
|
f.write(files)
|
||||||
f.write(')' & rodNL)
|
f.write(')' & rodNL)
|
||||||
|
|
||||||
f.write("INCLUDES(" & rodNL)
|
f.write("INCLUDES(" & rodNL)
|
||||||
f.write(w.inclDeps)
|
f.write(w.inclDeps)
|
||||||
f.write(')' & rodNL)
|
f.write(')' & rodNL)
|
||||||
|
|
||||||
f.write("DEPS:")
|
f.write("DEPS:")
|
||||||
f.write(w.modDeps)
|
f.write(w.modDeps)
|
||||||
f.write(rodNL)
|
f.write(rodNL)
|
||||||
|
|
||||||
f.write("INTERF(" & rodNL)
|
f.write("INTERF(" & rodNL)
|
||||||
f.write(w.interf)
|
f.write(w.interf)
|
||||||
f.write(')' & rodNL)
|
f.write(')' & rodNL)
|
||||||
|
|
||||||
f.write("COMPILERPROCS(" & rodNL)
|
f.write("COMPILERPROCS(" & rodNL)
|
||||||
f.write(w.compilerProcs)
|
f.write(w.compilerProcs)
|
||||||
f.write(')' & rodNL)
|
f.write(')' & rodNL)
|
||||||
|
|
@ -490,11 +491,11 @@ proc writeRod(w: PRodWriter) =
|
||||||
f.write("INDEX(" & rodNL)
|
f.write("INDEX(" & rodNL)
|
||||||
f.write(w.index.r)
|
f.write(w.index.r)
|
||||||
f.write(')' & rodNL)
|
f.write(')' & rodNL)
|
||||||
|
|
||||||
f.write("IMPORTS(" & rodNL)
|
f.write("IMPORTS(" & rodNL)
|
||||||
f.write(w.imports.r)
|
f.write(w.imports.r)
|
||||||
f.write(')' & rodNL)
|
f.write(')' & rodNL)
|
||||||
|
|
||||||
f.write("CONVERTERS:")
|
f.write("CONVERTERS:")
|
||||||
f.write(w.converters)
|
f.write(w.converters)
|
||||||
f.write(rodNL)
|
f.write(rodNL)
|
||||||
|
|
@ -502,11 +503,11 @@ proc writeRod(w: PRodWriter) =
|
||||||
f.write("METHODS:")
|
f.write("METHODS:")
|
||||||
f.write(w.methods)
|
f.write(w.methods)
|
||||||
f.write(rodNL)
|
f.write(rodNL)
|
||||||
|
|
||||||
f.write("INIT(" & rodNL)
|
f.write("INIT(" & rodNL)
|
||||||
f.write(w.init)
|
f.write(w.init)
|
||||||
f.write(')' & rodNL)
|
f.write(')' & rodNL)
|
||||||
|
|
||||||
f.write("DATA(" & rodNL)
|
f.write("DATA(" & rodNL)
|
||||||
f.write(w.data)
|
f.write(w.data)
|
||||||
f.write(')' & rodNL)
|
f.write(')' & rodNL)
|
||||||
|
|
@ -514,23 +515,23 @@ proc writeRod(w: PRodWriter) =
|
||||||
# for reading:
|
# for reading:
|
||||||
f.write("\0")
|
f.write("\0")
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
#echo "interf: ", w.interf.len
|
#echo "interf: ", w.interf.len
|
||||||
#echo "index: ", w.index.r.len
|
#echo "index: ", w.index.r.len
|
||||||
#echo "init: ", w.init.len
|
#echo "init: ", w.init.len
|
||||||
#echo "data: ", w.data.len
|
#echo "data: ", w.data.len
|
||||||
|
|
||||||
proc process(c: PPassContext, n: PNode): PNode =
|
proc process(c: PPassContext, n: PNode): PNode =
|
||||||
result = n
|
result = n
|
||||||
if c == nil: return
|
if c == nil: return
|
||||||
var w = PRodWriter(c)
|
var w = PRodWriter(c)
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkStmtList:
|
of nkStmtList:
|
||||||
for i in countup(0, sonsLen(n) - 1): discard process(c, n.sons[i])
|
for i in countup(0, sonsLen(n) - 1): discard process(c, n.sons[i])
|
||||||
#var s = n.sons[namePos].sym
|
#var s = n.sons[namePos].sym
|
||||||
#addInterfaceSym(w, s)
|
#addInterfaceSym(w, s)
|
||||||
of nkProcDef, nkMethodDef, nkIteratorDef, nkConverterDef,
|
of nkProcDef, nkMethodDef, nkIteratorDef, nkConverterDef,
|
||||||
nkTemplateDef, nkMacroDef:
|
nkTemplateDef, nkMacroDef:
|
||||||
var s = n.sons[namePos].sym
|
var s = n.sons[namePos].sym
|
||||||
if s == nil: internalError(n.info, "rodwrite.process")
|
if s == nil: internalError(n.info, "rodwrite.process")
|
||||||
if n.sons[bodyPos] == nil:
|
if n.sons[bodyPos] == nil:
|
||||||
|
|
@ -539,17 +540,17 @@ proc process(c: PPassContext, n: PNode): PNode =
|
||||||
sfForward notin s.flags:
|
sfForward notin s.flags:
|
||||||
addInterfaceSym(w, s)
|
addInterfaceSym(w, s)
|
||||||
of nkVarSection, nkLetSection, nkConstSection:
|
of nkVarSection, nkLetSection, nkConstSection:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
if a.kind == nkCommentStmt: continue
|
if a.kind == nkCommentStmt: continue
|
||||||
addInterfaceSym(w, a.sons[0].sym)
|
addInterfaceSym(w, a.sons[0].sym)
|
||||||
of nkTypeSection:
|
of nkTypeSection:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
if a.kind == nkCommentStmt: continue
|
if a.kind == nkCommentStmt: continue
|
||||||
if a.sons[0].kind != nkSym: internalError(a.info, "rodwrite.process")
|
if a.sons[0].kind != nkSym: internalError(a.info, "rodwrite.process")
|
||||||
var s = a.sons[0].sym
|
var s = a.sons[0].sym
|
||||||
addInterfaceSym(w, s)
|
addInterfaceSym(w, s)
|
||||||
# this takes care of enum fields too
|
# this takes care of enum fields too
|
||||||
# Note: The check for ``s.typ.kind = tyEnum`` is wrong for enum
|
# Note: The check for ``s.typ.kind = tyEnum`` is wrong for enum
|
||||||
# type aliasing! Otherwise the same enum symbol would be included
|
# type aliasing! Otherwise the same enum symbol would be included
|
||||||
|
|
@ -557,20 +558,20 @@ proc process(c: PPassContext, n: PNode): PNode =
|
||||||
#
|
#
|
||||||
# if (a.sons[2] <> nil) and (a.sons[2].kind = nkEnumTy) then begin
|
# if (a.sons[2] <> nil) and (a.sons[2].kind = nkEnumTy) then begin
|
||||||
# a := s.typ.n;
|
# a := s.typ.n;
|
||||||
# for j := 0 to sonsLen(a)-1 do
|
# for j := 0 to sonsLen(a)-1 do
|
||||||
# addInterfaceSym(w, a.sons[j].sym);
|
# addInterfaceSym(w, a.sons[j].sym);
|
||||||
# end
|
# end
|
||||||
of nkImportStmt:
|
of nkImportStmt:
|
||||||
for i in countup(0, sonsLen(n) - 1): addModDep(w, getModuleName(n.sons[i]))
|
for i in countup(0, sonsLen(n) - 1): addModDep(w, getModuleName(n.sons[i]))
|
||||||
addStmt(w, n)
|
addStmt(w, n)
|
||||||
of nkFromStmt:
|
of nkFromStmt:
|
||||||
addModDep(w, getModuleName(n.sons[0]))
|
addModDep(w, getModuleName(n.sons[0]))
|
||||||
addStmt(w, n)
|
addStmt(w, n)
|
||||||
of nkIncludeStmt:
|
of nkIncludeStmt:
|
||||||
for i in countup(0, sonsLen(n) - 1): addInclDep(w, getModuleName(n.sons[i]))
|
for i in countup(0, sonsLen(n) - 1): addInclDep(w, getModuleName(n.sons[i]))
|
||||||
of nkPragma:
|
of nkPragma:
|
||||||
addStmt(w, n)
|
addStmt(w, n)
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc myOpen(module: PSym): PPassContext =
|
proc myOpen(module: PSym): PPassContext =
|
||||||
|
|
@ -579,7 +580,7 @@ proc myOpen(module: PSym): PPassContext =
|
||||||
rawAddInterfaceSym(w, module)
|
rawAddInterfaceSym(w, module)
|
||||||
result = w
|
result = w
|
||||||
|
|
||||||
proc myClose(c: PPassContext, n: PNode): PNode =
|
proc myClose(c: PPassContext, n: PNode): PNode =
|
||||||
result = process(c, n)
|
result = process(c, n)
|
||||||
var w = PRodWriter(c)
|
var w = PRodWriter(c)
|
||||||
writeRod(w)
|
writeRod(w)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue