Skip to content

Commit 61215b6

Browse files
The branch node only needs to remember the positive condition.
use the sub-nodes of the branch to classify whether the execution is true or false
1 parent 8d81fbe commit 61215b6

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

headers/wasm/symbolic_rt.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,16 @@ static SymVal Concrete(Num num) {
7777

7878
class ExploreTree_t {
7979
public:
80-
std::monostate fillIfElseNode(SymVal s, bool branch) {
80+
std::monostate fillIfElseNode(SymVal s) {
8181
// fill the current node with the branch condition s
8282
// parameter branch is redundant, to hint which branch we've entered
8383
// Not implemented yet
8484
return std::monostate();
8585
}
86+
87+
std::monostate moveCursor(bool branch) {
88+
return std::monostate();
89+
}
8690
};
8791

8892
static ExploreTree_t ExploreTree;

src/main/scala/wasm/StagedConcolicMiniWasm.scala

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,12 @@ trait StagedWasmEvaluator extends SAIOps {
224224
eval(rest, kont, mk, trail)(newRestCtx)
225225
})
226226
// TODO: put the cond.s to path condition
227+
ExploreTree.fillWithIfElse(cond.s)
227228
if (cond.toInt != 0) {
228-
ExploreTree.fillWithIfElse(cond.s, true)
229+
ExploreTree.moveCursor(true)
229230
eval(thn, restK _, mkont, restK _ :: trail)(newCtx)
230231
} else {
231-
ExploreTree.fillWithIfElse(cond.s.not, false)
232+
ExploreTree.moveCursor(false)
232233
eval(els, restK _, mkont, restK _ :: trail)(newCtx)
233234
}
234235
()
@@ -239,13 +240,14 @@ trait StagedWasmEvaluator extends SAIOps {
239240
val (cond, newCtx) = Stack.pop()
240241
info(s"The br_if(${label})'s condition is ", cond.toInt)
241242
// TODO: put the cond.s to path condition
243+
ExploreTree.fillWithIfElse(cond.s)
242244
if (cond.toInt != 0) {
243245
info(s"Jump to $label")
244-
ExploreTree.fillWithIfElse(cond.s, true)
246+
ExploreTree.moveCursor(true)
245247
trail(label)(newCtx)(mkont)
246248
} else {
247249
info(s"Continue")
248-
ExploreTree.fillWithIfElse(cond.s.not, false)
250+
ExploreTree.moveCursor(false)
249251
eval(rest, kont, mkont, trail)(newCtx)
250252
}
251253
()
@@ -581,8 +583,12 @@ trait StagedWasmEvaluator extends SAIOps {
581583

582584
// Exploration tree,
583585
object ExploreTree {
584-
def fillWithIfElse(s: Rep[SymVal], branch: Boolean): Rep[Unit] = {
585-
"tree-fill-if-else".reflectCtrlWith[Unit](s, branch)
586+
def fillWithIfElse(s: Rep[SymVal]): Rep[Unit] = {
587+
"tree-fill-if-else".reflectCtrlWith[Unit](s)
588+
}
589+
590+
def moveCursor(branch: Boolean): Rep[Unit] = {
591+
"tree-move-cursor".reflectCtrlWith[Unit](branch)
586592
}
587593
}
588594

@@ -898,8 +904,10 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
898904
shallow(lhs); emit(" >= "); shallow(rhs)
899905
case Node(_, "num-to-int", List(num), _) =>
900906
shallow(num); emit(".toInt()")
901-
case Node(_, "tree-fill-if-else", List(s, b), _) =>
902-
emit("ExploreTree.fillIfElseNode("); shallow(s); emit(", "); shallow(b); emit(")")
907+
case Node(_, "tree-fill-if-else", List(s), _) =>
908+
emit("ExploreTree.fillIfElseNode("); shallow(s); emit(")")
909+
case Node(_, "tree-move-cursor", List(b), _) =>
910+
emit("ExploreTree.moveCursor("); shallow(b); emit(")")
903911
case Node(_, "sym-not", List(s), _) =>
904912
shallow(s); emit(".negate()")
905913
case Node(_, "dummy", _, _) => emit("std::monostate()")

0 commit comments

Comments
 (0)