Skip to content

Commit

Permalink
pass0: fix BitAnd and BitOr translation
Browse files Browse the repository at this point in the history
The implementation erroneously treated the trees as having only two
child nodes, while they actually have three (type, operand a, operand
b).
  • Loading branch information
zerbina committed Oct 13, 2024
1 parent 7525649 commit a4436c8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
10 changes: 6 additions & 4 deletions passes/pass0.nim
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,14 @@ proc genExpr(c; tree; val: NodeIndex) =
c.instr(opcBitNot)
c.mask(typ) # discard the unused higher bits
of BitAnd:
c.genExpr(tree, tree.child(val, 0))
c.genExpr(tree, tree.child(val, 1))
let (_, a, b) = tree.triplet(val)
c.genExpr(tree, a)
c.genExpr(tree, b)
c.instr(opcBitAnd)
of BitOr:
c.genExpr(tree, tree.child(val, 0))
c.genExpr(tree, tree.child(val, 1))
let (_, a, b) = tree.triplet(val)
c.genExpr(tree, a)
c.genExpr(tree, b)
c.instr(opcBitOr)
of BitXor:
c.genBinaryArithOp(tree, val, opcBitXor, opcBitXor, opcNop)
Expand Down
8 changes: 8 additions & 0 deletions tests/pass0/t03_bitand.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.type t0 (Int)
.type t1 (Proc t0)
.start t1 p0
LdImmInt 16
LdImmInt 48
BitAnd
Ret
.end
14 changes: 14 additions & 0 deletions tests/pass0/t03_bitand.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
discard """
output: "(Done 16)"
"""
(TypeDefs
(Int 8)
(ProcTy (Type 0)))
(GlobalDefs)
(ProcDefs
(ProcDef (Type 1) (Locals)
(Continuations
(Continuation (Params) 0
(Continue 1
(BitAnd (Type 0) (IntVal 16) (IntVal 48))))
(Continuation (Params (Type 0))))))
8 changes: 8 additions & 0 deletions tests/pass0/t03_bitor.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.type t0 (Int)
.type t1 (Proc t0)
.start t1 p0
LdImmInt 48
LdImmInt 40
BitOr
Ret
.end
14 changes: 14 additions & 0 deletions tests/pass0/t03_bitor.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
discard """
output: "(Done 56)"
"""
(TypeDefs
(Int 8)
(ProcTy (Type 0)))
(GlobalDefs)
(ProcDefs
(ProcDef (Type 1) (Locals)
(Continuations
(Continuation (Params) 0
(Continue 1
(BitOr (Type 0) (IntVal 48) (IntVal 40))))
(Continuation (Params (Type 0))))))

0 comments on commit a4436c8

Please sign in to comment.