From 88f556b486df195f82069b60aa21808eba6b6da4 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:07:11 +0800 Subject: [PATCH] merge upstream code --- compiler/cgen.nim | 2 +- compiler/nir/ast2ir.nim | 103 ++++++++++++++++------------------------ 2 files changed, 42 insertions(+), 63 deletions(-) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 6e1c6b44a1..e8b9839915 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -2112,7 +2112,7 @@ proc genTopLevelStmt*(m: BModule; n: PNode) = transformedN = injectDestructorCalls(m.g.graph, m.idgen, m.module, transformedN) if sfMainModule in m.module.flags: - let moduleCon = initModuleCon(m.config, m.module) + let moduleCon = initModuleCon(m.g.graph, m.config, m.module) var procCon = initProcCon(moduleCon, nil) genCode(procCon, transformedN) diff --git a/compiler/nir/ast2ir.nim b/compiler/nir/ast2ir.nim index a7e922e405..ef7788fe50 100644 --- a/compiler/nir/ast2ir.nim +++ b/compiler/nir/ast2ir.nim @@ -59,51 +59,51 @@ proc toLineInfo(c: var ProcCon; i: TLineInfo): PackedLineInfo = c.lastFileVal = val result = pack(c.m.man, val, int32 i.line, int32 i.col) -# when false: -# proc gen*(c: var ProcCon; dest: var Tree; n: PNode) -# proc genv*(c: var ProcCon; dest: var Tree; v: var Value; n: PNode) +when false: + proc gen*(c: var ProcCon; dest: var Tree; n: PNode) + proc genv*(c: var ProcCon; dest: var Tree; v: var Value; n: PNode) -# proc genx*(c: var ProcCon; dest: var Tree; n: PNode): SymId = -# let info = toLineInfo(c, n.info) -# let t = typeToIr(c.m.types, n.typ) -# result = allocTemp(c.sm, t) -# addSummon dest, info, result, t -# var ex = localToValue(info, result) -# genv(c, dest, ex, n) -# template withBlock(lab: LabelId; body: untyped) = -# body -# dest.addInstr(info, Label, lab) + proc genx*(c: var ProcCon; dest: var Tree; n: PNode): SymId = + let info = toLineInfo(c, n.info) + let t = typeToIr(c.m.types, n.typ) + result = allocTemp(c.sm, t) + addSummon dest, info, result, t + var ex = localToValue(info, result) + genv(c, dest, ex, n) + template withBlock(lab: LabelId; body: untyped) = + body + dest.addInstr(info, Label, lab) -# proc genWhile(c: var ProcCon; dest: var Tree; n: PNode) = -# # LoopLabel lab1: -# # cond, tmp -# # select cond -# # of false: goto lab2 -# # body -# # GotoLoop lab1 -# # Label lab2: -# let info = toLineInfo(c, n.info) -# let loopLab = dest.addLabel(c.labelGen, info, LoopLabel) -# let theEnd = newLabel(c.labelGen) -# withBlock(theEnd): -# if isTrue(n[0]): -# c.gen(dest, n[1]) -# dest.gotoLabel info, GotoLoop, loopLab -# else: -# let x = c.genx(dest, n[0]) -# #dest.addSelect toLineInfo(c, n[0].kind), x -# c.gen(dest, n[1]) -# dest.gotoLabel info, GotoLoop, loopLab + proc genWhile(c: var ProcCon; dest: var Tree; n: PNode) = + # LoopLabel lab1: + # cond, tmp + # select cond + # of false: goto lab2 + # body + # GotoLoop lab1 + # Label lab2: + let info = toLineInfo(c, n.info) + let loopLab = dest.addLabel(c.labelGen, info, LoopLabel) + let theEnd = newLabel(c.labelGen) + withBlock(theEnd): + if isTrue(n[0]): + c.gen(dest, n[1]) + dest.gotoLabel info, GotoLoop, loopLab + else: + let x = c.genx(dest, n[0]) + #dest.addSelect toLineInfo(c, n[0].kind), x + c.gen(dest, n[1]) + dest.gotoLabel info, GotoLoop, loopLab -# proc genv*(c: var ProcCon; dest: var Tree; v: var Value; n: PNode) = -# quit "too implement" + proc genv*(c: var ProcCon; dest: var Tree; v: var Value; n: PNode) = + quit "too implement" -# proc gen*(c: var ProcCon; dest: var Tree; n: PNode) = -# case n.kind -# of nkWhileStmt: -# genWhile c, dest, n -# else: -# discard + proc gen*(c: var ProcCon; dest: var Tree; n: PNode) = + case n.kind + of nkWhileStmt: + genWhile c, dest, n + else: + discard proc bestEffort(c: ProcCon): TLineInfo = if c.prc != nil: @@ -2071,27 +2071,6 @@ proc genParams(c: var ProcCon; params: PNode) = proc genCode*(c: var ProcCon; n: PNode) -# proc genWhile(c: var ProcCon; n: PNode) = -# # LoopLabel lab1: -# # cond, tmp -# # select cond -# # of false: goto lab2 -# # body -# # GotoLoop lab1 -# # Label lab2: -# let info = toLineInfo(c, n.info) -# let loopLab = c.code.addNewLabel(c.labelGen, info, LoopLabel) -# let theEnd = newLabel(c.labelGen) -# withBlock(theEnd): -# if isTrue(n[0]): -# c.gen(dest, n[1]) -# dest.gotoLabel info, GotoLoop, loopLab -# else: -# let x = c.genx(dest, n[0]) -# #dest.addSelect toLineInfo(c, n[0].kind), x -# c.gen(dest, n[1]) -# dest.gotoLabel info, GotoLoop, loopLab - proc gen(c: var ProcCon; n: PNode; dest: var Value; flags: GenFlags = {}) = case n.kind of nkBlockStmt: