summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/wasm-emscripten-finalize.cpp15
-rw-r--r--test/lld/em_asm.wast.mem.mem (renamed from test/lld/hello_world.wast.mem)bin581 -> 652 bytes
-rw-r--r--test/lld/em_asm.wast.mem.out117
3 files changed, 126 insertions, 6 deletions
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp
index d0b664c0c..f2c74221d 100644
--- a/src/tools/wasm-emscripten-finalize.cpp
+++ b/src/tools/wasm-emscripten-finalize.cpp
@@ -204,12 +204,8 @@ int main(int argc, const char *argv[]) {
generator.generateDynCallThunks();
generator.generateJSCallThunks(numReservedFunctionPointers);
- if (!dataSegmentFile.empty()) {
- Output memInitFile(dataSegmentFile, Flags::Binary, Flags::Release);
- generator.separateDataSegments(&memInitFile);
- }
- // Finally, legalize the wasm.
+ // Legalize the wasm.
{
PassRunner passRunner(&wasm);
passRunner.setDebug(options.debug);
@@ -221,9 +217,16 @@ int main(int argc, const char *argv[]) {
passRunner.run();
}
- // All changes to the wasm are done, create the metadata.
+ // Substantial changes to the wasm are done, enough to create the metadata.
std::string metadata = generator.generateEmscriptenMetadata(dataSize, initializerFunctions, numReservedFunctionPointers);
+ // Finally, separate out data segments if relevant (they may have been needed
+ // for metadata).
+ if (!dataSegmentFile.empty()) {
+ Output memInitFile(dataSegmentFile, Flags::Binary, Flags::Release);
+ generator.separateDataSegments(&memInitFile);
+ }
+
if (options.debug) {
std::cerr << "Module after:\n";
WasmPrinter::printModule(&wasm, std::cerr);
diff --git a/test/lld/hello_world.wast.mem b/test/lld/em_asm.wast.mem.mem
index 674c410a9..1e5476727 100644
--- a/test/lld/hello_world.wast.mem
+++ b/test/lld/em_asm.wast.mem.mem
Binary files differ
diff --git a/test/lld/em_asm.wast.mem.out b/test/lld/em_asm.wast.mem.out
new file mode 100644
index 000000000..e7c680764
--- /dev/null
+++ b/test/lld/em_asm.wast.mem.out
@@ -0,0 +1,117 @@
+(module
+ (type $0 (func (param i32) (result i32)))
+ (type $1 (func (param i32 i32 i32) (result i32)))
+ (type $2 (func (param i32 i32) (result i32)))
+ (type $3 (func (result i32)))
+ (type $4 (func))
+ (type $FUNCSIG$ii (func (param i32) (result i32)))
+ (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32)))
+ (type $FUNCSIG$iii (func (param i32 i32) (result i32)))
+ (import "env" "emscripten_asm_const_i" (func $emscripten_asm_const_i (param i32) (result i32)))
+ (import "env" "emscripten_asm_const_iii" (func $emscripten_asm_const_iii (param i32 i32 i32) (result i32)))
+ (import "env" "emscripten_asm_const_ii" (func $emscripten_asm_const_ii (param i32 i32) (result i32)))
+ (memory $0 2)
+ (table $0 1 1 funcref)
+ (global $global$0 (mut i32) (i32.const 16384))
+ (global $global$1 i32 (i32.const 66192))
+ (global $global$2 i32 (i32.const 652))
+ (export "memory" (memory $0))
+ (export "__post_instantiate" (func $__wasm_call_ctors))
+ (export "main" (func $main))
+ (export "__heap_base" (global $global$1))
+ (export "__data_end" (global $global$2))
+ (export "stackSave" (func $stackSave))
+ (export "stackAlloc" (func $stackAlloc))
+ (export "stackRestore" (func $stackRestore))
+ (export "__growWasmMemory" (func $__growWasmMemory))
+ (func $main (; 3 ;) (type $3) (result i32)
+ (drop
+ (call $emscripten_asm_const_i
+ (i32.const 0)
+ )
+ )
+ (drop
+ (call $emscripten_asm_const_ii
+ (i32.const 2)
+ (call $emscripten_asm_const_iii
+ (i32.const 1)
+ (i32.const 13)
+ (i32.const 27)
+ )
+ )
+ )
+ (i32.const 0)
+ )
+ (func $__wasm_call_ctors (; 4 ;) (type $4)
+ (nop)
+ )
+ (func $stackSave (; 5 ;) (result i32)
+ (global.get $global$0)
+ )
+ (func $stackAlloc (; 6 ;) (param $0 i32) (result i32)
+ (local $1 i32)
+ (global.set $global$0
+ (local.tee $1
+ (i32.and
+ (i32.sub
+ (global.get $global$0)
+ (local.get $0)
+ )
+ (i32.const -16)
+ )
+ )
+ )
+ (local.get $1)
+ )
+ (func $stackRestore (; 7 ;) (param $0 i32)
+ (global.set $global$0
+ (local.get $0)
+ )
+ )
+ (func $__growWasmMemory (; 8 ;) (param $newSize i32) (result i32)
+ (grow_memory
+ (local.get $newSize)
+ )
+ )
+)
+(;
+--BEGIN METADATA --
+{
+ "asmConsts": {
+ "2": ["{ Module.print(\"Got \" + $0); }", ["ii"], [""]],
+ "0": ["{ Module.print(\"Hello world\"); }", ["i"], [""]],
+ "1": ["{ return $0 + $1; }", ["iii"], [""]]
+ },
+ "staticBump": 84,
+ "tableSize": 1,
+ "initializers": [
+ "__post_instantiate"
+ ],
+ "declares": [
+ ],
+ "externs": [
+ ],
+ "implementedFunctions": [
+ "___post_instantiate",
+ "_main",
+ "_stackSave",
+ "_stackAlloc",
+ "_stackRestore",
+ "___growWasmMemory"
+ ],
+ "exports": [
+ "memory",
+ "__post_instantiate",
+ "main",
+ "__heap_base",
+ "__data_end",
+ "stackSave",
+ "stackAlloc",
+ "stackRestore",
+ "__growWasmMemory"
+ ],
+ "invokeFuncs": [
+ ]
+}
+-- END METADATA --
+;)