@@ -88,27 +88,38 @@ trait StagedWasmEvaluator extends SAIOps {
88
88
// no need to modify the stack when entering a block
89
89
// the type system guarantees that we will never take more than the input size from the stack
90
90
val funcTy = ty.funcType
91
+ val dummy = " dummy" .reflectCtrlWith[Unit ]()
91
92
// TODO: somehow the type of exitSize in residual program is nothing
92
93
def restK : Rep [Cont [Unit ]] = fun((_ : Rep [Unit ]) => {
94
+ info(s " Exiting the block, stackSize = " , Stack .size)
95
+ " dummy-op" .reflectCtrlWith[Unit ](dummy)
93
96
eval(rest, kont, trail)
94
97
})
95
98
eval(inner, restK, restK :: trail)
96
99
case Loop (ty, inner) =>
97
100
val funcTy = ty.funcType
98
101
val exitSize = Stack .size - funcTy.inps.size + funcTy.out.size
102
+ val dummy = " dummy" .reflectCtrlWith[Unit ]()
99
103
def restK = fun((_ : Rep [Unit ]) => {
104
+ " dummy-op" .reflectCtrlWith[Unit ](dummy)
105
+ info(s " Exiting the loop, stackSize = " , Stack .size)
100
106
eval(rest, kont, trail)
101
107
})
102
108
def loop : Rep [Unit => Unit ] = fun((_u : Rep [Unit ]) => {
109
+ " dummy-op" .reflectCtrlWith[Unit ](dummy)
110
+ info(s " Entered the loop, stackSize = " , Stack .size)
103
111
eval(inner, restK, loop :: trail)
104
112
})
105
113
loop(())
106
114
case If (ty, thn, els) =>
107
115
val funcTy = ty.funcType
108
116
val exitSize = Stack .size - funcTy.inps.size + funcTy.out.size
109
117
val cond = Stack .pop()
118
+ val dummy = " dummy" .reflectCtrlWith[Unit ]()
110
119
// TODO: can we avoid code duplication here?
111
120
def restK = fun((_ : Rep [Unit ]) => {
121
+ " dummy-op" .reflectCtrlWith[Unit ](dummy)
122
+ info(s " Exiting the if, stackSize = " , Stack .size)
112
123
eval(rest, kont, trail)
113
124
})
114
125
if (cond != Values .I32 (0 )) {
@@ -121,7 +132,7 @@ trait StagedWasmEvaluator extends SAIOps {
121
132
trail(label)(())
122
133
case BrIf (label) =>
123
134
val cond = Stack .pop()
124
- info(s " The br_if( ${label})'s condition is " , cond)
135
+ info(s " The br_if( ${label})'s condition is " , cond.toInt )
125
136
if (cond != Values .I32 (0 )) {
126
137
info(s " Jump to $label" )
127
138
trail(label)(())
@@ -157,14 +168,14 @@ trait StagedWasmEvaluator extends SAIOps {
157
168
case FuncDef (_, FuncBodyDef (ty, _, locals, body)) =>
158
169
val returnSize = Stack .size - ty.inps.size + ty.out.size
159
170
val args = Stack .take(ty.inps.size)
160
- info(" New frame:" , Frames .top)
171
+ // info("New frame:", Frames.top)
161
172
val callee =
162
173
if (compileCache.contains(funcIndex)) {
163
174
compileCache(funcIndex)
164
175
} else {
165
176
val callee = topFun(
166
177
(kont : Rep [Cont [Unit ]]) => {
167
- info(s " Entered the function at $funcIndex, stackSize = " , Stack .size, " , frame = " , Frames .top )
178
+ info(s " Entered the function at $funcIndex, stackSize = " , Stack .size)
168
179
eval(body, kont, kont:: Nil ): Rep [Unit ]
169
180
}
170
181
)
@@ -180,6 +191,7 @@ trait StagedWasmEvaluator extends SAIOps {
180
191
callee(trail.last)
181
192
} else {
182
193
val restK : Rep [Cont [Unit ]] = fun((_ : Rep [Unit ]) => {
194
+ info(s " Exiting the function at $funcIndex, stackSize = " , Stack .size)
183
195
Frames .popFrame()
184
196
eval(rest, kont, trail)
185
197
})
@@ -269,6 +281,7 @@ trait StagedWasmEvaluator extends SAIOps {
269
281
270
282
def evalTop (main : Option [String ], printRes : Boolean = false ): Rep [Unit ] = {
271
283
val haltK : Rep [Unit ] => Rep [Unit ] = (_) => {
284
+ info(" Exiting the program..." )
272
285
if (printRes) {
273
286
Stack .print()
274
287
}
@@ -773,6 +786,8 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
773
786
shallow(lhs); emit(" >= " ); shallow(rhs)
774
787
case Node (_, " num-to-int" , List (num), _) =>
775
788
shallow(num); emit(" .toInt()" )
789
+ case Node (_, " dummy" , _, _) => emit(" std::monostate()" )
790
+ case Node (_, " dummy-op" , _, _) => emit(" std::monostate()" )
776
791
case Node (_, " no-op" , _, _) =>
777
792
emit(" std::monostate()" )
778
793
case _ => super .shallow(n)
@@ -833,7 +848,19 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
833
848
#include <variant>
834
849
#include <vector>
835
850
836
- #define info(x, ...)
851
+ void info() {
852
+ #ifdef DEBUG
853
+ std::cout << std::endl;
854
+ #endif
855
+ }
856
+
857
+ template <typename T, typename... Args>
858
+ void info(const T &first, const Args &...args) {
859
+ #ifdef DEBUG
860
+ std::cout << first << " ";
861
+ info(args...);
862
+ #endif
863
+ }
837
864
838
865
class Num_t {
839
866
public:
0 commit comments