summaryrefslogtreecommitdiff
path: root/src/wasm-interpreter.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-05-01 14:48:41 -0700
committerGitHub <noreply@github.com>2019-05-01 14:48:41 -0700
commit2bd3758a22131cfd6925b3fd995657b211095c90 (patch)
tree2a38a48ab68c00ed1b55e885f86014bbdda92ff2 /src/wasm-interpreter.h
parent73709b4da08d285c2237c8c23a54ba53274c0c7f (diff)
downloadbinaryen-2bd3758a22131cfd6925b3fd995657b211095c90.tar.gz
binaryen-2bd3758a22131cfd6925b3fd995657b211095c90.tar.bz2
binaryen-2bd3758a22131cfd6925b3fd995657b211095c90.zip
clang-tidy braces changes (#2075)
Applies the changes in #2065, and temprarily disables the hook since it's too slow to run on a change this large. We should re-enable it in a later commit.
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r--src/wasm-interpreter.h255
1 files changed, 170 insertions, 85 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index dd6e2b073..02e065c5f 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -182,17 +182,20 @@ public:
Flow visitIf(If* curr) {
NOTE_ENTER("If");
Flow flow = visit(curr->condition);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
NOTE_EVAL1(flow.value);
if (flow.value.geti32()) {
Flow flow = visit(curr->ifTrue);
- if (!flow.breaking() && !curr->ifFalse)
+ if (!flow.breaking() && !curr->ifFalse) {
flow.value = Literal(); // if_else returns a value, but if does not
+ }
return flow;
}
- if (curr->ifFalse)
+ if (curr->ifFalse) {
return visit(curr->ifFalse);
+ }
return Flow();
}
Flow visitLoop(Loop* curr) {
@@ -200,8 +203,9 @@ public:
while (1) {
Flow flow = visit(curr->body);
if (flow.breaking()) {
- if (flow.breakTo == curr->name)
+ if (flow.breakTo == curr->name) {
continue; // lol
+ }
}
// loop does not loop automatically, only continue achieves that
return flow;
@@ -213,16 +217,19 @@ public:
Flow flow;
if (curr->value) {
flow = visit(curr->value);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
}
if (curr->condition) {
Flow conditionFlow = visit(curr->condition);
- if (conditionFlow.breaking())
+ if (conditionFlow.breaking()) {
return conditionFlow;
+ }
condition = conditionFlow.value.getInteger() != 0;
- if (!condition)
+ if (!condition) {
return flow;
+ }
}
flow.breakTo = curr->name;
return flow;
@@ -233,14 +240,16 @@ public:
Literal value;
if (curr->value) {
flow = visit(curr->value);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
value = flow.value;
NOTE_EVAL1(value);
}
flow = visit(curr->condition);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
int64_t index = flow.value.getInteger();
Name target = curr->default_;
if (index >= 0 && (size_t)index < curr->targets.size()) {
@@ -263,8 +272,9 @@ public:
Flow visitUnary(Unary* curr) {
NOTE_ENTER("Unary");
Flow flow = visit(curr->value);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal value = flow.value;
NOTE_EVAL1(value);
switch (curr->op) {
@@ -436,12 +446,14 @@ public:
Flow visitBinary(Binary* curr) {
NOTE_ENTER("Binary");
Flow flow = visit(curr->left);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal left = flow.value;
flow = visit(curr->right);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal right = flow.value;
NOTE_EVAL2(left, right);
assert(isConcreteType(curr->left->type) ? left.type == curr->left->type
@@ -465,53 +477,65 @@ public:
case MulFloat64:
return left.mul(right);
case DivSInt32: {
- if (right.getInteger() == 0)
+ if (right.getInteger() == 0) {
trap("i32.div_s by 0");
+ }
if (left.getInteger() == std::numeric_limits<int32_t>::min() &&
- right.getInteger() == -1)
+ right.getInteger() == -1) {
trap("i32.div_s overflow"); // signed division overflow
+ }
return left.divS(right);
}
case DivUInt32: {
- if (right.getInteger() == 0)
+ if (right.getInteger() == 0) {
trap("i32.div_u by 0");
+ }
return left.divU(right);
}
case RemSInt32: {
- if (right.getInteger() == 0)
+ if (right.getInteger() == 0) {
trap("i32.rem_s by 0");
+ }
if (left.getInteger() == std::numeric_limits<int32_t>::min() &&
- right.getInteger() == -1)
+ right.getInteger() == -1) {
return Literal(int32_t(0));
+ }
return left.remS(right);
}
case RemUInt32: {
- if (right.getInteger() == 0)
+ if (right.getInteger() == 0) {
trap("i32.rem_u by 0");
+ }
return left.remU(right);
}
case DivSInt64: {
- if (right.getInteger() == 0)
+ if (right.getInteger() == 0) {
trap("i64.div_s by 0");
- if (left.getInteger() == LLONG_MIN && right.getInteger() == -1LL)
+ }
+ if (left.getInteger() == LLONG_MIN && right.getInteger() == -1LL) {
trap("i64.div_s overflow"); // signed division overflow
+ }
return left.divS(right);
}
case DivUInt64: {
- if (right.getInteger() == 0)
+ if (right.getInteger() == 0) {
trap("i64.div_u by 0");
+ }
return left.divU(right);
}
case RemSInt64: {
- if (right.getInteger() == 0)
+ if (right.getInteger() == 0) {
trap("i64.rem_s by 0");
- if (left.getInteger() == LLONG_MIN && right.getInteger() == -1LL)
+ }
+ if (left.getInteger() == LLONG_MIN && right.getInteger() == -1LL) {
return Literal(int64_t(0));
+ }
return left.remS(right);
}
case RemUInt64: {
- if (right.getInteger() == 0)
+ if (right.getInteger() == 0) {
trap("i64.rem_u by 0");
+ }
return left.remU(right);
}
case DivFloat32:
@@ -763,8 +787,9 @@ public:
Flow visitSIMDExtract(SIMDExtract* curr) {
NOTE_ENTER("SIMDExtract");
Flow flow = this->visit(curr->vec);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal vec = flow.value;
switch (curr->op) {
case ExtractLaneSVecI8x16:
@@ -789,12 +814,14 @@ public:
Flow visitSIMDReplace(SIMDReplace* curr) {
NOTE_ENTER("SIMDReplace");
Flow flow = this->visit(curr->vec);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal vec = flow.value;
flow = this->visit(curr->value);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal value = flow.value;
switch (curr->op) {
case ReplaceLaneVecI8x16:
@@ -815,40 +842,47 @@ public:
Flow visitSIMDShuffle(SIMDShuffle* curr) {
NOTE_ENTER("SIMDShuffle");
Flow flow = this->visit(curr->left);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal left = flow.value;
flow = this->visit(curr->right);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal right = flow.value;
return left.shuffleV8x16(right, curr->mask);
}
Flow visitSIMDBitselect(SIMDBitselect* curr) {
NOTE_ENTER("SIMDBitselect");
Flow flow = this->visit(curr->left);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal left = flow.value;
flow = this->visit(curr->right);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal right = flow.value;
flow = this->visit(curr->cond);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal cond = flow.value;
return cond.bitselectV128(left, right);
}
Flow visitSIMDShift(SIMDShift* curr) {
NOTE_ENTER("SIMDShift");
Flow flow = this->visit(curr->vec);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal vec = flow.value;
flow = this->visit(curr->shift);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Literal shift = flow.value;
switch (curr->op) {
case ShlVecI8x16:
@@ -881,22 +915,26 @@ public:
Flow visitSelect(Select* curr) {
NOTE_ENTER("Select");
Flow ifTrue = visit(curr->ifTrue);
- if (ifTrue.breaking())
+ if (ifTrue.breaking()) {
return ifTrue;
+ }
Flow ifFalse = visit(curr->ifFalse);
- if (ifFalse.breaking())
+ if (ifFalse.breaking()) {
return ifFalse;
+ }
Flow condition = visit(curr->condition);
- if (condition.breaking())
+ if (condition.breaking()) {
return condition;
+ }
NOTE_EVAL1(condition.value);
return condition.value.geti32() ? ifTrue : ifFalse; // ;-)
}
Flow visitDrop(Drop* curr) {
NOTE_ENTER("Drop");
Flow value = visit(curr->value);
- if (value.breaking())
+ if (value.breaking()) {
return value;
+ }
return Flow();
}
Flow visitReturn(Return* curr) {
@@ -904,8 +942,9 @@ public:
Flow flow;
if (curr->value) {
flow = visit(curr->value);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
NOTE_EVAL1(flow.value);
}
flow.breakTo = RETURN_FLOW;
@@ -923,24 +962,29 @@ public:
Literal truncSFloat(Unary* curr, Literal value) {
double val = value.getFloat();
- if (std::isnan(val))
+ if (std::isnan(val)) {
trap("truncSFloat of nan");
+ }
if (curr->type == i32) {
if (value.type == f32) {
- if (!isInRangeI32TruncS(value.reinterpreti32()))
+ if (!isInRangeI32TruncS(value.reinterpreti32())) {
trap("i32.truncSFloat overflow");
+ }
} else {
- if (!isInRangeI32TruncS(value.reinterpreti64()))
+ if (!isInRangeI32TruncS(value.reinterpreti64())) {
trap("i32.truncSFloat overflow");
+ }
}
return Literal(int32_t(val));
} else {
if (value.type == f32) {
- if (!isInRangeI64TruncS(value.reinterpreti32()))
+ if (!isInRangeI64TruncS(value.reinterpreti32())) {
trap("i64.truncSFloat overflow");
+ }
} else {
- if (!isInRangeI64TruncS(value.reinterpreti64()))
+ if (!isInRangeI64TruncS(value.reinterpreti64())) {
trap("i64.truncSFloat overflow");
+ }
}
return Literal(int64_t(val));
}
@@ -948,24 +992,29 @@ public:
Literal truncUFloat(Unary* curr, Literal value) {
double val = value.getFloat();
- if (std::isnan(val))
+ if (std::isnan(val)) {
trap("truncUFloat of nan");
+ }
if (curr->type == i32) {
if (value.type == f32) {
- if (!isInRangeI32TruncU(value.reinterpreti32()))
+ if (!isInRangeI32TruncU(value.reinterpreti32())) {
trap("i32.truncUFloat overflow");
+ }
} else {
- if (!isInRangeI32TruncU(value.reinterpreti64()))
+ if (!isInRangeI32TruncU(value.reinterpreti64())) {
trap("i32.truncUFloat overflow");
+ }
}
return Literal(uint32_t(val));
} else {
if (value.type == f32) {
- if (!isInRangeI64TruncU(value.reinterpreti32()))
+ if (!isInRangeI64TruncU(value.reinterpreti32())) {
trap("i64.truncUFloat overflow");
+ }
} else {
- if (!isInRangeI64TruncU(value.reinterpreti64()))
+ if (!isInRangeI64TruncU(value.reinterpreti64())) {
trap("i64.truncUFloat overflow");
+ }
}
return Literal(uint64_t(val));
}
@@ -1193,8 +1242,9 @@ public:
// call an exported function
Literal callExport(Name name, const LiteralList& arguments) {
Export* export_ = wasm.getExportOrNull(name);
- if (!export_)
+ if (!export_) {
externalInterface->trap("callExport not found");
+ }
return callFunction(export_->value, arguments);
}
@@ -1203,12 +1253,14 @@ public:
// get an exported global
Literal getExport(Name name) {
Export* export_ = wasm.getExportOrNull(name);
- if (!export_)
+ if (!export_) {
externalInterface->trap("getExport external not found");
+ }
Name internalName = export_->value;
auto iter = globals.find(internalName);
- if (iter == globals.end())
+ if (iter == globals.end()) {
externalInterface->trap("getExport internal not found");
+ }
return iter->second;
}
@@ -1333,8 +1385,9 @@ private:
arguments.reserve(operands.size());
for (auto expression : operands) {
Flow flow = this->visit(expression);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
NOTE_EVAL1(flow.value);
arguments.push_back(flow.value);
}
@@ -1346,8 +1399,9 @@ private:
NOTE_NAME(curr->target);
LiteralList arguments;
Flow flow = generateArguments(curr->operands, arguments);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
auto* func = instance.wasm.getFunction(curr->target);
Flow ret;
if (func->imported()) {
@@ -1364,11 +1418,13 @@ private:
NOTE_ENTER("CallIndirect");
LiteralList arguments;
Flow flow = generateArguments(curr->operands, arguments);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
Flow target = this->visit(curr->target);
- if (target.breaking())
+ if (target.breaking()) {
return target;
+ }
Index index = target.value.geti32();
return instance.externalInterface->callTable(
index, arguments, curr->type, *instance.self());
@@ -1385,8 +1441,9 @@ private:
NOTE_ENTER("SetLocal");
auto index = curr->index;
Flow flow = this->visit(curr->value);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
NOTE_EVAL1(index);
NOTE_EVAL1(flow.value);
assert(curr->isTee() ? flow.value.type == curr->type : true);
@@ -1406,8 +1463,9 @@ private:
NOTE_ENTER("SetGlobal");
auto name = curr->name;
Flow flow = this->visit(curr->value);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
NOTE_EVAL1(name);
NOTE_EVAL1(flow.value);
instance.globals[name] = flow.value;
@@ -1417,8 +1475,9 @@ private:
Flow visitLoad(Load* curr) {
NOTE_ENTER("Load");
Flow flow = this->visit(curr->ptr);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
NOTE_EVAL1(flow);
auto addr = instance.getFinalAddress(curr, flow.value);
auto ret = instance.externalInterface->load(curr, addr);
@@ -1429,11 +1488,13 @@ private:
Flow visitStore(Store* curr) {
NOTE_ENTER("Store");
Flow ptr = this->visit(curr->ptr);
- if (ptr.breaking())
+ if (ptr.breaking()) {
return ptr;
+ }
Flow value = this->visit(curr->value);
- if (value.breaking())
+ if (value.breaking()) {
return value;
+ }
auto addr = instance.getFinalAddress(curr, ptr.value);
NOTE_EVAL1(addr);
NOTE_EVAL1(value);
@@ -1444,11 +1505,13 @@ private:
Flow visitAtomicRMW(AtomicRMW* curr) {
NOTE_ENTER("AtomicRMW");
Flow ptr = this->visit(curr->ptr);
- if (ptr.breaking())
+ if (ptr.breaking()) {
return ptr;
+ }
auto value = this->visit(curr->value);
- if (value.breaking())
+ if (value.breaking()) {
return value;
+ }
NOTE_EVAL1(ptr);
auto addr = instance.getFinalAddress(curr, ptr.value);
NOTE_EVAL1(addr);
@@ -1482,15 +1545,18 @@ private:
Flow visitAtomicCmpxchg(AtomicCmpxchg* curr) {
NOTE_ENTER("AtomicCmpxchg");
Flow ptr = this->visit(curr->ptr);
- if (ptr.breaking())
+ if (ptr.breaking()) {
return ptr;
+ }
NOTE_EVAL1(ptr);
auto expected = this->visit(curr->expected);
- if (expected.breaking())
+ if (expected.breaking()) {
return expected;
+ }
auto replacement = this->visit(curr->replacement);
- if (replacement.breaking())
+ if (replacement.breaking()) {
return replacement;
+ }
auto addr = instance.getFinalAddress(curr, ptr.value);
NOTE_EVAL1(addr);
NOTE_EVAL1(expected);
@@ -1505,17 +1571,20 @@ private:
Flow visitAtomicWait(AtomicWait* curr) {
NOTE_ENTER("AtomicWait");
Flow ptr = this->visit(curr->ptr);
- if (ptr.breaking())
+ if (ptr.breaking()) {
return ptr;
+ }
NOTE_EVAL1(ptr);
auto expected = this->visit(curr->expected);
NOTE_EVAL1(expected);
- if (expected.breaking())
+ if (expected.breaking()) {
return expected;
+ }
auto timeout = this->visit(curr->timeout);
NOTE_EVAL1(timeout);
- if (timeout.breaking())
+ if (timeout.breaking()) {
return timeout;
+ }
auto bytes = getTypeSize(curr->expectedType);
auto addr = instance.getFinalAddress(ptr.value, bytes);
auto loaded = instance.doAtomicLoad(addr, bytes, curr->expectedType);
@@ -1530,13 +1599,15 @@ private:
Flow visitAtomicNotify(AtomicNotify* curr) {
NOTE_ENTER("AtomicNotify");
Flow ptr = this->visit(curr->ptr);
- if (ptr.breaking())
+ if (ptr.breaking()) {
return ptr;
+ }
NOTE_EVAL1(ptr);
auto count = this->visit(curr->notifyCount);
NOTE_EVAL1(count);
- if (count.breaking())
+ if (count.breaking()) {
return count;
+ }
// TODO: add threads support!
return Literal(int32_t(0)); // none woken up
}
@@ -1548,17 +1619,21 @@ private:
case GrowMemory: {
auto fail = Literal(int32_t(-1));
Flow flow = this->visit(curr->operands[0]);
- if (flow.breaking())
+ if (flow.breaking()) {
return flow;
+ }
int32_t ret = instance.memorySize;
uint32_t delta = flow.value.geti32();
- if (delta > uint32_t(-1) / Memory::kPageSize)
+ if (delta > uint32_t(-1) / Memory::kPageSize) {
return fail;
- if (instance.memorySize >= uint32_t(-1) - delta)
+ }
+ if (instance.memorySize >= uint32_t(-1) - delta) {
return fail;
+ }
uint32_t newSize = instance.memorySize + delta;
- if (newSize > instance.wasm.memory.max)
+ if (newSize > instance.wasm.memory.max) {
return fail;
+ }
instance.externalInterface->growMemory(instance.memorySize *
Memory::kPageSize,
newSize * Memory::kPageSize);
@@ -1571,14 +1646,17 @@ private:
Flow visitMemoryInit(MemoryInit* curr) {
NOTE_ENTER("MemoryInit");
Flow dest = this->visit(curr->dest);
- if (dest.breaking())
+ if (dest.breaking()) {
return dest;
+ }
Flow offset = this->visit(curr->offset);
- if (offset.breaking())
+ if (offset.breaking()) {
return offset;
+ }
Flow size = this->visit(curr->size);
- if (size.breaking())
+ if (size.breaking()) {
return size;
+ }
NOTE_EVAL1(dest);
NOTE_EVAL1(offset);
NOTE_EVAL1(size);
@@ -1620,14 +1698,17 @@ private:
Flow visitMemoryCopy(MemoryCopy* curr) {
NOTE_ENTER("MemoryCopy");
Flow dest = this->visit(curr->dest);
- if (dest.breaking())
+ if (dest.breaking()) {
return dest;
+ }
Flow source = this->visit(curr->source);
- if (source.breaking())
+ if (source.breaking()) {
return source;
+ }
Flow size = this->visit(curr->size);
- if (size.breaking())
+ if (size.breaking()) {
return size;
+ }
NOTE_EVAL1(dest);
NOTE_EVAL1(source);
NOTE_EVAL1(size);
@@ -1662,14 +1743,17 @@ private:
Flow visitMemoryFill(MemoryFill* curr) {
NOTE_ENTER("MemoryFill");
Flow dest = this->visit(curr->dest);
- if (dest.breaking())
+ if (dest.breaking()) {
return dest;
+ }
Flow value = this->visit(curr->value);
- if (value.breaking())
+ if (value.breaking()) {
return value;
+ }
Flow size = this->visit(curr->size);
- if (size.breaking())
+ if (size.breaking()) {
return size;
+ }
NOTE_EVAL1(dest);
NOTE_EVAL1(value);
NOTE_EVAL1(size);
@@ -1704,8 +1788,9 @@ public:
// Internal function call. Must be public so that callTable implementations
// can use it (refactor?)
Literal callFunctionInternal(Name name, const LiteralList& arguments) {
- if (callDepth > maxCallDepth)
+ if (callDepth > maxCallDepth) {
externalInterface->trap("stack limit");
+ }
auto previousCallDepth = callDepth;
callDepth++;
auto previousFunctionStackSize = functionStack.size();