@@ -19,6 +19,26 @@ import gensym.wasm.symbolic.Concrete
1919import gensym .wasm .symbolic .ExploreTree
2020import gensym .structure .freer .Explore
2121
22+ object Counter {
23+ var currentId : Int = 0
24+ private val dict = new HashMap [WIR , Int ]()
25+
26+ def reset (): Unit = {
27+ currentId = 0
28+ dict.clear()
29+ }
30+
31+ def getId (wir : WIR ): Int = {
32+ if (dict.contains(wir)) {
33+ dict(wir)
34+ } else {
35+ val id = currentId
36+ currentId += 1
37+ dict(wir) = id
38+ id
39+ }
40+ }
41+ }
2242@ virtualize
2343trait StagedWasmEvaluator extends SAIOps {
2444 def module : ModuleInstance
@@ -365,7 +385,8 @@ trait StagedWasmEvaluator extends SAIOps {
365385 val newRestCtx = restCtx.shift(offset, funcTy.out.size)
366386 eval(rest, kont, mk, trail)(newRestCtx)
367387 })
368- ExploreTree .fillWithIfElse(symCond.s)
388+ val id = Counter .getId(inst)
389+ ExploreTree .fillWithIfElse(symCond.s, id)
369390 def thnK : Rep [Cont [Unit ]] = topFun((mk : Rep [MCont [Unit ]]) => {
370391 info(" Entering the true branch of the if" )
371392 eval(thn, restK _, mk, restK _ :: trail)(newCtx)
@@ -392,7 +413,8 @@ trait StagedWasmEvaluator extends SAIOps {
392413 val cond = Stack .popC(ty)
393414 val symCond = Stack .popS(ty)
394415 info(s " The br_if( ${label})'s condition is " , cond.toInt)
395- ExploreTree .fillWithIfElse(symCond.s)
416+ val id = Counter .getId(inst)
417+ ExploreTree .fillWithIfElse(symCond.s, id)
396418 def thnK : Rep [Cont [Unit ]] = topFun((mk : Rep [MCont [Unit ]]) => {
397419 trail(label)(newCtx)(mk)
398420 })
@@ -423,7 +445,8 @@ trait StagedWasmEvaluator extends SAIOps {
423445 val labelSym = Stack .peekS(ty)
424446 val cond = (label - toStagedNum(I32V (idx))).isZero()
425447 val condSym = (labelSym - toStagedSymbolicNum(I32V (idx))).isZero()
426- ExploreTree .fillWithIfElse(condSym.s)
448+ val id = Counter .getId(inst)
449+ ExploreTree .fillWithIfElse(condSym.s, id)
427450 // When moving the cursor to a branch, we mark another branch as
428451 // snapshotNode (this is done by moveCursor's runtime implementation)
429452 // TODO: store snapshot into this snapshot node
@@ -622,6 +645,7 @@ trait StagedWasmEvaluator extends SAIOps {
622645 }
623646
624647 def evalTop (mkont : Rep [MCont [Unit ]], main : Option [String ]): Rep [Unit ] = {
648+ Counter .reset()
625649 val funBody : FuncBodyDef = main match {
626650 case Some (func_name) =>
627651 module.defs.flatMap({
@@ -912,8 +936,8 @@ trait StagedWasmEvaluator extends SAIOps {
912936
913937 // Exploration tree,
914938 object ExploreTree {
915- def fillWithIfElse (s : Rep [SymVal ]): Rep [Unit ] = {
916- " tree-fill-if-else" .reflectCtrlWith[Unit ](s)
939+ def fillWithIfElse (s : Rep [SymVal ], id : Int ): Rep [Unit ] = {
940+ " tree-fill-if-else" .reflectCtrlWith[Unit ](s, id )
917941 }
918942
919943 def fillWithFinished (): Rep [Unit ] = {
@@ -1448,8 +1472,8 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
14481472 emit(" SymEnv.read(" ); shallow(sym); emit(" )" )
14491473 case Node (_, " assert-true" , List (cond), _) =>
14501474 emit(" GENSYM_ASSERT(" ); shallow(cond); emit(" )" )
1451- case Node (_, " tree-fill-if-else" , List (sym), _) =>
1452- emit(" ExploreTree.fillIfElseNode(" ); shallow(sym); emit(" )" )
1475+ case Node (_, " tree-fill-if-else" , List (sym, id ), _) =>
1476+ emit(" ExploreTree.fillIfElseNode(" ); shallow(sym); emit(" , " ); emit(id.toString); emit( " )" )
14531477 case Node (_, " tree-fill-finished" , List (), _) =>
14541478 emit(" ExploreTree.fillFinishedNode()" )
14551479 case Node (_, " tree-move-cursor" , List (b, snapshot), _) =>
@@ -1496,12 +1520,12 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
14961520 emitDatastructures(stream)
14971521 emitFunctions(stream)
14981522 emit(src)
1499- emitln("""
1523+ emitln(s """
15001524 |/*****************************************
15011525 |End of Generated Code
15021526 |*******************************************/
15031527 |int main(int argc, char *argv[]) {
1504- | start_concolic_execution_with(Snippet);
1528+ | start_concolic_execution_with(Snippet, ${ Counter .currentId} );
15051529 | return 0;
15061530 |} """ .stripMargin)
15071531 }
0 commit comments