diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-04-12 09:19:59 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2016-04-12 09:19:59 -0700 |
commit | 6302b75a023154bad7e11551e27d54bc35b415da (patch) | |
tree | a2d683e3b358173b31d2f879392b9fe6a42c739e /src/wasm-builder.h | |
parent | 73c606a04d01dc7018d028eed3216a507ab03ee9 (diff) | |
download | binaryen-6302b75a023154bad7e11551e27d54bc35b415da.tar.gz binaryen-6302b75a023154bad7e11551e27d54bc35b415da.tar.bz2 binaryen-6302b75a023154bad7e11551e27d54bc35b415da.zip |
Add a method to generate a dyncall thunk (#337)
Currently it's not called anywhere.
The bulk of this change is refactoring to add makeFunction, makeCallIndirect, and makeReturn
to wasm::Builder, and make S2wasmBuilder call it
Diffstat (limited to 'src/wasm-builder.h')
-rw-r--r-- | src/wasm-builder.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h index de3371274..22f713939 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -27,6 +27,18 @@ class Builder { public: Builder(AllocatingModule& wasm) : allocator(wasm.allocator) {} + Function* makeFunction(Name name, + std::vector<NameType>&& params, + WasmType resultType, + std::vector<NameType>&& locals) { + auto* func = allocator.alloc<Function>(); + func->name = name; + func->params = params; + func->result = resultType; + func->locals = locals; + return func; + } + // Nop TODO: add all the rest // Block If* makeIf(Expression* condition, Expression* ifTrue, Expression* ifFalse=nullptr) { @@ -41,6 +53,15 @@ public: // CallBase // Call // CallImport + // Also do a version which takes a sig? + CallIndirect* makeCallIndirect(FunctionType* type, Expression* target, std::vector<Expression*>&& args) { + auto* call = allocator.alloc<CallIndirect>(); + call->fullType = type; + call->type = type->result; + call->target = target; + call->operands = args; + return call; + } // FunctionType GetLocal* makeGetLocal(Name name, WasmType type) { auto* ret = allocator.alloc<GetLocal>(); @@ -104,7 +125,11 @@ public: return ret; } // Select - // Return + Return* makeReturn(Expression *value) { + auto* ret = allocator.alloc<Return>(); + ret->value = value; + return ret; + } // Host // Unreachable @@ -113,4 +138,3 @@ public: } // namespace wasm #endif // wasm_builder_h - |