summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/abi/stack.h2
-rw-r--r--src/ir/literal-utils.h3
-rw-r--r--src/ir/memory-utils.h2
-rw-r--r--src/ir/utils.h4
-rw-r--r--src/passes/AlignmentLowering.cpp20
-rw-r--r--src/passes/Asyncify.cpp19
-rw-r--r--src/passes/DeNaN.cpp4
-rw-r--r--src/passes/I64ToI32Lowering.cpp94
-rw-r--r--src/passes/InstrumentLocals.cpp22
-rw-r--r--src/passes/InstrumentMemory.cpp34
-rw-r--r--src/passes/LogExecution.cpp3
-rw-r--r--src/passes/MemoryPacking.cpp20
-rw-r--r--src/passes/PostEmscripten.cpp5
-rw-r--r--src/passes/RemoveUnusedBrs.cpp33
-rw-r--r--src/tools/fuzzing.h41
-rw-r--r--src/tools/wasm-ctor-eval.cpp2
-rw-r--r--src/tools/wasm-reduce.cpp4
-rw-r--r--src/tools/wasm2js.cpp3
-rw-r--r--src/wasm-builder.h1
-rw-r--r--src/wasm/wasm-emscripten.cpp4
20 files changed, 147 insertions, 173 deletions
diff --git a/src/abi/stack.h b/src/abi/stack.h
index c06caa2d0..e217d7caa 100644
--- a/src/abi/stack.h
+++ b/src/abi/stack.h
@@ -91,7 +91,7 @@ getStackSpace(Index local, Function* func, Index size, Module& wasm) {
if (PointerType == Type::i32) {
added = builder.makeBinary(AddInt32,
builder.makeLocalGet(local, PointerType),
- builder.makeConst(Literal(int32_t(size))));
+ builder.makeConst(int32_t(size)));
} else {
WASM_UNREACHABLE("unhandled PointerType");
}
diff --git a/src/ir/literal-utils.h b/src/ir/literal-utils.h
index a7ba10926..8b00ddcbf 100644
--- a/src/ir/literal-utils.h
+++ b/src/ir/literal-utils.h
@@ -36,8 +36,7 @@ inline Expression* makeZero(Type type, Module& wasm) {
// (https://bugs.chromium.org/p/v8/issues/detail?id=8460)
Builder builder(wasm);
if (type == Type::v128) {
- return builder.makeUnary(SplatVecI32x4,
- builder.makeConst(Literal(int32_t(0))));
+ return builder.makeUnary(SplatVecI32x4, builder.makeConst(int32_t(0)));
}
return builder.makeConstantExpression(Literal::makeZero(type));
}
diff --git a/src/ir/memory-utils.h b/src/ir/memory-utils.h
index 13b356ba8..432fed0aa 100644
--- a/src/ir/memory-utils.h
+++ b/src/ir/memory-utils.h
@@ -40,7 +40,7 @@ inline bool flatten(Memory& memory,
if (ensuredSegmentSize > 0) {
assert(module); // must provide a module if ensuring a size.
Builder builder(*module);
- memory.segments.emplace_back(builder.makeConst(Literal(int32_t(0))));
+ memory.segments.emplace_back(builder.makeConst(int32_t(0)));
memory.segments[0].data.resize(ensuredSegmentSize);
}
return true;
diff --git a/src/ir/utils.h b/src/ir/utils.h
index a06598095..a7f6f59bf 100644
--- a/src/ir/utils.h
+++ b/src/ir/utils.h
@@ -335,7 +335,7 @@ struct I64Utilities {
builder.makeUnary(ExtendUInt32, low),
builder.makeBinary(ShlInt64,
builder.makeUnary(ExtendUInt32, high),
- builder.makeConst(Literal(int64_t(32)))));
+ builder.makeConst(int64_t(32))));
};
static Expression* recreateI64(Builder& builder, Index low, Index high) {
@@ -349,7 +349,7 @@ struct I64Utilities {
WrapInt64,
builder.makeBinary(ShrUInt64,
builder.makeLocalGet(index, Type::i64),
- builder.makeConst(Literal(int64_t(32)))));
+ builder.makeConst(int64_t(32))));
}
static Expression* getI64Low(Builder& builder, Index index) {
diff --git a/src/passes/AlignmentLowering.cpp b/src/passes/AlignmentLowering.cpp
index 18fe46398..818189056 100644
--- a/src/passes/AlignmentLowering.cpp
+++ b/src/passes/AlignmentLowering.cpp
@@ -56,7 +56,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
1,
builder.makeLocalGet(temp, Type::i32),
Type::i32),
- builder.makeConst(Literal(int32_t(8)))));
+ builder.makeConst(int32_t(8))));
if (curr->signed_) {
ret = Bits::makeSignExt(ret, 2, *getModule());
}
@@ -80,7 +80,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
1,
builder.makeLocalGet(temp, Type::i32),
Type::i32),
- builder.makeConst(Literal(int32_t(8))))),
+ builder.makeConst(int32_t(8)))),
builder.makeBinary(
OrInt32,
builder.makeBinary(
@@ -91,7 +91,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
1,
builder.makeLocalGet(temp, Type::i32),
Type::i32),
- builder.makeConst(Literal(int32_t(16)))),
+ builder.makeConst(int32_t(16))),
builder.makeBinary(
ShlInt32,
builder.makeLoad(1,
@@ -100,7 +100,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
1,
builder.makeLocalGet(temp, Type::i32),
Type::i32),
- builder.makeConst(Literal(int32_t(24))))));
+ builder.makeConst(int32_t(24)))));
} else if (curr->align == 2) {
ret = builder.makeBinary(
OrInt32,
@@ -118,7 +118,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
2,
builder.makeLocalGet(temp, Type::i32),
Type::i32),
- builder.makeConst(Literal(int32_t(16)))));
+ builder.makeConst(int32_t(16))));
} else {
WASM_UNREACHABLE("invalid alignment");
}
@@ -160,7 +160,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
builder.makeLocalGet(tempPtr, Type::i32),
builder.makeBinary(ShrUInt32,
builder.makeLocalGet(tempValue, Type::i32),
- builder.makeConst(Literal(int32_t(8)))),
+ builder.makeConst(int32_t(8))),
Type::i32));
} else if (curr->bytes == 4) {
if (curr->align == 1) {
@@ -178,7 +178,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
builder.makeLocalGet(tempPtr, Type::i32),
builder.makeBinary(ShrUInt32,
builder.makeLocalGet(tempValue, Type::i32),
- builder.makeConst(Literal(int32_t(8)))),
+ builder.makeConst(int32_t(8))),
Type::i32));
block->list.push_back(builder.makeStore(
1,
@@ -187,7 +187,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
builder.makeLocalGet(tempPtr, Type::i32),
builder.makeBinary(ShrUInt32,
builder.makeLocalGet(tempValue, Type::i32),
- builder.makeConst(Literal(int32_t(16)))),
+ builder.makeConst(int32_t(16))),
Type::i32));
block->list.push_back(builder.makeStore(
1,
@@ -196,7 +196,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
builder.makeLocalGet(tempPtr, Type::i32),
builder.makeBinary(ShrUInt32,
builder.makeLocalGet(tempValue, Type::i32),
- builder.makeConst(Literal(int32_t(24)))),
+ builder.makeConst(int32_t(24))),
Type::i32));
} else if (curr->align == 2) {
block->list.push_back(
@@ -213,7 +213,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
builder.makeLocalGet(tempPtr, Type::i32),
builder.makeBinary(ShrUInt32,
builder.makeLocalGet(tempValue, Type::i32),
- builder.makeConst(Literal(int32_t(16)))),
+ builder.makeConst(int32_t(16))),
Type::i32));
} else {
WASM_UNREACHABLE("invalid alignment");
diff --git a/src/passes/Asyncify.cpp b/src/passes/Asyncify.cpp
index d4a788adb..61c1f0ff4 100644
--- a/src/passes/Asyncify.cpp
+++ b/src/passes/Asyncify.cpp
@@ -998,7 +998,7 @@ private:
// avoid saving/restoring that local later)
curr = builder->makeIf(
builder->makeIf(builder->makeStateCheck(State::Normal),
- builder->makeConst(Literal(int32_t(1))),
+ builder->makeConst(int32_t(1)),
makeCallIndexPeek(index)),
builder->makeSequence(curr, makePossibleUnwind(index, set)));
return curr;
@@ -1011,9 +1011,8 @@ private:
// it when we add its contents, later.)
return builder->makeIf(
builder->makeStateCheck(State::Unwinding),
- builder->makeCall(ASYNCIFY_UNWIND,
- {builder->makeConst(Literal(int32_t(index)))},
- Type::none),
+ builder->makeCall(
+ ASYNCIFY_UNWIND, {builder->makeConst(int32_t(index))}, Type::none),
ifNotUnwinding);
}
@@ -1021,7 +1020,7 @@ private:
// Emit an intrinsic for this, as we store the index into a local, and
// don't want it to be seen by asyncify itself.
return builder->makeCall(ASYNCIFY_CHECK_CALL_INDEX,
- {builder->makeConst(Literal(int32_t(index)))},
+ {builder->makeConst(int32_t(index))},
Type::i32);
}
@@ -1489,11 +1488,11 @@ private:
Builder builder(*module);
module->addGlobal(builder.makeGlobal(ASYNCIFY_STATE,
Type::i32,
- builder.makeConst(Literal(int32_t(0))),
+ builder.makeConst(int32_t(0)),
Builder::Mutable));
module->addGlobal(builder.makeGlobal(ASYNCIFY_DATA,
Type::i32,
- builder.makeConst(Literal(int32_t(0))),
+ builder.makeConst(int32_t(0)),
Builder::Mutable));
}
@@ -1506,7 +1505,7 @@ private:
}
auto* body = builder.makeBlock();
body->list.push_back(builder.makeGlobalSet(
- ASYNCIFY_STATE, builder.makeConst(Literal(int32_t(state)))));
+ ASYNCIFY_STATE, builder.makeConst(int32_t(state))));
if (setData) {
body->list.push_back(builder.makeGlobalSet(
ASYNCIFY_DATA, builder.makeLocalGet(0, Type::i32)));
@@ -1617,7 +1616,7 @@ struct ModAsyncify
value = 1 - value;
}
Builder builder(*this->getModule());
- this->replaceCurrent(builder.makeConst(Literal(int32_t(value))));
+ this->replaceCurrent(builder.makeConst(int32_t(value)));
}
void visitSelect(Select* curr) {
@@ -1630,7 +1629,7 @@ struct ModAsyncify
// we know we'll never rewind, we can optimize this.
if (neverRewind) {
Builder builder(*this->getModule());
- curr->condition = builder.makeConst(Literal(int32_t(0)));
+ curr->condition = builder.makeConst(int32_t(0));
}
}
diff --git a/src/passes/DeNaN.cpp b/src/passes/DeNaN.cpp
index c894cb3f1..8d0462718 100644
--- a/src/passes/DeNaN.cpp
+++ b/src/passes/DeNaN.cpp
@@ -51,13 +51,13 @@ struct DeNaN : public WalkerPass<
auto* c = expr->dynCast<Const>();
if (expr->type == Type::f32) {
if (c && c->value.isNaN()) {
- replacement = builder.makeConst(Literal(float(0)));
+ replacement = builder.makeConst(float(0));
} else {
replacement = builder.makeCall("deNan32", {expr}, Type::f32);
}
} else if (expr->type == Type::f64) {
if (c && c->value.isNaN()) {
- replacement = builder.makeConst(Literal(double(0)));
+ replacement = builder.makeConst(double(0));
} else {
replacement = builder.makeCall("deNan64", {expr}, Type::f64);
}
diff --git a/src/passes/I64ToI32Lowering.cpp b/src/passes/I64ToI32Lowering.cpp
index 912d6336c..78f15fcad 100644
--- a/src/passes/I64ToI32Lowering.cpp
+++ b/src/passes/I64ToI32Lowering.cpp
@@ -116,7 +116,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
curr->type = Type::i32;
auto* high = builder->makeGlobal(makeHighName(curr->name),
Type::i32,
- builder->makeConst(Literal(int32_t(0))),
+ builder->makeConst(int32_t(0)),
Builder::Mutable);
module->addGlobal(high);
if (curr->imported()) {
@@ -126,7 +126,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
uint64_t value = c->value.geti64();
c->value = Literal(uint32_t(value));
c->type = Type::i32;
- high->init = builder->makeConst(Literal(uint32_t(value >> 32)));
+ high->init = builder->makeConst(uint32_t(value >> 32));
} else if (auto* get = curr->init->dynCast<GlobalGet>()) {
high->init =
builder->makeGlobalGet(makeHighName(get->name), Type::i32);
@@ -142,7 +142,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
auto* highBits = new Global();
highBits->type = Type::i32;
highBits->name = INT64_TO_32_HIGH_BITS;
- highBits->init = builder->makeConst(Literal(int32_t(0)));
+ highBits->init = builder->makeConst(int32_t(0));
highBits->mutable_ = true;
module->addGlobal(highBits);
PostWalker<I64ToI32Lowering>::doWalkModule(module);
@@ -387,10 +387,10 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
highBits,
builder->makeBinary(ShrSInt32,
builder->makeLocalGet(lowBits, Type::i32),
- builder->makeConst(Literal(int32_t(31)))));
+ builder->makeConst(int32_t(31))));
} else {
- loadHigh = builder->makeLocalSet(highBits,
- builder->makeConst(Literal(int32_t(0))));
+ loadHigh =
+ builder->makeLocalSet(highBits, builder->makeConst(int32_t(0)));
}
curr->type = Type::i32;
curr->bytes = std::min(curr->bytes, uint8_t(4));
@@ -445,9 +445,9 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
TempVar highBits = getTemp();
auto* getLow = builder->makeCall(
ABI::wasm2js::ATOMIC_RMW_I64,
- {builder->makeConst(Literal(int32_t(curr->op))),
- builder->makeConst(Literal(int32_t(curr->bytes))),
- builder->makeConst(Literal(int32_t(curr->offset))),
+ {builder->makeConst(int32_t(curr->op)),
+ builder->makeConst(int32_t(curr->bytes)),
+ builder->makeConst(int32_t(curr->offset)),
curr->ptr,
curr->value,
builder->makeLocalGet(fetchOutParam(curr->value), Type::i32)},
@@ -487,11 +487,10 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
}
TempVar highBits = getTemp();
Const* lowVal =
- builder->makeConst(Literal(int32_t(curr->value.geti64() & 0xffffffff)));
- LocalSet* setHigh =
- builder->makeLocalSet(highBits,
- builder->makeConst(Literal(
- int32_t(uint64_t(curr->value.geti64()) >> 32))));
+ builder->makeConst(int32_t(curr->value.geti64() & 0xffffffff));
+ LocalSet* setHigh = builder->makeLocalSet(
+ highBits,
+ builder->makeConst(int32_t(uint64_t(curr->value.geti64()) >> 32)));
Block* result = builder->blockify(setHigh, lowVal);
setOutParam(result, std::move(highBits));
replaceCurrent(result);
@@ -511,7 +510,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
void lowerExtendUInt32(Unary* curr) {
TempVar highBits = getTemp();
Block* result = builder->blockify(
- builder->makeLocalSet(highBits, builder->makeConst(Literal(int32_t(0)))),
+ builder->makeLocalSet(highBits, builder->makeConst(int32_t(0))),
curr->value);
setOutParam(result, std::move(highBits));
replaceCurrent(result);
@@ -526,7 +525,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
highBits,
builder->makeBinary(ShrSInt32,
builder->makeLocalGet(lowBits, Type::i32),
- builder->makeConst(Literal(int32_t(31)))));
+ builder->makeConst(int32_t(31))));
Block* result = builder->blockify(
setLow, setHigh, builder->makeLocalGet(lowBits, Type::i32));
@@ -548,13 +547,12 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
Block* result = builder->blockify(
builder->makeCall(
ABI::wasm2js::SCRATCH_STORE_F64, {curr->value}, Type::none),
- builder->makeLocalSet(
- highBits,
- builder->makeCall(ABI::wasm2js::SCRATCH_LOAD_I32,
- {builder->makeConst(Literal(int32_t(1)))},
- Type::i32)),
+ builder->makeLocalSet(highBits,
+ builder->makeCall(ABI::wasm2js::SCRATCH_LOAD_I32,
+ {builder->makeConst(int32_t(1))},
+ Type::i32)),
builder->makeCall(ABI::wasm2js::SCRATCH_LOAD_I32,
- {builder->makeConst(Literal(int32_t(0)))},
+ {builder->makeConst(int32_t(0))},
Type::i32));
setOutParam(result, std::move(highBits));
replaceCurrent(result);
@@ -568,10 +566,10 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
TempVar highBits = fetchOutParam(curr->value);
Block* result = builder->blockify(
builder->makeCall(ABI::wasm2js::SCRATCH_STORE_I32,
- {builder->makeConst(Literal(int32_t(0))), curr->value},
+ {builder->makeConst(int32_t(0)), curr->value},
Type::none),
builder->makeCall(ABI::wasm2js::SCRATCH_STORE_I32,
- {builder->makeConst(Literal(int32_t(1))),
+ {builder->makeConst(int32_t(1)),
builder->makeLocalGet(highBits, Type::i32)},
Type::none),
builder->makeCall(ABI::wasm2js::SCRATCH_LOAD_F64, {}, Type::f64));
@@ -676,7 +674,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
builder->makeUnary(abs, builder->makeLocalGet(f, localType)),
builder->makeConst(litOne)),
highBitsCalc,
- builder->makeConst(Literal(int32_t(0))));
+ builder->makeConst(int32_t(0)));
Block* result = builder->blockify(
builder->makeLocalSet(f, curr->value),
builder->makeLocalSet(highBits, highBitsVal),
@@ -718,15 +716,14 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
Expression* result = builder->blockify(
builder->makeLocalSet(lowBits, curr->value),
- builder->makeLocalSet(highResult,
- builder->makeConst(Literal(int32_t(0)))),
+ builder->makeLocalSet(highResult, builder->makeConst(int32_t(0))),
builder->makeBinary(
AddFloat64,
builder->makeUnary(ConvertUInt32ToFloat64,
builder->makeLocalGet(lowBits, Type::i32)),
builder->makeBinary(
MulFloat64,
- builder->makeConst(Literal((double)UINT_MAX + 1)),
+ builder->makeConst((double)UINT_MAX + 1),
builder->makeUnary(convertHigh,
builder->makeLocalGet(highBits, Type::i32)))));
@@ -757,18 +754,18 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
Binary* check =
builder->makeBinary(EqInt32,
builder->makeLocalGet(firstResult, Type::i32),
- builder->makeConst(Literal(int32_t(32))));
+ builder->makeConst(int32_t(32)));
If* conditional = builder->makeIf(
check,
builder->makeBinary(
AddInt32,
builder->makeUnary(op32, builder->makeLocalGet(second, Type::i32)),
- builder->makeConst(Literal(int32_t(32)))),
+ builder->makeConst(int32_t(32))),
builder->makeLocalGet(firstResult, Type::i32));
- LocalSet* setHigh = builder->makeLocalSet(
- highResult, builder->makeConst(Literal(int32_t(0))));
+ LocalSet* setHigh =
+ builder->makeLocalSet(highResult, builder->makeConst(int32_t(0)));
setOutParam(result, std::move(highResult));
@@ -890,7 +887,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
highResult,
builder->makeBinary(AddInt32,
builder->makeLocalGet(highResult, Type::i32),
- builder->makeConst(Literal(int32_t(1)))));
+ builder->makeConst(int32_t(1))));
If* checkOverflow = builder->makeIf(
builder->makeBinary(LtUInt32,
builder->makeLocalGet(lowResult, Type::i32),
@@ -978,7 +975,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
builder->makeBinary(ShlInt32,
builder->makeLocalGet(leftLow, Type::i32),
builder->makeLocalGet(shift, Type::i32))),
- builder->makeConst(Literal(int32_t(0))));
+ builder->makeConst(int32_t(0)));
}
// a >> b where `b` >= 32
@@ -993,7 +990,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
highBits,
builder->makeBinary(ShrSInt32,
builder->makeLocalGet(leftHigh, Type::i32),
- builder->makeConst(Literal(int32_t(31))))),
+ builder->makeConst(int32_t(31)))),
builder->makeBinary(ShrSInt32,
builder->makeLocalGet(leftHigh, Type::i32),
builder->makeLocalGet(shift, Type::i32)));
@@ -1001,7 +998,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
Block* makeLargeShrU(Index highBits, Index leftHigh, Index shift) {
return builder->blockify(
- builder->makeLocalSet(highBits, builder->makeConst(Literal(int32_t(0)))),
+ builder->makeLocalSet(highBits, builder->makeConst(int32_t(0))),
builder->makeBinary(ShrUInt32,
builder->makeLocalGet(leftHigh, Type::i32),
builder->makeLocalGet(shift, Type::i32)));
@@ -1103,13 +1100,13 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
shift,
builder->makeBinary(AndInt32,
builder->makeLocalGet(rightLow, Type::i32),
- builder->makeConst(Literal(int32_t(32 - 1)))));
+ builder->makeConst(int32_t(32 - 1))));
Binary* isLargeShift = builder->makeBinary(
LeUInt32,
- builder->makeConst(Literal(int32_t(32))),
+ builder->makeConst(int32_t(32)),
builder->makeBinary(AndInt32,
builder->makeLocalGet(rightLow, Type::i32),
- builder->makeConst(Literal(int32_t(64 - 1)))));
+ builder->makeConst(int32_t(64 - 1))));
Block* largeShiftBlock;
switch (op) {
case ShlInt64:
@@ -1127,12 +1124,12 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
Binary* shiftMask = builder->makeBinary(
SubInt32,
builder->makeBinary(ShlInt32,
- builder->makeConst(Literal(int32_t(1))),
+ builder->makeConst(int32_t(1)),
builder->makeLocalGet(shift, Type::i32)),
- builder->makeConst(Literal(int32_t(1))));
+ builder->makeConst(int32_t(1)));
Binary* widthLessShift =
builder->makeBinary(SubInt32,
- builder->makeConst(Literal(int32_t(32))),
+ builder->makeConst(int32_t(32)),
builder->makeLocalGet(shift, Type::i32));
Block* smallShiftBlock;
switch (op) {
@@ -1283,13 +1280,12 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
builder->makeBinary(lowOp,
builder->makeLocalGet(leftLow, Type::i32),
builder->makeLocalGet(rightLow, Type::i32));
- If* lowIf = builder->makeIf(compLow,
- builder->makeConst(Literal(int32_t(0))),
- builder->makeConst(Literal(int32_t(1))));
- If* highIf2 = builder->makeIf(
- compHigh2, lowIf, builder->makeConst(Literal(int32_t(0))));
- If* highIf1 = builder->makeIf(
- compHigh1, builder->makeConst(Literal(int32_t(1))), highIf2);
+ If* lowIf = builder->makeIf(
+ compLow, builder->makeConst(int32_t(0)), builder->makeConst(int32_t(1)));
+ If* highIf2 =
+ builder->makeIf(compHigh2, lowIf, builder->makeConst(int32_t(0)));
+ If* highIf1 =
+ builder->makeIf(compHigh1, builder->makeConst(int32_t(1)), highIf2);
return builder->blockify(result, highIf1);
}
diff --git a/src/passes/InstrumentLocals.cpp b/src/passes/InstrumentLocals.cpp
index 2c74e5794..0bf22d29b 100644
--- a/src/passes/InstrumentLocals.cpp
+++ b/src/passes/InstrumentLocals.cpp
@@ -107,12 +107,11 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
case Type::unreachable:
WASM_UNREACHABLE("unexpected type");
}
- replaceCurrent(
- builder.makeCall(import,
- {builder.makeConst(Literal(int32_t(id++))),
- builder.makeConst(Literal(int32_t(curr->index))),
- curr},
- curr->type));
+ replaceCurrent(builder.makeCall(import,
+ {builder.makeConst(int32_t(id++)),
+ builder.makeConst(int32_t(curr->index)),
+ curr},
+ curr->type));
}
void visitLocalSet(LocalSet* curr) {
@@ -157,12 +156,11 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
case Type::none:
WASM_UNREACHABLE("unexpected type");
}
- curr->value =
- builder.makeCall(import,
- {builder.makeConst(Literal(int32_t(id++))),
- builder.makeConst(Literal(int32_t(curr->index))),
- curr->value},
- curr->value->type);
+ curr->value = builder.makeCall(import,
+ {builder.makeConst(int32_t(id++)),
+ builder.makeConst(int32_t(curr->index)),
+ curr->value},
+ curr->value->type);
}
void visitModule(Module* curr) {
diff --git a/src/passes/InstrumentMemory.cpp b/src/passes/InstrumentMemory.cpp
index 4db409c10..10574350b 100644
--- a/src/passes/InstrumentMemory.cpp
+++ b/src/passes/InstrumentMemory.cpp
@@ -78,13 +78,12 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> {
void visitLoad(Load* curr) {
id++;
Builder builder(*getModule());
- curr->ptr =
- builder.makeCall(load_ptr,
- {builder.makeConst(Literal(int32_t(id))),
- builder.makeConst(Literal(int32_t(curr->bytes))),
- builder.makeConst(Literal(int32_t(curr->offset.addr))),
- curr->ptr},
- Type::i32);
+ curr->ptr = builder.makeCall(load_ptr,
+ {builder.makeConst(int32_t(id)),
+ builder.makeConst(int32_t(curr->bytes)),
+ builder.makeConst(int32_t(curr->offset.addr)),
+ curr->ptr},
+ Type::i32);
Name target;
switch (curr->type.getSingle()) {
case Type::i32:
@@ -103,19 +102,18 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> {
return; // TODO: other types, unreachable, etc.
}
replaceCurrent(builder.makeCall(
- target, {builder.makeConst(Literal(int32_t(id))), curr}, curr->type));
+ target, {builder.makeConst(int32_t(id)), curr}, curr->type));
}
void visitStore(Store* curr) {
id++;
Builder builder(*getModule());
- curr->ptr =
- builder.makeCall(store_ptr,
- {builder.makeConst(Literal(int32_t(id))),
- builder.makeConst(Literal(int32_t(curr->bytes))),
- builder.makeConst(Literal(int32_t(curr->offset.addr))),
- curr->ptr},
- Type::i32);
+ curr->ptr = builder.makeCall(store_ptr,
+ {builder.makeConst(int32_t(id)),
+ builder.makeConst(int32_t(curr->bytes)),
+ builder.makeConst(int32_t(curr->offset.addr)),
+ curr->ptr},
+ Type::i32);
Name target;
switch (curr->value->type.getSingle()) {
case Type::i32:
@@ -133,10 +131,8 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> {
default:
return; // TODO: other types, unreachable, etc.
}
- curr->value =
- builder.makeCall(target,
- {builder.makeConst(Literal(int32_t(id))), curr->value},
- curr->value->type);
+ curr->value = builder.makeCall(
+ target, {builder.makeConst(int32_t(id)), curr->value}, curr->value->type);
}
void visitModule(Module* curr) {
diff --git a/src/passes/LogExecution.cpp b/src/passes/LogExecution.cpp
index a6caf1c1f..ebc1c5636 100644
--- a/src/passes/LogExecution.cpp
+++ b/src/passes/LogExecution.cpp
@@ -71,8 +71,7 @@ private:
static Index id = 0;
Builder builder(*getModule());
return builder.makeSequence(
- builder.makeCall(
- LOGGER, {builder.makeConst(Literal(int32_t(id++)))}, Type::none),
+ builder.makeCall(LOGGER, {builder.makeConst(int32_t(id++))}, Type::none),
curr);
}
};
diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp
index c6b8a281a..1a1e87502 100644
--- a/src/passes/MemoryPacking.cpp
+++ b/src/passes/MemoryPacking.cpp
@@ -79,7 +79,7 @@ namespace {
Expression* makeShiftedMemorySize(Builder& builder) {
return builder.makeBinary(ShlInt32,
builder.makeHost(MemorySize, Name(), {}),
- builder.makeConst(Literal(int32_t(16))));
+ builder.makeConst(int32_t(16)));
}
} // anonymous namespace
@@ -437,8 +437,7 @@ void MemoryPacking::createSplitSegments(Builder& builder,
Expression* offset = nullptr;
if (!segment.isPassive) {
if (auto* c = segment.offset->dynCast<Const>()) {
- offset =
- builder.makeConst(Literal(int32_t(c->value.geti32() + range.start)));
+ offset = builder.makeConst(int32_t(c->value.geti32() + range.start));
} else {
assert(ranges.size() == 1);
offset = segment.offset;
@@ -497,7 +496,7 @@ void MemoryPacking::createReplacements(Module* module,
std::to_string(dropStateGlobalCount++));
module->addGlobal(builder.makeGlobal(dropStateGlobal,
Type::i32,
- builder.makeConst(Literal(int32_t(0))),
+ builder.makeConst(int32_t(0)),
Builder::Mutable));
return dropStateGlobal;
};
@@ -576,21 +575,20 @@ void MemoryPacking::createReplacements(Module* module,
// Calculate dest, either as a const or as an addition to the dest local
Expression* dest;
if (auto* c = init->dest->dynCast<Const>()) {
- dest =
- builder.makeConst(Literal(int32_t(c->value.geti32() + bytesWritten)));
+ dest = builder.makeConst(int32_t(c->value.geti32() + bytesWritten));
} else {
auto* get = builder.makeLocalGet(-1, Type::i32);
getVars.push_back(&get->index);
dest = get;
if (bytesWritten > 0) {
- Const* addend = builder.makeConst(Literal(int32_t(bytesWritten)));
+ Const* addend = builder.makeConst(int32_t(bytesWritten));
dest = builder.makeBinary(AddInt32, dest, addend);
}
}
// How many bytes are read from this range
size_t bytes = std::min(range.end, end) - std::max(range.start, start);
- Expression* size = builder.makeConst(Literal(int32_t(bytes)));
+ Expression* size = builder.makeConst(int32_t(bytes));
bytesWritten += bytes;
// Create new memory.init or memory.fill
@@ -600,7 +598,7 @@ void MemoryPacking::createReplacements(Module* module,
appendResult(builder.makeMemoryFill(dest, value, size));
} else {
size_t offsetBytes = std::max(start, range.start) - range.start;
- Expression* offset = builder.makeConst(Literal(int32_t(offsetBytes)));
+ Expression* offset = builder.makeConst(int32_t(offsetBytes));
appendResult(builder.makeMemoryInit(initIndex, dest, offset, size));
initIndex++;
}
@@ -634,8 +632,8 @@ void MemoryPacking::createReplacements(Module* module,
// Track drop state in a global only if some memory.init required it
if (dropStateGlobal != Name()) {
- appendResult(builder.makeGlobalSet(
- dropStateGlobal, builder.makeConst(Literal(int32_t(1)))));
+ appendResult(
+ builder.makeGlobalSet(dropStateGlobal, builder.makeConst(int32_t(1))));
}
size_t dropIndex = segmentIndex;
for (auto range : ranges) {
diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp
index 68f0c06e0..00fb30b51 100644
--- a/src/passes/PostEmscripten.cpp
+++ b/src/passes/PostEmscripten.cpp
@@ -91,8 +91,7 @@ struct PostEmscripten : public Pass {
auto oldValue = stackPointer->init->cast<Const>()->value;
BYN_TRACE("updating __stack_pointer: " << oldValue.geti32() << " -> "
<< stackPtr << "\n");
- stackPointer->init =
- Builder(*module).makeConst(Literal(int32_t(stackPtr)));
+ stackPointer->init = Builder(*module).makeConst(int32_t(stackPtr));
}
}
@@ -105,7 +104,7 @@ struct PostEmscripten : public Pass {
auto* func = imports.getImportedFunction(ENV, "emscripten_get_sbrk_ptr");
if (func) {
Builder builder(*module);
- func->body = builder.makeConst(Literal(int32_t(sbrkPtr)));
+ func->body = builder.makeConst(int32_t(sbrkPtr));
func->module = func->base = Name();
}
// Apply the sbrk ptr value, if it was provided. This lets emscripten set
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index 5d1b70ad5..9d4575bb7 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -235,10 +235,8 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
}
curr->targets.resize(curr->targets.size() - removable);
Builder builder(*getModule());
- curr->condition =
- builder.makeBinary(SubInt32,
- curr->condition,
- builder.makeConst(Literal(int32_t(removable))));
+ curr->condition = builder.makeBinary(
+ SubInt32, curr->condition, builder.makeConst(int32_t(removable)));
}
// when there isn't a value, we can do some trivial optimizations without
// worrying about the value being executed before the condition
@@ -287,17 +285,16 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
Builder builder(*getModule());
auto temp = builder.addVar(getFunction(), Type::i32);
Expression* z;
- replaceCurrent(
- z = builder.makeIf(
- builder.makeLocalTee(temp, curr->condition, Type::i32),
- builder.makeIf(
- builder.makeBinary(
- EqInt32,
- builder.makeLocalGet(temp, Type::i32),
- builder.makeConst(Literal(int32_t(curr->targets.size() - 1)))),
- builder.makeBreak(curr->targets.back()),
- builder.makeBreak(curr->default_)),
- builder.makeBreak(curr->targets.front())));
+ replaceCurrent(z = builder.makeIf(
+ builder.makeLocalTee(temp, curr->condition, Type::i32),
+ builder.makeIf(builder.makeBinary(
+ EqInt32,
+ builder.makeLocalGet(temp, Type::i32),
+ builder.makeConst(
+ int32_t(curr->targets.size() - 1))),
+ builder.makeBreak(curr->targets.back()),
+ builder.makeBreak(curr->default_)),
+ builder.makeBreak(curr->targets.front())));
}
}
}
@@ -1262,10 +1259,8 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
Builder builder(*getModule());
// the table and condition are offset by the min
if (min != 0) {
- conditionValue =
- builder.makeBinary(SubInt32,
- conditionValue,
- builder.makeConst(Literal(int32_t(min))));
+ conditionValue = builder.makeBinary(
+ SubInt32, conditionValue, builder.makeConst(int32_t(min)));
}
list[end - 1] = builder.makeBlock(
defaultName,
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h
index 63f4b5a85..52a524e29 100644
--- a/src/tools/fuzzing.h
+++ b/src/tools/fuzzing.h
@@ -348,14 +348,14 @@ private:
segment.data[j] = upTo(512);
}
if (!segment.isPassive) {
- segment.offset = builder.makeConst(Literal(int32_t(memCovered)));
+ segment.offset = builder.makeConst(int32_t(memCovered));
memCovered += segSize;
}
wasm.memory.segments.push_back(segment);
}
} else {
// init some data
- wasm.memory.segments.emplace_back(builder.makeConst(Literal(int32_t(0))));
+ wasm.memory.segments.emplace_back(builder.makeConst(int32_t(0)));
auto num = upTo(USABLE_MEMORY * 2);
for (size_t i = 0; i < num; i++) {
auto value = upTo(512);
@@ -374,7 +374,7 @@ private:
// }
std::vector<Expression*> contents;
contents.push_back(
- builder.makeLocalSet(0, builder.makeConst(Literal(uint32_t(5381)))));
+ builder.makeLocalSet(0, builder.makeConst(uint32_t(5381))));
for (Index i = 0; i < USABLE_MEMORY; i++) {
contents.push_back(builder.makeLocalSet(
0,
@@ -384,14 +384,10 @@ private:
AddInt32,
builder.makeBinary(ShlInt32,
builder.makeLocalGet(0, Type::i32),
- builder.makeConst(Literal(uint32_t(5)))),
+ builder.makeConst(uint32_t(5))),
builder.makeLocalGet(0, Type::i32)),
- builder.makeLoad(1,
- false,
- i,
- 1,
- builder.makeConst(Literal(uint32_t(0))),
- Type::i32))));
+ builder.makeLoad(
+ 1, false, i, 1, builder.makeConst(uint32_t(0)), Type::i32))));
}
contents.push_back(builder.makeLocalGet(0, Type::i32));
auto* body = builder.makeBlock(contents);
@@ -405,7 +401,7 @@ private:
void setupTable() {
wasm.table.exists = true;
- wasm.table.segments.emplace_back(builder.makeConst(Literal(int32_t(0))));
+ wasm.table.segments.emplace_back(builder.makeConst(int32_t(0)));
}
std::map<Type, std::vector<Name>> globalsByType;
@@ -443,18 +439,17 @@ private:
const Name HANG_LIMIT_GLOBAL = "hangLimit";
void addHangLimitSupport() {
- auto* glob =
- builder.makeGlobal(HANG_LIMIT_GLOBAL,
- Type::i32,
- builder.makeConst(Literal(int32_t(HANG_LIMIT))),
- Builder::Mutable);
+ auto* glob = builder.makeGlobal(HANG_LIMIT_GLOBAL,
+ Type::i32,
+ builder.makeConst(int32_t(HANG_LIMIT)),
+ Builder::Mutable);
wasm.addGlobal(glob);
auto* func = new Function;
func->name = "hangLimitInitializer";
func->sig = Signature(Type::none, Type::none);
- func->body = builder.makeGlobalSet(
- glob->name, builder.makeConst(Literal(int32_t(HANG_LIMIT))));
+ func->body =
+ builder.makeGlobalSet(glob->name, builder.makeConst(int32_t(HANG_LIMIT)));
wasm.addFunction(func);
auto* export_ = new Export;
@@ -486,7 +481,7 @@ private:
HANG_LIMIT_GLOBAL,
builder.makeBinary(BinaryOp::SubInt32,
builder.makeGlobalGet(HANG_LIMIT_GLOBAL, Type::i32),
- builder.makeConst(Literal(int32_t(1))))));
+ builder.makeConst(int32_t(1)))));
}
// function generation state
@@ -1209,7 +1204,7 @@ private:
// going to trap
Expression* target;
if (!allowOOB || !oneIn(10)) {
- target = builder.makeConst(Literal(int32_t(i)));
+ target = builder.makeConst(int32_t(i));
} else {
target = make(Type::i32);
}
@@ -1312,7 +1307,7 @@ private:
// most memory ops will just trap
if (!allowOOB || !oneIn(10)) {
ret = builder.makeBinary(
- AndInt32, ret, builder.makeConst(Literal(int32_t(USABLE_MEMORY - 1))));
+ AndInt32, ret, builder.makeConst(int32_t(USABLE_MEMORY - 1)));
}
return ret;
}
@@ -2605,8 +2600,8 @@ private:
size_t offsetVal = upTo(totalSize);
size_t sizeVal = upTo(totalSize - offsetVal);
Expression* dest = makePointer();
- Expression* offset = builder.makeConst(Literal(int32_t(offsetVal)));
- Expression* size = builder.makeConst(Literal(int32_t(sizeVal)));
+ Expression* offset = builder.makeConst(int32_t(offsetVal));
+ Expression* size = builder.makeConst(int32_t(sizeVal));
return builder.makeMemoryInit(segment, dest, offset, size);
}
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index 7ef52dd5f..c6734fdc1 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -316,7 +316,7 @@ private:
std::vector<char> temp;
Builder builder(*wasm);
wasm->memory.segments.push_back(
- Memory::Segment(builder.makeConst(Literal(int32_t(0))), temp));
+ Memory::Segment(builder.makeConst(int32_t(0)), temp));
}
// memory should already have been flattened
assert(wasm->memory.segments[0].offset->cast<Const>()->value.getInteger() ==
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp
index ab593c76c..029b9092d 100644
--- a/src/tools/wasm-reduce.cpp
+++ b/src/tools/wasm-reduce.cpp
@@ -982,7 +982,7 @@ struct Reducer
if (condition->is<Const>()) {
return;
}
- auto* c = builder->makeConst(Literal(int32_t(0)));
+ auto* c = builder->makeConst(int32_t(0));
if (!tryToReplaceChild(condition, c)) {
c->value = Literal(int32_t(1));
tryToReplaceChild(condition, c);
@@ -1019,7 +1019,7 @@ struct Reducer
builder->makeConstantExpression(Literal::makeZero(curr->type));
return tryToReplaceCurrent(n);
}
- Const* c = builder->makeConst(Literal(int32_t(0)));
+ Const* c = builder->makeConst(int32_t(0));
if (tryToReplaceCurrent(c)) {
return true;
}
diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp
index f12d5189d..fb63627a3 100644
--- a/src/tools/wasm2js.cpp
+++ b/src/tools/wasm2js.cpp
@@ -591,8 +591,7 @@ Ref AssertionEmitter::emitAssertReturnFunc(Builder& wasmBuilder,
Expression* body = nullptr;
if (e.size() == 2) {
if (actual->type == Type::none) {
- body = wasmBuilder.blockify(actual,
- wasmBuilder.makeConst(Literal(uint32_t(1))));
+ body = wasmBuilder.blockify(actual, wasmBuilder.makeConst(uint32_t(1)));
} else {
body = actual;
}
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index 5c6792a82..e41bd769c 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -478,6 +478,7 @@ public:
ret->type = value.type;
return ret;
}
+ template<typename T> Const* makeConst(T x) { return makeConst(Literal(x)); }
Unary* makeUnary(UnaryOp op, Expression* value) {
auto* ret = allocator.alloc<Unary>();
ret->op = op;
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index 4a8f2c0c3..2fcabb3b2 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -144,7 +144,7 @@ Function* EmscriptenGlueGenerator::generateAssignGOTEntriesFunction() {
}
// Make this an internal, non-imported, global.
g->module.clear();
- g->init = Builder(wasm).makeConst(Literal(0));
+ g->init = Builder(wasm).makeConst(int32_t(0));
}
if (!gotFuncEntries.size() && !gotMemEntries.size()) {
@@ -507,7 +507,7 @@ void EmscriptenGlueGenerator::enforceStackLimit() {
auto* stackLimit = builder.makeGlobal(STACK_LIMIT,
stackPointer->type,
- builder.makeConst(Literal(0)),
+ builder.makeConst(int32_t(0)),
Builder::Mutable);
wasm.addGlobal(stackLimit);