From 2129cef6acbbe4acd5fd675fbb00c329e2220a40 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Thu, 4 Apr 2019 15:45:57 -0700 Subject: wasm-emscripten-finalize: add namedGlobals to output metadata (#1979) This key is used by emscripten when building with MAIN_MODULE in order to export global variables from the main module to the side modules. --- src/wasm/wasm-emscripten.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/wasm/wasm-emscripten.cpp') diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 404d93ca3..0c02c758e 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -261,7 +261,6 @@ void EmscriptenGlueGenerator::generatePostInstantiateFunction() { ex->name = POST_INSTANTIATE; ex->kind = ExternalKind::Function; wasm.addExport(ex); - wasm.updateMaps(); } Function* EmscriptenGlueGenerator::generateMemoryGrowthFunction() { @@ -897,9 +896,24 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata( meta << " \"exports\": ["; commaFirst = true; for (const auto& ex : wasm.exports) { - meta << nextElement() << '"' << ex->name.str << '"'; + if (ex->kind == ExternalKind::Function) { + meta << nextElement() << '"' << ex->name.str << '"'; + } } meta << "\n ],\n"; + + meta << " \"namedGlobals\": {"; + commaFirst = true; + for (const auto& ex : wasm.exports) { + if (ex->kind == ExternalKind::Global) { + const Global* g = wasm.getGlobal(ex->value); + assert(g->type == i32); + Const* init = g->init->cast(); + uint32_t addr = init->value.geti32(); + meta << nextElement() << '"' << ex->name.str << "\" : \"" << addr << '"'; + } + } + meta << "\n },\n"; } meta << " \"invokeFuncs\": ["; -- cgit v1.2.3