diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-28 19:02:38 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-28 19:02:38 -0800 |
commit | 5c19367f08d59d0edb17f7acdafe122e1d10e2a6 (patch) | |
tree | 59d74f359dda8f677e9e51f7441469a983da9447 /src/asm2wasm.h | |
parent | 2d43e52b3ae1589d0f3127373e92a689e651ed33 (diff) | |
download | binaryen-5c19367f08d59d0edb17f7acdafe122e1d10e2a6.tar.gz binaryen-5c19367f08d59d0edb17f7acdafe122e1d10e2a6.tar.bz2 binaryen-5c19367f08d59d0edb17f7acdafe122e1d10e2a6.zip |
optionally emit mappedGlobals in asm2wasm, and use that to help when parsing s-expressions
Diffstat (limited to 'src/asm2wasm.h')
-rw-r--r-- | src/asm2wasm.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index ed376f576..8dcefec0e 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -143,6 +143,25 @@ class Asm2WasmBuilder { public: std::map<IString, MappedGlobal> mappedGlobals; + // the global mapping info is not present in the output wasm. We need to save it on the side + // if we intend to load and run this module's wasm. + void serializeMappedGlobals(const char *filename) { + FILE *f = fopen(filename, "w"); + assert(f); + fprintf(f, "{\n"); + bool first = true; + for (auto& pair : mappedGlobals) { + auto name = pair.first; + auto& global = pair.second; + if (first) first = false; + else fprintf(f, ","); + fprintf(f, "\"%s\": { \"address\": %d, \"type\": %d, \"import\": %d, \"module\": \"%s\", \"base\": \"%s\" }\n", + name.str, global.address, global.type, global.import, global.module.str, global.base.str); + } + fprintf(f, "}"); + fclose(f); + } + private: void allocateGlobal(IString name, WasmType type, bool import, IString module = IString(), IString base = IString()) { assert(mappedGlobals.find(name) == mappedGlobals.end()); |