From 2e5363210f7ef4861bf734e89fef96176b4157bc Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 12 Jan 2016 11:24:34 -0800 Subject: ensure function types for all functions in wasm-as, as the binary format requires it --- src/wasm-binary.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/wasm-binary.h') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index c67670c67..1f6b5b0e4 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -26,6 +26,7 @@ #include "wasm.h" #include "shared-constants.h" +#include "asm_v_wasm.h" namespace wasm { @@ -326,8 +327,21 @@ class WasmBinaryWriter : public WasmVisitor { Module* wasm; BufferWithRandomAccess& o; + MixedArena allocator; + + void prepare() { + // we need function types for all our functions + for (auto func : wasm->functions) { + func->type = ensureFunctionType(getSig(func), wasm, allocator)->name; + } + } + public: - WasmBinaryWriter(Module* wasm, BufferWithRandomAccess& o) : wasm(wasm), o(o) {} + WasmBinaryWriter(Module* input, BufferWithRandomAccess& o) : o(o) { + wasm = allocator.alloc(); + *wasm = *input; // simple shallow copy; we won't be modifying any internals, just adding some function types, so this is fine + prepare(); + } void write() { writeMemory(); -- cgit v1.2.3