summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-01-12 11:24:34 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-01-12 11:25:17 -0800
commit2e5363210f7ef4861bf734e89fef96176b4157bc (patch)
tree34434e313d87e0e202f45996f506a60b47df844f /src
parent3cb2281ac161edb08a2fd79cd66302caa330d583 (diff)
downloadbinaryen-2e5363210f7ef4861bf734e89fef96176b4157bc.tar.gz
binaryen-2e5363210f7ef4861bf734e89fef96176b4157bc.tar.bz2
binaryen-2e5363210f7ef4861bf734e89fef96176b4157bc.zip
ensure function types for all functions in wasm-as, as the binary format requires it
Diffstat (limited to 'src')
-rw-r--r--src/wasm-binary.h16
1 files changed, 15 insertions, 1 deletions
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<void> {
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<Module>();
+ *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();