da7a248472c2 — Vesa Norilo 5 months ago
small modifications in kwasm driver
1 files changed, 12 insertions(+), 5 deletions(-)

M src/driver/kwasm.cpp
M src/driver/kwasm.cpp +12 -5
@@ 157,9 157,10 @@ public:
 	picojson::object errorMessage;
 
 	void Initialize() {
-		std::clog << "Kronos   [" KRONOS_PACKAGE_VERSION 
-			" (" KRONOS_CORE_LIBRARY_REPOSITORY " " KRONOS_CORE_LIBRARY_VERSION ")]\n";
-		std::clog << "Binaryen [" BINARYEN_VERSION "]\n";
+		std::clog << 
+		"Kronos   [" KRONOS_PACKAGE_VERSION "]\n"
+		"Library  [" KRONOS_CORE_LIBRARY_REPOSITORY " " KRONOS_CORE_LIBRARY_VERSION "]\n"
+		"Binaryen [" BINARYEN_VERSION "]\n";
 		cx = CreateContext(PathResolver, this);
 #ifndef NDEBUG
 		std::clog << "[ DEBUG MODE ]\n";

          
@@ 179,7 180,6 @@ public:
 					StreamBuf sbuf(sz.rdbuf());
 					ty->_GetFirst()->ToStream(sbuf, nullptr, IType::WithoutParens);
 					sz << "\"," << std::to_string(ty->SizeOf()) << "]}";
-					std::clog << sz.str();
 					self->specializationMonitor(sz.str());
 				}
 				return;

          
@@ 242,7 242,7 @@ public:
 	try_finally:
 		symbolChanges = MoveString(cx.DrainRecentSymbolChanges());
 		resolutionTrace = MoveString(cx.GetResolutionTrace());
-		std::clog << "Returning " << moduleBuffer.size() << " bytes\n";
+		std::clog << "Wasm blob is " << moduleBuffer.size() << " bytes\n";
 		return emscripten::val{ emscripten::typed_memory_view(moduleBuffer.size(), moduleBuffer.data()) };
 	}
 

          
@@ 300,6 300,12 @@ public:
 		}
 		return slurp.str();
 	}
+
+	int WriteFile(const std::string& path, const std::string& body) {
+		std::ofstream write{ path };
+		write << body;
+		return write.is_open();
+	}
 };
 
 using namespace emscripten;

          
@@ 309,6 315,7 @@ EMSCRIPTEN_BINDINGS(KronosWASM) {
 		.constructor<>()
 		.function("Initialize", &WasmCompiler::Initialize)
 		.function("Parse", &WasmCompiler::Parse)
+		.function("WriteFile", &WasmCompiler::WriteFile)
 		.function("SetSpecializationMonitor", &WasmCompiler::SetSpecializationMonitor)
 		.function("SetFetchFn", &WasmCompiler::SetFetchFn)
 		.function("GetSymbolChanges", &WasmCompiler::GetSymbolChanges)