symbol files: baby steps to a working solution

This commit is contained in:
Araq 2018-02-26 17:39:19 +01:00
commit ac6d9a3079

View file

@ -400,8 +400,9 @@ proc storeNode*(module: PSym; n: PNode) =
w.module = module w.module = module
var buf = newStringOfCap(160) var buf = newStringOfCap(160)
encodeNode(w, module.info, n, buf) encodeNode(w, module.info, n, buf)
db.exec(sql"insert into toplevelstmts(module, data) values (?, ?)", db.exec(sql"insert into toplevelstmts(module, position, data) values (?, ?, ?)",
abs(module.id), buf) abs(module.id), module.offset, buf)
inc module.offset
var i = 0 var i = 0
while true: while true:
if i > 10_000: if i > 10_000:
@ -812,14 +813,14 @@ proc loadModuleSymTab(r; module: PSym) =
if sfSystemModule in module.flags: if sfSystemModule in module.flags:
magicsys.systemModule = module magicsys.systemModule = module
proc loadNode*(module: PSym; index: var int): PNode = proc loadNode*(module: PSym; index: int): PNode =
assert gSymbolFiles == v2Sf assert gSymbolFiles == v2Sf
if index == 0: if index == 0:
loadModuleSymTab(gr, module) loadModuleSymTab(gr, module)
index = parseInt db.getValue( #index = parseInt db.getValue(
sql"select min(id) from toplevelstmts where module = ?", abs module.id) # sql"select min(id) from toplevelstmts where module = ?", abs module.id)
var b = BlobReader(pos: 0) var b = BlobReader(pos: 0)
b.s = db.getValue(sql"select data from toplevelstmts where id = ? and module = ?", b.s = db.getValue(sql"select data from toplevelstmts where position = ? and module = ?",
index, abs module.id) index, abs module.id)
if b.s.len == 0: if b.s.len == 0:
db.exec(sql"insert into controlblock(idgen) values (?)", gFrontEndId) db.exec(sql"insert into controlblock(idgen) values (?)", gFrontEndId)
@ -908,12 +909,14 @@ proc createDb() =
db.exec(sql""" db.exec(sql"""
create table if not exists toplevelstmts( create table if not exists toplevelstmts(
id integer primary key, id integer primary key,
position integer not null,
module integer not null, module integer not null,
data blob not null, data blob not null,
foreign key (module) references module(id) foreign key (module) references module(id)
); );
""") """)
db.exec sql"create index TopLevelStmtByModuleIdx on toplevelstmts(module);" db.exec sql"create index TopLevelStmtByModuleIdx on toplevelstmts(module);"
db.exec sql"create index TopLevelStmtByPositionIdx on toplevelstmts(position);"
db.exec(sql""" db.exec(sql"""
create table if not exists statics( create table if not exists statics(