@@ -57,6 +57,15 @@ trait StagedWasmEvaluator extends SAIOps {
5757 case NumType (F32Type ) => 4
5858 case NumType (F64Type ) => 8
5959 }
60+
61+ def toTagger : (Rep [Num ], Rep [SymVal ]) => StagedNum = {
62+ ty match {
63+ case NumType (I32Type ) => I32
64+ case NumType (I64Type ) => I64
65+ case NumType (F32Type ) => F32
66+ case NumType (F64Type ) => F64
67+ }
68+ }
6069 }
6170
6271 case class Context (
@@ -121,6 +130,14 @@ trait StagedWasmEvaluator extends SAIOps {
121130 case WasmConst (num) =>
122131 val newCtx = Stack .push(toStagedNum(num))
123132 eval(rest, kont, mkont, trail)(newCtx)
133+ case Symbolic (ty) =>
134+ val (id, newCtx1) = Stack .pop()
135+ val symVal = id.makeSymbolic()
136+ val concVal = SymEnv .read(symVal)
137+ val tagger = ty.toTagger
138+ val value = tagger(concVal, symVal)
139+ val newCtx2 = Stack .push(value)(newCtx1)
140+ eval(rest, kont, mkont, trail)(newCtx2)
124141 case LocalGet (i) =>
125142 val newCtx = Stack .push(Frames .get(i))
126143 eval(rest, kont, mkont, trail)(newCtx)
@@ -326,6 +343,10 @@ trait StagedWasmEvaluator extends SAIOps {
326343 val (v, newCtx) = Stack .pop()
327344 println(v.toInt)
328345 eval(rest, kont, mkont, trail)(newCtx)
346+ case Import (" console" , " assert" , _) =>
347+ val (v, newCtx) = Stack .pop()
348+ runtimeAssert(v.toInt != 0 )
349+ eval(rest, kont, mkont, trail)(newCtx)
329350 case Import (_, _, _) => throw new Exception (s " Unknown import at $funcIndex" )
330351 case _ => throw new Exception (s " Definition at $funcIndex is not callable " )
331352 }
@@ -414,6 +435,10 @@ trait StagedWasmEvaluator extends SAIOps {
414435 evalTop(temp, main)
415436 }
416437
438+ def runtimeAssert (b : Rep [Boolean ]): Rep [Unit ] = {
439+ " assert-true" .reflectCtrlWith[Unit ](b)
440+ }
441+
417442 // stack operations
418443 object Stack {
419444 def shift (offset : Int , size : Int )(ctx : Context ): Context = {
@@ -598,6 +623,12 @@ trait StagedWasmEvaluator extends SAIOps {
598623 }
599624 }
600625
626+ object SymEnv {
627+ def read (sym : Rep [SymVal ]): Rep [Num ] = {
628+ " sym-env-read" .reflectCtrlWith[Num ](sym)
629+ }
630+ }
631+
601632 // runtime Num type
602633 implicit class StagedNumOps (num : StagedNum ) {
603634
@@ -622,6 +653,10 @@ trait StagedWasmEvaluator extends SAIOps {
622653 case I64 (x_c, x_s) => I64 (" popcnt" .reflectCtrlWith[Num ](x_c), " sym-popcnt" .reflectCtrlWith[SymVal ](x_s))
623654 }
624655
656+ def makeSymbolic (): Rep [SymVal ] = {
657+ " make-symbolic" .reflectCtrlWith[SymVal ](num.s)
658+ }
659+
625660 def + (rhs : StagedNum ): StagedNum = {
626661 (num, rhs) match {
627662 case (I32 (x_c, x_s), I32 (y_c, y_s)) => I32 (" binary-add" .reflectCtrlWith[Num ](x_c, y_c), " sym-binary-add" .reflectCtrlWith[SymVal ](x_s, y_s))
@@ -778,6 +813,7 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
778813 override def mayInline (n : Node ): Boolean = n match {
779814 case Node (_, " stack-pop" , _, _)
780815 | Node (_, " stack-peek" , _, _)
816+ | Node (_, " sym-stack-pop" , _, _)
781817 => false
782818 case _ => super .mayInline(n)
783819 }
@@ -874,8 +910,6 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
874910 shallow(s_num); emit(" .is_zero()" )
875911 case Node (_, " binary-add" , List (lhs, rhs), _) =>
876912 shallow(lhs); emit(" + " ); shallow(rhs)
877- case Node (_, " sym-binary-add" , List (lhs, rhs), _) =>
878- shallow(lhs); emit(" + " ); shallow(rhs)
879913 case Node (_, " binary-sub" , List (lhs, rhs), _) =>
880914 shallow(lhs); emit(" - " ); shallow(rhs)
881915 case Node (_, " binary-mul" , List (lhs, rhs), _) =>
@@ -908,8 +942,32 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
908942 shallow(lhs); emit(" >= " ); shallow(rhs)
909943 case Node (_, " relation-geu" , List (lhs, rhs), _) =>
910944 shallow(lhs); emit(" >= " ); shallow(rhs)
945+ case Node (_, " sym-binary-add" , List (lhs, rhs), _) =>
946+ shallow(lhs); emit(" .add(" ); shallow(rhs); emit(" )" )
947+ case Node (_, " sym-binary-mul" , List (lhs, rhs), _) =>
948+ shallow(lhs); emit(" .mul(" ); shallow(rhs); emit(" )" )
949+ case Node (_, " sym-binary-div" , List (lhs, rhs), _) =>
950+ shallow(lhs); emit(" .div(" ); shallow(rhs); emit(" )" )
951+ case Node (_, " sym-relation-le" , List (lhs, rhs), _) =>
952+ shallow(lhs); emit(" .leq(" ); shallow(rhs); emit(" )" )
953+ case Node (_, " sym-relation-leu" , List (lhs, rhs), _) =>
954+ shallow(lhs); emit(" .leu(" ); shallow(rhs); emit(" )" )
955+ case Node (_, " sym-relation-ge" , List (lhs, rhs), _) =>
956+ shallow(lhs); emit(" .ge(" ); shallow(rhs); emit(" )" )
957+ case Node (_, " sym-relation-geu" , List (lhs, rhs), _) =>
958+ shallow(lhs); emit(" .geu(" ); shallow(rhs); emit(" )" )
959+ case Node (_, " sym-relation-eq" , List (lhs, rhs), _) =>
960+ shallow(lhs); emit(" .eq(" ); shallow(rhs); emit(" )" )
961+ case Node (_, " sym-relation-ne" , List (lhs, rhs), _) =>
962+ shallow(lhs); emit(" .neq(" ); shallow(rhs); emit(" )" )
911963 case Node (_, " num-to-int" , List (num), _) =>
912964 shallow(num); emit(" .toInt()" )
965+ case Node (_, " make-symbolic" , List (num), _) =>
966+ shallow(num); emit(" .makeSymbolic()" )
967+ case Node (_, " sym-env-read" , List (sym), _) =>
968+ emit(" SymEnv.read(" ); shallow(sym); emit(" )" )
969+ case Node (_, " assert-true" , List (cond), _) =>
970+ emit(" assert(" ); shallow(cond); emit(" )" )
913971 case Node (_, " tree-fill-if-else" , List (s), _) =>
914972 emit(" ExploreTree.fillIfElseNode(" ); shallow(s); emit(" )" )
915973 case Node (_, " tree-move-cursor" , List (b), _) =>
0 commit comments