summaryrefslogtreecommitdiff
path: root/src/wasm-builder.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-04-26 16:59:41 -0700
committerGitHub <noreply@github.com>2019-04-26 16:59:41 -0700
commitdb9124f1de0478dcac525009b6f1589b44a7edd8 (patch)
treefa26395a0f6cca53cf5cb6e10189f989c5bfa847 /src/wasm-builder.h
parent87636dccd404a340d75acb1d96301581343f29ca (diff)
downloadbinaryen-db9124f1de0478dcac525009b6f1589b44a7edd8.tar.gz
binaryen-db9124f1de0478dcac525009b6f1589b44a7edd8.tar.bz2
binaryen-db9124f1de0478dcac525009b6f1589b44a7edd8.zip
Apply format changes from #2048 (#2059)
Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
Diffstat (limited to 'src/wasm-builder.h')
-rw-r--r--src/wasm-builder.h246
1 files changed, 169 insertions, 77 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index 0bbc8eebc..8e7cc9908 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -17,8 +17,8 @@
#ifndef wasm_wasm_builder_h
#define wasm_wasm_builder_h
-#include "wasm.h"
#include "ir/manipulation.h"
+#include "wasm.h"
namespace wasm {
@@ -90,9 +90,7 @@ public:
// IR nodes
- Nop* makeNop() {
- return allocator.alloc<Nop>();
- }
+ Nop* makeNop() { return allocator.alloc<Nop>(); }
Block* makeBlock(Expression* first = nullptr) {
auto* ret = allocator.alloc<Block>();
if (first) {
@@ -139,53 +137,75 @@ public:
ret->finalize(type);
return ret;
}
- If* makeIf(Expression* condition, Expression* ifTrue, Expression* ifFalse = nullptr) {
+ If* makeIf(Expression* condition,
+ Expression* ifTrue,
+ Expression* ifFalse = nullptr) {
auto* ret = allocator.alloc<If>();
- ret->condition = condition; ret->ifTrue = ifTrue; ret->ifFalse = ifFalse;
+ ret->condition = condition;
+ ret->ifTrue = ifTrue;
+ ret->ifFalse = ifFalse;
ret->finalize();
return ret;
}
- If* makeIf(Expression* condition, Expression* ifTrue, Expression* ifFalse, Type type) {
+ If* makeIf(Expression* condition,
+ Expression* ifTrue,
+ Expression* ifFalse,
+ Type type) {
auto* ret = allocator.alloc<If>();
- ret->condition = condition; ret->ifTrue = ifTrue; ret->ifFalse = ifFalse;
+ ret->condition = condition;
+ ret->ifTrue = ifTrue;
+ ret->ifFalse = ifFalse;
ret->finalize(type);
return ret;
}
Loop* makeLoop(Name name, Expression* body) {
auto* ret = allocator.alloc<Loop>();
- ret->name = name; ret->body = body;
+ ret->name = name;
+ ret->body = body;
ret->finalize();
return ret;
}
- Break* makeBreak(Name name, Expression* value = nullptr, Expression* condition = nullptr) {
+ Break* makeBreak(Name name,
+ Expression* value = nullptr,
+ Expression* condition = nullptr) {
auto* ret = allocator.alloc<Break>();
- ret->name = name; ret->value = value; ret->condition = condition;
+ ret->name = name;
+ ret->value = value;
+ ret->condition = condition;
ret->finalize();
return ret;
}
template<typename T>
- Switch* makeSwitch(T& list, Name default_, Expression* condition, Expression* value = nullptr) {
+ Switch* makeSwitch(T& list,
+ Name default_,
+ Expression* condition,
+ Expression* value = nullptr) {
auto* ret = allocator.alloc<Switch>();
ret->targets.set(list);
- ret->default_ = default_; ret->value = value; ret->condition = condition;
+ ret->default_ = default_;
+ ret->value = value;
+ ret->condition = condition;
return ret;
}
Call* makeCall(Name target, const std::vector<Expression*>& args, Type type) {
auto* call = allocator.alloc<Call>();
- call->type = type; // not all functions may exist yet, so type must be provided
+ // not all functions may exist yet, so type must be provided
+ call->type = type;
call->target = target;
call->operands.set(args);
return call;
}
- template<typename T>
- Call* makeCall(Name target, const T& args, Type type) {
+ template<typename T> Call* makeCall(Name target, const T& args, Type type) {
auto* call = allocator.alloc<Call>();
- call->type = type; // not all functions may exist yet, so type must be provided
+ // not all functions may exist yet, so type must be provided
+ call->type = type;
call->target = target;
call->operands.set(args);
return call;
}
- CallIndirect* makeCallIndirect(FunctionType* type, Expression* target, const std::vector<Expression*>& args) {
+ CallIndirect* makeCallIndirect(FunctionType* type,
+ Expression* target,
+ const std::vector<Expression*>& args) {
auto* call = allocator.alloc<CallIndirect>();
call->fullType = type->name;
call->type = type->result;
@@ -193,7 +213,10 @@ public:
call->operands.set(args);
return call;
}
- CallIndirect* makeCallIndirect(Name fullType, Expression* target, const std::vector<Expression*>& args, Type type) {
+ CallIndirect* makeCallIndirect(Name fullType,
+ Expression* target,
+ const std::vector<Expression*>& args,
+ Type type) {
auto* call = allocator.alloc<CallIndirect>();
call->fullType = fullType;
call->type = type;
@@ -235,19 +258,33 @@ public:
ret->finalize();
return ret;
}
- Load* makeLoad(unsigned bytes, bool signed_, uint32_t offset, unsigned align, Expression *ptr, Type type) {
+ Load* makeLoad(unsigned bytes,
+ bool signed_,
+ uint32_t offset,
+ unsigned align,
+ Expression* ptr,
+ Type type) {
auto* ret = allocator.alloc<Load>();
ret->isAtomic = false;
- ret->bytes = bytes; ret->signed_ = signed_; ret->offset = offset; ret->align = align; ret->ptr = ptr;
+ ret->bytes = bytes;
+ ret->signed_ = signed_;
+ ret->offset = offset;
+ ret->align = align;
+ ret->ptr = ptr;
ret->type = type;
return ret;
}
- Load* makeAtomicLoad(unsigned bytes, uint32_t offset, Expression* ptr, Type type) {
+ Load*
+ makeAtomicLoad(unsigned bytes, uint32_t offset, Expression* ptr, Type type) {
Load* load = makeLoad(bytes, false, offset, bytes, ptr, type);
load->isAtomic = true;
return load;
}
- AtomicWait* makeAtomicWait(Expression* ptr, Expression* expected, Expression* timeout, Type expectedType, Address offset) {
+ AtomicWait* makeAtomicWait(Expression* ptr,
+ Expression* expected,
+ Expression* timeout,
+ Type expectedType,
+ Address offset) {
auto* wait = allocator.alloc<AtomicWait>();
wait->offset = offset;
wait->ptr = ptr;
@@ -257,7 +294,8 @@ public:
wait->finalize();
return wait;
}
- AtomicNotify* makeAtomicNotify(Expression* ptr, Expression* notifyCount, Address offset) {
+ AtomicNotify*
+ makeAtomicNotify(Expression* ptr, Expression* notifyCount, Address offset) {
auto* notify = allocator.alloc<AtomicNotify>();
notify->offset = offset;
notify->ptr = ptr;
@@ -265,21 +303,39 @@ public:
notify->finalize();
return notify;
}
- Store* makeStore(unsigned bytes, uint32_t offset, unsigned align, Expression *ptr, Expression *value, Type type) {
+ Store* makeStore(unsigned bytes,
+ uint32_t offset,
+ unsigned align,
+ Expression* ptr,
+ Expression* value,
+ Type type) {
auto* ret = allocator.alloc<Store>();
ret->isAtomic = false;
- ret->bytes = bytes; ret->offset = offset; ret->align = align; ret->ptr = ptr; ret->value = value; ret->valueType = type;
+ ret->bytes = bytes;
+ ret->offset = offset;
+ ret->align = align;
+ ret->ptr = ptr;
+ ret->value = value;
+ ret->valueType = type;
ret->finalize();
assert(isConcreteType(ret->value->type) ? ret->value->type == type : true);
return ret;
}
- Store* makeAtomicStore(unsigned bytes, uint32_t offset, Expression* ptr, Expression* value, Type type) {
+ Store* makeAtomicStore(unsigned bytes,
+ uint32_t offset,
+ Expression* ptr,
+ Expression* value,
+ Type type) {
Store* store = makeStore(bytes, offset, bytes, ptr, value, type);
store->isAtomic = true;
return store;
}
- AtomicRMW* makeAtomicRMW(AtomicRMWOp op, unsigned bytes, uint32_t offset,
- Expression* ptr, Expression* value, Type type) {
+ AtomicRMW* makeAtomicRMW(AtomicRMWOp op,
+ unsigned bytes,
+ uint32_t offset,
+ Expression* ptr,
+ Expression* value,
+ Type type) {
auto* ret = allocator.alloc<AtomicRMW>();
ret->op = op;
ret->bytes = bytes;
@@ -290,9 +346,12 @@ public:
ret->finalize();
return ret;
}
- AtomicCmpxchg* makeAtomicCmpxchg(unsigned bytes, uint32_t offset,
- Expression* ptr, Expression* expected,
- Expression* replacement, Type type) {
+ AtomicCmpxchg* makeAtomicCmpxchg(unsigned bytes,
+ uint32_t offset,
+ Expression* ptr,
+ Expression* expected,
+ Expression* replacement,
+ Type type) {
auto* ret = allocator.alloc<AtomicCmpxchg>();
ret->bytes = bytes;
ret->offset = offset;
@@ -303,7 +362,8 @@ public:
ret->finalize();
return ret;
}
- SIMDExtract* makeSIMDExtract(SIMDExtractOp op, Expression* vec, uint8_t index) {
+ SIMDExtract*
+ makeSIMDExtract(SIMDExtractOp op, Expression* vec, uint8_t index) {
auto* ret = allocator.alloc<SIMDExtract>();
ret->op = op;
ret->vec = vec;
@@ -311,7 +371,10 @@ public:
ret->finalize();
return ret;
}
- SIMDReplace* makeSIMDReplace(SIMDReplaceOp op, Expression* vec, uint8_t index, Expression* value) {
+ SIMDReplace* makeSIMDReplace(SIMDReplaceOp op,
+ Expression* vec,
+ uint8_t index,
+ Expression* value) {
auto* ret = allocator.alloc<SIMDReplace>();
ret->op = op;
ret->vec = vec;
@@ -320,7 +383,9 @@ public:
ret->finalize();
return ret;
}
- SIMDShuffle* makeSIMDShuffle(Expression* left, Expression* right, const std::array<uint8_t, 16>& mask) {
+ SIMDShuffle* makeSIMDShuffle(Expression* left,
+ Expression* right,
+ const std::array<uint8_t, 16>& mask) {
auto* ret = allocator.alloc<SIMDShuffle>();
ret->left = left;
ret->right = right;
@@ -328,7 +393,8 @@ public:
ret->finalize();
return ret;
}
- SIMDBitselect* makeSIMDBitselect(Expression* left, Expression* right, Expression* cond) {
+ SIMDBitselect*
+ makeSIMDBitselect(Expression* left, Expression* right, Expression* cond) {
auto* ret = allocator.alloc<SIMDBitselect>();
ret->left = left;
ret->right = right;
@@ -344,7 +410,10 @@ public:
ret->finalize();
return ret;
}
- MemoryInit* makeMemoryInit(uint32_t segment, Expression* dest, Expression* offset, Expression* size) {
+ MemoryInit* makeMemoryInit(uint32_t segment,
+ Expression* dest,
+ Expression* offset,
+ Expression* size) {
auto* ret = allocator.alloc<MemoryInit>();
ret->segment = segment;
ret->dest = dest;
@@ -359,7 +428,8 @@ public:
ret->finalize();
return ret;
}
- MemoryCopy* makeMemoryCopy(Expression* dest, Expression* source, Expression* size) {
+ MemoryCopy*
+ makeMemoryCopy(Expression* dest, Expression* source, Expression* size) {
auto* ret = allocator.alloc<MemoryCopy>();
ret->dest = dest;
ret->source = source;
@@ -367,7 +437,8 @@ public:
ret->finalize();
return ret;
}
- MemoryFill* makeMemoryFill(Expression* dest, Expression* value, Expression* size) {
+ MemoryFill*
+ makeMemoryFill(Expression* dest, Expression* value, Expression* size) {
auto* ret = allocator.alloc<MemoryFill>();
ret->dest = dest;
ret->value = value;
@@ -382,30 +453,37 @@ public:
ret->type = value.type;
return ret;
}
- Unary* makeUnary(UnaryOp op, Expression *value) {
+ Unary* makeUnary(UnaryOp op, Expression* value) {
auto* ret = allocator.alloc<Unary>();
- ret->op = op; ret->value = value;
+ ret->op = op;
+ ret->value = value;
ret->finalize();
return ret;
}
- Binary* makeBinary(BinaryOp op, Expression *left, Expression *right) {
+ Binary* makeBinary(BinaryOp op, Expression* left, Expression* right) {
auto* ret = allocator.alloc<Binary>();
- ret->op = op; ret->left = left; ret->right = right;
+ ret->op = op;
+ ret->left = left;
+ ret->right = right;
ret->finalize();
return ret;
}
- Select* makeSelect(Expression* condition, Expression *ifTrue, Expression *ifFalse) {
+ Select*
+ makeSelect(Expression* condition, Expression* ifTrue, Expression* ifFalse) {
auto* ret = allocator.alloc<Select>();
- ret->condition = condition; ret->ifTrue = ifTrue; ret->ifFalse = ifFalse;
+ ret->condition = condition;
+ ret->ifTrue = ifTrue;
+ ret->ifFalse = ifFalse;
ret->finalize();
return ret;
}
- Return* makeReturn(Expression *value = nullptr) {
+ Return* makeReturn(Expression* value = nullptr) {
auto* ret = allocator.alloc<Return>();
ret->value = value;
return ret;
}
- Host* makeHost(HostOp op, Name nameOperand, std::vector<Expression*>&& operands) {
+ Host*
+ makeHost(HostOp op, Name nameOperand, std::vector<Expression*>&& operands) {
auto* ret = allocator.alloc<Host>();
ret->op = op;
ret->nameOperand = nameOperand;
@@ -413,13 +491,11 @@ public:
ret->finalize();
return ret;
}
- Unreachable* makeUnreachable() {
- return allocator.alloc<Unreachable>();
- }
+ Unreachable* makeUnreachable() { return allocator.alloc<Unreachable>(); }
// Additional helpers
- Drop* makeDrop(Expression *value) {
+ Drop* makeDrop(Expression* value) {
auto* ret = allocator.alloc<Drop>();
ret->value = value;
ret->finalize();
@@ -467,11 +543,14 @@ public:
clearLocalNames(func);
}
- // ensure a node is a block, if it isn't already, and optionally append to the block
+ // ensure a node is a block, if it isn't already, and optionally append to the
+ // block
Block* blockify(Expression* any, Expression* append = nullptr) {
Block* block = nullptr;
- if (any) block = any->dynCast<Block>();
- if (!block) block = makeBlock(any);
+ if (any)
+ block = any->dynCast<Block>();
+ if (!block)
+ block = makeBlock(any);
if (append) {
block->list.push_back(append);
block->finalize();
@@ -479,17 +558,21 @@ public:
return block;
}
- template<typename ...Ts>
+ template<typename... Ts>
Block* blockify(Expression* any, Expression* append, Ts... args) {
return blockify(blockify(any, append), args...);
}
- // ensure a node is a block, if it isn't already, and optionally append to the block
- // this variant sets a name for the block, so it will not reuse a block already named
- Block* blockifyWithName(Expression* any, Name name, Expression* append = nullptr) {
+ // ensure a node is a block, if it isn't already, and optionally append to the
+ // block this variant sets a name for the block, so it will not reuse a block
+ // already named
+ Block*
+ blockifyWithName(Expression* any, Name name, Expression* append = nullptr) {
Block* block = nullptr;
- if (any) block = any->dynCast<Block>();
- if (!block || block->name.is()) block = makeBlock(any);
+ if (any)
+ block = any->dynCast<Block>();
+ if (!block || block->name.is())
+ block = makeBlock(any);
block->name = name;
if (append) {
block->list.push_back(append);
@@ -498,8 +581,8 @@ public:
return block;
}
- // a helper for the common pattern of a sequence of two expressions. Similar to
- // blockify, but does *not* reuse a block if the first is one.
+ // a helper for the common pattern of a sequence of two expressions. Similar
+ // to blockify, but does *not* reuse a block if the first is one.
Block* makeSequence(Expression* left, Expression* right) {
auto* block = makeBlock(left);
block->list.push_back(right);
@@ -508,7 +591,8 @@ public:
}
// Grab a slice out of a block, replacing it with nops, and returning
- // either another block with the contents (if more than 1) or a single expression
+ // either another block with the contents (if more than 1) or a single
+ // expression
Expression* stealSlice(Block* input, Index from, Index to) {
Expression* ret;
if (to == from + 1) {
@@ -535,7 +619,8 @@ public:
// Drop an expression if it has a concrete type
Expression* dropIfConcretelyTyped(Expression* curr) {
- if (!isConcreteType(curr->type)) return curr;
+ if (!isConcreteType(curr->type))
+ return curr;
return makeDrop(curr);
}
@@ -547,35 +632,42 @@ public:
// returns a replacement with the precise same type, and with
// minimal contents. as a replacement, this may reuse the
// input node
- template<typename T>
- Expression* replaceWithIdenticalType(T* curr) {
+ template<typename T> Expression* replaceWithIdenticalType(T* curr) {
Literal value;
// TODO: reuse node conditionally when possible for literals
switch (curr->type) {
- case i32: value = Literal(int32_t(0)); break;
- case i64: value = Literal(int64_t(0)); break;
- case f32: value = Literal(float(0)); break;
- case f64: value = Literal(double(0)); break;
+ case i32:
+ value = Literal(int32_t(0));
+ break;
+ case i64:
+ value = Literal(int64_t(0));
+ break;
+ case f32:
+ value = Literal(float(0));
+ break;
+ case f64:
+ value = Literal(double(0));
+ break;
case v128: {
std::array<uint8_t, 16> bytes;
bytes.fill(0);
value = Literal(bytes.data());
break;
}
- case none: return ExpressionManipulator::nop(curr);
- case unreachable: return ExpressionManipulator::convert<T, Unreachable>(curr);
+ case none:
+ return ExpressionManipulator::nop(curr);
+ case unreachable:
+ return ExpressionManipulator::convert<T, Unreachable>(curr);
}
return makeConst(value);
}
// Module-level helpers
- enum Mutability {
- Mutable,
- Immutable
- };
+ enum Mutability { Mutable, Immutable };
- static Global* makeGlobal(Name name, Type type, Expression* init, Mutability mutable_) {
+ static Global*
+ makeGlobal(Name name, Type type, Expression* init, Mutability mutable_) {
auto* glob = new Global;
glob->name = name;
glob->type = type;