[WASM] Wrap generated code in a module instruction.
This is in preparation to switch to binaryen. Even if module is optional in the WASM text format, binaryen only implements a subset of the spec and requires the module declaration.
@@ -61,12 +61,15 @@ public class WasmModuleGenerator {
public void generateOutputs(List<CompilationUnit> compilationUnits) {
environment = new GenerationEnvironment(compilationUnits);
- builder.append(";;; Code generated by J2WASM");
+ builder.appendln(";;; Code generated by J2WASM");
+ builder.append("(module");
emitRttHierarchy(compilationUnits);
emitGlobals(compilationUnits);
emitDynamicDispatchMethodTypes(compilationUnits);
emitTypes(compilationUnits);
emitRuntimeInitialization(compilationUnits);
+ builder.newLine();
+ builder.append(")");
OutputUtils.writeToFile(outputPath.resolve("module.wat"), builder.build(), problems);
if (!pendingEntryPoints.isEmpty()) {
problems.error("Entry points %s not found.", pendingEntryPoints);
