diff options
-rwxr-xr-x | auto_update_tests.py | 2 | ||||
-rw-r--r-- | src/tools/wasm-emscripten-finalize.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 116 | ||||
-rw-r--r-- | test/lld/duplicate_imports.wast.out | 38 | ||||
-rw-r--r-- | test/lld/em_asm.wast.out | 41 | ||||
-rw-r--r-- | test/lld/em_asm_table.wast.out | 32 | ||||
-rw-r--r-- | test/lld/hello_world.wast.mem.out | 37 | ||||
-rw-r--r-- | test/lld/hello_world.wast.out | 37 | ||||
-rw-r--r-- | test/lld/init.wast.out | 36 | ||||
-rw-r--r-- | test/lld/recursive.wast.out | 37 | ||||
-rw-r--r-- | test/lld/reserved_func_ptr.wast.jscall.out | 48 | ||||
-rw-r--r-- | test/lld/reserved_func_ptr.wast.out | 39 |
12 files changed, 400 insertions, 67 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py index 9d156472c..5134f89c5 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -421,8 +421,8 @@ def update_reduce_tests(): def main(): - update_asm_js_tests() update_lld_tests() + return update_wasm_opt_tests() update_bin_fmt_tests() update_example_tests() diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp index 6b13bd5ce..d477061ae 100644 --- a/src/tools/wasm-emscripten-finalize.cpp +++ b/src/tools/wasm-emscripten-finalize.cpp @@ -222,7 +222,9 @@ int main(int argc, const char *argv[]) { if (emitBinary) { std::cout << metadata; } else { - output << ";; METADATA: " << metadata; + output << "(;\n"; + output << "--BEGIN METADATA --\n" << metadata << "-- END METADATA --\n"; + output << ";)\n"; } return 0; diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index a43fc1fe7..92a11b8f1 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -755,73 +755,76 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata( Address staticBump, std::vector<Name> const& initializerFunctions, unsigned numReservedFunctionPointers) { bool commaFirst; - auto maybeComma = [&commaFirst]() { + auto nextElement = [&commaFirst]() { if (commaFirst) { commaFirst = false; - return ""; + return "\n "; } else { - return ","; + return ",\n "; } }; std::stringstream meta; - meta << "{ "; + meta << "{\n"; AsmConstWalker emAsmWalker = fixEmAsmConstsAndReturnWalker(wasm); // print commaFirst = true; - meta << "\"asmConsts\": {"; - for (auto& pair : emAsmWalker.sigsForCode) { - auto& code = pair.first; - auto& sigs = pair.second; - meta << maybeComma(); - meta << '"' << emAsmWalker.ids[code] << "\": [\"" << code << "\", "; - printSet(meta, sigs); - meta << ", "; + if (!emAsmWalker.sigsForCode.empty()) { + meta << " \"asmConsts\": {"; + for (auto& pair : emAsmWalker.sigsForCode) { + auto& code = pair.first; + auto& sigs = pair.second; + meta << nextElement(); + meta << '"' << emAsmWalker.ids[code] << "\": [\"" << code << "\", "; + printSet(meta, sigs); + meta << ", "; - // TODO: proxying to main thread. Currently this is unsupported, so proxy - // mode is "none", represented by an empty string. - meta << "[\"\"]"; + // TODO: proxying to main thread. Currently this is unsupported, so proxy + // mode is "none", represented by an empty string. + meta << "[\"\"]"; - meta << "]"; + meta << "]"; + } + meta << "\n },\n"; } - meta << "},"; EmJsWalker emJsWalker = fixEmJsFuncsAndReturnWalker(wasm); - if (emJsWalker.codeByName.size() > 0) { - meta << "\"emJsFuncs\": {"; + if (!emJsWalker.codeByName.empty()) { + meta << "\" emJsFuncs\": {"; commaFirst = true; for (auto& pair : emJsWalker.codeByName) { auto& name = pair.first; auto& code = pair.second; - meta << maybeComma(); + meta << nextElement(); meta << '"' << name << "\": \"" << code << '"'; } - meta << "},"; + meta << "\n },\n"; } - meta << "\"staticBump\": " << staticBump << ", "; + meta << " \"staticBump\": " << staticBump << ",\n"; - meta << "\"initializers\": ["; - commaFirst = true; - for (const auto& func : initializerFunctions) { - meta << maybeComma(); - meta << "\"" << func.c_str() << "\""; + if (!initializerFunctions.empty()) { + meta << " \"initializers\": ["; + commaFirst = true; + for (const auto& func : initializerFunctions) { + meta << nextElement(); + meta << "\"" << func.c_str() << "\""; + } + meta << "\n ],\n"; } - meta << "]"; if (numReservedFunctionPointers) { JSCallWalker jsCallWalker = getJSCallWalker(wasm); - meta << ", "; - meta << "\"jsCallStartIndex\": " << jsCallWalker.jsCallStartIndex << ", "; - meta << "\"jsCallFuncType\": ["; + meta << " \"jsCallStartIndex\": " << jsCallWalker.jsCallStartIndex << ",\n"; + meta << " \"jsCallFuncType\": ["; commaFirst = true; for (std::string sig : jsCallWalker.indirectlyCallableSigs) { - meta << maybeComma(); + meta << nextElement(); meta << "\"" << sig << "\""; } - meta << "]"; + meta << "\n ],\n"; } // Avoid adding duplicate imports to `declares' or `invokeFuncs`. Even @@ -833,7 +836,7 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata( // We use the `base` rather than the `name` of the imports here and below // becasue this is the externally visible name that the embedder (JS) will // see. - meta << ", \"declares\": ["; + meta << " \"declares\": ["; commaFirst = true; ModuleUtils::iterImportedFunctions(wasm, [&](Function* import) { if (emJsWalker.codeByName.count(import->base.str) == 0 && @@ -841,47 +844,48 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata( !import->base.startsWith("invoke_") && !import->base.startsWith("jsCall_")) { if (declares.insert(import->base.str).second) { - meta << maybeComma() << '"' << import->base.str << '"'; + meta << nextElement() << '"' << import->base.str << '"'; } } }); - meta << "]"; + meta << "\n ],\n"; - meta << ", \"externs\": ["; + meta << " \"externs\": ["; commaFirst = true; ModuleUtils::iterImportedGlobals(wasm, [&](Global* import) { - meta << maybeComma() << "\"_" << import->base.str << '"'; + meta << nextElement() << "\"_" << import->base.str << '"'; }); - meta << "]"; + meta << "\n ],\n"; - meta << ", \"implementedFunctions\": ["; - commaFirst = true; - for (const auto& ex : wasm.exports) { - if (ex->kind == ExternalKind::Function) { - meta << maybeComma() << "\"_" << ex->name.str << '"'; + if (!wasm.exports.empty()) { + meta << " \"implementedFunctions\": ["; + commaFirst = true; + for (const auto& ex : wasm.exports) { + if (ex->kind == ExternalKind::Function) { + meta << nextElement() << "\"_" << ex->name.str << '"'; + } } - } - meta << "]"; + meta << "\n ],\n"; - meta << ", \"exports\": ["; - commaFirst = true; - for (const auto& ex : wasm.exports) { - meta << maybeComma() << '"' << ex->name.str << '"'; + meta << " \"exports\": ["; + commaFirst = true; + for (const auto& ex : wasm.exports) { + meta << nextElement() << '"' << ex->name.str << '"'; + } + meta << "\n ],\n"; } - meta << "]"; - meta << ", \"invokeFuncs\": ["; + meta << " \"invokeFuncs\": ["; commaFirst = true; ModuleUtils::iterImportedFunctions(wasm, [&](Function* import) { if (import->base.startsWith("invoke_")) { if (invokeFuncs.insert(import->base.str).second) { - meta << maybeComma() << '"' << import->base.str << '"'; + meta << nextElement() << '"' << import->base.str << '"'; } } }); - meta << "]"; - - meta << " }\n"; + meta << "\n ]\n"; + meta << "}\n"; return meta.str(); } diff --git a/test/lld/duplicate_imports.wast.out b/test/lld/duplicate_imports.wast.out index 996a419fa..3edf1a8a7 100644 --- a/test/lld/duplicate_imports.wast.out +++ b/test/lld/duplicate_imports.wast.out @@ -101,4 +101,40 @@ ) ) ) -;; METADATA: { "asmConsts": {},"staticBump": 13, "initializers": ["__post_instantiate"], "declares": ["puts"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": ["invoke_ffd"] } +(; +--BEGIN METADATA -- +{ + "staticBump": 13, + "initializers": [ + "__post_instantiate" + ], + "declares": [ + "puts" + ], + "externs": [ + ], + "implementedFunctions": [ + "___post_instantiate", + "_main", + "_stackSave", + "_stackAlloc", + "_stackRestore", + "___growWasmMemory" + ], + "exports": [ + "memory", + "__post_instantiate", + "main", + "__heap_base", + "__data_end", + "stackSave", + "stackAlloc", + "stackRestore", + "__growWasmMemory" + ], + "invokeFuncs": [ + "invoke_ffd" + ] +} +-- END METADATA -- +;) diff --git a/test/lld/em_asm.wast.out b/test/lld/em_asm.wast.out index f878bb9cf..bceda9a75 100644 --- a/test/lld/em_asm.wast.out +++ b/test/lld/em_asm.wast.out @@ -75,4 +75,43 @@ ) ) ) -;; METADATA: { "asmConsts": {"2": ["{ Module.print(\"Got \" + $0); }", ["ii"], [""]],"0": ["{ Module.print(\"Hello world\"); }", ["i"], [""]],"1": ["{ return $0 + $1; }", ["iii"], [""]]},"staticBump": 84, "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": [] } +(; +--BEGIN METADATA -- +{ + "asmConsts": { + "2": ["{ Module.print(\"Got \" + $0); }", ["ii"], [""]], + "0": ["{ Module.print(\"Hello world\"); }", ["i"], [""]], + "1": ["{ return $0 + $1; }", ["iii"], [""]] + }, + "staticBump": 84, + "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 -- +;) diff --git a/test/lld/em_asm_table.wast.out b/test/lld/em_asm_table.wast.out index 8d99e9a6f..be0d1a794 100644 --- a/test/lld/em_asm_table.wast.out +++ b/test/lld/em_asm_table.wast.out @@ -61,4 +61,34 @@ ) ) ) -;; METADATA: { "asmConsts": {},"staticBump": 480, "initializers": [], "declares": ["emscripten_log"], "externs": [], "implementedFunctions": ["_stackSave","_stackAlloc","_stackRestore","___growWasmMemory","_dynCall_vii","_dynCall_iiii"], "exports": ["__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory","dynCall_vii","dynCall_iiii"], "invokeFuncs": [] } +(; +--BEGIN METADATA -- +{ + "staticBump": 480, + "declares": [ + "emscripten_log" + ], + "externs": [ + ], + "implementedFunctions": [ + "_stackSave", + "_stackAlloc", + "_stackRestore", + "___growWasmMemory", + "_dynCall_vii", + "_dynCall_iiii" + ], + "exports": [ + "__data_end", + "stackSave", + "stackAlloc", + "stackRestore", + "__growWasmMemory", + "dynCall_vii", + "dynCall_iiii" + ], + "invokeFuncs": [ + ] +} +-- END METADATA -- +;) diff --git a/test/lld/hello_world.wast.mem.out b/test/lld/hello_world.wast.mem.out index b38b7ff3e..2a8a0a062 100644 --- a/test/lld/hello_world.wast.mem.out +++ b/test/lld/hello_world.wast.mem.out @@ -58,4 +58,39 @@ ) ) ) -;; METADATA: { "asmConsts": {},"staticBump": 13, "initializers": ["__post_instantiate"], "declares": ["puts"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] } +(; +--BEGIN METADATA -- +{ + "staticBump": 13, + "initializers": [ + "__post_instantiate" + ], + "declares": [ + "puts" + ], + "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 -- +;) diff --git a/test/lld/hello_world.wast.out b/test/lld/hello_world.wast.out index 40fd6a1fe..e20a58d16 100644 --- a/test/lld/hello_world.wast.out +++ b/test/lld/hello_world.wast.out @@ -59,4 +59,39 @@ ) ) ) -;; METADATA: { "asmConsts": {},"staticBump": 13, "initializers": ["__post_instantiate"], "declares": ["puts"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] } +(; +--BEGIN METADATA -- +{ + "staticBump": 13, + "initializers": [ + "__post_instantiate" + ], + "declares": [ + "puts" + ], + "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 -- +;) diff --git a/test/lld/init.wast.out b/test/lld/init.wast.out index 3c9afa227..fb944aff4 100644 --- a/test/lld/init.wast.out +++ b/test/lld/init.wast.out @@ -71,4 +71,38 @@ ) ) ) -;; METADATA: { "asmConsts": {},"staticBump": 8, "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": [] } +(; +--BEGIN METADATA -- +{ + "staticBump": 8, + "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 -- +;) diff --git a/test/lld/recursive.wast.out b/test/lld/recursive.wast.out index e17247950..6a705085e 100644 --- a/test/lld/recursive.wast.out +++ b/test/lld/recursive.wast.out @@ -117,4 +117,39 @@ ) ) ) -;; METADATA: { "asmConsts": {},"staticBump": 19, "initializers": ["__post_instantiate"], "declares": ["printf"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] } +(; +--BEGIN METADATA -- +{ + "staticBump": 19, + "initializers": [ + "__post_instantiate" + ], + "declares": [ + "printf" + ], + "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 -- +;) diff --git a/test/lld/reserved_func_ptr.wast.jscall.out b/test/lld/reserved_func_ptr.wast.jscall.out index 7e612a72c..7e95fb080 100644 --- a/test/lld/reserved_func_ptr.wast.jscall.out +++ b/test/lld/reserved_func_ptr.wast.jscall.out @@ -294,4 +294,50 @@ ) ) ) -;; METADATA: { "asmConsts": {},"staticBump": 0, "initializers": ["__post_instantiate"], "jsCallStartIndex": 3, "jsCallFuncType": ["ddi","fffi","iii","v","vi","viii"], "declares": ["_Z4atoiPKc"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory","_dynCall_viii"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory","dynCall_viii"], "invokeFuncs": [] } +(; +--BEGIN METADATA -- +{ + "staticBump": 0, + "initializers": [ + "__post_instantiate" + ], + "jsCallStartIndex": 3, + "jsCallFuncType": [ + "ddi", + "fffi", + "iii", + "v", + "vi", + "viii" + ], + "declares": [ + "_Z4atoiPKc" + ], + "externs": [ + ], + "implementedFunctions": [ + "___post_instantiate", + "_main", + "_stackSave", + "_stackAlloc", + "_stackRestore", + "___growWasmMemory", + "_dynCall_viii" + ], + "exports": [ + "memory", + "__post_instantiate", + "main", + "__heap_base", + "__data_end", + "stackSave", + "stackAlloc", + "stackRestore", + "__growWasmMemory", + "dynCall_viii" + ], + "invokeFuncs": [ + ] +} +-- END METADATA -- +;) diff --git a/test/lld/reserved_func_ptr.wast.out b/test/lld/reserved_func_ptr.wast.out index 0b244a9bd..1c448d4ed 100644 --- a/test/lld/reserved_func_ptr.wast.out +++ b/test/lld/reserved_func_ptr.wast.out @@ -155,4 +155,41 @@ ) ) ) -;; METADATA: { "asmConsts": {},"staticBump": 0, "initializers": ["__post_instantiate"], "declares": ["_Z4atoiPKc"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory","_dynCall_viii"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory","dynCall_viii"], "invokeFuncs": [] } +(; +--BEGIN METADATA -- +{ + "staticBump": 0, + "initializers": [ + "__post_instantiate" + ], + "declares": [ + "_Z4atoiPKc" + ], + "externs": [ + ], + "implementedFunctions": [ + "___post_instantiate", + "_main", + "_stackSave", + "_stackAlloc", + "_stackRestore", + "___growWasmMemory", + "_dynCall_viii" + ], + "exports": [ + "memory", + "__post_instantiate", + "main", + "__heap_base", + "__data_end", + "stackSave", + "stackAlloc", + "stackRestore", + "__growWasmMemory", + "dynCall_viii" + ], + "invokeFuncs": [ + ] +} +-- END METADATA -- +;) |