@@ -422,12 +422,15 @@ trait StagedWasmEvaluator extends SAIOps {
422422 Frames .popFrame(locals.size)
423423 }
424424
425- def evalTop (main : Option [String ], printRes : Boolean = false ): Rep [Unit ] = {
425+ def evalTop (main : Option [String ], printRes : Boolean , dumpTree : Option [ String ] ): Rep [Unit ] = {
426426 val haltK : Rep [Unit ] => Rep [Unit ] = (_) => {
427427 info(" Exiting the program..." )
428428 if (printRes) {
429429 Stack .print()
430- ExploreTree .print()
430+ }
431+ dumpTree match {
432+ case Some (filePath) => ExploreTree .dumpGraphiviz(filePath)
433+ case None => ()
431434 }
432435 " no-op" .reflectCtrlWith[Unit ]()
433436 }
@@ -621,6 +624,10 @@ trait StagedWasmEvaluator extends SAIOps {
621624 def print (): Rep [Unit ] = {
622625 " tree-print" .reflectCtrlWith[Unit ]()
623626 }
627+
628+ def dumpGraphiviz (filePath : String ): Rep [Unit ] = {
629+ " tree-dump-graphviz" .reflectCtrlWith[Unit ](filePath)
630+ }
624631 }
625632
626633 object SymEnv {
@@ -974,6 +981,8 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
974981 emit(" ExploreTree.moveCursor(" ); shallow(b); emit(" )" )
975982 case Node (_, " tree-print" , List (), _) =>
976983 emit(" ExploreTree.print()" )
984+ case Node (_, " tree-dump-graphviz" , List (f), _) =>
985+ emit(" ExploreTree.dump_graphviz(" ); shallow(f); emit(" )" )
977986 case Node (_, " sym-not" , List (s), _) =>
978987 shallow(s); emit(" .negate()" )
979988 case Node (_, " dummy" , _, _) => emit(" std::monostate()" )
@@ -1033,12 +1042,12 @@ trait WasmToCppCompilerDriver[A, B] extends CppSAIDriver[A, B] with StagedWasmEv
10331042object WasmToCppCompiler {
10341043 case class GeneratedCpp (source : String , headerFolders : List [String ])
10351044
1036- def compile (moduleInst : ModuleInstance , main : Option [String ], printRes : Boolean = false ): GeneratedCpp = {
1045+ def compile (moduleInst : ModuleInstance , main : Option [String ], printRes : Boolean , dumpTree : Option [ String ] ): GeneratedCpp = {
10371046 println(s " Now compiling wasm module with entry function $main" )
10381047 val driver = new WasmToCppCompilerDriver [Unit , Unit ] {
10391048 def module : ModuleInstance = moduleInst
10401049 def snippet (x : Rep [Unit ]): Rep [Unit ] = {
1041- evalTop(main, printRes)
1050+ evalTop(main, printRes, dumpTree )
10421051 }
10431052 }
10441053 GeneratedCpp (driver.code, driver.codegen.includePaths.toList)
@@ -1048,8 +1057,9 @@ object WasmToCppCompiler {
10481057 main : Option [String ],
10491058 outputCpp : String ,
10501059 outputExe : String ,
1051- printRes : Boolean = false ): Unit = {
1052- val generated = compile(moduleInst, main, printRes)
1060+ printRes : Boolean ,
1061+ dumpTree : Option [String ]): Unit = {
1062+ val generated = compile(moduleInst, main, printRes, dumpTree)
10531063 val code = generated.source
10541064
10551065 val writer = new java.io.PrintWriter (new java.io.File (outputCpp))
0 commit comments