Skip to content

Commit

Permalink
Fix multiple void return points and fix val pointer copies
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrulich committed Aug 13, 2024
1 parent 4a52e95 commit e09ac12
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
B0($1:i32)
CONST $2 42 :i32
EQ $3 $1 $2 :bool
CMP $4 $3 B1() B2() :void
B1()
CONST $5 1 :i32
JMP $0 B3($5) :void
B2()
CONST $7 120 :i32
JMP $0 B3($7) :void
B3($5:i32)
RETURN $5 :i32
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
B0($1:ptr)
LOAD $4 $1 :i32
CONST $5 10 :i32
GT $6 $4 $5 :bool
CMP $7 $6 B1($1) B2($1) :void
B1($1:ptr)
CONST $10 1 :i32
STORE $1 $10 :i32
JMP $0 B3() :void
B2($1:ptr)
CONST $14 42 :i32
STORE $1 $14 :i32
JMP $0 B3() :void
B3()
RETURN $0 :void
19 changes: 19 additions & 0 deletions nautilus/test/data/control-flow-tests/ir/conditionalReturn.trace
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
NESIR {
execute() {
Block_0($1:i32):
$2 = 42 :i32
$3 = $1 == $2 :bool
if $3 ? Block_1() : Block_2() :void

Block_1():
$5 = 1 :i32
br Block_3($5) :void

Block_3($5:i32):
return ($5) :i32

Block_2():
$7 = 120 :i32
br Block_3($7) :void
}
} //NESIR
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
NESIR {
execute() {
Block_0($1:ptr):
$4 = load($1) :i32
$5 = 10 :i32
$6 = $4 > $5 :bool
if $6 ? Block_1($1) : Block_2($1) :void

Block_1($1:ptr):
$10 = 1 :i32
store($10, $1) :void
br Block_3() :void

Block_3():
return :void

Block_2($1:ptr):
$14 = 42 :i32
store($14, $1) :void
br Block_3() :void
}
} //NESIR
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
B0($1:i32)
CONST $2 42 :i32
EQ $3 $1 $2 :bool
CMP $4 $3 B1() B2() :void
B1()
CONST $5 1 :i32
RETURN $5 :i32
B2()
CONST $7 120 :i32
RETURN $7 :i32
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
B0($1:ptr)
ASSIGN $2 $1 :ptr
ASSIGN $3 $2 :ptr
LOAD $4 $3 :i32
CONST $5 10 :i32
GT $6 $4 $5 :bool
CMP $7 $6 B1() B2() :void
B1()
ASSIGN $8 $1 :ptr
ASSIGN $9 $8 :ptr
CONST $10 1 :i32
STORE $1 $10 :i32
RETURN $0 :void
B2()
ASSIGN $12 $1 :ptr
ASSIGN $13 $12 :ptr
CONST $14 42 :i32
STORE $1 $14 :i32
RETURN $0 :void
4 changes: 2 additions & 2 deletions nautilus/test/execution-tests/TracingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ TEST_CASE("Expression Trace Test") {
}
TEST_CASE("Control-flow Trace Test") {
auto tests = std::vector<std::tuple<std::string, std::function<void()>>> {{"ifThenCondition", details::createFunctionWrapper(ifThenCondition)},
//{"conditionalReturn",
// details::createFunctionWrapper(conditionalReturn)},
{"multipleVoidReturnsFunction", details::createFunctionWrapper(multipleVoidReturnsFunction)},
{"conditionalReturn",details::createFunctionWrapper(conditionalReturn)},
{"ifThenElseCondition", details::createFunctionWrapper(ifThenElseCondition)},
{"nestedIfThenElseCondition", details::createFunctionWrapper(nestedIfThenElseCondition)},
{"nestedIfNoElseCondition", details::createFunctionWrapper(nestedIfNoElseCondition)},
Expand Down

0 comments on commit e09ac12

Please sign in to comment.