Skip to content

Commit 8d81fbe

Browse files
record path conditions
1 parent 2143050 commit 8d81fbe

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

headers/wasm/symbolic_rt.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ class SymVal {
1717
// Not implemented yet
1818
return SymVal();
1919
}
20+
21+
SymVal negate() const {
22+
// negate the symbolic condition by creating a new symbolic value
23+
// not implemented yet
24+
return SymVal();
25+
}
2026
};
2127

2228
class SymStack_t {
@@ -69,4 +75,16 @@ static SymVal Concrete(Num num) {
6975
return SymVal();
7076
}
7177

78+
class ExploreTree_t {
79+
public:
80+
std::monostate fillIfElseNode(SymVal s, bool branch) {
81+
// fill the current node with the branch condition s
82+
// parameter branch is redundant, to hint which branch we've entered
83+
// Not implemented yet
84+
return std::monostate();
85+
}
86+
};
87+
88+
static ExploreTree_t ExploreTree;
89+
7290
#endif // WASM_SYMBOLIC_RT_HPP

src/main/scala/wasm/StagedConcolicMiniWasm.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,10 @@ trait StagedWasmEvaluator extends SAIOps {
225225
})
226226
// TODO: put the cond.s to path condition
227227
if (cond.toInt != 0) {
228+
ExploreTree.fillWithIfElse(cond.s, true)
228229
eval(thn, restK _, mkont, restK _ :: trail)(newCtx)
229230
} else {
231+
ExploreTree.fillWithIfElse(cond.s.not, false)
230232
eval(els, restK _, mkont, restK _ :: trail)(newCtx)
231233
}
232234
()
@@ -239,9 +241,11 @@ trait StagedWasmEvaluator extends SAIOps {
239241
// TODO: put the cond.s to path condition
240242
if (cond.toInt != 0) {
241243
info(s"Jump to $label")
244+
ExploreTree.fillWithIfElse(cond.s, true)
242245
trail(label)(newCtx)(mkont)
243246
} else {
244247
info(s"Continue")
248+
ExploreTree.fillWithIfElse(cond.s.not, false)
245249
eval(rest, kont, mkont, trail)(newCtx)
246250
}
247251
()
@@ -575,6 +579,13 @@ trait StagedWasmEvaluator extends SAIOps {
575579
}
576580
}
577581

582+
// Exploration tree,
583+
object ExploreTree {
584+
def fillWithIfElse(s: Rep[SymVal], branch: Boolean): Rep[Unit] = {
585+
"tree-fill-if-else".reflectCtrlWith[Unit](s, branch)
586+
}
587+
}
588+
578589
// runtime Num type
579590
implicit class StagedNumOps(num: StagedNum) {
580591

@@ -733,6 +744,12 @@ trait StagedWasmEvaluator extends SAIOps {
733744
}
734745
}
735746
}
747+
748+
implicit class SymbolicOps(s: Rep[SymVal]) {
749+
def not(): Rep[SymVal] = {
750+
"sym-not".reflectCtrlWith(s)
751+
}
752+
}
736753
}
737754

738755
trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
@@ -881,6 +898,10 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
881898
shallow(lhs); emit(" >= "); shallow(rhs)
882899
case Node(_, "num-to-int", List(num), _) =>
883900
shallow(num); emit(".toInt()")
901+
case Node(_, "tree-fill-if-else", List(s, b), _) =>
902+
emit("ExploreTree.fillIfElseNode("); shallow(s); emit(", "); shallow(b); emit(")")
903+
case Node(_, "sym-not", List(s), _) =>
904+
shallow(s); emit(".negate()")
884905
case Node(_, "dummy", _, _) => emit("std::monostate()")
885906
case Node(_, "dummy-op", _, _) => emit("std::monostate()")
886907
case Node(_, "no-op", _, _) =>

0 commit comments

Comments
 (0)