Skip to content

Commit 51dd632

Browse files
redirect generated code to a file
1 parent 8e293b8 commit 51dd632

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/main/scala/wasm/StagedMiniWasm.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ object Main {
681681

682682

683683
object WasmToScalaCompiler {
684-
def apply(moduleInst: ModuleInstance, main: Option[String], printRes: Boolean = false): String = {
684+
def compile(moduleInst: ModuleInstance, main: Option[String], printRes: Boolean = false): String = {
685685
println(s"Now compiling wasm module with entry function $main")
686686
val code = new WasmToScalaCompilerDriver[Unit, Unit] {
687687
def module: ModuleInstance = moduleInst
@@ -1146,7 +1146,7 @@ trait WasmToCppCompilerDriver[A, B] extends CppSAIDriver[A, B] with StagedWasmEv
11461146
}
11471147

11481148
object WasmToCppCompiler {
1149-
def apply(moduleInst: ModuleInstance, main: Option[String], printRes: Boolean = false): String = {
1149+
def compile(moduleInst: ModuleInstance, main: Option[String], printRes: Boolean = false): String = {
11501150
println(s"Now compiling wasm module with entry function $main")
11511151
val code = new WasmToCppCompilerDriver[Unit, Unit] {
11521152
def module: ModuleInstance = moduleInst

src/test/scala/genwasym/TestStagedEval.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import gensym.wasm.miniwasm._
1010
class TestStagedEval extends FunSuite {
1111
def testFileToScala(filename: String, main: Option[String] = None, printRes: Boolean = false) = {
1212
val moduleInst = ModuleInstance(Parser.parseFile(filename))
13-
val code = WasmToScalaCompiler(moduleInst, main, true)
13+
val code = WasmToScalaCompiler.compile(moduleInst, main, true)
1414
println(code)
1515
}
1616

@@ -26,7 +26,15 @@ class TestStagedEval extends FunSuite {
2626

2727
def testFileToCpp(filename: String, main: Option[String] = None, printRes: Boolean = false) = {
2828
val moduleInst = ModuleInstance(Parser.parseFile(filename))
29-
val code = WasmToCppCompiler(moduleInst, main, true)
29+
val code = WasmToCppCompiler.compile(moduleInst, main, true)
30+
if (printRes) {
31+
val writer = new java.io.PrintWriter(new java.io.File(s"$filename.cpp"))
32+
try {
33+
writer.write(code)
34+
} finally {
35+
writer.close()
36+
}
37+
}
3038
println(code)
3139
}
3240

0 commit comments

Comments
 (0)