@@ -57,6 +57,15 @@ trait StagedWasmEvaluator extends SAIOps {
57
57
case NumType (F32Type ) => 4
58
58
case NumType (F64Type ) => 8
59
59
}
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
+ }
60
69
}
61
70
62
71
case class Context (
@@ -121,6 +130,14 @@ trait StagedWasmEvaluator extends SAIOps {
121
130
case WasmConst (num) =>
122
131
val newCtx = Stack .push(toStagedNum(num))
123
132
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)
124
141
case LocalGet (i) =>
125
142
val newCtx = Stack .push(Frames .get(i))
126
143
eval(rest, kont, mkont, trail)(newCtx)
@@ -326,6 +343,10 @@ trait StagedWasmEvaluator extends SAIOps {
326
343
val (v, newCtx) = Stack .pop()
327
344
println(v.toInt)
328
345
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)
329
350
case Import (_, _, _) => throw new Exception (s " Unknown import at $funcIndex" )
330
351
case _ => throw new Exception (s " Definition at $funcIndex is not callable " )
331
352
}
@@ -414,6 +435,10 @@ trait StagedWasmEvaluator extends SAIOps {
414
435
evalTop(temp, main)
415
436
}
416
437
438
+ def runtimeAssert (b : Rep [Boolean ]): Rep [Unit ] = {
439
+ " assert-true" .reflectCtrlWith[Unit ](b)
440
+ }
441
+
417
442
// stack operations
418
443
object Stack {
419
444
def shift (offset : Int , size : Int )(ctx : Context ): Context = {
@@ -598,6 +623,12 @@ trait StagedWasmEvaluator extends SAIOps {
598
623
}
599
624
}
600
625
626
+ object SymEnv {
627
+ def read (sym : Rep [SymVal ]): Rep [Num ] = {
628
+ " sym-env-read" .reflectCtrlWith[Num ](sym)
629
+ }
630
+ }
631
+
601
632
// runtime Num type
602
633
implicit class StagedNumOps (num : StagedNum ) {
603
634
@@ -622,6 +653,10 @@ trait StagedWasmEvaluator extends SAIOps {
622
653
case I64 (x_c, x_s) => I64 (" popcnt" .reflectCtrlWith[Num ](x_c), " sym-popcnt" .reflectCtrlWith[SymVal ](x_s))
623
654
}
624
655
656
+ def makeSymbolic (): Rep [SymVal ] = {
657
+ " make-symbolic" .reflectCtrlWith[SymVal ](num.s)
658
+ }
659
+
625
660
def + (rhs : StagedNum ): StagedNum = {
626
661
(num, rhs) match {
627
662
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 {
778
813
override def mayInline (n : Node ): Boolean = n match {
779
814
case Node (_, " stack-pop" , _, _)
780
815
| Node (_, " stack-peek" , _, _)
816
+ | Node (_, " sym-stack-pop" , _, _)
781
817
=> false
782
818
case _ => super .mayInline(n)
783
819
}
@@ -874,8 +910,6 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
874
910
shallow(s_num); emit(" .is_zero()" )
875
911
case Node (_, " binary-add" , List (lhs, rhs), _) =>
876
912
shallow(lhs); emit(" + " ); shallow(rhs)
877
- case Node (_, " sym-binary-add" , List (lhs, rhs), _) =>
878
- shallow(lhs); emit(" + " ); shallow(rhs)
879
913
case Node (_, " binary-sub" , List (lhs, rhs), _) =>
880
914
shallow(lhs); emit(" - " ); shallow(rhs)
881
915
case Node (_, " binary-mul" , List (lhs, rhs), _) =>
@@ -908,8 +942,32 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
908
942
shallow(lhs); emit(" >= " ); shallow(rhs)
909
943
case Node (_, " relation-geu" , List (lhs, rhs), _) =>
910
944
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(" )" )
911
963
case Node (_, " num-to-int" , List (num), _) =>
912
964
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(" )" )
913
971
case Node (_, " tree-fill-if-else" , List (s), _) =>
914
972
emit(" ExploreTree.fillIfElseNode(" ); shallow(s); emit(" )" )
915
973
case Node (_, " tree-move-cursor" , List (b), _) =>
0 commit comments