summary refs log tree commit diff stats
path: root/compiler/nir/nirinsts.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/nir/nirinsts.nim')
-rw-r--r--compiler/nir/nirinsts.nim28
1 files changed, 23 insertions, 5 deletions
diff --git a/compiler/nir/nirinsts.nim b/compiler/nir/nirinsts.nim
index 873004408..5c2901540 100644
--- a/compiler/nir/nirinsts.nim
+++ b/compiler/nir/nirinsts.nim
@@ -63,8 +63,10 @@ type
     Kill, # `Kill x`: scope end for `x`
 
     AddrOf,
-    ArrayAt, # addr(a[i])
-    FieldAt, # addr(obj.field)
+    ArrayAt, # a[i]
+    DerefArrayAt, # a[i] where `a` is a PtrArray; `a[][i]`
+    FieldAt, # obj.field
+    DerefFieldAt, # obj[].field
 
     Load, # a[]
     Store, # a[] = b
@@ -162,7 +164,9 @@ const
     AddrOf,
     Load,
     ArrayAt,
+    DerefArrayAt,
     FieldAt,
+    DerefFieldAt,
     TestOf
   }
 
@@ -240,6 +244,8 @@ proc next*(tree: Tree; pos: var NodePos) {.inline.} = nextChild tree, int(pos)
 
 template firstSon*(n: NodePos): NodePos = NodePos(n.int+1)
 
+template skipTyped*(n: NodePos): NodePos = NodePos(n.int+2)
+
 iterator sons*(tree: Tree; n: NodePos): NodePos =
   var pos = n.int
   assert tree.nodes[pos].kind > LastAtomicValue
@@ -259,6 +265,17 @@ iterator sonsFrom1*(tree: Tree; n: NodePos): NodePos =
     yield NodePos pos
     nextChild tree, pos
 
+iterator sonsFromN*(tree: Tree; n: NodePos; toSkip = 2): NodePos =
+  var pos = n.int
+  assert tree.nodes[pos].kind > LastAtomicValue
+  let last = pos + tree.nodes[pos].rawSpan
+  inc pos
+  for i in 1..toSkip:
+    nextChild tree, pos
+  while pos < last:
+    yield NodePos pos
+    nextChild tree, pos
+
 template `[]`*(t: Tree; n: NodePos): Instr = t.nodes[n.int]
 
 proc span(tree: Tree; pos: int): int {.inline.} =
@@ -327,9 +344,6 @@ proc addNewLabel*(t: var Tree; labelGen: var int; info: PackedLineInfo; k: Opcod
   t.nodes.add Instr(x: toX(k, uint32(result)), info: info)
   inc labelGen
 
-proc boolVal*(t: var Tree; info: PackedLineInfo; b: bool) =
-  t.nodes.add Instr(x: toX(ImmediateVal, uint32(b)), info: info)
-
 proc gotoLabel*(t: var Tree; info: PackedLineInfo; k: Opcode; L: LabelId) =
   assert k in {Goto, GotoLoop, CheckedGoto}
   t.nodes.add Instr(x: toX(k, uint32(L)), info: info)
@@ -367,6 +381,10 @@ proc addIntVal*(t: var Tree; integers: var BiTable[int64]; info: PackedLineInfo;
   buildTyped t, info, NumberConv, typ:
     t.nodes.add Instr(x: toX(IntVal, uint32(integers.getOrIncl(x))), info: info)
 
+proc boolVal*(t: var Tree; integers: var BiTable[int64]; info: PackedLineInfo; b: bool) =
+  buildTyped t, info, NumberConv, Bool8Id:
+    t.nodes.add Instr(x: toX(IntVal, uint32(integers.getOrIncl(ord b))), info: info)
+
 proc addStrVal*(t: var Tree; strings: var BiTable[string]; info: PackedLineInfo; s: string) =
   t.nodes.add Instr(x: toX(StrVal, uint32(strings.getOrIncl(s))), info: info)