|
|
|
|
@@ -12,7 +12,7 @@
|
|
|
|
|
# Reading and writing binary files are really hard to debug. Therefore we use
|
|
|
|
|
# a "creative" text/binary hybrid format. ROD-files are more efficient
|
|
|
|
|
# to process because symbols can be loaded on demand.
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# A ROD file consists of:
|
|
|
|
|
#
|
|
|
|
|
# - a header:
|
|
|
|
|
@@ -44,7 +44,7 @@
|
|
|
|
|
# )
|
|
|
|
|
# - a compiler proc section:
|
|
|
|
|
# COMPILERPROCS(
|
|
|
|
|
# identifier1 id\n # id is the symbol's id
|
|
|
|
|
# identifier1 id\n # id is the symbol's id
|
|
|
|
|
# )
|
|
|
|
|
# - an index consisting of (ID, linenumber)-pairs:
|
|
|
|
|
# INDEX(
|
|
|
|
|
@@ -52,7 +52,7 @@
|
|
|
|
|
# id-diff idx-diff\n
|
|
|
|
|
# )
|
|
|
|
|
#
|
|
|
|
|
# Since the whole index has to be read in advance, we compress it by
|
|
|
|
|
# Since the whole index has to be read in advance, we compress it by
|
|
|
|
|
# storing the integer differences to the last entry instead of using the
|
|
|
|
|
# real numbers.
|
|
|
|
|
#
|
|
|
|
|
@@ -88,11 +88,11 @@
|
|
|
|
|
# by using a mem'mapped file.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
import
|
|
|
|
|
os, options, strutils, nversion, ast, astalgo, msgs, platform, condsyms,
|
|
|
|
|
import
|
|
|
|
|
os, options, strutils, nversion, ast, astalgo, msgs, platform, condsyms,
|
|
|
|
|
ropes, idents, securehash, idgen, types, rodutils, memfiles
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
type
|
|
|
|
|
TReasonForRecompile* = enum ## all the reasons that can trigger recompilation
|
|
|
|
|
rrEmpty, # dependencies not yet computed
|
|
|
|
|
rrNone, # no need to recompile
|
|
|
|
|
@@ -104,14 +104,14 @@ type
|
|
|
|
|
rrInclDeps, # an include has changed
|
|
|
|
|
rrModDeps # a module this module depends on has been changed
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
reasonToFrmt*: array[TReasonForRecompile, string] = ["",
|
|
|
|
|
"no need to recompile: $1", "symbol file for $1 does not exist",
|
|
|
|
|
"symbol file for $1 has the wrong version",
|
|
|
|
|
"file edited since last compilation: $1",
|
|
|
|
|
"list of conditional symbols changed for: $1",
|
|
|
|
|
"list of options changed for: $1",
|
|
|
|
|
"an include file edited: $1",
|
|
|
|
|
const
|
|
|
|
|
reasonToFrmt*: array[TReasonForRecompile, string] = ["",
|
|
|
|
|
"no need to recompile: $1", "symbol file for $1 does not exist",
|
|
|
|
|
"symbol file for $1 has the wrong version",
|
|
|
|
|
"file edited since last compilation: $1",
|
|
|
|
|
"list of conditional symbols changed for: $1",
|
|
|
|
|
"list of options changed for: $1",
|
|
|
|
|
"an include file edited: $1",
|
|
|
|
|
"a module $1 depends on has changed"]
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
@@ -120,7 +120,7 @@ type
|
|
|
|
|
tab*: TIITable
|
|
|
|
|
r*: string # writers use this
|
|
|
|
|
offset*: int # readers use this
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TRodReader* = object of RootObj
|
|
|
|
|
pos: int # position; used for parsing
|
|
|
|
|
s: cstring # mmap'ed file contents
|
|
|
|
|
@@ -142,7 +142,7 @@ type
|
|
|
|
|
methods*: TSymSeq
|
|
|
|
|
origFile: string
|
|
|
|
|
inViewMode: bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRodReader* = ref TRodReader
|
|
|
|
|
|
|
|
|
|
var rodCompilerprocs*: TStrTable
|
|
|
|
|
@@ -161,16 +161,16 @@ proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym
|
|
|
|
|
# `info` is only used for debugging purposes
|
|
|
|
|
proc rrGetType(r: PRodReader, id: int, info: TLineInfo): PType
|
|
|
|
|
|
|
|
|
|
proc decodeLineInfo(r: PRodReader, info: var TLineInfo) =
|
|
|
|
|
if r.s[r.pos] == '?':
|
|
|
|
|
proc decodeLineInfo(r: PRodReader, info: var TLineInfo) =
|
|
|
|
|
if r.s[r.pos] == '?':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
if r.s[r.pos] == ',': info.col = -1'i16
|
|
|
|
|
else: info.col = int16(decodeVInt(r.s, r.pos))
|
|
|
|
|
if r.s[r.pos] == ',':
|
|
|
|
|
if r.s[r.pos] == ',':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
if r.s[r.pos] == ',': info.line = -1'i16
|
|
|
|
|
else: info.line = int16(decodeVInt(r.s, r.pos))
|
|
|
|
|
if r.s[r.pos] == ',':
|
|
|
|
|
if r.s[r.pos] == ',':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
info = newLineInfo(r.files[decodeVInt(r.s, r.pos)], info.line, info.col)
|
|
|
|
|
|
|
|
|
|
@@ -188,56 +188,56 @@ proc skipNode(r: PRodReader) =
|
|
|
|
|
inc pos
|
|
|
|
|
r.pos = pos+1 # skip ')'
|
|
|
|
|
|
|
|
|
|
proc decodeNodeLazyBody(r: PRodReader, fInfo: TLineInfo,
|
|
|
|
|
belongsTo: PSym): PNode =
|
|
|
|
|
proc decodeNodeLazyBody(r: PRodReader, fInfo: TLineInfo,
|
|
|
|
|
belongsTo: PSym): PNode =
|
|
|
|
|
result = nil
|
|
|
|
|
if r.s[r.pos] == '(':
|
|
|
|
|
if r.s[r.pos] == '(':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
if r.s[r.pos] == ')':
|
|
|
|
|
if r.s[r.pos] == ')':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
return # nil node
|
|
|
|
|
result = newNodeI(TNodeKind(decodeVInt(r.s, r.pos)), fInfo)
|
|
|
|
|
decodeLineInfo(r, result.info)
|
|
|
|
|
if r.s[r.pos] == '$':
|
|
|
|
|
if r.s[r.pos] == '$':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.flags = cast[TNodeFlags](int32(decodeVInt(r.s, r.pos)))
|
|
|
|
|
if r.s[r.pos] == '^':
|
|
|
|
|
if r.s[r.pos] == '^':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
var id = decodeVInt(r.s, r.pos)
|
|
|
|
|
result.typ = rrGetType(r, id, result.info)
|
|
|
|
|
case result.kind
|
|
|
|
|
of nkCharLit..nkInt64Lit:
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
of nkCharLit..nkInt64Lit:
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.intVal = decodeVBiggestInt(r.s, r.pos)
|
|
|
|
|
of nkFloatLit..nkFloat64Lit:
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
of nkFloatLit..nkFloat64Lit:
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
var fl = decodeStr(r.s, r.pos)
|
|
|
|
|
result.floatVal = parseFloat(fl)
|
|
|
|
|
of nkStrLit..nkTripleStrLit:
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
of nkStrLit..nkTripleStrLit:
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.strVal = decodeStr(r.s, r.pos)
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
result.strVal = "" # BUGFIX
|
|
|
|
|
of nkIdent:
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
of nkIdent:
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
var fl = decodeStr(r.s, r.pos)
|
|
|
|
|
result.ident = getIdent(fl)
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
internalError(result.info, "decodeNode: nkIdent")
|
|
|
|
|
of nkSym:
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
of nkSym:
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
var id = decodeVInt(r.s, r.pos)
|
|
|
|
|
result.sym = rrGetSym(r, id, result.info)
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
internalError(result.info, "decodeNode: nkSym")
|
|
|
|
|
else:
|
|
|
|
|
var i = 0
|
|
|
|
|
while r.s[r.pos] != ')':
|
|
|
|
|
while r.s[r.pos] != ')':
|
|
|
|
|
if belongsTo != nil and i == bodyPos:
|
|
|
|
|
addSonNilAllowed(result, nil)
|
|
|
|
|
belongsTo.offset = r.pos
|
|
|
|
|
@@ -252,93 +252,93 @@ proc decodeNodeLazyBody(r: PRodReader, fInfo: TLineInfo,
|
|
|
|
|
|
|
|
|
|
proc decodeNode(r: PRodReader, fInfo: TLineInfo): PNode =
|
|
|
|
|
result = decodeNodeLazyBody(r, fInfo, nil)
|
|
|
|
|
|
|
|
|
|
proc decodeLoc(r: PRodReader, loc: var TLoc, info: TLineInfo) =
|
|
|
|
|
if r.s[r.pos] == '<':
|
|
|
|
|
|
|
|
|
|
proc decodeLoc(r: PRodReader, loc: var TLoc, info: TLineInfo) =
|
|
|
|
|
if r.s[r.pos] == '<':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
if r.s[r.pos] in {'0'..'9', 'a'..'z', 'A'..'Z'}:
|
|
|
|
|
if r.s[r.pos] in {'0'..'9', 'a'..'z', 'A'..'Z'}:
|
|
|
|
|
loc.k = TLocKind(decodeVInt(r.s, r.pos))
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
loc.k = low(loc.k)
|
|
|
|
|
if r.s[r.pos] == '*':
|
|
|
|
|
if r.s[r.pos] == '*':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
loc.s = TStorageLoc(decodeVInt(r.s, r.pos))
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
loc.s = low(loc.s)
|
|
|
|
|
if r.s[r.pos] == '$':
|
|
|
|
|
if r.s[r.pos] == '$':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
loc.flags = cast[TLocFlags](int32(decodeVInt(r.s, r.pos)))
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
loc.flags = {}
|
|
|
|
|
if r.s[r.pos] == '^':
|
|
|
|
|
if r.s[r.pos] == '^':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
loc.t = rrGetType(r, decodeVInt(r.s, r.pos), info)
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
loc.t = nil
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
loc.r = rope(decodeStr(r.s, r.pos))
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
loc.r = nil
|
|
|
|
|
if r.s[r.pos] == '>': inc(r.pos)
|
|
|
|
|
else: internalError(info, "decodeLoc " & r.s[r.pos])
|
|
|
|
|
|
|
|
|
|
proc decodeType(r: PRodReader, info: TLineInfo): PType =
|
|
|
|
|
|
|
|
|
|
proc decodeType(r: PRodReader, info: TLineInfo): PType =
|
|
|
|
|
result = nil
|
|
|
|
|
if r.s[r.pos] == '[':
|
|
|
|
|
if r.s[r.pos] == '[':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
if r.s[r.pos] == ']':
|
|
|
|
|
if r.s[r.pos] == ']':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
return # nil type
|
|
|
|
|
new(result)
|
|
|
|
|
result.kind = TTypeKind(decodeVInt(r.s, r.pos))
|
|
|
|
|
if r.s[r.pos] == '+':
|
|
|
|
|
if r.s[r.pos] == '+':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.id = decodeVInt(r.s, r.pos)
|
|
|
|
|
setId(result.id)
|
|
|
|
|
if debugIds: registerID(result)
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
internalError(info, "decodeType: no id")
|
|
|
|
|
# here this also avoids endless recursion for recursive type
|
|
|
|
|
idTablePut(gTypeTable, result, result)
|
|
|
|
|
idTablePut(gTypeTable, result, result)
|
|
|
|
|
if r.s[r.pos] == '(': result.n = decodeNode(r, unknownLineInfo())
|
|
|
|
|
if r.s[r.pos] == '$':
|
|
|
|
|
if r.s[r.pos] == '$':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.flags = cast[TTypeFlags](int32(decodeVInt(r.s, r.pos)))
|
|
|
|
|
if r.s[r.pos] == '?':
|
|
|
|
|
if r.s[r.pos] == '?':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.callConv = TCallingConvention(decodeVInt(r.s, r.pos))
|
|
|
|
|
if r.s[r.pos] == '*':
|
|
|
|
|
if r.s[r.pos] == '*':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.owner = rrGetSym(r, decodeVInt(r.s, r.pos), info)
|
|
|
|
|
if r.s[r.pos] == '&':
|
|
|
|
|
if r.s[r.pos] == '&':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.sym = rrGetSym(r, decodeVInt(r.s, r.pos), info)
|
|
|
|
|
if r.s[r.pos] == '/':
|
|
|
|
|
if r.s[r.pos] == '/':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.size = decodeVInt(r.s, r.pos)
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
result.size = - 1
|
|
|
|
|
if r.s[r.pos] == '=':
|
|
|
|
|
if r.s[r.pos] == '=':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.align = decodeVInt(r.s, r.pos).int16
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
result.align = 2
|
|
|
|
|
decodeLoc(r, result.loc, info)
|
|
|
|
|
while r.s[r.pos] == '^':
|
|
|
|
|
while r.s[r.pos] == '^':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
if r.s[r.pos] == '(':
|
|
|
|
|
if r.s[r.pos] == '(':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
if r.s[r.pos] == ')': inc(r.pos)
|
|
|
|
|
else: internalError(info, "decodeType ^(" & r.s[r.pos])
|
|
|
|
|
rawAddSon(result, nil)
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
var d = decodeVInt(r.s, r.pos)
|
|
|
|
|
rawAddSon(result, rrGetType(r, d, info))
|
|
|
|
|
|
|
|
|
|
proc decodeLib(r: PRodReader, info: TLineInfo): PLib =
|
|
|
|
|
proc decodeLib(r: PRodReader, info: TLineInfo): PLib =
|
|
|
|
|
result = nil
|
|
|
|
|
if r.s[r.pos] == '|':
|
|
|
|
|
if r.s[r.pos] == '|':
|
|
|
|
|
new(result)
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.kind = TLibKind(decodeVInt(r.s, r.pos))
|
|
|
|
|
@@ -349,31 +349,31 @@ proc decodeLib(r: PRodReader, info: TLineInfo): PLib =
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.path = decodeNode(r, info)
|
|
|
|
|
|
|
|
|
|
proc decodeSym(r: PRodReader, info: TLineInfo): PSym =
|
|
|
|
|
var
|
|
|
|
|
proc decodeSym(r: PRodReader, info: TLineInfo): PSym =
|
|
|
|
|
var
|
|
|
|
|
id: int
|
|
|
|
|
ident: PIdent
|
|
|
|
|
result = nil
|
|
|
|
|
if r.s[r.pos] == '{':
|
|
|
|
|
if r.s[r.pos] == '{':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
if r.s[r.pos] == '}':
|
|
|
|
|
if r.s[r.pos] == '}':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
return # nil sym
|
|
|
|
|
var k = TSymKind(decodeVInt(r.s, r.pos))
|
|
|
|
|
if r.s[r.pos] == '+':
|
|
|
|
|
if r.s[r.pos] == '+':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
id = decodeVInt(r.s, r.pos)
|
|
|
|
|
setId(id)
|
|
|
|
|
else:
|
|
|
|
|
internalError(info, "decodeSym: no id")
|
|
|
|
|
if r.s[r.pos] == '&':
|
|
|
|
|
if r.s[r.pos] == '&':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
ident = getIdent(decodeStr(r.s, r.pos))
|
|
|
|
|
else:
|
|
|
|
|
internalError(info, "decodeSym: no ident")
|
|
|
|
|
#echo "decoding: {", ident.s
|
|
|
|
|
result = PSym(idTableGet(r.syms, id))
|
|
|
|
|
if result == nil:
|
|
|
|
|
if result == nil:
|
|
|
|
|
new(result)
|
|
|
|
|
result.id = id
|
|
|
|
|
idTablePut(r.syms, result, result)
|
|
|
|
|
@@ -388,35 +388,35 @@ proc decodeSym(r: PRodReader, info: TLineInfo): PSym =
|
|
|
|
|
result.id = id
|
|
|
|
|
result.kind = k
|
|
|
|
|
result.name = ident # read the rest of the symbol description:
|
|
|
|
|
if r.s[r.pos] == '^':
|
|
|
|
|
if r.s[r.pos] == '^':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.typ = rrGetType(r, decodeVInt(r.s, r.pos), info)
|
|
|
|
|
decodeLineInfo(r, result.info)
|
|
|
|
|
if r.s[r.pos] == '*':
|
|
|
|
|
if r.s[r.pos] == '*':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.owner = rrGetSym(r, decodeVInt(r.s, r.pos), result.info)
|
|
|
|
|
if r.s[r.pos] == '$':
|
|
|
|
|
if r.s[r.pos] == '$':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.flags = cast[TSymFlags](int32(decodeVInt(r.s, r.pos)))
|
|
|
|
|
if r.s[r.pos] == '@':
|
|
|
|
|
if r.s[r.pos] == '@':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.magic = TMagic(decodeVInt(r.s, r.pos))
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
if r.s[r.pos] == '!':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
result.options = r.options
|
|
|
|
|
if r.s[r.pos] == '%':
|
|
|
|
|
if r.s[r.pos] == '%':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.position = decodeVInt(r.s, r.pos)
|
|
|
|
|
elif result.kind notin routineKinds + {skModule}:
|
|
|
|
|
result.position = 0
|
|
|
|
|
# this may have been misused as reader index! But we still
|
|
|
|
|
# need it for routines as the body is loaded lazily.
|
|
|
|
|
if r.s[r.pos] == '`':
|
|
|
|
|
if r.s[r.pos] == '`':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
result.offset = decodeVInt(r.s, r.pos)
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
result.offset = - 1
|
|
|
|
|
decodeLoc(r, result.loc, result.info)
|
|
|
|
|
result.annex = decodeLib(r, info)
|
|
|
|
|
@@ -433,35 +433,35 @@ proc decodeSym(r: PRodReader, info: TLineInfo): PSym =
|
|
|
|
|
result.ast = decodeNode(r, result.info)
|
|
|
|
|
#echo "decoded: ", ident.s, "}"
|
|
|
|
|
|
|
|
|
|
proc skipSection(r: PRodReader) =
|
|
|
|
|
if r.s[r.pos] == ':':
|
|
|
|
|
proc skipSection(r: PRodReader) =
|
|
|
|
|
if r.s[r.pos] == ':':
|
|
|
|
|
while r.s[r.pos] > '\x0A': inc(r.pos)
|
|
|
|
|
elif r.s[r.pos] == '(':
|
|
|
|
|
elif r.s[r.pos] == '(':
|
|
|
|
|
var c = 0 # count () pairs
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
while true:
|
|
|
|
|
while true:
|
|
|
|
|
case r.s[r.pos]
|
|
|
|
|
of '\x0A': inc(r.line)
|
|
|
|
|
of '(': inc(c)
|
|
|
|
|
of ')':
|
|
|
|
|
if c == 0:
|
|
|
|
|
of ')':
|
|
|
|
|
if c == 0:
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
break
|
|
|
|
|
elif c > 0:
|
|
|
|
|
break
|
|
|
|
|
elif c > 0:
|
|
|
|
|
dec(c)
|
|
|
|
|
of '\0': break # end of file
|
|
|
|
|
else: discard
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
internalError("skipSection " & $r.line)
|
|
|
|
|
|
|
|
|
|
proc rdWord(r: PRodReader): string =
|
|
|
|
|
|
|
|
|
|
proc rdWord(r: PRodReader): string =
|
|
|
|
|
result = ""
|
|
|
|
|
while r.s[r.pos] in {'A'..'Z', '_', 'a'..'z', '0'..'9'}:
|
|
|
|
|
while r.s[r.pos] in {'A'..'Z', '_', 'a'..'z', '0'..'9'}:
|
|
|
|
|
add(result, r.s[r.pos])
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
|
|
|
|
|
proc newStub(r: PRodReader, name: string, id: int): PSym =
|
|
|
|
|
proc newStub(r: PRodReader, name: string, id: int): PSym =
|
|
|
|
|
new(result)
|
|
|
|
|
result.kind = skStub
|
|
|
|
|
result.id = id
|
|
|
|
|
@@ -469,11 +469,11 @@ proc newStub(r: PRodReader, name: string, id: int): PSym =
|
|
|
|
|
result.position = r.readerIndex
|
|
|
|
|
setId(id) #MessageOut(result.name.s);
|
|
|
|
|
if debugIds: registerID(result)
|
|
|
|
|
|
|
|
|
|
proc processInterf(r: PRodReader, module: PSym) =
|
|
|
|
|
|
|
|
|
|
proc processInterf(r: PRodReader, module: PSym) =
|
|
|
|
|
if r.interfIdx == 0: internalError("processInterf")
|
|
|
|
|
r.pos = r.interfIdx
|
|
|
|
|
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
|
|
|
|
|
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
|
|
|
|
|
var w = decodeStr(r.s, r.pos)
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
var key = decodeVInt(r.s, r.pos)
|
|
|
|
|
@@ -483,28 +483,28 @@ proc processInterf(r: PRodReader, module: PSym) =
|
|
|
|
|
strTableAdd(module.tab, s)
|
|
|
|
|
idTablePut(r.syms, s, s)
|
|
|
|
|
|
|
|
|
|
proc processCompilerProcs(r: PRodReader, module: PSym) =
|
|
|
|
|
proc processCompilerProcs(r: PRodReader, module: PSym) =
|
|
|
|
|
if r.compilerProcsIdx == 0: internalError("processCompilerProcs")
|
|
|
|
|
r.pos = r.compilerProcsIdx
|
|
|
|
|
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
|
|
|
|
|
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
|
|
|
|
|
var w = decodeStr(r.s, r.pos)
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
var key = decodeVInt(r.s, r.pos)
|
|
|
|
|
inc(r.pos) # #10
|
|
|
|
|
var s = PSym(idTableGet(r.syms, key))
|
|
|
|
|
if s == nil:
|
|
|
|
|
if s == nil:
|
|
|
|
|
s = newStub(r, w, key)
|
|
|
|
|
s.owner = module
|
|
|
|
|
idTablePut(r.syms, s, s)
|
|
|
|
|
strTableAdd(rodCompilerprocs, s)
|
|
|
|
|
|
|
|
|
|
proc processIndex(r: PRodReader; idx: var TIndex; outf: File = nil) =
|
|
|
|
|
proc processIndex(r: PRodReader; idx: var TIndex; outf: File = nil) =
|
|
|
|
|
var key, val, tmp: int
|
|
|
|
|
inc(r.pos, 2) # skip "(\10"
|
|
|
|
|
inc(r.line)
|
|
|
|
|
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
|
|
|
|
|
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
|
|
|
|
|
tmp = decodeVInt(r.s, r.pos)
|
|
|
|
|
if r.s[r.pos] == ' ':
|
|
|
|
|
if r.s[r.pos] == ' ':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
key = idx.lastIdxKey + tmp
|
|
|
|
|
val = decodeVInt(r.s, r.pos) + idx.lastIdxVal
|
|
|
|
|
@@ -516,11 +516,11 @@ proc processIndex(r: PRodReader; idx: var TIndex; outf: File = nil) =
|
|
|
|
|
idx.lastIdxKey = key
|
|
|
|
|
idx.lastIdxVal = val
|
|
|
|
|
setId(key) # ensure that this id will not be used
|
|
|
|
|
if r.s[r.pos] == '\x0A':
|
|
|
|
|
if r.s[r.pos] == '\x0A':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
inc(r.line)
|
|
|
|
|
if r.s[r.pos] == ')': inc(r.pos)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cmdChangeTriggersRecompilation(old, new: TCommands): bool =
|
|
|
|
|
if old == new: return false
|
|
|
|
|
# we use a 'case' statement without 'else' so that addition of a
|
|
|
|
|
@@ -532,34 +532,34 @@ proc cmdChangeTriggersRecompilation(old, new: TCommands): bool =
|
|
|
|
|
cmdInteractive}:
|
|
|
|
|
return false
|
|
|
|
|
of cmdNone, cmdDoc, cmdInterpret, cmdPretty, cmdGenDepend, cmdDump,
|
|
|
|
|
cmdCheck, cmdParse, cmdScan, cmdIdeTools, cmdDef,
|
|
|
|
|
cmdCheck, cmdParse, cmdScan, cmdIdeTools, cmdDef,
|
|
|
|
|
cmdRst2html, cmdRst2tex, cmdInteractive, cmdRun:
|
|
|
|
|
discard
|
|
|
|
|
# else: trigger recompilation:
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
|
|
proc processRodFile(r: PRodReader, crc: SecureHash) =
|
|
|
|
|
var
|
|
|
|
|
|
|
|
|
|
proc processRodFile(r: PRodReader, crc: SecureHash) =
|
|
|
|
|
var
|
|
|
|
|
w: string
|
|
|
|
|
d: int
|
|
|
|
|
var inclCrc: SecureHash
|
|
|
|
|
while r.s[r.pos] != '\0':
|
|
|
|
|
while r.s[r.pos] != '\0':
|
|
|
|
|
var section = rdWord(r)
|
|
|
|
|
if r.reason != rrNone:
|
|
|
|
|
if r.reason != rrNone:
|
|
|
|
|
break # no need to process this file further
|
|
|
|
|
case section
|
|
|
|
|
of "CRC":
|
|
|
|
|
case section
|
|
|
|
|
of "CRC":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
if crc != parseSecureHash(decodeStr(r.s, r.pos)):
|
|
|
|
|
r.reason = rrCrcChange
|
|
|
|
|
of "ID":
|
|
|
|
|
of "ID":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
r.moduleID = decodeVInt(r.s, r.pos)
|
|
|
|
|
setId(r.moduleID)
|
|
|
|
|
of "ORIGFILE":
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
r.origFile = decodeStr(r.s, r.pos)
|
|
|
|
|
of "OPTIONS":
|
|
|
|
|
of "OPTIONS":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
|
|
|
|
|
if options.gOptions != r.options: r.reason = rrOptions
|
|
|
|
|
@@ -574,14 +574,14 @@ proc processRodFile(r: PRodReader, crc: SecureHash) =
|
|
|
|
|
of "DEFINES":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
d = 0
|
|
|
|
|
while r.s[r.pos] > '\x0A':
|
|
|
|
|
while r.s[r.pos] > '\x0A':
|
|
|
|
|
w = decodeStr(r.s, r.pos)
|
|
|
|
|
inc(d)
|
|
|
|
|
if not condsyms.isDefined(getIdent(w)):
|
|
|
|
|
if not condsyms.isDefined(getIdent(w)):
|
|
|
|
|
r.reason = rrDefines #MessageOut('not defined, but should: ' + w);
|
|
|
|
|
if r.s[r.pos] == ' ': inc(r.pos)
|
|
|
|
|
if (d != countDefinedSymbols()): r.reason = rrDefines
|
|
|
|
|
of "FILES":
|
|
|
|
|
of "FILES":
|
|
|
|
|
inc(r.pos, 2) # skip "(\10"
|
|
|
|
|
inc(r.line)
|
|
|
|
|
while r.s[r.pos] != ')':
|
|
|
|
|
@@ -592,17 +592,17 @@ proc processRodFile(r: PRodReader, crc: SecureHash) =
|
|
|
|
|
inc(r.pos) # skip #10
|
|
|
|
|
inc(r.line)
|
|
|
|
|
if r.s[r.pos] == ')': inc(r.pos)
|
|
|
|
|
of "INCLUDES":
|
|
|
|
|
of "INCLUDES":
|
|
|
|
|
inc(r.pos, 2) # skip "(\10"
|
|
|
|
|
inc(r.line)
|
|
|
|
|
while r.s[r.pos] != ')':
|
|
|
|
|
while r.s[r.pos] != ')':
|
|
|
|
|
w = r.files[decodeVInt(r.s, r.pos)].toFullPath
|
|
|
|
|
inc(r.pos) # skip ' '
|
|
|
|
|
inclCrc = parseSecureHash(decodeStr(r.s, r.pos))
|
|
|
|
|
if r.reason == rrNone:
|
|
|
|
|
if not existsFile(w) or (inclCrc != secureHashFile(w)):
|
|
|
|
|
if r.reason == rrNone:
|
|
|
|
|
if not existsFile(w) or (inclCrc != secureHashFile(w)):
|
|
|
|
|
r.reason = rrInclDeps
|
|
|
|
|
if r.s[r.pos] == '\x0A':
|
|
|
|
|
if r.s[r.pos] == '\x0A':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
inc(r.line)
|
|
|
|
|
if r.s[r.pos] == ')': inc(r.pos)
|
|
|
|
|
@@ -611,28 +611,28 @@ proc processRodFile(r: PRodReader, crc: SecureHash) =
|
|
|
|
|
while r.s[r.pos] > '\x0A':
|
|
|
|
|
r.modDeps.add(r.files[int32(decodeVInt(r.s, r.pos))])
|
|
|
|
|
if r.s[r.pos] == ' ': inc(r.pos)
|
|
|
|
|
of "INTERF":
|
|
|
|
|
of "INTERF":
|
|
|
|
|
r.interfIdx = r.pos + 2
|
|
|
|
|
skipSection(r)
|
|
|
|
|
of "COMPILERPROCS":
|
|
|
|
|
of "COMPILERPROCS":
|
|
|
|
|
r.compilerProcsIdx = r.pos + 2
|
|
|
|
|
skipSection(r)
|
|
|
|
|
of "INDEX":
|
|
|
|
|
of "INDEX":
|
|
|
|
|
processIndex(r, r.index)
|
|
|
|
|
of "IMPORTS":
|
|
|
|
|
of "IMPORTS":
|
|
|
|
|
processIndex(r, r.imports)
|
|
|
|
|
of "CONVERTERS":
|
|
|
|
|
of "CONVERTERS":
|
|
|
|
|
r.convertersIdx = r.pos + 1
|
|
|
|
|
skipSection(r)
|
|
|
|
|
of "METHODS":
|
|
|
|
|
r.methodsIdx = r.pos + 1
|
|
|
|
|
skipSection(r)
|
|
|
|
|
of "DATA":
|
|
|
|
|
of "DATA":
|
|
|
|
|
r.dataIdx = r.pos + 2 # "(\10"
|
|
|
|
|
# We do not read the DATA section here! We read the needed objects on
|
|
|
|
|
# demand. And the DATA section comes last in the file, so we stop here:
|
|
|
|
|
break
|
|
|
|
|
of "INIT":
|
|
|
|
|
of "INIT":
|
|
|
|
|
r.initIdx = r.pos + 2 # "(\10"
|
|
|
|
|
skipSection(r)
|
|
|
|
|
else:
|
|
|
|
|
@@ -641,7 +641,7 @@ proc processRodFile(r: PRodReader, crc: SecureHash) =
|
|
|
|
|
#MsgWriteln("skipping section: " & section &
|
|
|
|
|
# " at " & $r.line & " in " & r.filename)
|
|
|
|
|
skipSection(r)
|
|
|
|
|
if r.s[r.pos] == '\x0A':
|
|
|
|
|
if r.s[r.pos] == '\x0A':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
inc(r.line)
|
|
|
|
|
|
|
|
|
|
@@ -652,7 +652,7 @@ proc startsWith(buf: cstring, token: string, pos = 0): bool =
|
|
|
|
|
result = s == token.len
|
|
|
|
|
|
|
|
|
|
proc newRodReader(modfilename: string, crc: SecureHash,
|
|
|
|
|
readerIndex: int): PRodReader =
|
|
|
|
|
readerIndex: int): PRodReader =
|
|
|
|
|
new(result)
|
|
|
|
|
try:
|
|
|
|
|
result.memfile = memfiles.open(modfilename)
|
|
|
|
|
@@ -671,7 +671,7 @@ proc newRodReader(modfilename: string, crc: SecureHash,
|
|
|
|
|
# we terminate the file explicitly with ``\0``, so the cast to `cstring`
|
|
|
|
|
# is safe:
|
|
|
|
|
r.s = cast[cstring](r.memfile.mem)
|
|
|
|
|
if startsWith(r.s, "NIM:"):
|
|
|
|
|
if startsWith(r.s, "NIM:"):
|
|
|
|
|
initIiTable(r.index.tab)
|
|
|
|
|
initIiTable(r.imports.tab) # looks like a ROD file
|
|
|
|
|
inc(r.pos, 4)
|
|
|
|
|
@@ -680,16 +680,16 @@ proc newRodReader(modfilename: string, crc: SecureHash,
|
|
|
|
|
add(version, r.s[r.pos])
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
if r.s[r.pos] == '\x0A': inc(r.pos)
|
|
|
|
|
if version != RodFileVersion:
|
|
|
|
|
if version != RodFileVersion:
|
|
|
|
|
# since ROD files are only for caching, no backwards compatibility is
|
|
|
|
|
# needed
|
|
|
|
|
result = nil
|
|
|
|
|
else:
|
|
|
|
|
result = nil
|
|
|
|
|
|
|
|
|
|
proc rrGetType(r: PRodReader, id: int, info: TLineInfo): PType =
|
|
|
|
|
|
|
|
|
|
proc rrGetType(r: PRodReader, id: int, info: TLineInfo): PType =
|
|
|
|
|
result = PType(idTableGet(gTypeTable, id))
|
|
|
|
|
if result == nil:
|
|
|
|
|
if result == nil:
|
|
|
|
|
# load the type:
|
|
|
|
|
var oldPos = r.pos
|
|
|
|
|
var d = iiTableGet(r.index.tab, id)
|
|
|
|
|
@@ -698,8 +698,8 @@ proc rrGetType(r: PRodReader, id: int, info: TLineInfo): PType =
|
|
|
|
|
result = decodeType(r, info)
|
|
|
|
|
r.pos = oldPos
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
TFileModuleRec{.final.} = object
|
|
|
|
|
type
|
|
|
|
|
TFileModuleRec{.final.} = object
|
|
|
|
|
filename*: string
|
|
|
|
|
reason*: TReasonForRecompile
|
|
|
|
|
rd*: PRodReader
|
|
|
|
|
@@ -710,7 +710,7 @@ type
|
|
|
|
|
|
|
|
|
|
var gMods*: TFileModuleMap = @[]
|
|
|
|
|
|
|
|
|
|
proc decodeSymSafePos(rd: PRodReader, offset: int, info: TLineInfo): PSym =
|
|
|
|
|
proc decodeSymSafePos(rd: PRodReader, offset: int, info: TLineInfo): PSym =
|
|
|
|
|
# all compiled modules
|
|
|
|
|
if rd.dataIdx == 0: internalError(info, "dataIdx == 0")
|
|
|
|
|
var oldPos = rd.pos
|
|
|
|
|
@@ -719,9 +719,9 @@ proc decodeSymSafePos(rd: PRodReader, offset: int, info: TLineInfo): PSym =
|
|
|
|
|
rd.pos = oldPos
|
|
|
|
|
|
|
|
|
|
proc findSomeWhere(id: int) =
|
|
|
|
|
for i in countup(0, high(gMods)):
|
|
|
|
|
for i in countup(0, high(gMods)):
|
|
|
|
|
var rd = gMods[i].rd
|
|
|
|
|
if rd != nil:
|
|
|
|
|
if rd != nil:
|
|
|
|
|
var d = iiTableGet(rd.index.tab, id)
|
|
|
|
|
if d != InvalidKey:
|
|
|
|
|
echo "found id ", id, " in ", gMods[i].filename
|
|
|
|
|
@@ -736,12 +736,12 @@ proc getReader(moduleId: int): PRodReader =
|
|
|
|
|
if result != nil and result.moduleID == moduleId: return result
|
|
|
|
|
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))
|
|
|
|
|
if result == nil:
|
|
|
|
|
if result == nil:
|
|
|
|
|
# load the symbol:
|
|
|
|
|
var d = iiTableGet(r.index.tab, id)
|
|
|
|
|
if d == InvalidKey:
|
|
|
|
|
if d == InvalidKey:
|
|
|
|
|
# import from other module:
|
|
|
|
|
var moduleID = iiTableGet(r.imports.tab, id)
|
|
|
|
|
if moduleID < 0:
|
|
|
|
|
@@ -750,24 +750,24 @@ proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym =
|
|
|
|
|
internalError(info, "missing from both indexes: +" & x)
|
|
|
|
|
var rd = getReader(moduleID)
|
|
|
|
|
d = iiTableGet(rd.index.tab, id)
|
|
|
|
|
if d != InvalidKey:
|
|
|
|
|
if d != InvalidKey:
|
|
|
|
|
result = decodeSymSafePos(rd, d, info)
|
|
|
|
|
else:
|
|
|
|
|
var x = ""
|
|
|
|
|
encodeVInt(id, x)
|
|
|
|
|
when false: findSomeWhere(id)
|
|
|
|
|
internalError(info, "rrGetSym: no reader found: +" & x)
|
|
|
|
|
else:
|
|
|
|
|
else:
|
|
|
|
|
# own symbol:
|
|
|
|
|
result = decodeSymSafePos(r, d, info)
|
|
|
|
|
if result != nil and result.kind == skStub: rawLoadStub(result)
|
|
|
|
|
|
|
|
|
|
proc loadInitSection(r: PRodReader): PNode =
|
|
|
|
|
|
|
|
|
|
proc loadInitSection(r: PRodReader): PNode =
|
|
|
|
|
if r.initIdx == 0 or r.dataIdx == 0: internalError("loadInitSection")
|
|
|
|
|
var oldPos = r.pos
|
|
|
|
|
r.pos = r.initIdx
|
|
|
|
|
result = newNode(nkStmtList)
|
|
|
|
|
while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')':
|
|
|
|
|
while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')':
|
|
|
|
|
var d = decodeVInt(r.s, r.pos)
|
|
|
|
|
inc(r.pos) # #10
|
|
|
|
|
var p = r.pos
|
|
|
|
|
@@ -776,13 +776,13 @@ proc loadInitSection(r: PRodReader): PNode =
|
|
|
|
|
r.pos = p
|
|
|
|
|
r.pos = oldPos
|
|
|
|
|
|
|
|
|
|
proc loadConverters(r: PRodReader) =
|
|
|
|
|
proc loadConverters(r: PRodReader) =
|
|
|
|
|
# We have to ensure that no exported converter is a stub anymore, and the
|
|
|
|
|
# import mechanism takes care of the rest.
|
|
|
|
|
if r.convertersIdx == 0 or r.dataIdx == 0:
|
|
|
|
|
if r.convertersIdx == 0 or r.dataIdx == 0:
|
|
|
|
|
internalError("importConverters")
|
|
|
|
|
r.pos = r.convertersIdx
|
|
|
|
|
while r.s[r.pos] > '\x0A':
|
|
|
|
|
while r.s[r.pos] > '\x0A':
|
|
|
|
|
var d = decodeVInt(r.s, r.pos)
|
|
|
|
|
discard rrGetSym(r, d, unknownLineInfo())
|
|
|
|
|
if r.s[r.pos] == ' ': inc(r.pos)
|
|
|
|
|
@@ -801,7 +801,7 @@ proc getCRC*(fileIdx: int32): SecureHash =
|
|
|
|
|
|
|
|
|
|
if gMods[fileIdx].crcDone:
|
|
|
|
|
return gMods[fileIdx].crc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = secureHashFile(fileIdx.toFilename)
|
|
|
|
|
gMods[fileIdx].crc = result
|
|
|
|
|
|
|
|
|
|
@@ -811,7 +811,7 @@ template growCache*(cache, pos) =
|
|
|
|
|
proc checkDep(fileIdx: int32): TReasonForRecompile =
|
|
|
|
|
assert fileIdx != InvalidFileIDX
|
|
|
|
|
growCache gMods, fileIdx
|
|
|
|
|
if gMods[fileIdx].reason != rrEmpty:
|
|
|
|
|
if gMods[fileIdx].reason != rrEmpty:
|
|
|
|
|
# reason has already been computed for this module:
|
|
|
|
|
return gMods[fileIdx].reason
|
|
|
|
|
let filename = fileIdx.toFilename
|
|
|
|
|
@@ -821,12 +821,12 @@ proc checkDep(fileIdx: int32): TReasonForRecompile =
|
|
|
|
|
var r: PRodReader = nil
|
|
|
|
|
var rodfile = toGeneratedFile(filename.withPackageName, RodExt)
|
|
|
|
|
r = newRodReader(rodfile, crc, fileIdx)
|
|
|
|
|
if r == nil:
|
|
|
|
|
if r == nil:
|
|
|
|
|
result = (if existsFile(rodfile): rrRodInvalid else: rrRodDoesNotExist)
|
|
|
|
|
else:
|
|
|
|
|
processRodFile(r, crc)
|
|
|
|
|
result = r.reason
|
|
|
|
|
if result == rrNone:
|
|
|
|
|
if result == rrNone:
|
|
|
|
|
# check modules it depends on
|
|
|
|
|
# NOTE: we need to process the entire module graph so that no ID will
|
|
|
|
|
# be used twice! However, compilation speed does not suffer much from
|
|
|
|
|
@@ -846,10 +846,10 @@ proc checkDep(fileIdx: int32): TReasonForRecompile =
|
|
|
|
|
r = nil
|
|
|
|
|
gMods[fileIdx].rd = r
|
|
|
|
|
gMods[fileIdx].reason = result # now we know better
|
|
|
|
|
|
|
|
|
|
proc handleSymbolFile(module: PSym): PRodReader =
|
|
|
|
|
|
|
|
|
|
proc handleSymbolFile(module: PSym): PRodReader =
|
|
|
|
|
let fileIdx = module.fileIdx
|
|
|
|
|
if optSymbolFiles notin gGlobalOptions:
|
|
|
|
|
if optSymbolFiles notin gGlobalOptions:
|
|
|
|
|
module.id = getID()
|
|
|
|
|
return nil
|
|
|
|
|
idgen.loadMaxIds(options.gProjectPath / options.gProjectName)
|
|
|
|
|
@@ -857,7 +857,7 @@ proc handleSymbolFile(module: PSym): PRodReader =
|
|
|
|
|
discard checkDep(fileIdx)
|
|
|
|
|
if gMods[fileIdx].reason == rrEmpty: internalError("handleSymbolFile")
|
|
|
|
|
result = gMods[fileIdx].rd
|
|
|
|
|
if result != nil:
|
|
|
|
|
if result != nil:
|
|
|
|
|
module.id = result.moduleID
|
|
|
|
|
idTablePut(result.syms, module, module)
|
|
|
|
|
processInterf(result, module)
|
|
|
|
|
@@ -878,13 +878,13 @@ proc rawLoadStub(s: PSym) =
|
|
|
|
|
#echo "rs: ", toHex(cast[int](rs.position), int.sizeof * 2),
|
|
|
|
|
# "\ns: ", toHex(cast[int](s.position), int.sizeof * 2)
|
|
|
|
|
internalError(rs.info, "loadStub: wrong symbol")
|
|
|
|
|
elif rs.id != theId:
|
|
|
|
|
internalError(rs.info, "loadStub: wrong ID")
|
|
|
|
|
elif rs.id != theId:
|
|
|
|
|
internalError(rs.info, "loadStub: wrong ID")
|
|
|
|
|
#MessageOut('loaded stub: ' + s.name.s);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc loadStub*(s: PSym) =
|
|
|
|
|
## loads the stub symbol `s`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# deactivate the GC here because we do a deep recursion and generate no
|
|
|
|
|
# garbage when restoring parts of the object graph anyway.
|
|
|
|
|
# Since we die with internal errors if this fails, no try-finally is
|
|
|
|
|
@@ -892,7 +892,7 @@ proc loadStub*(s: PSym) =
|
|
|
|
|
GC_disable()
|
|
|
|
|
rawLoadStub(s)
|
|
|
|
|
GC_enable()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc getBody*(s: PSym): PNode =
|
|
|
|
|
## retrieves the AST's body of `s`. If `s` has been loaded from a rod-file
|
|
|
|
|
## it may perform an expensive reload operation. Otherwise it's a simple
|
|
|
|
|
@@ -908,7 +908,7 @@ proc getBody*(s: PSym): PNode =
|
|
|
|
|
r.pos = oldPos
|
|
|
|
|
s.ast.sons[bodyPos] = result
|
|
|
|
|
s.offset = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initIdTable(gTypeTable)
|
|
|
|
|
initStrTable(rodCompilerprocs)
|
|
|
|
|
|
|
|
|
|
@@ -921,16 +921,16 @@ proc writeNode(f: File; n: PNode) =
|
|
|
|
|
f.write('^')
|
|
|
|
|
f.write(n.typ.id)
|
|
|
|
|
case n.kind
|
|
|
|
|
of nkCharLit..nkInt64Lit:
|
|
|
|
|
of nkCharLit..nkInt64Lit:
|
|
|
|
|
if n.intVal != 0:
|
|
|
|
|
f.write('!')
|
|
|
|
|
f.write(n.intVal)
|
|
|
|
|
of nkFloatLit..nkFloat64Lit:
|
|
|
|
|
if n.floatVal != 0.0:
|
|
|
|
|
of nkFloatLit..nkFloat64Lit:
|
|
|
|
|
if n.floatVal != 0.0:
|
|
|
|
|
f.write('!')
|
|
|
|
|
f.write($n.floatVal)
|
|
|
|
|
of nkStrLit..nkTripleStrLit:
|
|
|
|
|
if n.strVal != "":
|
|
|
|
|
if n.strVal != "":
|
|
|
|
|
f.write('!')
|
|
|
|
|
f.write(n.strVal.escape)
|
|
|
|
|
of nkIdent:
|
|
|
|
|
@@ -940,7 +940,7 @@ proc writeNode(f: File; n: PNode) =
|
|
|
|
|
f.write('!')
|
|
|
|
|
f.write(n.sym.id)
|
|
|
|
|
else:
|
|
|
|
|
for i in countup(0, sonsLen(n) - 1):
|
|
|
|
|
for i in countup(0, sonsLen(n) - 1):
|
|
|
|
|
writeNode(f, n.sons[i])
|
|
|
|
|
f.write(")")
|
|
|
|
|
|
|
|
|
|
@@ -966,10 +966,10 @@ proc writeSym(f: File; s: PSym) =
|
|
|
|
|
if s.magic != mNone:
|
|
|
|
|
f.write('@')
|
|
|
|
|
f.write($s.magic)
|
|
|
|
|
if s.options != gOptions:
|
|
|
|
|
if s.options != gOptions:
|
|
|
|
|
f.write('!')
|
|
|
|
|
f.write($s.options)
|
|
|
|
|
if s.position != 0:
|
|
|
|
|
if s.position != 0:
|
|
|
|
|
f.write('%')
|
|
|
|
|
f.write($s.position)
|
|
|
|
|
if s.offset != -1:
|
|
|
|
|
@@ -990,12 +990,12 @@ proc writeType(f: File; t: PType) =
|
|
|
|
|
f.write($t.kind)
|
|
|
|
|
f.write('+')
|
|
|
|
|
f.write($t.id)
|
|
|
|
|
if t.n != nil:
|
|
|
|
|
if t.n != nil:
|
|
|
|
|
f.writeNode(t.n)
|
|
|
|
|
if t.flags != {}:
|
|
|
|
|
f.write('$')
|
|
|
|
|
f.write($t.flags)
|
|
|
|
|
if t.callConv != low(t.callConv):
|
|
|
|
|
if t.callConv != low(t.callConv):
|
|
|
|
|
f.write('?')
|
|
|
|
|
f.write($t.callConv)
|
|
|
|
|
if t.owner != nil:
|
|
|
|
|
@@ -1010,11 +1010,11 @@ proc writeType(f: File; t: PType) =
|
|
|
|
|
if t.align != 2:
|
|
|
|
|
f.write('=')
|
|
|
|
|
f.write($t.align)
|
|
|
|
|
for i in countup(0, sonsLen(t) - 1):
|
|
|
|
|
if t.sons[i] == nil:
|
|
|
|
|
for i in countup(0, sonsLen(t) - 1):
|
|
|
|
|
if t.sons[i] == nil:
|
|
|
|
|
f.write("^()")
|
|
|
|
|
else:
|
|
|
|
|
f.write('^')
|
|
|
|
|
f.write('^')
|
|
|
|
|
f.write($t.sons[i].id)
|
|
|
|
|
f.write("]\n")
|
|
|
|
|
|
|
|
|
|
@@ -1031,28 +1031,28 @@ proc viewFile(rodfile: string) =
|
|
|
|
|
case section
|
|
|
|
|
of "CRC":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
outf.writeln("CRC:", $decodeVInt(r.s, r.pos))
|
|
|
|
|
of "ID":
|
|
|
|
|
outf.writeLine("CRC:", $decodeVInt(r.s, r.pos))
|
|
|
|
|
of "ID":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
r.moduleID = decodeVInt(r.s, r.pos)
|
|
|
|
|
setId(r.moduleID)
|
|
|
|
|
outf.writeln("ID:", $r.moduleID)
|
|
|
|
|
outf.writeLine("ID:", $r.moduleID)
|
|
|
|
|
of "ORIGFILE":
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
r.origFile = decodeStr(r.s, r.pos)
|
|
|
|
|
outf.writeln("ORIGFILE:", r.origFile)
|
|
|
|
|
outf.writeLine("ORIGFILE:", r.origFile)
|
|
|
|
|
of "OPTIONS":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
|
|
|
|
|
outf.writeln("OPTIONS:", $r.options)
|
|
|
|
|
outf.writeLine("OPTIONS:", $r.options)
|
|
|
|
|
of "GOPTIONS":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
let dep = cast[TGlobalOptions](int32(decodeVInt(r.s, r.pos)))
|
|
|
|
|
outf.writeln("GOPTIONS:", $dep)
|
|
|
|
|
outf.writeLine("GOPTIONS:", $dep)
|
|
|
|
|
of "CMD":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
let dep = cast[TCommands](int32(decodeVInt(r.s, r.pos)))
|
|
|
|
|
outf.writeln("CMD:", $dep)
|
|
|
|
|
outf.writeLine("CMD:", $dep)
|
|
|
|
|
of "DEFINES":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
var d = 0
|
|
|
|
|
@@ -1074,18 +1074,18 @@ proc viewFile(rodfile: string) =
|
|
|
|
|
r.files.add(finalPath.fileInfoIdx)
|
|
|
|
|
inc(r.pos) # skip #10
|
|
|
|
|
inc(r.line)
|
|
|
|
|
outf.writeln finalPath
|
|
|
|
|
outf.writeLine finalPath
|
|
|
|
|
if r.s[r.pos] == ')': inc(r.pos)
|
|
|
|
|
outf.write(")\n")
|
|
|
|
|
of "INCLUDES":
|
|
|
|
|
of "INCLUDES":
|
|
|
|
|
inc(r.pos, 2) # skip "(\10"
|
|
|
|
|
inc(r.line)
|
|
|
|
|
outf.write("INCLUDES(\n")
|
|
|
|
|
while r.s[r.pos] != ')':
|
|
|
|
|
while r.s[r.pos] != ')':
|
|
|
|
|
let w = r.files[decodeVInt(r.s, r.pos)]
|
|
|
|
|
inc(r.pos) # skip ' '
|
|
|
|
|
let inclCrc = decodeVInt(r.s, r.pos)
|
|
|
|
|
if r.s[r.pos] == '\x0A':
|
|
|
|
|
if r.s[r.pos] == '\x0A':
|
|
|
|
|
inc(r.pos)
|
|
|
|
|
inc(r.line)
|
|
|
|
|
outf.write(w, " ", inclCrc, "\n")
|
|
|
|
|
@@ -1094,7 +1094,7 @@ proc viewFile(rodfile: string) =
|
|
|
|
|
of "DEPS":
|
|
|
|
|
inc(r.pos) # skip ':'
|
|
|
|
|
outf.write("DEPS:")
|
|
|
|
|
while r.s[r.pos] > '\x0A':
|
|
|
|
|
while r.s[r.pos] > '\x0A':
|
|
|
|
|
let v = int32(decodeVInt(r.s, r.pos))
|
|
|
|
|
r.modDeps.add(r.files[v])
|
|
|
|
|
if r.s[r.pos] == ' ': inc(r.pos)
|
|
|
|
|
@@ -1126,7 +1126,7 @@ proc viewFile(rodfile: string) =
|
|
|
|
|
if section == "METHODS": r.methodsIdx = r.pos
|
|
|
|
|
else: r.convertersIdx = r.pos
|
|
|
|
|
outf.write(section, ":")
|
|
|
|
|
while r.s[r.pos] > '\x0A':
|
|
|
|
|
while r.s[r.pos] > '\x0A':
|
|
|
|
|
let d = decodeVInt(r.s, r.pos)
|
|
|
|
|
outf.write(" ", $d)
|
|
|
|
|
if r.s[r.pos] == ' ': inc(r.pos)
|
|
|
|
|
@@ -1152,7 +1152,7 @@ proc viewFile(rodfile: string) =
|
|
|
|
|
outf.write("INIT(\n")
|
|
|
|
|
inc r.pos, 2
|
|
|
|
|
r.initIdx = r.pos
|
|
|
|
|
while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')':
|
|
|
|
|
while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')':
|
|
|
|
|
let d = decodeVInt(r.s, r.pos)
|
|
|
|
|
inc(r.pos) # #10
|
|
|
|
|
#let p = r.pos
|
|
|
|
|
|