Skip to content

Commit 8739369

Browse files
dump graphviz by default
1 parent 314ff5f commit 8739369

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

headers/wasm/symbolic_rt.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "concrete_rt.hpp"
55
#include <cassert>
66
#include <cstdio>
7+
#include <fstream>
78
#include <iterator>
89
#include <memory>
910
#include <ostream>
@@ -324,6 +325,15 @@ class ExploreTree_t {
324325
return std::monostate();
325326
}
326327

328+
std::monostate dump_graphviz(std::string filepath) {
329+
std::ofstream ofs(filepath);
330+
if (!ofs.is_open()) {
331+
throw std::runtime_error("Failed to open explore_tree.dot for writing");
332+
}
333+
to_graphviz(ofs);
334+
return std::monostate();
335+
}
336+
327337
private:
328338
std::unique_ptr<NodeBox> root;
329339
NodeBox *cursor;

src/main/scala/wasm/StagedConcolicMiniWasm.scala

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
10331042
object 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))

src/test/scala/genwasym/TestStagedConcolicEval.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class TestStagedConcolicEval extends FunSuite {
1313
val moduleInst = ModuleInstance(Parser.parseFile(filename))
1414
val cppFile = s"$filename.cpp"
1515
val exe = s"$cppFile.exe"
16-
WasmToCppCompiler.compileToExe(moduleInst, main, cppFile, exe, true)
16+
val exploreTreeFile = s"$filename.tree.dot"
17+
WasmToCppCompiler.compileToExe(moduleInst, main, cppFile, exe, true, Some(exploreTreeFile))
1718

1819
import sys.process._
1920
val result = s"./$exe".!!

0 commit comments

Comments
 (0)