Skip to content

Commit

Permalink
cgir: remove the legacy CGIR variant (nim-lang#1234)
Browse files Browse the repository at this point in the history
## Summary

All code generators use the new goto-using variant of the CGIR now,
rendering the legacy variant obsolete. This is an internal-only
refactoring.

## Details

* remove the `cgirgen_legacy` module
* remove the node kinds belonging to the legacy variant
* remove the sets introduced for the transition
* remove some leftover usages of `cnkStmtListExpr` (they were dead code
  already)
  • Loading branch information
zerbina committed Mar 13, 2024
1 parent f3f83e7 commit 0d03576
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 976 deletions.
10 changes: 1 addition & 9 deletions compiler/backend/backends.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import
compiler/backend/[
cgmeth,
cgir,
cgirgen,
cgirgen_legacy
cgirgen
],
compiler/front/[
msgs,
Expand Down Expand Up @@ -371,13 +370,6 @@ proc generateIR*(graph: ModuleGraph, idgen: IdGenerator, env: MirEnv,
result = cgirgen.generateIR(graph, idgen, env, owner, body)
echoOutput(graph.config, owner, result)

proc generateIRLegacy*(graph: ModuleGraph, idgen: IdGenerator, env: MirEnv,
owner: PSym, body: sink MirBody): Body =
## Translates the MIR code provided by `code` into legacy ``CgNode`` IR and,
## if enabled, echoes the result.
result = cgirgen_legacy.generateIR(graph, idgen, env, owner, body)
echoOutput(graph.config, owner, result)

# ------- handling of lifted globals ---------

proc produceFragmentsForGlobals(
Expand Down
4 changes: 2 additions & 2 deletions compiler/backend/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2130,8 +2130,8 @@ proc expr(p: BProc, n: CgNode, d: var TLoc) =
of cnkJoinStmt, cnkGotoStmt:
unreachable("handled separately")
of cnkInvalid, cnkType, cnkAstLit, cnkMagic, cnkRange, cnkBinding, cnkBranch,
cnkLabel, cnkTargetList, cnkStmtListExpr, cnkField, cnkStmtList,
cnkLeave, cnkResume, cnkLegacyNodes:
cnkLabel, cnkTargetList, cnkField, cnkStmtList,
cnkLeave, cnkResume:
internalError(p.config, n.info, "expr(" & $n.kind & "); unknown node kind")

proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo): Rope =
Expand Down
22 changes: 4 additions & 18 deletions compiler/backend/cgir.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,23 @@ type
## different type

cnkStmtList
cnkStmtListExpr
# XXX: both stmtlist and stmtlistexpr are obsolete. They're only kept for
# grouping the top-level statements under a single node
# XXX: stmtlist is obsolete, and only kept temporarily to group statements
# together under a single node

cnkVoidStmt ## discard the operand value (i.e., do nothing with it)
cnkEmitStmt ## an ``emit`` statement
cnkAsmStmt ## an ``asm`` statement

cnkIfStmt ## only execute the body when the condition expression
## evaluates to 'true'
cnkRepeatStmt ## execute the body indefinitely
cnkCaseStmt ## a ``case`` statement
cnkBranch ## the branch of a ``case`` statement
cnkBlockStmt ## an (optionally) labeled block
cnkTryStmt

cnkGotoStmt
cnkLoopStmt ## jump back to a loop join point
cnkBreakStmt ## break out of labeled block, or, if no label is provided,
## the closest ``repeat`` loop
cnkRaiseStmt ## raise(x) -- set the `x` as the current exception and start
## exceptional control-flow. `x` can be ``cnkEmpty`` in which
## case "set current exception" part is skipped
cnkReturnStmt
cnkContinueStmt## jump to the next target in the active jump list

cnkJoinStmt ## join point for gotos
Expand All @@ -155,19 +148,12 @@ const
cnkWithOperand* = {cnkConv, cnkHiddenConv, cnkDeref, cnkAddr, cnkHiddenAddr,
cnkDerefView, cnkObjDownConv, cnkObjUpConv, cnkCast,
cnkLvalueConv}
cnkAtoms* = {cnkInvalid..cnkResume, cnkReturnStmt}
cnkAtoms* = {cnkInvalid..cnkResume}
## node kinds that denote leafs
cnkWithItems* = AllKinds - cnkWithOperand - cnkAtoms
## node kinds for which the ``items`` iterator is available

cnkLiterals* = {cnkIntLit, cnkUIntLit, cnkFloatLit, cnkStrLit}
cnkLegacyNodes* = {cnkBlockStmt, cnkTryStmt, cnkReturnStmt, cnkBreakStmt,
cnkRepeatStmt}
## node kinds that belong to the legacy control-flow representation
cnkNewCfNodes* = {cnkGotoStmt, cnkJoinStmt, cnkLeave, cnkResume,
cnkContinueStmt, cnkLoopStmt, cnkLoopJoinStmt,
cnkEnd, cnkTargetList}
## node kinds that belong to the new-style control-flow representation

type
Local* = object
Expand Down Expand Up @@ -199,7 +185,7 @@ type
info*: TLineInfo
typ*: PType
case kind*: CgNodeKind
of cnkInvalid, cnkEmpty, cnkType, cnkNilLit, cnkReturnStmt, cnkResume:
of cnkInvalid, cnkEmpty, cnkType, cnkNilLit, cnkResume:
discard
of cnkIntLit, cnkUIntLit:
# future direction: use a ``BiggestUint`` for uint values
Expand Down
Loading

0 comments on commit 0d03576

Please sign in to comment.