diff options
Diffstat (limited to 'compiler/nir/nir.nim')
-rw-r--r-- | compiler/nir/nir.nim | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/compiler/nir/nir.nim b/compiler/nir/nir.nim index 0669bc222..c4fb5322d 100644 --- a/compiler/nir/nir.nim +++ b/compiler/nir/nir.nim @@ -12,8 +12,9 @@ from os import addFileExt, `/`, createDir +import std / assertions import ".." / [ast, modulegraphs, renderer, transf, options, msgs, lineinfos] -import nirtypes, nirinsts, ast2ir, nirlineinfos +import nirtypes, nirinsts, ast2ir, nirlineinfos, nirfiles, nirvm import ".." / ic / [rodfiles, bitabs] @@ -22,13 +23,18 @@ type m: ModuleCon c: ProcCon oldErrorCount: int + bytecode: Bytecode proc newCtx*(module: PSym; g: ModuleGraph; idgen: IdGenerator): PCtx = - let m = initModuleCon(g, g.config, idgen, module) - PCtx(m: m, c: initProcCon(m, nil, g.config), idgen: idgen) + var lit = Literals() + var nirm = (ref NirModule)(types: initTypeGraph(lit), lit: lit) + var m = initModuleCon(g, g.config, idgen, module, nirm) + m.noModularity = true + PCtx(m: m, c: initProcCon(m, nil, g.config), idgen: idgen, bytecode: initBytecode(nirm)) proc refresh*(c: PCtx; module: PSym; idgen: IdGenerator) = - c.m = initModuleCon(c.m.graph, c.m.graph.config, idgen, module) + #c.m = initModuleCon(c.m.graph, c.m.graph.config, idgen, module, c.m.nirm) + #c.m.noModularity = true c.c = initProcCon(c.m, nil, c.m.graph.config) c.idgen = idgen @@ -46,14 +52,13 @@ proc setupNirReplGen*(graph: ModuleGraph; module: PSym; idgen: IdGenerator): PPa proc evalStmt(c: PCtx; n: PNode) = let n = transformExpr(c.m.graph, c.idgen, c.m.module, n) let pc = genStmt(c.c, n) - - var res = "" - if pc < c.c.code.len: - toString c.c.code, NodePos(pc), c.m.lit.strings, c.m.lit.numbers, res + #var res = "" + #toString c.m.nirm.code, NodePos(pc), c.m.nirm.lit.strings, c.m.nirm.lit.numbers, c.m.symnames, res #res.add "\n--------------------------\n" #toString res, c.m.types.g - echo res - + if pc.int < c.m.nirm.code.len: + execCode c.bytecode, c.m.nirm.code, pc + #echo res proc runCode*(c: PPassContext; n: PNode): PNode = let c = PCtx(c) @@ -71,7 +76,9 @@ type c: ProcCon proc openNirBackend*(g: ModuleGraph; module: PSym; idgen: IdGenerator): PPassContext = - let m = initModuleCon(g, g.config, idgen, module) + var lit = Literals() + var nirm = (ref NirModule)(types: initTypeGraph(lit), lit: lit) + let m = initModuleCon(g, g.config, idgen, module, nirm) NirPassContext(m: m, c: initProcCon(m, nil, g.config), idgen: idgen) proc gen(c: NirPassContext; n: PNode) = @@ -89,27 +96,9 @@ proc closeNirBackend*(c: PPassContext; finalNode: PNode) = let nimcache = getNimcacheDir(c.c.config).string createDir nimcache let outp = nimcache / c.m.module.name.s.addFileExt("nir") - var r = rodfiles.create(outp) + #c.m.nirm.code = move c.c.code try: - r.storeHeader(nirCookie) - r.storeSection stringsSection - r.store c.m.lit.strings - - r.storeSection numbersSection - r.store c.m.lit.numbers - - r.storeSection bodiesSection - r.store c.c.code - - r.storeSection typesSection - r.store c.m.types.g - - r.storeSection sideChannelSection - r.store c.m.man - - finally: - r.close() - if r.err != ok: - rawMessage(c.c.config, errFatal, "serialization failed: " & outp) - else: + store c.m.nirm[], outp echo "created: ", outp + except IOError: + rawMessage(c.c.config, errFatal, "serialization failed: " & outp) |