diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-06-26 11:00:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-26 11:00:02 -0700 |
commit | 45b358706c86415c5982f9e777fa9e19a33b27a3 (patch) | |
tree | d1caa4180c8d0f4a76319fd11f8b18f9f446e6c3 /src/wasm-builder.h | |
parent | c410d93d3af9813f889b4011f964d4becf43bc27 (diff) | |
parent | 87f3020cf4e666a6eb6620106e48ee042cd2f666 (diff) | |
download | binaryen-45b358706c86415c5982f9e777fa9e19a33b27a3.tar.gz binaryen-45b358706c86415c5982f9e777fa9e19a33b27a3.tar.bz2 binaryen-45b358706c86415c5982f9e777fa9e19a33b27a3.zip |
Merge pull request #602 from WebAssembly/dsl-nice
Use a DSL in OptimizeInstructions
Diffstat (limited to 'src/wasm-builder.h')
-rw-r--r-- | src/wasm-builder.h | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h index 2eb051251..501124999 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -93,13 +93,23 @@ public: ret->finalize(); return ret; } - // Switch - // CallBase - // Call - // Also do a version which takes a sig? - CallImport* makeCallImport(Name target, const std::vector<Expression*>& args) { + template<typename T> + Switch* makeSwitch(T& list, Name default_, Expression* condition, Expression* value = nullptr) { + auto* ret = wasm.allocator.alloc<Switch>(); + ret->targets.set(list); + ret->default_ = default_; ret->value = value; ret->condition = condition; + return ret; + } + Call* makeCall(Name target, const std::vector<Expression*>& args, WasmType type) { + auto* call = wasm.allocator.alloc<Call>(); + call->type = type; // not all functions may exist yet, so type must be provided + call->target = target; + call->operands.set(args); + return call; + } + CallImport* makeCallImport(Name target, const std::vector<Expression*>& args, WasmType type) { auto* call = wasm.allocator.alloc<CallImport>(); - call->type = wasm.getImport(target)->type->result; + call->type = type; // similar to makeCall, for consistency call->target = target; call->operands.set(args); return call; @@ -112,6 +122,14 @@ public: call->operands.set(args); return call; } + CallIndirect* makeCallIndirect(Name fullType, Expression* target, const std::vector<Expression*>& args, WasmType type) { + auto* call = wasm.allocator.alloc<CallIndirect>(); + call->fullType = fullType; + call->type = type; + call->target = target; + call->operands.set(args); + return call; + } // FunctionType GetLocal* makeGetLocal(Index index, WasmType type) { auto* ret = wasm.allocator.alloc<GetLocal>(); @@ -126,7 +144,12 @@ public: ret->type = value->type; return ret; } - // Load + Load* makeLoad(unsigned bytes, bool signed_, uint32_t offset, unsigned align, Expression *ptr, WasmType type) { + auto* ret = wasm.allocator.alloc<Load>(); + ret->bytes = bytes; ret->signed_ = signed_; ret->offset = offset; ret->align = align; ret->ptr = ptr; + ret->type = type; + return ret; + } Store* makeStore(unsigned bytes, uint32_t offset, unsigned align, Expression *ptr, Expression *value) { auto* ret = wasm.allocator.alloc<Store>(); ret->bytes = bytes; ret->offset = offset; ret->align = align; ret->ptr = ptr; ret->value = value; @@ -152,7 +175,12 @@ public: ret->finalize(); return ret; } - // Select + Select* makeSelect(Expression* condition, Expression *ifTrue, Expression *ifFalse) { + auto* ret = wasm.allocator.alloc<Select>(); + ret->condition = condition; ret->ifTrue = ifTrue; ret->ifFalse = ifFalse; + ret->finalize(); + return ret; + } Return* makeReturn(Expression *value) { auto* ret = wasm.allocator.alloc<Return>(); ret->value = value; @@ -165,7 +193,9 @@ public: ret->operands.set(operands); return ret; } - // Unreachable + Unreachable* makeUnreachable() { + return wasm.allocator.alloc<Unreachable>(); + } // Additional utility functions for building on top of nodes |