summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/abi/abi.h2
-rw-r--r--src/asm2wasm.h70
-rw-r--r--src/asm_v_wasm.h12
-rw-r--r--src/asmjs/asm_v_wasm.cpp38
-rw-r--r--src/binaryen-c.cpp62
-rw-r--r--src/ir/bits.h2
-rw-r--r--src/ir/block-utils.h4
-rw-r--r--src/ir/branch-utils.h2
-rw-r--r--src/ir/literal-utils.h8
-rw-r--r--src/ir/load-utils.h2
-rw-r--r--src/ir/type-updating.h10
-rw-r--r--src/ir/utils.h16
-rw-r--r--src/literal.h36
-rw-r--r--src/parsing.h4
-rw-r--r--src/passes/CoalesceLocals.cpp2
-rw-r--r--src/passes/CodeFolding.cpp4
-rw-r--r--src/passes/ConstHoisting.cpp2
-rw-r--r--src/passes/DeadCodeElimination.cpp2
-rw-r--r--src/passes/Flatten.cpp22
-rw-r--r--src/passes/I64ToI32Lowering.cpp12
-rw-r--r--src/passes/LocalCSE.cpp2
-rw-r--r--src/passes/MergeBlocks.cpp4
-rw-r--r--src/passes/OptimizeInstructions.cpp6
-rw-r--r--src/passes/Precompute.cpp2
-rw-r--r--src/passes/Print.cpp46
-rw-r--r--src/passes/RemoveImports.cpp2
-rw-r--r--src/passes/RemoveUnusedBrs.cpp8
-rw-r--r--src/passes/SSAify.cpp2
-rw-r--r--src/passes/SafeHeap.cpp16
-rw-r--r--src/passes/SpillPointers.cpp8
-rw-r--r--src/passes/TrapMode.cpp8
-rw-r--r--src/passes/Vacuum.cpp10
-rw-r--r--src/s2wasm.h46
-rw-r--r--src/shell-interface.h2
-rw-r--r--src/tools/execution-results.h2
-rw-r--r--src/tools/fuzzing.h92
-rw-r--r--src/tools/js-wrapper.h4
-rw-r--r--src/tools/spec-wrapper.h2
-rw-r--r--src/tools/wasm-ctor-eval.cpp2
-rw-r--r--src/tools/wasm-reduce.cpp2
-rw-r--r--src/tools/wasm-shell.cpp2
-rw-r--r--src/wasm-binary.h8
-rw-r--r--src/wasm-builder.h54
-rw-r--r--src/wasm-interpreter.h18
-rw-r--r--src/wasm-js.cpp18
-rw-r--r--src/wasm-linker.cpp4
-rw-r--r--src/wasm-s-parser.h36
-rw-r--r--src/wasm-type.h14
-rw-r--r--src/wasm.h28
-rw-r--r--src/wasm/literal.cpp274
-rw-r--r--src/wasm/wasm-binary.cpp52
-rw-r--r--src/wasm/wasm-s-parser.cpp86
-rw-r--r--src/wasm/wasm-type.cpp40
-rw-r--r--src/wasm/wasm-validator.cpp58
-rw-r--r--src/wasm/wasm.cpp22
-rw-r--r--src/wasm2asm.h22
56 files changed, 657 insertions, 657 deletions
diff --git a/src/abi/abi.h b/src/abi/abi.h
index ff1864efa..239efd3f3 100644
--- a/src/abi/abi.h
+++ b/src/abi/abi.h
@@ -24,7 +24,7 @@ namespace wasm {
namespace ABI {
// The pointer type. Will need to update this for wasm64
-const static WasmType PointerType = WasmType::i32;
+const static Type PointerType = Type::i32;
} // namespace ABI
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index aa8394d3a..63b88f5fe 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -398,12 +398,12 @@ public:
// globals
struct MappedGlobal {
- WasmType type;
+ Type type;
bool import; // if true, this is an import - we should read the value, not just set a zero
IString module, base;
MappedGlobal() : type(none), import(false) {}
- MappedGlobal(WasmType type) : type(type), import(false) {}
- MappedGlobal(WasmType type, bool import, IString module, IString base) : type(type), import(import), module(module), base(base) {}
+ MappedGlobal(Type type) : type(type), import(false) {}
+ MappedGlobal(Type type, bool import, IString module, IString base) : type(type), import(import), module(module), base(base) {}
};
// function table
@@ -422,7 +422,7 @@ public:
std::map<IString, MappedGlobal> mappedGlobals;
private:
- void allocateGlobal(IString name, WasmType type) {
+ void allocateGlobal(IString name, Type type) {
assert(mappedGlobals.find(name) == mappedGlobals.end());
mappedGlobals.emplace(name, MappedGlobal(type));
wasm.addGlobal(builder.makeGlobal(
@@ -478,7 +478,7 @@ private:
std::map<IString, std::unique_ptr<FunctionType>> importedFunctionTypes;
- void noteImportedFunctionCall(Ref ast, WasmType resultType, CallImport* call) {
+ void noteImportedFunctionCall(Ref ast, Type resultType, CallImport* call) {
assert(ast[0] == CALL && ast[1]->isString());
IString importName = ast[1]->getIString();
auto type = make_unique<FunctionType>();
@@ -517,7 +517,7 @@ private:
}
}
- WasmType getResultTypeOfCallUsingParent(Ref parent, AsmData* data) {
+ Type getResultTypeOfCallUsingParent(Ref parent, AsmData* data) {
auto result = none;
if (!!parent) {
// if the parent is a seq, we cannot be the last element in it (we would have a coercion, which would be
@@ -530,7 +530,7 @@ private:
}
FunctionType* getFunctionType(Ref parent, ExpressionList& operands, AsmData* data) {
- WasmType result = getResultTypeOfCallUsingParent(parent, data);
+ Type result = getResultTypeOfCallUsingParent(parent, data);
return ensureFunctionType(getSig(result, operands), &wasm);
}
@@ -569,7 +569,7 @@ private:
return detectType(ast, data, false, Math_fround, wasmOnly);
}
- WasmType detectWasmType(Ref ast, AsmData *data) {
+ Type detectWasmType(Ref ast, AsmData *data) {
return asmToWasmType(detectAsmType(ast, data));
}
@@ -586,8 +586,8 @@ private:
}
BinaryOp parseAsmBinaryOp(IString op, Ref left, Ref right, Expression* leftWasm, Expression* rightWasm) {
- WasmType leftType = leftWasm->type;
- bool isInteger = leftType == WasmType::i32;
+ Type leftType = leftWasm->type;
+ bool isInteger = leftType == Type::i32;
if (op == PLUS) return isInteger ? BinaryOp::AddInt32 : (leftType == f32 ? BinaryOp::AddFloat32 : BinaryOp::AddFloat64);
if (op == MINUS) return isInteger ? BinaryOp::SubInt32 : (leftType == f32 ? BinaryOp::SubFloat32 : BinaryOp::SubFloat64);
@@ -694,7 +694,7 @@ private:
return ret;
}
- void fixCallType(Expression* call, WasmType type) {
+ void fixCallType(Expression* call, Type type) {
if (call->is<Call>()) call->cast<Call>()->type = type;
if (call->is<CallImport>()) call->cast<CallImport>()->type = type;
else if (call->is<CallIndirect>()) call->cast<CallIndirect>()->type = type;
@@ -704,7 +704,7 @@ private:
if (module == GLOBAL_MATH) {
if (base == ABS) {
assert(operands && operands->size() == 1);
- WasmType type = (*operands)[0]->type;
+ Type type = (*operands)[0]->type;
if (type == i32) return ensureFunctionType("ii", &wasm);
if (type == f32) return ensureFunctionType("ff", &wasm);
if (type == f64) return ensureFunctionType("dd", &wasm);
@@ -800,7 +800,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
wasm.addImport(import);
}
- auto addImport = [&](IString name, Ref imported, WasmType type) {
+ auto addImport = [&](IString name, Ref imported, Type type) {
assert(imported[0] == DOT);
Ref module = imported[1];
IString moduleName;
@@ -910,9 +910,9 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
import->base = imported[2]->getIString();
// special-case some asm builtins
if (import->module == GLOBAL && (import->base == NAN_ || import->base == INFINITY_)) {
- type = WasmType::f64;
+ type = Type::f64;
}
- if (type != WasmType::none) {
+ if (type != Type::none) {
// this is a global
import->kind = ExternalKind::Global;
import->globalType = type;
@@ -986,12 +986,12 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
if (value->isNumber()) {
// global int
assert(value->getNumber() == 0);
- allocateGlobal(name, WasmType::i32);
+ allocateGlobal(name, Type::i32);
} else if (value[0] == BINARY) {
// int import
assert(value[1] == OR && value[3]->isNumber() && value[3]->getNumber() == 0);
Ref import = value[2]; // env.what
- addImport(name, import, WasmType::i32);
+ addImport(name, import, Type::i32);
} else if (value[0] == UNARY_PREFIX) {
// double import or global
assert(value[1] == PLUS);
@@ -999,14 +999,14 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
if (import->isNumber()) {
// global
assert(import->getNumber() == 0);
- allocateGlobal(name, WasmType::f64);
+ allocateGlobal(name, Type::f64);
} else {
// import
- addImport(name, import, WasmType::f64);
+ addImport(name, import, Type::f64);
}
} else if (value[0] == CALL) {
assert(value[1]->isString() && value[1] == Math_fround && value[2][0]->isNumber() && value[2][0]->getNumber() == 0);
- allocateGlobal(name, WasmType::f32);
+ allocateGlobal(name, Type::f32);
} else if (value[0] == DOT) {
// simple module.base import. can be a view, or a function.
if (value[1]->isString()) {
@@ -1033,7 +1033,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
}
}
// function import
- addImport(name, value, WasmType::none);
+ addImport(name, value, Type::none);
} else if (value[0] == NEW) {
// ignore imports of typed arrays, but note the names of the arrays
value = value[1];
@@ -1641,7 +1641,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
auto conv = allocator.alloc<Unary>();
conv->op = DemoteFloat64;
conv->value = ret->value;
- conv->type = WasmType::f32;
+ conv->type = Type::f32;
ret->value = conv;
} else if (ret->valueType == f64 && ret->value->type == f32) {
ret->value = ensureDouble(ret->value);
@@ -1663,7 +1663,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
ret->right = process(ast[3]);
ret->op = parseAsmBinaryOp(ast[1]->getIString(), ast[2], ast[3], ret->left, ret->right);
ret->finalize();
- if (ret->op == BinaryOp::RemSInt32 && isWasmTypeFloat(ret->type)) {
+ if (ret->op == BinaryOp::RemSInt32 && isTypeFloat(ret->type)) {
// WebAssembly does not have floating-point remainder, we have to emit a call to a special import of ours
CallImport *call = allocator.alloc<CallImport>();
call->target = F64_REM;
@@ -1697,7 +1697,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
ret->offset = 0;
ret->align = view.bytes;
ret->ptr = processUnshifted(ast[2], view.bytes);
- ret->type = getWasmType(view.bytes, !view.integer);
+ ret->type = getType(view.bytes, !view.integer);
return ret;
} else if (what == UNARY_PREFIX) {
if (ast[1] == PLUS) {
@@ -1710,7 +1710,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
auto conv = allocator.alloc<Unary>();
conv->op = isUnsignedCoercion(ast[2]) ? ConvertUInt32ToFloat64 : ConvertSInt32ToFloat64;
conv->value = ret;
- conv->type = WasmType::f64;
+ conv->type = Type::f64;
return conv;
}
if (ret->type == f32) {
@@ -1732,17 +1732,17 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
ret->op = SubInt32;
ret->left = builder.makeConst(Literal((int32_t)0));
ret->right = process(ast[2]);
- ret->type = WasmType::i32;
+ ret->type = Type::i32;
return ret;
}
auto ret = allocator.alloc<Unary>();
ret->value = process(ast[2]);
if (asmType == ASM_DOUBLE) {
ret->op = NegFloat64;
- ret->type = WasmType::f64;
+ ret->type = Type::f64;
} else if (asmType == ASM_FLOAT) {
ret->op = NegFloat32;
- ret->type = WasmType::f32;
+ ret->type = Type::f32;
} else {
abort();
}
@@ -1771,7 +1771,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
ret->op = XorInt32;
ret->left = process(ast[2]);
ret->right = builder.makeConst(Literal(int32_t(-1)));
- ret->type = WasmType::i32;
+ ret->type = Type::i32;
return ret;
} else if (ast[1] == L_NOT) {
auto ret = allocator.alloc<Unary>();
@@ -1794,7 +1794,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
ret->op = MulInt32;
ret->left = process(ast[2][0]);
ret->right = process(ast[2][1]);
- ret->type = WasmType::i32;
+ ret->type = Type::i32;
return ret;
}
if (name == Math_clz32 || name == llvm_cttz_i32) {
@@ -1802,7 +1802,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
auto ret = allocator.alloc<Unary>();
ret->op = name == Math_clz32 ? ClzInt32 : CtzInt32;
ret->value = process(ast[2][0]);
- ret->type = WasmType::i32;
+ ret->type = Type::i32;
return ret;
}
if (name == Math_fround) {
@@ -2193,7 +2193,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
ret->target = builder.makeBinary(BinaryOp::AddInt32, ret->target, builder.makeCallImport(target[1]->getIString(), {}, i32));
return ret;
} else if (what == RETURN) {
- WasmType type = !!ast[1] ? detectWasmType(ast[1], &asmData) : none;
+ Type type = !!ast[1] ? detectWasmType(ast[1], &asmData) : none;
if (seenReturn) {
assert(function->result == type);
} else {
@@ -2306,7 +2306,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
if (seeker.found == 0) {
auto block = allocator.alloc<Block>();
block->list.push_back(child);
- if (isConcreteWasmType(child->type)) {
+ if (isConcreteType(child->type)) {
block->list.push_back(builder.makeNop()); // ensure a nop at the end, so the block has guaranteed none type and no values fall through
}
block->name = stop;
@@ -2443,7 +2443,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
auto conv = allocator.alloc<Unary>();
conv->op = ReinterpretInt32;
conv->value = process(writtenValue);
- conv->type = WasmType::f32;
+ conv->type = Type::f32;
if (readType == ASM_DOUBLE) {
return ensureDouble(conv);
}
@@ -2456,7 +2456,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
// this has an implicit f64->f32 in the write to memory
conv->value = builder.makeUnary(DemoteFloat64, conv->value);
}
- conv->type = WasmType::i32;
+ conv->type = Type::i32;
return conv;
}
}
diff --git a/src/asm_v_wasm.h b/src/asm_v_wasm.h
index d42a1082a..c79c73674 100644
--- a/src/asm_v_wasm.h
+++ b/src/asm_v_wasm.h
@@ -23,11 +23,11 @@
namespace wasm {
-WasmType asmToWasmType(AsmType asmType);
+Type asmToWasmType(AsmType asmType);
-AsmType wasmToAsmType(WasmType type);
+AsmType wasmToAsmType(Type type);
-char getSig(WasmType type);
+char getSig(Type type);
std::string getSig(const FunctionType *type);
@@ -45,7 +45,7 @@ std::string getSig(T *call) {
}
template<typename ListType>
-std::string getSig(WasmType result, const ListType& operands) {
+std::string getSig(Type result, const ListType& operands) {
std::string ret;
ret += getSig(result);
for (auto operand : operands) {
@@ -55,7 +55,7 @@ std::string getSig(WasmType result, const ListType& operands) {
}
template<typename ListType>
-std::string getSigFromStructs(WasmType result, const ListType& operands) {
+std::string getSigFromStructs(Type result, const ListType& operands) {
std::string ret;
ret += getSig(result);
for (auto operand : operands) {
@@ -64,7 +64,7 @@ std::string getSigFromStructs(WasmType result, const ListType& operands) {
return ret;
}
-WasmType sigToWasmType(char sig);
+Type sigToType(char sig);
FunctionType* sigToFunctionType(std::string sig);
diff --git a/src/asmjs/asm_v_wasm.cpp b/src/asmjs/asm_v_wasm.cpp
index bfb04a9fd..bda1c3080 100644
--- a/src/asmjs/asm_v_wasm.cpp
+++ b/src/asmjs/asm_v_wasm.cpp
@@ -20,31 +20,31 @@
namespace wasm {
-WasmType asmToWasmType(AsmType asmType) {
+Type asmToWasmType(AsmType asmType) {
switch (asmType) {
- case ASM_INT: return WasmType::i32;
- case ASM_DOUBLE: return WasmType::f64;
- case ASM_FLOAT: return WasmType::f32;
- case ASM_INT64: return WasmType::i64;
- case ASM_NONE: return WasmType::none;
+ case ASM_INT: return Type::i32;
+ case ASM_DOUBLE: return Type::f64;
+ case ASM_FLOAT: return Type::f32;
+ case ASM_INT64: return Type::i64;
+ case ASM_NONE: return Type::none;
default: {}
}
abort();
}
-AsmType wasmToAsmType(WasmType type) {
+AsmType wasmToAsmType(Type type) {
switch (type) {
- case WasmType::i32: return ASM_INT;
- case WasmType::f32: return ASM_FLOAT;
- case WasmType::f64: return ASM_DOUBLE;
- case WasmType::i64: return ASM_INT64;
- case WasmType::none: return ASM_NONE;
+ case Type::i32: return ASM_INT;
+ case Type::f32: return ASM_FLOAT;
+ case Type::f64: return ASM_DOUBLE;
+ case Type::i64: return ASM_INT64;
+ case Type::none: return ASM_NONE;
default: {}
}
abort();
}
-char getSig(WasmType type) {
+char getSig(Type type) {
switch (type) {
case i32: return 'i';
case i64: return 'j';
@@ -73,7 +73,7 @@ std::string getSig(Function *func) {
return ret;
}
-WasmType sigToWasmType(char sig) {
+Type sigToType(char sig) {
switch (sig) {
case 'i': return i32;
case 'j': return i64;
@@ -86,9 +86,9 @@ WasmType sigToWasmType(char sig) {
FunctionType* sigToFunctionType(std::string sig) {
auto ret = new FunctionType;
- ret->result = sigToWasmType(sig[0]);
+ ret->result = sigToType(sig[0]);
for (size_t i = 1; i < sig.size(); i++) {
- ret->params.push_back(sigToWasmType(sig[i]));
+ ret->params.push_back(sigToType(sig[i]));
}
return ret;
}
@@ -101,9 +101,9 @@ FunctionType* ensureFunctionType(std::string sig, Module* wasm) {
// add new type
auto type = new FunctionType;
type->name = name;
- type->result = sigToWasmType(sig[0]);
+ type->result = sigToType(sig[0]);
for (size_t i = 1; i < sig.size(); i++) {
- type->params.push_back(sigToWasmType(sig[i]));
+ type->params.push_back(sigToType(sig[i]));
}
wasm->addFunctionType(type);
return type;
@@ -114,7 +114,7 @@ Expression* ensureDouble(Expression* expr, MixedArena& allocator) {
auto conv = allocator.alloc<Unary>();
conv->op = PromoteFloat32;
conv->value = expr;
- conv->type = WasmType::f64;
+ conv->type = Type::f64;
return conv;
}
assert(expr->type == f64);
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index f3f21bc15..8d7f9b0bc 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -44,10 +44,10 @@ BinaryenLiteral toBinaryenLiteral(Literal x) {
BinaryenLiteral ret;
ret.type = x.type;
switch (x.type) {
- case WasmType::i32: ret.i32 = x.geti32(); break;
- case WasmType::i64: ret.i64 = x.geti64(); break;
- case WasmType::f32: ret.i32 = x.reinterpreti32(); break;
- case WasmType::f64: ret.i64 = x.reinterpreti64(); break;
+ case Type::i32: ret.i32 = x.geti32(); break;
+ case Type::i64: ret.i64 = x.geti64(); break;
+ case Type::f32: ret.i32 = x.reinterpreti32(); break;
+ case Type::f64: ret.i64 = x.reinterpreti64(); break;
default: abort();
}
return ret;
@@ -55,10 +55,10 @@ BinaryenLiteral toBinaryenLiteral(Literal x) {
Literal fromBinaryenLiteral(BinaryenLiteral x) {
switch (x.type) {
- case WasmType::i32: return Literal(x.i32);
- case WasmType::i64: return Literal(x.i64);
- case WasmType::f32: return Literal(x.i32).castToF32();
- case WasmType::f64: return Literal(x.i64).castToF64();
+ case Type::i32: return Literal(x.i32);
+ case Type::i64: return Literal(x.i64);
+ case Type::f32: return Literal(x.i32).castToF32();
+ case Type::f64: return Literal(x.i64).castToF64();
default: abort();
}
}
@@ -195,9 +195,9 @@ BinaryenFunctionTypeRef BinaryenAddFunctionType(BinaryenModuleRef module, const
auto* ret = new FunctionType;
if (name) ret->name = name;
else ret->name = Name::fromInt(wasm->functionTypes.size());
- ret->result = WasmType(result);
+ ret->result = Type(result);
for (BinaryenIndex i = 0; i < numParams; i++) {
- ret->params.push_back(WasmType(paramTypes[i]));
+ ret->params.push_back(Type(paramTypes[i]));
}
// Lock. This can be called from multiple threads at once, and is a
@@ -376,7 +376,7 @@ BinaryenExpressionRef BinaryenBlock(BinaryenModuleRef module, const char* name,
for (BinaryenIndex i = 0; i < numChildren; i++) {
ret->list.push_back((Expression*)children[i]);
}
- if (type != BinaryenTypeAuto()) ret->finalize(WasmType(type));
+ if (type != BinaryenTypeAuto()) ret->finalize(Type(type));
else ret->finalize();
if (tracing) {
@@ -484,7 +484,7 @@ BinaryenExpressionRef BinaryenCall(BinaryenModuleRef module, const char *target,
for (BinaryenIndex i = 0; i < numOperands; i++) {
ret->operands.push_back((Expression*)operands[i]);
}
- ret->type = WasmType(returnType);
+ ret->type = Type(returnType);
ret->finalize();
return static_cast<Expression*>(ret);
}
@@ -509,7 +509,7 @@ BinaryenExpressionRef BinaryenCallImport(BinaryenModuleRef module, const char *t
for (BinaryenIndex i = 0; i < numOperands; i++) {
ret->operands.push_back((Expression*)operands[i]);
}
- ret->type = WasmType(returnType);
+ ret->type = Type(returnType);
ret->finalize();
return static_cast<Expression*>(ret);
}
@@ -549,7 +549,7 @@ BinaryenExpressionRef BinaryenGetLocal(BinaryenModuleRef module, BinaryenIndex i
}
ret->index = index;
- ret->type = WasmType(type);
+ ret->type = Type(type);
ret->finalize();
return static_cast<Expression*>(ret);
}
@@ -590,7 +590,7 @@ BinaryenExpressionRef BinaryenGetGlobal(BinaryenModuleRef module, const char *na
}
ret->name = name;
- ret->type = WasmType(type);
+ ret->type = Type(type);
ret->finalize();
return static_cast<Expression*>(ret);
}
@@ -619,7 +619,7 @@ BinaryenExpressionRef BinaryenLoad(BinaryenModuleRef module, uint32_t bytes, int
ret->signed_ = !!signed_;
ret->offset = offset;
ret->align = align ? align : bytes;
- ret->type = WasmType(type);
+ ret->type = Type(type);
ret->ptr = (Expression*)ptr;
ret->finalize();
return static_cast<Expression*>(ret);
@@ -637,7 +637,7 @@ BinaryenExpressionRef BinaryenStore(BinaryenModuleRef module, uint32_t bytes, ui
ret->align = align ? align : bytes;
ret->ptr = (Expression*)ptr;
ret->value = (Expression*)value;
- ret->valueType = WasmType(type);
+ ret->valueType = Type(type);
ret->finalize();
return static_cast<Expression*>(ret);
}
@@ -646,16 +646,16 @@ BinaryenExpressionRef BinaryenConst(BinaryenModuleRef module, BinaryenLiteral va
if (tracing) {
auto id = noteExpression(ret);
switch (value.type) {
- case WasmType::i32: std::cout << " expressions[" << id << "] = BinaryenConst(the_module, BinaryenLiteralInt32(" << value.i32 << "));\n"; break;
- case WasmType::i64: std::cout << " expressions[" << id << "] = BinaryenConst(the_module, BinaryenLiteralInt64(" << value.i64 << "));\n"; break;
- case WasmType::f32: {
+ case Type::i32: std::cout << " expressions[" << id << "] = BinaryenConst(the_module, BinaryenLiteralInt32(" << value.i32 << "));\n"; break;
+ case Type::i64: std::cout << " expressions[" << id << "] = BinaryenConst(the_module, BinaryenLiteralInt64(" << value.i64 << "));\n"; break;
+ case Type::f32: {
std::cout << " expressions[" << id << "] = BinaryenConst(the_module, BinaryenLiteralFloat32(";
if (std::isnan(value.f32)) std::cout << "NAN";
else std::cout << value.f32;
std::cout << "));\n";
break;
}
- case WasmType::f64: {
+ case Type::f64: {
std::cout << " expressions[" << id << "] = BinaryenConst(the_module, BinaryenLiteralFloat64(";
if (std::isnan(value.f64)) std::cout << "NAN";
else std::cout << value.f64;
@@ -769,7 +769,7 @@ BinaryenExpressionRef BinaryenUnreachable(BinaryenModuleRef module) {
return static_cast<Expression*>(ret);
}
BinaryenExpressionRef BinaryenAtomicLoad(BinaryenModuleRef module, uint32_t bytes, uint32_t offset, BinaryenType type, BinaryenExpressionRef ptr) {
- auto* ret = Builder(*((Module*)module)).makeAtomicLoad(bytes, offset, (Expression*)ptr, WasmType(type));
+ auto* ret = Builder(*((Module*)module)).makeAtomicLoad(bytes, offset, (Expression*)ptr, Type(type));
if (tracing) {
auto id = noteExpression(ret);
@@ -779,7 +779,7 @@ BinaryenExpressionRef BinaryenAtomicLoad(BinaryenModuleRef module, uint32_t byte
return static_cast<Expression*>(ret);
}
BinaryenExpressionRef BinaryenAtomicStore(BinaryenModuleRef module, uint32_t bytes, uint32_t offset, BinaryenExpressionRef ptr, BinaryenExpressionRef value, BinaryenType type) {
- auto* ret = Builder(*((Module*)module)).makeAtomicStore(bytes, offset, (Expression*)ptr, (Expression*)value, WasmType(type));
+ auto* ret = Builder(*((Module*)module)).makeAtomicStore(bytes, offset, (Expression*)ptr, (Expression*)value, Type(type));
if (tracing) {
auto id = noteExpression(ret);
@@ -789,7 +789,7 @@ BinaryenExpressionRef BinaryenAtomicStore(BinaryenModuleRef module, uint32_t byt
return static_cast<Expression*>(ret);
}
BinaryenExpressionRef BinaryenAtomicRMW(BinaryenModuleRef module, BinaryenOp op, BinaryenIndex bytes, BinaryenIndex offset, BinaryenExpressionRef ptr, BinaryenExpressionRef value, BinaryenType type) {
- auto* ret = Builder(*((Module*)module)).makeAtomicRMW(AtomicRMWOp(op), bytes, offset, (Expression*)ptr, (Expression*)value, WasmType(type));
+ auto* ret = Builder(*((Module*)module)).makeAtomicRMW(AtomicRMWOp(op), bytes, offset, (Expression*)ptr, (Expression*)value, Type(type));
if (tracing) {
auto id = noteExpression(ret);
@@ -799,7 +799,7 @@ BinaryenExpressionRef BinaryenAtomicRMW(BinaryenModuleRef module, BinaryenOp op,
return static_cast<Expression*>(ret);
}
BinaryenExpressionRef BinaryenAtomicCmpxchg(BinaryenModuleRef module, BinaryenIndex bytes, BinaryenIndex offset, BinaryenExpressionRef ptr, BinaryenExpressionRef expected, BinaryenExpressionRef replacement, BinaryenType type) {
- auto* ret = Builder(*((Module*)module)).makeAtomicCmpxchg(bytes, offset, (Expression*)ptr, (Expression*)expected, (Expression*)replacement, WasmType(type));
+ auto* ret = Builder(*((Module*)module)).makeAtomicCmpxchg(bytes, offset, (Expression*)ptr, (Expression*)expected, (Expression*)replacement, Type(type));
if (tracing) {
auto id = noteExpression(ret);
@@ -809,7 +809,7 @@ BinaryenExpressionRef BinaryenAtomicCmpxchg(BinaryenModuleRef module, BinaryenIn
return static_cast<Expression*>(ret);
}
BinaryenExpressionRef BinaryenAtomicWait(BinaryenModuleRef module, BinaryenExpressionRef ptr, BinaryenExpressionRef expected, BinaryenExpressionRef timeout, BinaryenType expectedType) {
- auto* ret = Builder(*((Module*)module)).makeAtomicWait((Expression*)ptr, (Expression*)expected, (Expression*)timeout, WasmType(expectedType), 0);
+ auto* ret = Builder(*((Module*)module)).makeAtomicWait((Expression*)ptr, (Expression*)expected, (Expression*)timeout, Type(expectedType), 0);
if (tracing) {
auto id = noteExpression(ret);
@@ -1635,7 +1635,7 @@ BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module, const char* na
ret->result = functionType->result;
ret->params = functionType->params;
for (BinaryenIndex i = 0; i < numVarTypes; i++) {
- ret->vars.push_back(WasmType(varTypes[i]));
+ ret->vars.push_back(Type(varTypes[i]));
}
ret->body = (Expression*)body;
@@ -1673,7 +1673,7 @@ BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module, const char* name,
auto* wasm = (Module*)module;
auto* ret = new Global();
ret->name = name;
- ret->type = WasmType(type);
+ ret->type = Type(type);
ret->mutable_ = !!mutable_;
ret->init = (Expression*)init;
wasm->addGlobal(ret);
@@ -1756,7 +1756,7 @@ BinaryenImportRef BinaryenAddGlobalImport(BinaryenModuleRef module, const char*
ret->name = internalName;
ret->module = externalModuleName;
ret->base = externalBaseName;
- ret->globalType = WasmType(globalType);
+ ret->globalType = Type(globalType);
ret->kind = ExternalKind::Global;
wasm->addImport(ret);
return ret;
@@ -2560,9 +2560,9 @@ BinaryenFunctionTypeRef BinaryenGetFunctionTypeBySignature(BinaryenModuleRef mod
auto* wasm = (Module*)module;
FunctionType test;
- test.result = WasmType(result);
+ test.result = Type(result);
for (BinaryenIndex i = 0; i < numParams; i++) {
- test.params.push_back(WasmType(paramTypes[i]));
+ test.params.push_back(Type(paramTypes[i]));
}
// Lock. Guard against reading the list while types are being added.
diff --git a/src/ir/bits.h b/src/ir/bits.h
index 4196b74c1..ec33c4b11 100644
--- a/src/ir/bits.h
+++ b/src/ir/bits.h
@@ -44,7 +44,7 @@ struct Bits {
// gets the number of effective shifts a shift operation does. In
// wasm, only 5 bits matter for 32-bit shifts, and 6 for 64.
- static Index getEffectiveShifts(Index amount, WasmType type) {
+ static Index getEffectiveShifts(Index amount, Type type) {
if (type == i32) {
return amount & 31;
} else if (type == i64) {
diff --git a/src/ir/block-utils.h b/src/ir/block-utils.h
index f7c68aa39..e3ad370db 100644
--- a/src/ir/block-utils.h
+++ b/src/ir/block-utils.h
@@ -34,7 +34,7 @@ namespace BlockUtils {
// just one element. try to replace the block
auto* singleton = list[0];
auto sideEffects = EffectAnalyzer(parent->getPassOptions(), singleton).hasSideEffects();
- if (!sideEffects && !isConcreteWasmType(singleton->type)) {
+ if (!sideEffects && !isConcreteType(singleton->type)) {
// no side effects, and singleton is not returning a value, so we can throw away
// the block and its contents, basically
return Builder(*parent->getModule()).replaceWithIdenticalType(block);
@@ -44,7 +44,7 @@ namespace BlockUtils {
// (side effects +) type change, must be block with declared value but inside is unreachable
// (if both concrete, must match, and since no name on block, we can't be
// branched to, so if singleton is unreachable, so is the block)
- assert(isConcreteWasmType(block->type) && singleton->type == unreachable);
+ assert(isConcreteType(block->type) && singleton->type == unreachable);
// we could replace with unreachable, but would need to update all
// the parent's types
}
diff --git a/src/ir/branch-utils.h b/src/ir/branch-utils.h
index 26e8e7c87..84be9f897 100644
--- a/src/ir/branch-utils.h
+++ b/src/ir/branch-utils.h
@@ -110,7 +110,7 @@ struct BranchSeeker : public PostWalker<BranchSeeker> {
bool named = true;
Index found;
- WasmType valueType;
+ Type valueType;
BranchSeeker(Name target) : target(target), found(0) {}
diff --git a/src/ir/literal-utils.h b/src/ir/literal-utils.h
index a702c52eb..166897739 100644
--- a/src/ir/literal-utils.h
+++ b/src/ir/literal-utils.h
@@ -23,7 +23,7 @@ namespace wasm {
namespace LiteralUtils {
-inline Literal makeLiteralFromInt32(int32_t x, WasmType type) {
+inline Literal makeLiteralFromInt32(int32_t x, Type type) {
switch (type) {
case i32: return Literal(int32_t(x)); break;
case i64: return Literal(int64_t(x)); break;
@@ -33,18 +33,18 @@ inline Literal makeLiteralFromInt32(int32_t x, WasmType type) {
}
}
-inline Literal makeLiteralZero(WasmType type) {
+inline Literal makeLiteralZero(Type type) {
return makeLiteralFromInt32(0, type);
}
-inline Expression* makeFromInt32(int32_t x, WasmType type, Module& wasm) {
+inline Expression* makeFromInt32(int32_t x, Type type, Module& wasm) {
auto* ret = wasm.allocator.alloc<Const>();
ret->value = makeLiteralFromInt32(x, type);
ret->type = type;
return ret;
}
-inline Expression* makeZero(WasmType type, Module& wasm) {
+inline Expression* makeZero(Type type, Module& wasm) {
return makeFromInt32(0, type, wasm);
}
diff --git a/src/ir/load-utils.h b/src/ir/load-utils.h
index 45882dc6c..41b3c69ef 100644
--- a/src/ir/load-utils.h
+++ b/src/ir/load-utils.h
@@ -29,7 +29,7 @@ namespace LoadUtils {
inline bool isSignRelevant(Load* load) {
auto type = load->type;
if (load->type == unreachable) return false;
- return !isWasmTypeFloat(type) && load->bytes < getWasmTypeSize(type);
+ return !isTypeFloat(type) && load->bytes < getTypeSize(type);
}
// check if a load can be signed (which some opts want to do)
diff --git a/src/ir/type-updating.h b/src/ir/type-updating.h
index 79b26aa43..ba06bccf9 100644
--- a/src/ir/type-updating.h
+++ b/src/ir/type-updating.h
@@ -187,7 +187,7 @@ struct TypeUpdater : public ExpressionStackWalker<TypeUpdater, UnifiedExpression
// alters the type of a node to a new type.
// this propagates the type change through all the parents.
- void changeTypeTo(Expression* curr, WasmType newType) {
+ void changeTypeTo(Expression* curr, Type newType) {
if (curr->type == newType) return; // nothing to do
curr->type = newType;
propagateTypesUp(curr);
@@ -214,7 +214,7 @@ struct TypeUpdater : public ExpressionStackWalker<TypeUpdater, UnifiedExpression
// but exceptions exist
if (auto* block = curr->dynCast<Block>()) {
// if the block has a fallthrough, it can keep its type
- if (isConcreteWasmType(block->list.back()->type)) {
+ if (isConcreteType(block->list.back()->type)) {
return; // did not turn
}
// if the block has breaks, it can keep its type
@@ -240,7 +240,7 @@ struct TypeUpdater : public ExpressionStackWalker<TypeUpdater, UnifiedExpression
// unreachable, and it does this efficiently, without scanning the full
// contents
void maybeUpdateTypeToUnreachable(Block* curr) {
- if (!isConcreteWasmType(curr->type)) {
+ if (!isConcreteType(curr->type)) {
return; // nothing concrete to change to unreachable
}
if (curr->name.is() && blockInfos[curr->name].numBreaks > 0) {
@@ -255,7 +255,7 @@ struct TypeUpdater : public ExpressionStackWalker<TypeUpdater, UnifiedExpression
return; // no change possible
}
if (!curr->list.empty() &&
- isConcreteWasmType(curr->list.back()->type)) {
+ isConcreteType(curr->list.back()->type)) {
return; // should keep type due to fallthrough, even if has an unreachable child
}
for (auto* child : curr->list) {
@@ -271,7 +271,7 @@ struct TypeUpdater : public ExpressionStackWalker<TypeUpdater, UnifiedExpression
// can remove a concrete type and turn the if unreachable when it is
// unreachable
void maybeUpdateTypeToUnreachable(If* curr) {
- if (!isConcreteWasmType(curr->type)) {
+ if (!isConcreteType(curr->type)) {
return; // nothing concrete to change to unreachable
}
curr->finalize();
diff --git a/src/ir/utils.h b/src/ir/utils.h
index 786e04e45..fa08122b5 100644
--- a/src/ir/utils.h
+++ b/src/ir/utils.h
@@ -86,7 +86,7 @@ struct ReFinalize : public WalkerPass<PostWalker<ReFinalize, OverriddenVisitor<R
// block finalization is O(bad) if we do each block by itself, so do it in bulk,
// tracking break value types so we just do a linear pass
- std::map<Name, WasmType> breakValues;
+ std::map<Name, Type> breakValues;
void visitBlock(Block *curr) {
if (curr->list.size() == 0) {
@@ -99,7 +99,7 @@ struct ReFinalize : public WalkerPass<PostWalker<ReFinalize, OverriddenVisitor<R
curr->type = curr->list.back()->type;
// if concrete, it doesn't matter if we have an unreachable child, and we
// don't need to look at breaks
- if (isConcreteWasmType(curr->type)) return;
+ if (isConcreteType(curr->type)) return;
// otherwise, we have no final fallthrough element to determine the type,
// could be determined by breaks
if (curr->name.is()) {
@@ -111,7 +111,7 @@ struct ReFinalize : public WalkerPass<PostWalker<ReFinalize, OverriddenVisitor<R
// all we have are breaks with values of type unreachable, and no
// concrete fallthrough either. we must have had an existing type, then
curr->type = old;
- assert(isConcreteWasmType(curr->type));
+ assert(isConcreteType(curr->type));
} else {
curr->type = type;
}
@@ -183,11 +183,11 @@ struct ReFinalize : public WalkerPass<PostWalker<ReFinalize, OverriddenVisitor<R
void visitMemory(Memory* curr) { WASM_UNREACHABLE(); }
void visitModule(Module* curr) { WASM_UNREACHABLE(); }
- WasmType getValueType(Expression* value) {
+ Type getValueType(Expression* value) {
return value ? value->type : none;
}
- void updateBreakValueType(Name name, WasmType type) {
+ void updateBreakValueType(Name name, Type type) {
if (type != unreachable || breakValues.count(name) == 0) {
breakValues[name] = type;
}
@@ -256,7 +256,7 @@ struct AutoDrop : public WalkerPass<ExpressionStackWalker<AutoDrop>> {
bool maybeDrop(Expression*& child) {
bool acted = false;
- if (isConcreteWasmType(child->type)) {
+ if (isConcreteType(child->type)) {
expressionStack.push_back(child);
if (!ExpressionAnalyzer::isResultUsed(expressionStack, getFunction()) && !ExpressionAnalyzer::isResultDropped(expressionStack)) {
child = Builder(*getModule()).makeDrop(child);
@@ -275,7 +275,7 @@ struct AutoDrop : public WalkerPass<ExpressionStackWalker<AutoDrop>> {
if (curr->list.size() == 0) return;
for (Index i = 0; i < curr->list.size() - 1; i++) {
auto* child = curr->list[i];
- if (isConcreteWasmType(child->type)) {
+ if (isConcreteType(child->type)) {
curr->list[i] = Builder(*getModule()).makeDrop(child);
}
}
@@ -300,7 +300,7 @@ struct AutoDrop : public WalkerPass<ExpressionStackWalker<AutoDrop>> {
void doWalkFunction(Function* curr) {
ReFinalize().walkFunctionInModule(curr, getModule());
walk(curr->body);
- if (curr->result == none && isConcreteWasmType(curr->body->type)) {
+ if (curr->result == none && isConcreteType(curr->body->type)) {
curr->body = Builder(*getModule()).makeDrop(curr->body);
}
ReFinalize().walkFunctionInModule(curr, getModule());
diff --git a/src/literal.h b/src/literal.h
index 55efbd31e..72bd36019 100644
--- a/src/literal.h
+++ b/src/literal.h
@@ -28,7 +28,7 @@ namespace wasm {
class Literal {
public:
- WasmType type;
+ Type type;
private:
// store only integers, whose bits are deterministic. floats
@@ -45,14 +45,14 @@ private:
}
public:
- Literal() : type(WasmType::none), i64(0) {}
- explicit Literal(WasmType type) : type(type), i64(0) {}
- explicit Literal(int32_t init) : type(WasmType::i32), i32(init) {}
- explicit Literal(uint32_t init) : type(WasmType::i32), i32(init) {}
- explicit Literal(int64_t init) : type(WasmType::i64), i64(init) {}
- explicit Literal(uint64_t init) : type(WasmType::i64), i64(init) {}
- explicit Literal(float init) : type(WasmType::f32), i32(bit_cast<int32_t>(init)) {}
- explicit Literal(double init) : type(WasmType::f64), i64(bit_cast<int64_t>(init)) {}
+ Literal() : type(Type::none), i64(0) {}
+ explicit Literal(Type type) : type(type), i64(0) {}
+ explicit Literal(int32_t init) : type(Type::i32), i32(init) {}
+ explicit Literal(uint32_t init) : type(Type::i32), i32(init) {}
+ explicit Literal(int64_t init) : type(Type::i64), i64(init) {}
+ explicit Literal(uint64_t init) : type(Type::i64), i64(init) {}
+ explicit Literal(float init) : type(Type::f32), i32(bit_cast<int32_t>(init)) {}
+ explicit Literal(double init) : type(Type::f64), i64(bit_cast<int64_t>(init)) {}
bool isConcrete() { return type != none; }
bool isNull() { return type == none; }
@@ -62,17 +62,17 @@ public:
Literal castToI32();
Literal castToI64();
- int32_t geti32() const { assert(type == WasmType::i32); return i32; }
- int64_t geti64() const { assert(type == WasmType::i64); return i64; }
- float getf32() const { assert(type == WasmType::f32); return bit_cast<float>(i32); }
- double getf64() const { assert(type == WasmType::f64); return bit_cast<double>(i64); }
+ int32_t geti32() const { assert(type == Type::i32); return i32; }
+ int64_t geti64() const { assert(type == Type::i64); return i64; }
+ float getf32() const { assert(type == Type::f32); return bit_cast<float>(i32); }
+ double getf64() const { assert(type == Type::f64); return bit_cast<double>(i64); }
- int32_t* geti32Ptr() { assert(type == WasmType::i32); return &i32; } // careful!
+ int32_t* geti32Ptr() { assert(type == Type::i32); return &i32; } // careful!
- int32_t reinterpreti32() const { assert(type == WasmType::f32); return i32; }
- int64_t reinterpreti64() const { assert(type == WasmType::f64); return i64; }
- float reinterpretf32() const { assert(type == WasmType::i32); return bit_cast<float>(i32); }
- double reinterpretf64() const { assert(type == WasmType::i64); return bit_cast<double>(i64); }
+ int32_t reinterpreti32() const { assert(type == Type::f32); return i32; }
+ int64_t reinterpreti64() const { assert(type == Type::f64); return i64; }
+ float reinterpretf32() const { assert(type == Type::i32); return bit_cast<float>(i32); }
+ double reinterpretf64() const { assert(type == Type::i64); return bit_cast<double>(i64); }
int64_t getInteger() const;
double getFloat() const;
diff --git a/src/parsing.h b/src/parsing.h
index 15f22040d..cb6ee8c4b 100644
--- a/src/parsing.h
+++ b/src/parsing.h
@@ -76,11 +76,11 @@ struct MapParseException {
}
};
-inline Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allocator) {
+inline Expression* parseConst(cashew::IString s, Type type, MixedArena& allocator) {
const char *str = s.str;
auto ret = allocator.alloc<Const>();
ret->type = type;
- if (isWasmTypeFloat(type)) {
+ if (isTypeFloat(type)) {
if (s == _INFINITY) {
switch (type) {
case f32: ret->value = Literal(std::numeric_limits<float>::infinity()); break;
diff --git a/src/passes/CoalesceLocals.cpp b/src/passes/CoalesceLocals.cpp
index b6c96902b..e5c5585f4 100644
--- a/src/passes/CoalesceLocals.cpp
+++ b/src/passes/CoalesceLocals.cpp
@@ -201,7 +201,7 @@ void CoalesceLocals::pickIndicesFromOrder(std::vector<Index>& order, std::vector
}
#endif
// TODO: take into account distribution (99-1 is better than 50-50 with two registers, for gzip)
- std::vector<WasmType> types;
+ std::vector<Type> types;
std::vector<bool> newInterferences; // new index * numLocals => list of all interferences of locals merged to it
std::vector<uint8_t> newCopies; // new index * numLocals => list of all copies of locals merged to it
indices.resize(numLocals);
diff --git a/src/passes/CodeFolding.cpp b/src/passes/CodeFolding.cpp
index 05ae93f73..c2ad07595 100644
--- a/src/passes/CodeFolding.cpp
+++ b/src/passes/CodeFolding.cpp
@@ -132,7 +132,7 @@ struct CodeFolding : public WalkerPass<ControlFlowWalker<CodeFolding>> {
// elements out of it if there is a value being returned)
Block* parent = controlFlowStack.back()->dynCast<Block>();
if (parent && curr == parent->list.back() &&
- !isConcreteWasmType(parent->list.back()->type)) {
+ !isConcreteType(parent->list.back()->type)) {
breakTails[curr->name].push_back(Tail(curr, parent));
} else {
unoptimizables.insert(curr->name);
@@ -175,7 +175,7 @@ struct CodeFolding : public WalkerPass<ControlFlowWalker<CodeFolding>> {
if (!curr->name.is()) return;
if (unoptimizables.count(curr->name) > 0) return;
// we can't optimize a fallthrough value
- if (isConcreteWasmType(curr->list.back()->type)) {
+ if (isConcreteType(curr->list.back()->type)) {
return;
}
auto iter = breakTails.find(curr->name);
diff --git a/src/passes/ConstHoisting.cpp b/src/passes/ConstHoisting.cpp
index bddc0b5c5..e808f7af4 100644
--- a/src/passes/ConstHoisting.cpp
+++ b/src/passes/ConstHoisting.cpp
@@ -84,7 +84,7 @@ private:
}
case f32:
case f64: {
- size = getWasmTypeSize(value.type);
+ size = getTypeSize(value.type);
break;
}
default: WASM_UNREACHABLE();
diff --git a/src/passes/DeadCodeElimination.cpp b/src/passes/DeadCodeElimination.cpp
index 97c63baf5..a2f3b895c 100644
--- a/src/passes/DeadCodeElimination.cpp
+++ b/src/passes/DeadCodeElimination.cpp
@@ -331,7 +331,7 @@ struct DeadCodeElimination : public WalkerPass<PostWalker<DeadCodeElimination>>
// Append the reachable operands of the current node to a block, and replace
// it with the block
- void blockifyReachableOperands(std::vector<Expression*>&& list, WasmType type) {
+ void blockifyReachableOperands(std::vector<Expression*>&& list, Type type) {
for (size_t i = 0; i < list.size(); ++i) {
auto* elem = list[i];
if (isUnreachable(elem)) {
diff --git a/src/passes/Flatten.cpp b/src/passes/Flatten.cpp
index 53fd6a02b..b3266e89b 100644
--- a/src/passes/Flatten.cpp
+++ b/src/passes/Flatten.cpp
@@ -109,7 +109,7 @@ struct Flatten : public WalkerPass<ExpressionStackWalker<Flatten, UnifiedExpress
block->list.swap(newList);
// remove a block return value
auto type = block->type;
- if (isConcreteWasmType(type)) {
+ if (isConcreteType(type)) {
// if there is a temp index for breaking to the block, use that
Index temp;
auto iter = breakTemps.find(block->name);
@@ -119,7 +119,7 @@ struct Flatten : public WalkerPass<ExpressionStackWalker<Flatten, UnifiedExpress
temp = builder.addVar(getFunction(), type);
}
auto*& last = block->list.back();
- if (isConcreteWasmType(last->type)) {
+ if (isConcreteType(last->type)) {
last = builder.makeSetLocal(temp, last);
}
block->finalize(none);
@@ -139,12 +139,12 @@ struct Flatten : public WalkerPass<ExpressionStackWalker<Flatten, UnifiedExpress
auto* originalIfFalse = iff->ifFalse;
auto type = iff->type;
Expression* prelude = nullptr;
- if (isConcreteWasmType(type)) {
+ if (isConcreteType(type)) {
Index temp = builder.addVar(getFunction(), type);
- if (isConcreteWasmType(iff->ifTrue->type)) {
+ if (isConcreteType(iff->ifTrue->type)) {
iff->ifTrue = builder.makeSetLocal(temp, iff->ifTrue);
}
- if (iff->ifFalse && isConcreteWasmType(iff->ifFalse->type)) {
+ if (iff->ifFalse && isConcreteType(iff->ifFalse->type)) {
iff->ifFalse = builder.makeSetLocal(temp, iff->ifFalse);
}
// the whole if (+any preludes from the condition) is now a prelude
@@ -165,7 +165,7 @@ struct Flatten : public WalkerPass<ExpressionStackWalker<Flatten, UnifiedExpress
Expression* rep = loop;
auto* originalBody = loop->body;
auto type = loop->type;
- if (isConcreteWasmType(type)) {
+ if (isConcreteType(type)) {
Index temp = builder.addVar(getFunction(), type);
loop->body = builder.makeSetLocal(temp, loop->body);
// and we leave just a get of the value
@@ -202,14 +202,14 @@ struct Flatten : public WalkerPass<ExpressionStackWalker<Flatten, UnifiedExpress
} else if (auto* br = curr->dynCast<Break>()) {
if (br->value) {
auto type = br->value->type;
- if (isConcreteWasmType(type)) {
+ if (isConcreteType(type)) {
// we are sending a value. use a local instead
Index temp = getTempForBreakTarget(br->name, type);
ourPreludes.push_back(builder.makeSetLocal(temp, br->value));
if (br->condition) {
// the value must also flow out
ourPreludes.push_back(br);
- if (isConcreteWasmType(br->type)) {
+ if (isConcreteType(br->type)) {
replaceCurrent(builder.makeGetLocal(temp, type));
} else {
assert(br->type == unreachable);
@@ -227,7 +227,7 @@ struct Flatten : public WalkerPass<ExpressionStackWalker<Flatten, UnifiedExpress
} else if (auto* sw = curr->dynCast<Switch>()) {
if (sw->value) {
auto type = sw->value->type;
- if (isConcreteWasmType(type)) {
+ if (isConcreteType(type)) {
// we are sending a value. use a local instead
Index temp = builder.addVar(getFunction(), type);
ourPreludes.push_back(builder.makeSetLocal(temp, sw->value));
@@ -299,7 +299,7 @@ struct Flatten : public WalkerPass<ExpressionStackWalker<Flatten, UnifiedExpress
void visitFunction(Function* curr) {
auto* originalBody = curr->body;
// if the body is a block with a result, turn that into a return
- if (isConcreteWasmType(curr->body->type)) {
+ if (isConcreteType(curr->body->type)) {
curr->body = Builder(*getModule()).makeReturn(curr->body);
}
// the body may have preludes
@@ -333,7 +333,7 @@ private:
// get the temp local to be used for breaks to that target. allocates
// one if there isn't one yet
- Index getTempForBreakTarget(Name name, WasmType type) {
+ Index getTempForBreakTarget(Name name, Type type) {
auto iter = breakTemps.find(name);
if (iter != breakTemps.end()) {
return iter->second;
diff --git a/src/passes/I64ToI32Lowering.cpp b/src/passes/I64ToI32Lowering.cpp
index e617c3b83..4135cb154 100644
--- a/src/passes/I64ToI32Lowering.cpp
+++ b/src/passes/I64ToI32Lowering.cpp
@@ -113,7 +113,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
}
void visitFunctionType(FunctionType* curr) {
- std::vector<WasmType> params;
+ std::vector<Type> params;
for (auto t : curr->params) {
if (t == i64) {
params.push_back(i32);
@@ -146,10 +146,10 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
assert(oldFunc.hasLocalName(i));
Name lowName = oldFunc.getLocalName(i);
Name highName = makeHighName(lowName);
- WasmType paramType = oldFunc.getLocalType(i);
+ Type paramType = oldFunc.getLocalType(i);
auto builderFunc = (i < oldFunc.getVarIndexBase()) ?
Builder::addParam :
- static_cast<Index (*)(Function*, Name, WasmType)>(Builder::addVar);
+ static_cast<Index (*)(Function*, Name, Type)>(Builder::addVar);
if (paramType == i64) {
builderFunc(func, lowName, i32);
builderFunc(func, highName, i32);
@@ -312,7 +312,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
}
template <typename T>
- using BuilderFunc = std::function<T*(std::vector<Expression*>&, WasmType)>;
+ using BuilderFunc = std::function<T*(std::vector<Expression*>&, Type)>;
template <typename T>
void visitGenericCall(T* curr, BuilderFunc<T> callBuilder) {
@@ -346,7 +346,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
void visitCall(Call* curr) {
visitGenericCall<Call>(
curr,
- [&](std::vector<Expression*>& args, WasmType ty) {
+ [&](std::vector<Expression*>& args, Type ty) {
return builder->makeCall(curr->target, args, ty);
}
);
@@ -360,7 +360,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
void visitCallIndirect(CallIndirect* curr) {
visitGenericCall<CallIndirect>(
curr,
- [&](std::vector<Expression*>& args, WasmType ty) {
+ [&](std::vector<Expression*>& args, Type ty) {
return builder->makeCallIndirect(
curr->fullType,
curr->target,
diff --git a/src/passes/LocalCSE.cpp b/src/passes/LocalCSE.cpp
index 7b27e06d3..7524ad0fa 100644
--- a/src/passes/LocalCSE.cpp
+++ b/src/passes/LocalCSE.cpp
@@ -118,7 +118,7 @@ struct LocalCSE : public WalkerPass<LinearExecutionWalker<LocalCSE>> {
if (curr->is<GetLocal>()) {
return false; // trivial, this is what we optimize to!
}
- if (!isConcreteWasmType(curr->type)) {
+ if (!isConcreteType(curr->type)) {
return false; // don't bother with unreachable etc.
}
if (EffectAnalyzer(getPassOptions(), curr).hasSideEffects()) {
diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp
index 798ad927f..2f59de539 100644
--- a/src/passes/MergeBlocks.cpp
+++ b/src/passes/MergeBlocks.cpp
@@ -148,7 +148,7 @@ struct BreakValueDropper : public ControlFlowWalker<BreakValueDropper> {
void visitDrop(Drop* curr) {
// if we dropped a br_if whose value we removed, then we are now dropping a (block (drop value) (br_if)) with type none, which does not need a drop
// likewise, unreachable does not need to be dropped, so we just leave drops of concrete values
- if (!isConcreteWasmType(curr->value->type)) {
+ if (!isConcreteType(curr->value->type)) {
replaceCurrent(curr->value);
}
}
@@ -228,7 +228,7 @@ static void optimizeBlock(Block* curr, Module* module, PassOptions& passOptions)
if (!merged.empty()) {
auto* last = merged.back();
for (auto*& item : merged) {
- if (item != last && isConcreteWasmType(item->type)) {
+ if (item != last && isConcreteType(item->type)) {
Builder builder(*module);
item = builder.makeDrop(item);
}
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index efea99247..7bd7aaa51 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -116,7 +116,7 @@ struct Match {
if (!call || call->operands.size() != 1 || call->operands[0]->type != i32 || !call->operands[0]->is<Const>()) return false;
Index index = call->operands[0]->cast<Const>()->value.geti32();
// handle our special functions
- auto checkMatch = [&](WasmType type) {
+ auto checkMatch = [&](Type type) {
if (type != none && subSeen->type != type) return false;
while (index >= wildcards.size()) {
wildcards.push_back(nullptr);
@@ -338,7 +338,7 @@ struct LocalScanner : PostWalker<LocalScanner> {
return getBitsForType(get->type);
}
- Index getBitsForType(WasmType type) {
+ Index getBitsForType(Type type) {
switch (type) {
case i32: return 32;
case i64: return 64;
@@ -704,7 +704,7 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
} else {
// the types diff. as the condition is reachable, that means the if must be
// concrete while the arm is not
- assert(isConcreteWasmType(iff->type) && iff->ifTrue->type == unreachable);
+ assert(isConcreteType(iff->type) && iff->ifTrue->type == unreachable);
// emit a block with a forced type
auto* ret = builder.makeBlock();
if (needCondition) {
diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp
index 68133edca..ed3d51701 100644
--- a/src/passes/Precompute.cpp
+++ b/src/passes/Precompute.cpp
@@ -181,7 +181,7 @@ struct Precompute : public WalkerPass<PostWalker<Precompute, UnifiedExpressionVi
return;
}
// this was precomputed
- if (isConcreteWasmType(flow.value.type)) {
+ if (isConcreteType(flow.value.type)) {
replaceCurrent(Builder(*getModule()).makeConst(flow.value));
} else {
ExpressionManipulator::nop(curr);
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 66b0fa8f5..700ddf734 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -95,7 +95,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
void printFullLine(Expression *expression) {
!minify && doIndent(o, indent);
if (full) {
- o << "[" << printWasmType(expression->type) << "] ";
+ o << "[" << printType(expression->type) << "] ";
}
visit(expression);
o << maybeNewLine;
@@ -129,15 +129,15 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
if (stack.size() > 0) doIndent(o, indent);
stack.push_back(curr);
if (full) {
- o << "[" << printWasmType(curr->type) << "] ";
+ o << "[" << printType(curr->type) << "] ";
}
printOpening(o, "block");
if (curr->name.is()) {
o << ' ';
printName(curr->name);
}
- if (isConcreteWasmType(curr->type)) {
- o << " (result " << printWasmType(curr->type) << ')';
+ if (isConcreteType(curr->type)) {
+ o << " (result " << printType(curr->type) << ')';
}
incIndent();
if (curr->list.size() > 0 && curr->list[0]->is<Block>()) {
@@ -167,8 +167,8 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
}
void visitIf(If *curr) {
printOpening(o, "if");
- if (isConcreteWasmType(curr->type)) {
- o << " (result " << printWasmType(curr->type) << ')';
+ if (isConcreteType(curr->type)) {
+ o << " (result " << printType(curr->type) << ')';
}
incIndent();
printFullLine(curr->condition);
@@ -192,8 +192,8 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
if (curr->name.is()) {
o << ' ' << curr->name;
}
- if (isConcreteWasmType(curr->type)) {
- o << " (result " << printWasmType(curr->type) << ')';
+ if (isConcreteType(curr->type)) {
+ o << " (result " << printType(curr->type) << ')';
}
incIndent();
auto block = curr->body->dynCast<Block>();
@@ -299,7 +299,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
}
void visitLoad(Load *curr) {
o << '(';
- prepareColor(o) << printWasmType(curr->type);
+ prepareColor(o) << printType(curr->type);
if (curr->isAtomic) o << ".atomic";
o << ".load";
if (curr->bytes < 4 || (curr->type == i64 && curr->bytes < 8)) {
@@ -327,7 +327,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
}
void visitStore(Store *curr) {
o << '(';
- prepareColor(o) << printWasmType(curr->valueType);
+ prepareColor(o) << printType(curr->valueType);
if (curr->isAtomic) o << ".atomic";
o << ".store";
if (curr->bytes < 4 || (curr->valueType == i64 && curr->bytes < 8)) {
@@ -353,11 +353,11 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
printFullLine(curr->value);
decIndent();
}
- static void printRMWSize(std::ostream& o, WasmType type, uint8_t bytes) {
- prepareColor(o) << printWasmType(type) << ".atomic.rmw";
+ static void printRMWSize(std::ostream& o, Type type, uint8_t bytes) {
+ prepareColor(o) << printType(type) << ".atomic.rmw";
if (type == unreachable) {
o << '?';
- } else if (bytes != getWasmTypeSize(type)) {
+ } else if (bytes != getTypeSize(type)) {
if (bytes == 1) {
o << '8';
} else if (bytes == 2) {
@@ -410,7 +410,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
void visitAtomicWait(AtomicWait* curr) {
o << '(' ;
prepareColor(o);
- o << printWasmType(curr->expectedType) << ".wait";
+ o << printType(curr->expectedType) << ".wait";
if (curr->offset) {
o << " offset=" << curr->offset;
}
@@ -643,13 +643,13 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
o << maybeSpace;
printMinorOpening(o, "param");
for (auto& param : curr->params) {
- o << ' ' << printWasmType(param);
+ o << ' ' << printType(param);
}
o << ')';
}
if (curr->result != none) {
o << maybeSpace;
- printMinorOpening(o, "result ") << printWasmType(curr->result) << ')';
+ printMinorOpening(o, "result ") << printType(curr->result) << ')';
}
o << ")";
}
@@ -661,7 +661,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
case ExternalKind::Function: if (curr->functionType.is()) visitFunctionType(currModule->getFunctionType(curr->functionType), &curr->name); break;
case ExternalKind::Table: printTableHeader(&currModule->table); break;
case ExternalKind::Memory: printMemoryHeader(&currModule->memory); break;
- case ExternalKind::Global: o << "(global " << curr->name << ' ' << printWasmType(curr->globalType) << ")"; break;
+ case ExternalKind::Global: o << "(global " << curr->name << ' ' << printType(curr->globalType) << ")"; break;
default: WASM_UNREACHABLE();
}
o << ')';
@@ -683,9 +683,9 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
printOpening(o, "global ");
printName(curr->name) << ' ';
if (curr->mutable_) {
- o << "(mut " << printWasmType(curr->type) << ") ";
+ o << "(mut " << printType(curr->type) << ") ";
} else {
- o << printWasmType(curr->type) << ' ';
+ o << printType(curr->type) << ' ';
}
visit(curr->init);
o << ')';
@@ -709,17 +709,17 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
if (curr->params.size() > 0) {
for (size_t i = 0; i < curr->params.size(); i++) {
o << maybeSpace;
- printMinorOpening(o, "param ") << printableLocal(i) << ' ' << printWasmType(curr->getLocalType(i)) << ')';
+ printMinorOpening(o, "param ") << printableLocal(i) << ' ' << printType(curr->getLocalType(i)) << ')';
}
}
if (curr->result != none) {
o << maybeSpace;
- printMinorOpening(o, "result ") << printWasmType(curr->result) << ')';
+ printMinorOpening(o, "result ") << printType(curr->result) << ')';
}
incIndent();
for (size_t i = curr->getVarIndexBase(); i < curr->getNumLocals(); i++) {
doIndent(o, indent);
- printMinorOpening(o, "local ") << printableLocal(i) << ' ' << printWasmType(curr->getLocalType(i)) << ')';
+ printMinorOpening(o, "local ") << printableLocal(i) << ' ' << printType(curr->getLocalType(i)) << ')';
o << maybeNewLine;
}
// It is ok to emit a block here, as a function can directly contain a list, even if our
@@ -913,7 +913,7 @@ std::ostream& WasmPrinter::printExpression(Expression* expression, std::ostream&
print.setMinify(minify);
if (full || isFullForced()) {
print.setFull(true);
- o << "[" << printWasmType(expression->type) << "] ";
+ o << "[" << printType(expression->type) << "] ";
}
print.visit(expression);
return o;
diff --git a/src/passes/RemoveImports.cpp b/src/passes/RemoveImports.cpp
index 6de151230..116cd3296 100644
--- a/src/passes/RemoveImports.cpp
+++ b/src/passes/RemoveImports.cpp
@@ -29,7 +29,7 @@ namespace wasm {
struct RemoveImports : public WalkerPass<PostWalker<RemoveImports>> {
void visitCallImport(CallImport *curr) {
- WasmType type = getModule()->getFunctionType(getModule()->getImport(curr->target)->functionType)->result;
+ Type type = getModule()->getFunctionType(getModule()->getImport(curr->target)->functionType)->result;
if (type == none) {
replaceCurrent(getModule()->allocator.alloc<Nop>());
} else {
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index 9145e5e2c..8bf1588e0 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -260,7 +260,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
} else {
// this is already an if-else. if one side is a dead end, we can append to the other, if
// there is no returned value to concern us
- assert(!isConcreteWasmType(iff->type)); // can't be, since in the middle of a block
+ assert(!isConcreteType(iff->type)); // can't be, since in the middle of a block
// ensures the first node is a block, if it isn't already, and merges in the second,
// either as a single element or, if a block, by appending to the first block. this
@@ -275,7 +275,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
if (!block || block->name.is()) {
block = builder.makeBlock(any);
} else {
- assert(!isConcreteWasmType(block->type));
+ assert(!isConcreteType(block->type));
}
auto* other = append->dynCast<Block>();
if (!other) {
@@ -461,7 +461,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
auto& list = curr->list;
for (Index i = 0; i < list.size(); i++) {
auto* iff = list[i]->dynCast<If>();
- if (!iff || !iff->ifFalse || isConcreteWasmType(iff->type)) continue; // if it lacked an if-false, it would already be a br_if, as that's the easy case
+ if (!iff || !iff->ifFalse || isConcreteType(iff->type)) continue; // if it lacked an if-false, it would already be a br_if, as that's the easy case
auto* ifTrueBreak = iff->ifTrue->dynCast<Break>();
if (ifTrueBreak && !ifTrueBreak->condition && canTurnIfIntoBrIf(iff->condition, ifTrueBreak->value, passOptions)) {
// we are an if-else where the ifTrue is a break without a condition, so we can do this
@@ -542,7 +542,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
// we may have simplified ifs enough to turn them into selects
// this is helpful for code size, but can be a tradeoff with performance as we run both code paths
if (!shrink) return;
- if (curr->ifFalse && isConcreteWasmType(curr->ifTrue->type) && isConcreteWasmType(curr->ifFalse->type)) {
+ if (curr->ifFalse && isConcreteType(curr->ifTrue->type) && isConcreteType(curr->ifFalse->type)) {
// if with else, consider turning it into a select if there is no control flow
// TODO: estimate cost
EffectAnalyzer condition(passOptions, curr->condition);
diff --git a/src/passes/SSAify.cpp b/src/passes/SSAify.cpp
index 5271087a9..9c680b942 100644
--- a/src/passes/SSAify.cpp
+++ b/src/passes/SSAify.cpp
@@ -167,7 +167,7 @@ struct SSAify : public Pass {
}
}
- Index addLocal(WasmType type) {
+ Index addLocal(Type type) {
return Builder::addVar(func, type);
}
diff --git a/src/passes/SafeHeap.cpp b/src/passes/SafeHeap.cpp
index 3349f983a..61db334a0 100644
--- a/src/passes/SafeHeap.cpp
+++ b/src/passes/SafeHeap.cpp
@@ -36,9 +36,9 @@ const Name DYNAMICTOP_PTR_IMPORT("DYNAMICTOP_PTR"),
static Name getLoadName(Load* curr) {
std::string ret = "SAFE_HEAP_LOAD_";
- ret += printWasmType(curr->type);
+ ret += printType(curr->type);
ret += "_" + std::to_string(curr->bytes) + "_";
- if (!isWasmTypeFloat(curr->type) && !curr->signed_) {
+ if (!isTypeFloat(curr->type) && !curr->signed_) {
ret += "U_";
}
if (curr->isAtomic) {
@@ -51,7 +51,7 @@ static Name getLoadName(Load* curr) {
static Name getStoreName(Store* curr) {
std::string ret = "SAFE_HEAP_STORE_";
- ret += printWasmType(curr->valueType);
+ ret += printType(curr->valueType);
ret += "_" + std::to_string(curr->bytes) + "_";
if (curr->isAtomic) {
ret += "A";
@@ -157,10 +157,10 @@ struct SafeHeap : public Pass {
load.type = type;
for (Index bytes : { 1, 2, 4, 8 }) {
load.bytes = bytes;
- if (bytes > getWasmTypeSize(type)) continue;
+ if (bytes > getTypeSize(type)) continue;
for (auto signed_ : { true, false }) {
load.signed_ = signed_;
- if (isWasmTypeFloat(type) && signed_) continue;
+ if (isTypeFloat(type) && signed_) continue;
for (Index align : { 1, 2, 4, 8 }) {
load.align = align;
if (align > bytes) continue;
@@ -181,7 +181,7 @@ struct SafeHeap : public Pass {
store.type = none;
for (Index bytes : { 1, 2, 4, 8 }) {
store.bytes = bytes;
- if (bytes > getWasmTypeSize(valueType)) continue;
+ if (bytes > getTypeSize(valueType)) continue;
for (Index align : { 1, 2, 4, 8 }) {
store.align = align;
if (align > bytes) continue;
@@ -295,7 +295,7 @@ struct SafeHeap : public Pass {
);
}
- Expression* makeBoundsCheck(WasmType type, Builder& builder, Index local) {
+ Expression* makeBoundsCheck(Type type, Builder& builder, Index local) {
return builder.makeIf(
builder.makeBinary(
OrInt32,
@@ -309,7 +309,7 @@ struct SafeHeap : public Pass {
builder.makeBinary(
AddInt32,
builder.makeGetLocal(local, i32),
- builder.makeConst(Literal(int32_t(getWasmTypeSize(type))))
+ builder.makeConst(Literal(int32_t(getTypeSize(type))))
),
builder.makeLoad(4, false, 0, 4,
builder.makeGetGlobal(dynamicTopPtr, i32), i32
diff --git a/src/passes/SpillPointers.cpp b/src/passes/SpillPointers.cpp
index 492a90501..d65c89d3e 100644
--- a/src/passes/SpillPointers.cpp
+++ b/src/passes/SpillPointers.cpp
@@ -83,7 +83,7 @@ struct SpillPointers : public WalkerPass<LivenessWalker<SpillPointers, Visitor<S
PointerMap pointerMap;
for (Index i = 0; i < func->getNumLocals(); i++) {
if (func->getLocalType(i) == ABI::PointerType) {
- auto offset = pointerMap.size() * getWasmTypeSize(ABI::PointerType);
+ auto offset = pointerMap.size() * getTypeSize(ABI::PointerType);
pointerMap[i] = offset;
}
}
@@ -136,7 +136,7 @@ struct SpillPointers : public WalkerPass<LivenessWalker<SpillPointers, Visitor<S
}
if (spilled) {
// get the stack space, and set the local to it
- ABI::getStackSpace(spillLocal, func, getWasmTypeSize(ABI::PointerType) * pointerMap.size(), *getModule());
+ ABI::getStackSpace(spillLocal, func, getTypeSize(ABI::PointerType) * pointerMap.size(), *getModule());
}
}
@@ -176,9 +176,9 @@ struct SpillPointers : public WalkerPass<LivenessWalker<SpillPointers, Visitor<S
// add the spills
for (auto index : toSpill) {
block->list.push_back(builder.makeStore(
- getWasmTypeSize(ABI::PointerType),
+ getTypeSize(ABI::PointerType),
pointerMap[index],
- getWasmTypeSize(ABI::PointerType),
+ getTypeSize(ABI::PointerType),
builder.makeGetLocal(spillLocal, ABI::PointerType),
builder.makeGetLocal(index, ABI::PointerType),
ABI::PointerType
diff --git a/src/passes/TrapMode.cpp b/src/passes/TrapMode.cpp
index 727d61102..68d6aad4b 100644
--- a/src/passes/TrapMode.cpp
+++ b/src/passes/TrapMode.cpp
@@ -78,7 +78,7 @@ bool isTruncOpSigned(UnaryOp op) {
Function* generateBinaryFunc(Module& wasm, Binary *curr) {
BinaryOp op = curr->op;
- WasmType type = curr->type;
+ Type type = curr->type;
bool isI64 = type == i64;
Builder builder(wasm);
Expression* result = builder.makeBinary(op,
@@ -134,8 +134,8 @@ void makeClampLimitLiterals(Literal& iMin, Literal& fMin, Literal& fMax) {
}
Function* generateUnaryFunc(Module& wasm, Unary *curr) {
- WasmType type = curr->value->type;
- WasmType retType = curr->type;
+ Type type = curr->value->type;
+ Type retType = curr->type;
UnaryOp truncOp = curr->op;
bool isF64 = type == f64;
@@ -238,7 +238,7 @@ Expression* makeTrappingBinary(Binary* curr, TrappingFunctionContainer &trapping
}
// the wasm operation might trap if done over 0, so generate a safe call
- WasmType type = curr->type;
+ Type type = curr->type;
Module& wasm = trappingFunctions.getModule();
Builder builder(wasm);
ensureBinaryFunc(curr, wasm, trappingFunctions);
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp
index 4326bbc3b..f24f76881 100644
--- a/src/passes/Vacuum.cpp
+++ b/src/passes/Vacuum.cpp
@@ -174,7 +174,7 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum>> {
size_t size = list.size();
for (size_t z = 0; z < size; z++) {
auto* child = list[z];
- auto* optimized = optimize(child, z == size - 1 && isConcreteWasmType(curr->type));
+ auto* optimized = optimize(child, z == size - 1 && isConcreteType(curr->type));
if (!optimized) {
typeUpdater.noteRecursiveRemoval(child);
skip++;
@@ -294,7 +294,7 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum>> {
// note that the last element may be concrete but not the block, if the
// block has an unreachable element in the middle, making the block unreachable
// despite later elements and in particular the last
- if (isConcreteWasmType(last->type) && block->type == last->type) {
+ if (isConcreteType(last->type) && block->type == last->type) {
last = optimize(last, false);
if (!last) {
// we may be able to remove this, if there are no brs
@@ -327,14 +327,14 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum>> {
}
// sink a drop into an arm of an if-else if the other arm ends in an unreachable, as it if is a branch, this can make that branch optimizable and more vaccuming possible
auto* iff = curr->value->dynCast<If>();
- if (iff && iff->ifFalse && isConcreteWasmType(iff->type)) {
+ if (iff && iff->ifFalse && isConcreteType(iff->type)) {
// reuse the drop in both cases
- if (iff->ifTrue->type == unreachable && isConcreteWasmType(iff->ifFalse->type)) {
+ if (iff->ifTrue->type == unreachable && isConcreteType(iff->ifFalse->type)) {
curr->value = iff->ifFalse;
iff->ifFalse = curr;
iff->type = none;
replaceCurrent(iff);
- } else if (iff->ifFalse->type == unreachable && isConcreteWasmType(iff->ifTrue->type)) {
+ } else if (iff->ifFalse->type == unreachable && isConcreteType(iff->ifTrue->type)) {
curr->value = iff->ifTrue;
iff->ifTrue = curr;
iff->type = none;
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 634aa43e5..58d7e1951 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -391,7 +391,7 @@ class S2WasmBuilder {
return str;
}
- WasmType tryGetType() {
+ Type tryGetType() {
if (match("i32")) return i32;
if (match("i64")) return i64;
if (match("f32")) return f32;
@@ -399,9 +399,9 @@ class S2WasmBuilder {
return none;
}
- WasmType tryGetTypeWithoutNewline() {
+ Type tryGetTypeWithoutNewline() {
const char* saved = s;
- WasmType type = tryGetType();
+ Type type = tryGetType();
if (type != none && strchr(saved, '\n') > s) {
s = saved;
type = none;
@@ -409,8 +409,8 @@ class S2WasmBuilder {
return type;
}
- WasmType getType() {
- WasmType t = tryGetType();
+ Type getType() {
+ Type t = tryGetType();
if (t != none) {
return t;
}
@@ -690,16 +690,16 @@ class S2WasmBuilder {
};
wasm::Builder builder(*wasm);
std::vector<NameType> params;
- WasmType resultType = none;
+ Type resultType = none;
std::vector<NameType> vars;
- std::map<Name, WasmType> localTypes;
+ std::map<Name, Type> localTypes;
// params and result
while (1) {
if (match(".param")) {
while (1) {
Name name = getNextId();
- WasmType type = getType();
+ Type type = getType();
params.emplace_back(name, type);
localTypes[name] = type;
skipWhitespace();
@@ -717,7 +717,7 @@ class S2WasmBuilder {
} else if (match(".local")) {
while (1) {
Name name = getNextId();
- WasmType type = getType();
+ Type type = getType();
vars.emplace_back(name, type);
localTypes[name] = type;
skipWhitespace();
@@ -810,7 +810,7 @@ class S2WasmBuilder {
auto setOutput = [&](Expression* curr, Name assign) {
if (assign.isNull() || assign.str[0] == 'd') { // drop
auto* add = curr;
- if (isConcreteWasmType(curr->type)) {
+ if (isConcreteType(curr->type)) {
add = builder.makeDrop(curr);
}
addToBlock(add);
@@ -843,7 +843,7 @@ class S2WasmBuilder {
return attributes;
};
//
- auto makeBinary = [&](BinaryOp op, WasmType type) {
+ auto makeBinary = [&](BinaryOp op, Type type) {
Name assign = getAssign();
skipComma();
auto curr = allocator->alloc<Binary>();
@@ -855,7 +855,7 @@ class S2WasmBuilder {
assert(curr->type == type);
setOutput(curr, assign);
};
- auto makeUnary = [&](UnaryOp op, WasmType type) {
+ auto makeUnary = [&](UnaryOp op, Type type) {
Name assign = getAssign();
skipComma();
auto curr = allocator->alloc<Unary>();
@@ -898,13 +898,13 @@ class S2WasmBuilder {
add->right = reloc;
return (Expression*)add;
};
- auto makeLoad = [&](WasmType type) {
+ auto makeLoad = [&](Type type) {
skipComma();
auto curr = allocator->alloc<Load>();
curr->isAtomic = false;
curr->type = type;
int32_t bytes = getInt() / CHAR_BIT;
- curr->bytes = bytes > 0 ? bytes : getWasmTypeSize(type);
+ curr->bytes = bytes > 0 ? bytes : getTypeSize(type);
curr->signed_ = match("_s");
match("_u");
Name assign = getAssign();
@@ -919,7 +919,7 @@ class S2WasmBuilder {
}
setOutput(curr, assign);
};
- auto makeStore = [&](WasmType type) {
+ auto makeStore = [&](Type type) {
auto curr = allocator->alloc<Store>();
curr->isAtomic = false;
curr->valueType = type;
@@ -927,7 +927,7 @@ class S2WasmBuilder {
if(!isspace(*s)) {
curr->bytes = getInt() / CHAR_BIT;
} else {
- curr->bytes = getWasmTypeSize(type);
+ curr->bytes = getTypeSize(type);
}
skipWhitespace();
auto relocation = getRelocatableExpression(&curr->offset.addr);
@@ -944,7 +944,7 @@ class S2WasmBuilder {
curr->finalize();
addToBlock(curr);
};
- auto makeSelect = [&](WasmType type) {
+ auto makeSelect = [&](Type type) {
Name assign = getAssign();
skipComma();
auto curr = allocator->alloc<Select>();
@@ -956,7 +956,7 @@ class S2WasmBuilder {
curr->type = type;
setOutput(curr, assign);
};
- auto makeCall = [&](WasmType type) {
+ auto makeCall = [&](Type type) {
if (match("_indirect")) {
// indirect call
Name assign = getAssign();
@@ -996,7 +996,7 @@ class S2WasmBuilder {
#define BINARY_INT_OR_FLOAT(op) (type == i32 ? BinaryOp::op##Int32 : (type == i64 ? BinaryOp::op##Int64 : (type == f32 ? BinaryOp::op##Float32 : BinaryOp::op##Float64)))
#define BINARY_INT(op) (type == i32 ? BinaryOp::op##Int32 : BinaryOp::op##Int64)
#define BINARY_FLOAT(op) (type == f32 ? BinaryOp::op##Float32 : BinaryOp::op##Float64)
- auto handleTyped = [&](WasmType type) {
+ auto handleTyped = [&](Type type) {
switch (*s) {
case 'a': {
if (match("add")) makeBinary(BINARY_INT_OR_FLOAT(Add), type);
@@ -1171,7 +1171,7 @@ class S2WasmBuilder {
} else if (match("f64.")) {
handleTyped(f64);
} else if (match("block")) {
- WasmType blockType = tryGetTypeWithoutNewline();
+ Type blockType = tryGetTypeWithoutNewline();
auto curr = allocator->alloc<Block>();
curr->type = blockType;
curr->name = getNextLabel();
@@ -1180,7 +1180,7 @@ class S2WasmBuilder {
} else if (match("end_block")) {
auto* block = bstack.back()->cast<Block>();
block->finalize(block->type);
- if (isConcreteWasmType(block->type) && block->list.size() == 0) {
+ if (isConcreteType(block->type) && block->list.size() == 0) {
// empty blocks that return a value are not valid, fix that up
block->list.push_back(allocator->alloc<Unreachable>());
block->finalize();
@@ -1194,7 +1194,7 @@ class S2WasmBuilder {
recordLabel();
} else s = strchr(s, '\n');
} else if (match("loop")) {
- WasmType loopType = tryGetTypeWithoutNewline();
+ Type loopType = tryGetTypeWithoutNewline();
auto curr = allocator->alloc<Loop>();
addToBlock(curr);
curr->type = loopType;
@@ -1472,7 +1472,7 @@ class S2WasmBuilder {
// 2. Converts invoke wrapper names.
// Refer to the comments in fixEmExceptionInvoke below.
template<typename ListType>
- Name fixEmEHSjLjNames(const Name &name, WasmType result,
+ Name fixEmEHSjLjNames(const Name &name, Type result,
const ListType &operands) {
return fixEmEHSjLjNames(name, getSig(result, operands));
}
diff --git a/src/shell-interface.h b/src/shell-interface.h
index 53a954aef..e41d9de24 100644
--- a/src/shell-interface.h
+++ b/src/shell-interface.h
@@ -146,7 +146,7 @@ struct ShellExternalInterface final : ModuleInstance::ExternalInterface {
<< import->name.str;
}
- Literal callTable(Index index, LiteralList& arguments, WasmType result, ModuleInstance& instance) override {
+ Literal callTable(Index index, LiteralList& arguments, Type result, ModuleInstance& instance) override {
if (index >= table.size()) trap("callTable overflow");
auto* func = instance.wasm.getFunctionOrNull(table[index]);
if (!func) trap("uninitialized table element");
diff --git a/src/tools/execution-results.h b/src/tools/execution-results.h
index 1fee4ffb0..7537d9911 100644
--- a/src/tools/execution-results.h
+++ b/src/tools/execution-results.h
@@ -105,7 +105,7 @@ struct ExecutionResults {
instance.callFunction("hangLimitInitializer", arguments);
}
// call the method
- for (WasmType param : func->params) {
+ for (Type param : func->params) {
// zeros in arguments TODO: more?
arguments.push_back(Literal(param));
}
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h
index 19bff428e..d90660e89 100644
--- a/src/tools/fuzzing.h
+++ b/src/tools/fuzzing.h
@@ -243,7 +243,7 @@ private:
wasm.table.segments.emplace_back(builder.makeConst(Literal(int32_t(0))));
}
- std::map<WasmType, std::vector<Name>> globalsByType;
+ std::map<Type, std::vector<Name>> globalsByType;
void setupGlobals() {
size_t index = 0;
@@ -314,7 +314,7 @@ private:
}
void addDeNanSupport() {
- auto add = [&](Name name, WasmType type, Literal literal, BinaryOp op) {
+ auto add = [&](Name name, Type type, Literal literal, BinaryOp op) {
auto* func = new Function;
func->name = name;
func->params.push_back(type);
@@ -354,7 +354,7 @@ private:
// which we try to minimize the risk of
std::vector<Expression*> hangStack;
- std::map<WasmType, std::vector<Index>> typeLocals; // type => list of locals with that type
+ std::map<Type, std::vector<Index>> typeLocals; // type => list of locals with that type
Function* addFunction() {
Index num = wasm.functions.size();
@@ -427,7 +427,7 @@ private:
args.push_back(makeConst(type));
}
Expression* invoke = builder.makeCall(func->name, args, func->result);
- if (isConcreteWasmType(func->result)) {
+ if (isConcreteType(func->result)) {
invoke = builder.makeDrop(invoke);
}
invocations.push_back(invoke);
@@ -454,12 +454,12 @@ private:
int nesting = 0;
- Expression* make(WasmType type) {
+ Expression* make(Type type) {
// when we should stop, emit something small (but not necessarily trivial)
if (finishedInput ||
nesting >= 5 * NESTING_LIMIT || // hard limit
(nesting >= NESTING_LIMIT && !oneIn(3))) {
- if (isConcreteWasmType(type)) {
+ if (isConcreteType(type)) {
if (oneIn(2)) {
return makeConst(type);
} else {
@@ -491,7 +491,7 @@ private:
return ret;
}
- Expression* _makeConcrete(WasmType type) {
+ Expression* _makeConcrete(Type type) {
auto choice = upTo(100);
if (choice < 10) return makeConst(type);
if (choice < 30) return makeSetLocal(type);
@@ -565,8 +565,8 @@ private:
}
// make something with no chance of infinite recursion
- Expression* makeTrivial(WasmType type) {
- if (isConcreteWasmType(type)) {
+ Expression* makeTrivial(Type type) {
+ if (isConcreteType(type)) {
if (oneIn(2)) {
return makeGetLocal(type);
} else {
@@ -577,7 +577,7 @@ private:
}
assert(type == unreachable);
Expression* ret = nullptr;
- if (isConcreteWasmType(func->result)) {
+ if (isConcreteType(func->result)) {
ret = makeTrivial(func->result);
}
return builder.makeReturn(ret);
@@ -585,7 +585,7 @@ private:
// specific expression creators
- Expression* makeBlock(WasmType type) {
+ Expression* makeBlock(Type type) {
auto* ret = builder.makeBlock();
ret->type = type; // so we have it during child creation
ret->name = makeLabel();
@@ -609,13 +609,13 @@ private:
}
// give a chance to make the final element an unreachable break, instead
// of concrete - a common pattern (branch to the top of a loop etc.)
- if (!finishedInput && isConcreteWasmType(type) && oneIn(2)) {
+ if (!finishedInput && isConcreteType(type) && oneIn(2)) {
ret->list.push_back(makeBreak(unreachable));
} else {
ret->list.push_back(make(type));
}
breakableStack.pop_back();
- if (isConcreteWasmType(type)) {
+ if (isConcreteType(type)) {
ret->finalize(type);
} else {
ret->finalize();
@@ -628,7 +628,7 @@ private:
return ret;
}
- Expression* makeLoop(WasmType type) {
+ Expression* makeLoop(Type type) {
auto* ret = wasm.allocator.alloc<Loop>();
ret->type = type; // so we have it during child creation
ret->name = makeLabel();
@@ -669,7 +669,7 @@ private:
}
// make something, with a good chance of it being a block
- Expression* makeMaybeBlock(WasmType type) {
+ Expression* makeMaybeBlock(Type type) {
// if past the limit, prefer not to emit blocks
if (nesting >= NESTING_LIMIT || oneIn(3)) {
return make(type);
@@ -678,7 +678,7 @@ private:
}
}
- Expression* makeIf(WasmType type) {
+ Expression* makeIf(Type type) {
auto* condition = makeCondition();
hangStack.push_back(nullptr);
auto* ret = makeIf({ condition, makeMaybeBlock(type), makeMaybeBlock(type) });
@@ -690,7 +690,7 @@ private:
return builder.makeIf(args.a, args.b, args.c);
}
- Expression* makeBreak(WasmType type) {
+ Expression* makeBreak(Type type) {
if (breakableStack.empty()) return makeTrivial(type);
Expression* condition = nullptr;
if (type != unreachable) {
@@ -703,7 +703,7 @@ private:
auto* target = vectorPick(breakableStack);
auto name = getTargetName(target);
auto valueType = getTargetType(target);
- if (isConcreteWasmType(type)) {
+ if (isConcreteType(type)) {
// we are flowing out a value
if (valueType != type) {
// we need to break to a proper place
@@ -765,7 +765,7 @@ private:
return makeTrivial(type);
}
- Expression* makeCall(WasmType type) {
+ Expression* makeCall(Type type) {
// seems ok, go on
int tries = TRIES;
while (tries-- > 0) {
@@ -787,7 +787,7 @@ private:
return make(type);
}
- Expression* makeCallIndirect(WasmType type) {
+ Expression* makeCallIndirect(Type type) {
auto& data = wasm.table.segments[0].data;
if (data.empty()) return make(type);
// look for a call target with the right type
@@ -825,15 +825,15 @@ private:
);
}
- Expression* makeGetLocal(WasmType type) {
+ Expression* makeGetLocal(Type type) {
auto& locals = typeLocals[type];
if (locals.empty()) return makeConst(type);
return builder.makeGetLocal(vectorPick(locals), type);
}
- Expression* makeSetLocal(WasmType type) {
+ Expression* makeSetLocal(Type type) {
bool tee = type != none;
- WasmType valueType;
+ Type valueType;
if (tee) {
valueType = type;
} else {
@@ -849,13 +849,13 @@ private:
}
}
- Expression* makeGetGlobal(WasmType type) {
+ Expression* makeGetGlobal(Type type) {
auto& globals = globalsByType[type];
if (globals.empty()) return makeConst(type);
return builder.makeGetGlobal(vectorPick(globals), type);
}
- Expression* makeSetGlobal(WasmType type) {
+ Expression* makeSetGlobal(Type type) {
assert(type == none);
type = getConcreteType();
auto& globals = globalsByType[type];
@@ -878,7 +878,7 @@ private:
return ret;
}
- Load* makeNonAtomicLoad(WasmType type) {
+ Load* makeNonAtomicLoad(Type type) {
auto offset = logify(get());
auto ptr = makePointer();
switch (type) {
@@ -911,7 +911,7 @@ private:
}
}
- Expression* makeLoad(WasmType type) {
+ Expression* makeLoad(Type type) {
auto* ret = makeNonAtomicLoad(type);
if (type != i32 && type != i64) return ret;
if (!ATOMICS || oneIn(2)) return ret;
@@ -923,7 +923,7 @@ private:
return ret;
}
- Store* makeNonAtomicStore(WasmType type) {
+ Store* makeNonAtomicStore(Type type) {
if (type == unreachable) {
// make a normal store, then make it unreachable
auto* ret = makeNonAtomicStore(getConcreteType());
@@ -971,7 +971,7 @@ private:
}
}
- Store* makeStore(WasmType type) {
+ Store* makeStore(Type type) {
auto* ret = makeNonAtomicStore(type);
if (ret->value->type != i32 && ret->value->type != i64) return ret;
if (!ATOMICS || oneIn(2)) return ret;
@@ -982,7 +982,7 @@ private:
return ret;
}
- Expression* makeConst(WasmType type) {
+ Expression* makeConst(Type type) {
Literal value;
switch (upTo(4)) {
case 0: {
@@ -1085,7 +1085,7 @@ private:
return builder.makeUnary(args.a, args.b);
}
- Expression* makeUnary(WasmType type) {
+ Expression* makeUnary(Type type) {
if (type == unreachable) {
if (auto* unary = makeUnary(getConcreteType())->dynCast<Unary>()) {
return makeDeNanOp(builder.makeUnary(unary->op, make(unreachable)));
@@ -1153,7 +1153,7 @@ private:
return builder.makeBinary(args.a, args.b, args.c);
}
- Expression* makeBinary(WasmType type) {
+ Expression* makeBinary(Type type) {
if (type == unreachable) {
if (auto* binary = makeBinary(getConcreteType())->dynCast<Binary>()) {
return makeDeNanOp(makeBinary({ binary->op, make(unreachable), make(unreachable) }));
@@ -1189,17 +1189,17 @@ private:
return builder.makeSelect(args.a, args.b, args.c);
}
- Expression* makeSelect(WasmType type) {
+ Expression* makeSelect(Type type) {
return makeDeNanOp(makeSelect({ make(i32), make(type), make(type) }));
}
- Expression* makeSwitch(WasmType type) {
+ Expression* makeSwitch(Type type) {
assert(type == unreachable);
if (breakableStack.empty()) return make(type);
// we need to find proper targets to break to; try a bunch
int tries = TRIES;
std::vector<Name> names;
- WasmType valueType = unreachable;
+ Type valueType = unreachable;
while (tries-- > 0) {
auto* target = vectorPick(breakableStack);
auto name = getTargetName(target);
@@ -1219,29 +1219,29 @@ private:
}
auto default_ = names.back();
names.pop_back();
- auto temp1 = make(i32), temp2 = isConcreteWasmType(valueType) ? make(valueType) : nullptr;
+ auto temp1 = make(i32), temp2 = isConcreteType(valueType) ? make(valueType) : nullptr;
return builder.makeSwitch(names, default_, temp1, temp2);
}
- Expression* makeDrop(WasmType type) {
+ Expression* makeDrop(Type type) {
return builder.makeDrop(make(type == unreachable ? type : getConcreteType()));
}
- Expression* makeReturn(WasmType type) {
- return builder.makeReturn(isConcreteWasmType(func->result) ? make(func->result) : nullptr);
+ Expression* makeReturn(Type type) {
+ return builder.makeReturn(isConcreteType(func->result) ? make(func->result) : nullptr);
}
- Expression* makeNop(WasmType type) {
+ Expression* makeNop(Type type) {
assert(type == none);
return builder.makeNop();
}
- Expression* makeUnreachable(WasmType type) {
+ Expression* makeUnreachable(Type type) {
assert(type == unreachable);
return builder.makeUnreachable();
}
- Expression* makeAtomic(WasmType type) {
+ Expression* makeAtomic(Type type) {
if (!ATOMICS || (type != i32 && type != i64)) return makeTrivial(type);
wasm.memory.shared = true;
if (type == i32 && oneIn(2)) {
@@ -1295,7 +1295,7 @@ private:
// special getters
- WasmType getType() {
+ Type getType() {
switch (upTo(6)) {
case 0: return i32;
case 1: return i64;
@@ -1307,7 +1307,7 @@ private:
WASM_UNREACHABLE();
}
- WasmType getReachableType() {
+ Type getReachableType() {
switch (upTo(5)) {
case 0: return i32;
case 1: return i64;
@@ -1318,7 +1318,7 @@ private:
WASM_UNREACHABLE();
}
- WasmType getConcreteType() {
+ Type getConcreteType() {
switch (upTo(4)) {
case 0: return i32;
case 1: return i64;
@@ -1423,7 +1423,7 @@ private:
WASM_UNREACHABLE();
}
- WasmType getTargetType(Expression* target) {
+ Type getTargetType(Expression* target) {
if (auto* block = target->dynCast<Block>()) {
return block->type;
} else if (target->is<Loop>()) {
diff --git a/src/tools/js-wrapper.h b/src/tools/js-wrapper.h
index 90453eb35..cb5c0bd5b 100644
--- a/src/tools/js-wrapper.h
+++ b/src/tools/js-wrapper.h
@@ -49,7 +49,7 @@ static std::string generateJSWrapper(Module& wasm) {
auto* func = wasm.getFunctionOrNull(exp->value);
if (!func) continue; // something exported other than a function
auto bad = false; // check for things we can't support
- for (WasmType param : func->params) {
+ for (Type param : func->params) {
if (param == i64) bad = true;
}
if (func->result == i64) bad = true;
@@ -62,7 +62,7 @@ static std::string generateJSWrapper(Module& wasm) {
}
ret += std::string("instance.exports.") + exp->name.str + "(";
bool first = true;
- for (WasmType param : func->params) {
+ for (Type param : func->params) {
WASM_UNUSED(param);
// zeros in arguments TODO more?
if (first) {
diff --git a/src/tools/spec-wrapper.h b/src/tools/spec-wrapper.h
index 4da746a5d..82c45ffb6 100644
--- a/src/tools/spec-wrapper.h
+++ b/src/tools/spec-wrapper.h
@@ -27,7 +27,7 @@ static std::string generateSpecWrapper(Module& wasm) {
auto* func = wasm.getFunctionOrNull(exp->value);
if (!func) continue; // something exported other than a function
ret += std::string("(invoke \"hangLimitInitializer\") (invoke \"") + exp->name.str + "\" ";
- for (WasmType param : func->params) {
+ for (Type param : func->params) {
// zeros in arguments TODO more?
switch (param) {
case i32: ret += "(i32.const 0)"; break;
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index 631966d40..da7c2042a 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -207,7 +207,7 @@ struct CtorEvalExternalInterface : EvallingModuleInstance::ExternalInterface {
throw FailToEvalException(std::string("call import: ") + import->module.str + "." + import->base.str + extra);
}
- Literal callTable(Index index, LiteralList& arguments, WasmType result, EvallingModuleInstance& instance) override {
+ Literal callTable(Index index, LiteralList& arguments, Type result, EvallingModuleInstance& instance) override {
// we assume the table is not modified (hmm)
// look through the segments, try to find the function
for (auto& segment : wasm->table.segments) {
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp
index 85d00dda1..a5e6b2803 100644
--- a/src/tools/wasm-reduce.cpp
+++ b/src/tools/wasm-reduce.cpp
@@ -279,7 +279,7 @@ struct Reducer : public WalkerPass<PostWalker<Reducer, UnifiedExpressionVisitor<
void visitExpression(Expression* curr) {
if (curr->type == none) {
if (tryToReduceCurrentToNone()) return;
- } else if (isConcreteWasmType(curr->type)) {
+ } else if (isConcreteType(curr->type)) {
if (tryToReduceCurrentToConst()) return;
} else {
assert(curr->type == unreachable);
diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp
index 965887cf9..613fc8040 100644
--- a/src/tools/wasm-shell.cpp
+++ b/src/tools/wasm-shell.cpp
@@ -104,7 +104,7 @@ static void run_asserts(Name moduleName, size_t* i, bool* checked, Module* wasm,
std::cerr << "Unknown entry " << entry << std::endl;
} else {
LiteralList arguments;
- for (WasmType param : function->params) {
+ for (Type param : function->params) {
arguments.push_back(Literal(param));
}
try {
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 2ac0ef2d0..cc98ebf8b 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -638,7 +638,7 @@ enum MemoryFlags {
} // namespace BinaryConsts
-inline S32LEB binaryWasmType(WasmType type) {
+inline S32LEB binaryType(Type type) {
int ret;
switch (type) {
// None only used for block signatures. TODO: Separate out?
@@ -704,7 +704,7 @@ public:
void writeImports();
std::map<Index, size_t> mappedLocals; // local index => index in compact form of [all int32s][all int64s]etc
- std::map<WasmType, size_t> numLocalsByType; // type => number of locals of that type in the compact form
+ std::map<Type, size_t> numLocalsByType; // type => number of locals of that type in the compact form
void mapLocals(Function* function);
void writeFunctionSignatures();
@@ -839,7 +839,7 @@ public:
uint64_t getU64LEB();
int32_t getS32LEB();
int64_t getS64LEB();
- WasmType getWasmType();
+ Type getType();
Name getString();
Name getInlineString();
void verifyInt8(int8_t x);
@@ -934,7 +934,7 @@ public:
void visitBlock(Block *curr);
// Gets a block of expressions. If it's just one, return that singleton.
- Expression* getBlockOrSingleton(WasmType type);
+ Expression* getBlockOrSingleton(Type type);
void visitIf(If *curr);
void visitLoop(Loop *curr);
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index ca04c08b9..94699df7e 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -26,9 +26,9 @@ namespace wasm {
struct NameType {
Name name;
- WasmType type;
+ Type type;
NameType() : name(nullptr), type(none) {}
- NameType(Name name, WasmType type) : name(name), type(type) {}
+ NameType(Name name, Type type) : name(name), type(type) {}
};
// General AST node builder
@@ -44,7 +44,7 @@ public:
Function* makeFunction(Name name,
std::vector<NameType>&& params,
- WasmType resultType,
+ Type resultType,
std::vector<NameType>&& vars,
Expression* body = nullptr) {
auto* func = new Function;
@@ -97,7 +97,7 @@ public:
ret->finalize();
return ret;
}
- Block* makeBlock(const ExpressionList& items, WasmType type) {
+ Block* makeBlock(const ExpressionList& items, Type type) {
auto* ret = allocator.alloc<Block>();
ret->list.set(items);
ret->finalize(type);
@@ -110,7 +110,7 @@ public:
ret->finalize();
return ret;
}
- Block* makeBlock(Name name, const ExpressionList& items, WasmType type) {
+ Block* makeBlock(Name name, const ExpressionList& items, Type type) {
auto* ret = allocator.alloc<Block>();
ret->name = name;
ret->list.set(items);
@@ -123,7 +123,7 @@ public:
ret->finalize();
return ret;
}
- If* makeIf(Expression* condition, Expression* ifTrue, Expression* ifFalse, WasmType 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->finalize(type);
@@ -148,14 +148,14 @@ public:
ret->default_ = default_; ret->value = value; ret->condition = condition;
return ret;
}
- Call* makeCall(Name target, const std::vector<Expression*>& args, WasmType type) {
+ 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
call->target = target;
call->operands.set(args);
return call;
}
- CallImport* makeCallImport(Name target, const std::vector<Expression*>& args, WasmType type) {
+ CallImport* makeCallImport(Name target, const std::vector<Expression*>& args, Type type) {
auto* call = allocator.alloc<CallImport>();
call->type = type; // similar to makeCall, for consistency
call->target = target;
@@ -163,7 +163,7 @@ public:
return call;
}
template<typename T>
- Call* makeCall(Name target, const T& args, WasmType type) {
+ 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
call->target = target;
@@ -171,7 +171,7 @@ public:
return call;
}
template<typename T>
- CallImport* makeCallImport(Name target, const T& args, WasmType type) {
+ CallImport* makeCallImport(Name target, const T& args, Type type) {
auto* call = allocator.alloc<CallImport>();
call->type = type; // similar to makeCall, for consistency
call->target = target;
@@ -186,7 +186,7 @@ public:
call->operands.set(args);
return call;
}
- CallIndirect* makeCallIndirect(Name fullType, Expression* target, const std::vector<Expression*>& args, WasmType 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;
@@ -195,7 +195,7 @@ public:
return call;
}
// FunctionType
- GetLocal* makeGetLocal(Index index, WasmType type) {
+ GetLocal* makeGetLocal(Index index, Type type) {
auto* ret = allocator.alloc<GetLocal>();
ret->index = index;
ret->type = type;
@@ -215,7 +215,7 @@ public:
ret->setTee(true);
return ret;
}
- GetGlobal* makeGetGlobal(Name name, WasmType type) {
+ GetGlobal* makeGetGlobal(Name name, Type type) {
auto* ret = allocator.alloc<GetGlobal>();
ret->name = name;
ret->type = type;
@@ -228,19 +228,19 @@ public:
ret->finalize();
return ret;
}
- Load* makeLoad(unsigned bytes, bool signed_, uint32_t offset, unsigned align, Expression *ptr, WasmType 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->type = type;
return ret;
}
- Load* makeAtomicLoad(unsigned bytes, uint32_t offset, Expression* ptr, WasmType 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, WasmType 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;
@@ -258,21 +258,21 @@ public:
wake->finalize();
return wake;
}
- Store* makeStore(unsigned bytes, uint32_t offset, unsigned align, Expression *ptr, Expression *value, WasmType 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->finalize();
- assert(isConcreteWasmType(ret->value->type) ? ret->value->type == type : true);
+ assert(isConcreteType(ret->value->type) ? ret->value->type == type : true);
return ret;
}
- Store* makeAtomicStore(unsigned bytes, uint32_t offset, Expression* ptr, Expression* value, WasmType 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, WasmType type) {
+ Expression* ptr, Expression* value, Type type) {
auto* ret = allocator.alloc<AtomicRMW>();
ret->op = op;
ret->bytes = bytes;
@@ -285,7 +285,7 @@ public:
}
AtomicCmpxchg* makeAtomicCmpxchg(unsigned bytes, uint32_t offset,
Expression* ptr, Expression* expected,
- Expression* replacement, WasmType type) {
+ Expression* replacement, Type type) {
auto* ret = allocator.alloc<AtomicCmpxchg>();
ret->bytes = bytes;
ret->offset = offset;
@@ -297,7 +297,7 @@ public:
return ret;
}
Const* makeConst(Literal value) {
- assert(isConcreteWasmType(value.type));
+ assert(isConcreteType(value.type));
auto* ret = allocator.alloc<Const>();
ret->value = value;
ret->type = value.type;
@@ -350,7 +350,7 @@ public:
// Additional utility functions for building on top of nodes
// Convenient to have these on Builder, as it has allocation built in
- static Index addParam(Function* func, Name name, WasmType type) {
+ static Index addParam(Function* func, Name name, Type type) {
// only ok to add a param if no vars, otherwise indices are invalidated
assert(func->localIndices.size() == func->params.size());
assert(name.is());
@@ -361,7 +361,7 @@ public:
return index;
}
- static Index addVar(Function* func, Name name, WasmType type) {
+ static Index addVar(Function* func, Name name, Type type) {
// always ok to add a var, it does not affect other indices
Index index = func->getNumLocals();
if (name.is()) {
@@ -372,7 +372,7 @@ public:
return index;
}
- static Index addVar(Function* func, WasmType type) {
+ static Index addVar(Function* func, Type type) {
return addVar(func, Name(), type);
}
@@ -451,7 +451,7 @@ public:
// Drop an expression if it has a concrete type
Expression* dropIfConcretelyTyped(Expression* curr) {
- if (!isConcreteWasmType(curr->type)) return curr;
+ if (!isConcreteType(curr->type)) return curr;
return makeDrop(curr);
}
@@ -485,7 +485,7 @@ public:
Immutable
};
- static Global* makeGlobal(Name name, WasmType 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;
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index c8b48e477..7dc59333a 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -120,10 +120,10 @@ class ExpressionRunner : public Visitor<SubType, Flow> {
public:
Flow visit(Expression *curr) {
auto ret = Visitor<SubType, Flow>::visit(curr);
- if (!ret.breaking() && (isConcreteWasmType(curr->type) || isConcreteWasmType(ret.value.type))) {
+ if (!ret.breaking() && (isConcreteType(curr->type) || isConcreteType(ret.value.type))) {
#if 1 // def WASM_INTERPRETER_DEBUG
if (ret.value.type != curr->type) {
- std::cerr << "expected " << printWasmType(curr->type) << ", seeing " << printWasmType(ret.value.type) << " from\n" << curr << '\n';
+ std::cerr << "expected " << printType(curr->type) << ", seeing " << printType(ret.value.type) << " from\n" << curr << '\n';
}
#endif
assert(ret.value.type == curr->type);
@@ -333,8 +333,8 @@ public:
if (flow.breaking()) return flow;
Literal right = flow.value;
NOTE_EVAL2(left, right);
- assert(isConcreteWasmType(curr->left->type) ? left.type == curr->left->type : true);
- assert(isConcreteWasmType(curr->right->type) ? right.type == curr->right->type : true);
+ assert(isConcreteType(curr->left->type) ? left.type == curr->left->type : true);
+ assert(isConcreteType(curr->right->type) ? right.type == curr->right->type : true);
if (left.type == i32) {
switch (curr->op) {
case AddInt32: return left.add(right);
@@ -568,7 +568,7 @@ public:
virtual void init(Module& wasm, SubType& instance) {}
virtual void importGlobals(GlobalManager& globals, Module& wasm) = 0;
virtual Literal callImport(Import* import, LiteralList& arguments) = 0;
- virtual Literal callTable(Index index, LiteralList& arguments, WasmType result, SubType& instance) = 0;
+ virtual Literal callTable(Index index, LiteralList& arguments, Type result, SubType& instance) = 0;
virtual void growMemory(Address oldSize, Address newSize) = 0;
virtual void trap(const char* why) = 0;
@@ -740,9 +740,9 @@ public:
assert(function->isParam(i));
if (function->params[i] != arguments[i].type) {
std::cerr << "Function `" << function->name << "` expects type "
- << printWasmType(function->params[i])
+ << printType(function->params[i])
<< " for parameter " << i << ", got "
- << printWasmType(arguments[i].type) << "." << std::endl;
+ << printType(arguments[i].type) << "." << std::endl;
WASM_UNREACHABLE();
}
locals[i] = arguments[i];
@@ -922,7 +922,7 @@ public:
auto timeout = this->visit(curr->timeout);
NOTE_EVAL1(timeout);
if (timeout.breaking()) return timeout;
- auto bytes = getWasmTypeSize(curr->expectedType);
+ auto bytes = getTypeSize(curr->expectedType);
auto addr = instance.getFinalAddress(ptr.value, bytes);
auto loaded = instance.doAtomicLoad(addr, bytes, curr->expectedType);
NOTE_EVAL1(loaded);
@@ -1050,7 +1050,7 @@ protected:
trapIfGt(addr, memorySizeBytes - bytes, "highest > memory");
}
- Literal doAtomicLoad(Address addr, Index bytes, WasmType type) {
+ Literal doAtomicLoad(Address addr, Index bytes, Type type) {
checkLoadAddress(addr, bytes);
Const ptr;
ptr.value = Literal(int32_t(addr));
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp
index 0a0961066..a2f09504d 100644
--- a/src/wasm-js.cpp
+++ b/src/wasm-js.cpp
@@ -264,7 +264,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() {
}
}
- Literal getResultFromJS(double ret, WasmType type) {
+ Literal getResultFromJS(double ret, Type type) {
switch (type) {
case none: return Literal();
case i32: return Literal((int32_t)ret);
@@ -308,7 +308,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() {
return getResultFromJS(ret, module->getFunctionType(import->functionType)->result);
}
- Literal callTable(Index index, LiteralList& arguments, WasmType result, ModuleInstance& instance) override {
+ Literal callTable(Index index, LiteralList& arguments, Type result, ModuleInstance& instance) override {
void* ptr = (void*)EM_ASM_INT({
var value = Module['outside']['wasmTable'][$0];
return typeof value === "number" ? value : -1;
@@ -369,8 +369,8 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() {
}
HEAP32[0] = save0; HEAP32[1] = save1;
return ret;
- }, (uint32_t)addr, load->bytes, isWasmTypeFloat(load->type), load->signed_, &out64);
- if (!isWasmTypeFloat(load->type)) {
+ }, (uint32_t)addr, load->bytes, isTypeFloat(load->type), load->signed_, &out64);
+ if (!isTypeFloat(load->type)) {
if (load->type == i64) {
if (load->bytes == 8) {
return Literal(out64);
@@ -391,7 +391,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() {
abort();
}
// nicely aligned
- if (!isWasmTypeFloat(load->type)) {
+ if (!isTypeFloat(load->type)) {
int64_t ret;
if (load->bytes == 1) {
if (load->signed_) {
@@ -430,7 +430,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() {
void store(Store* store_, Address address, Literal value) override {
uint32_t addr = address;
// support int64 stores
- if (value.type == WasmType::i64 && store_->bytes == 8) {
+ if (value.type == Type::i64 && store_->bytes == 8) {
Store fake = *store_;
fake.bytes = 4;
fake.type = i32;
@@ -463,11 +463,11 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() {
Module["info"].parent["HEAPU8"][addr + i] = HEAPU8[i];
}
HEAP32[0] = save0; HEAP32[1] = save1;
- }, (uint32_t)addr, store_->bytes, isWasmTypeFloat(store_->valueType), isWasmTypeFloat(store_->valueType) ? value.getFloat() : (double)value.getInteger());
+ }, (uint32_t)addr, store_->bytes, isTypeFloat(store_->valueType), isTypeFloat(store_->valueType) ? value.getFloat() : (double)value.getInteger());
return;
}
// nicely aligned
- if (!isWasmTypeFloat(store_->valueType)) {
+ if (!isTypeFloat(store_->valueType)) {
if (store_->bytes == 1) {
EM_ASM_INT({ Module['info'].parent['HEAP8'][$0] = $1 }, addr, (uint32_t)value.getInteger());
} else if (store_->bytes == 2) {
@@ -539,7 +539,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE call_from_js(const char *target) {
size_t actual = function->params.size();
LiteralList arguments;
for (size_t i = 0; i < actual; i++) {
- WasmType type = function->params[i];
+ Type type = function->params[i];
// add the parameter, with a zero value if JS did not provide it.
if (type == i32) {
arguments.push_back(Literal(i < seen ? EM_ASM_INT({ return Module['tempArguments'][$0] }, i) : (int32_t)0));
diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp
index dacc3cf51..c284de81f 100644
--- a/src/wasm-linker.cpp
+++ b/src/wasm-linker.cpp
@@ -235,7 +235,7 @@ void Linker::layout() {
// TODO allow calling with non-default values.
std::vector<Expression*> args;
Index paramNum = 0;
- for (WasmType type : target->params) {
+ for (Type type : target->params) {
Name name = Name::fromInt(paramNum++);
Builder::addVar(func, name, type);
auto* param = builder.makeGetLocal(func->getLocalIndex(name), type);
@@ -382,7 +382,7 @@ void Linker::makeDummyFunction() {
if (!create) return;
wasm::Builder wasmBuilder(out.wasm);
Expression *unreachable = wasmBuilder.makeUnreachable();
- Function *dummy = wasmBuilder.makeFunction(Name(dummyFunction), {}, WasmType::none, {}, unreachable);
+ Function *dummy = wasmBuilder.makeFunction(Name(dummyFunction), {}, Type::none, {}, unreachable);
out.wasm.addFunction(dummy);
getFunctionIndex(dummy->name);
}
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 31abb8fb9..02a20b651 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -113,7 +113,7 @@ class SExpressionWasmBuilder {
std::vector<Name> globalNames;
int functionCounter;
int globalCounter;
- std::map<Name, WasmType> functionTypes; // we need to know function return types before we parse their contents
+ std::map<Name, Type> functionTypes; // we need to know function return types before we parse their contents
std::unordered_map<cashew::IString, Index> debugInfoFileIndices;
public:
@@ -129,7 +129,7 @@ private:
// function parsing state
std::unique_ptr<Function> currFunction;
- std::map<Name, WasmType> currLocalTypes;
+ std::map<Name, Type> currLocalTypes;
size_t localIndex; // params and vars
size_t otherIndex;
bool brokeToAutoBlock;
@@ -145,12 +145,12 @@ private:
size_t parseFunctionNames(Element& s, Name& name, Name& exportName);
void parseFunction(Element& s, bool preParseImport = false);
- WasmType stringToWasmType(cashew::IString str, bool allowError=false, bool prefix=false) {
- return stringToWasmType(str.str, allowError, prefix);
+ Type stringToType(cashew::IString str, bool allowError=false, bool prefix=false) {
+ return stringToType(str.str, allowError, prefix);
}
- WasmType stringToWasmType(const char* str, bool allowError=false, bool prefix=false);
- bool isWasmType(cashew::IString str) {
- return stringToWasmType(str, true) != none;
+ Type stringToType(const char* str, bool allowError=false, bool prefix=false);
+ bool isType(cashew::IString str) {
+ return stringToType(str, true) != none;
}
public:
@@ -165,8 +165,8 @@ public:
private:
Expression* makeExpression(Element& s);
- Expression* makeBinary(Element& s, BinaryOp op, WasmType type);
- Expression* makeUnary(Element& s, UnaryOp op, WasmType type);
+ Expression* makeBinary(Element& s, BinaryOp op, Type type);
+ Expression* makeUnary(Element& s, UnaryOp op, Type type);
Expression* makeSelect(Element& s);
Expression* makeDrop(Element& s);
Expression* makeHost(Element& s, HostOp op);
@@ -178,16 +178,16 @@ private:
Expression* makeSetGlobal(Element& s);
Expression* makeBlock(Element& s);
Expression* makeThenOrElse(Element& s);
- Expression* makeConst(Element& s, WasmType type);
- Expression* makeLoad(Element& s, WasmType type, bool isAtomic);
- Expression* makeStore(Element& s, WasmType type, bool isAtomic);
- Expression* makeAtomicRMWOrCmpxchg(Element& s, WasmType type);
- Expression* makeAtomicRMW(Element& s, WasmType type, uint8_t bytes, const char* extra);
- Expression* makeAtomicCmpxchg(Element& s, WasmType type, uint8_t bytes, const char* extra);
- Expression* makeAtomicWait(Element& s, WasmType type);
+ Expression* makeConst(Element& s, Type type);
+ Expression* makeLoad(Element& s, Type type, bool isAtomic);
+ Expression* makeStore(Element& s, Type type, bool isAtomic);
+ Expression* makeAtomicRMWOrCmpxchg(Element& s, Type type);
+ Expression* makeAtomicRMW(Element& s, Type type, uint8_t bytes, const char* extra);
+ Expression* makeAtomicCmpxchg(Element& s, Type type, uint8_t bytes, const char* extra);
+ Expression* makeAtomicWait(Element& s, Type type);
Expression* makeAtomicWake(Element& s);
Expression* makeIf(Element& s);
- Expression* makeMaybeBlock(Element& s, size_t i, WasmType type);
+ Expression* makeMaybeBlock(Element& s, size_t i, Type type);
Expression* makeLoop(Element& s);
Expression* makeCall(Element& s);
Expression* makeCallImport(Element& s);
@@ -204,7 +204,7 @@ private:
Expression* makeBreakTable(Element& s);
Expression* makeReturn(Element& s);
- WasmType parseOptionalResultType(Element& s, Index& i);
+ Type parseOptionalResultType(Element& s, Index& i);
Index parseMemoryLimits(Element& s, Index i);
void stringToBinary(const char* input, size_t size, std::vector<char>& data);
diff --git a/src/wasm-type.h b/src/wasm-type.h
index 560a846ae..e7da782d7 100644
--- a/src/wasm-type.h
+++ b/src/wasm-type.h
@@ -19,7 +19,7 @@
namespace wasm {
-enum WasmType {
+enum Type {
none,
i32,
i64,
@@ -30,12 +30,12 @@ enum WasmType {
// type checking across branches
};
-const char* printWasmType(WasmType type);
-unsigned getWasmTypeSize(WasmType type);
-bool isWasmTypeFloat(WasmType type);
-WasmType getWasmType(unsigned size, bool float_);
-WasmType getReachableWasmType(WasmType a, WasmType b);
-bool isConcreteWasmType(WasmType type);
+const char* printType(Type type);
+unsigned getTypeSize(Type type);
+bool isTypeFloat(Type type);
+Type getType(unsigned size, bool float_);
+Type getReachableType(Type a, Type b);
+bool isConcreteType(Type type);
} // namespace wasm
diff --git a/src/wasm.h b/src/wasm.h
index cf783adf2..f5802052b 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -200,7 +200,7 @@ public:
};
Id _id;
- WasmType type; // the type of the expression: its *output*, not necessarily its input(s)
+ Type type; // the type of the expression: its *output*, not necessarily its input(s)
Expression(Id id) : _id(id), type(none) {}
@@ -253,7 +253,7 @@ public:
// set the type given you know its type, which is the case when parsing
// s-expression or binary, as explicit types are given. the only additional work
// this does is to set the type to unreachable in the cases that is needed.
- void finalize(WasmType type_);
+ void finalize(Type type_);
// set the type purely based on its contents. this scans the block, so it is not fast
void finalize();
@@ -271,7 +271,7 @@ public:
// set the type given you know its type, which is the case when parsing
// s-expression or binary, as explicit types are given. the only additional work
// this does is to set the type to unreachable in the cases that is needed.
- void finalize(WasmType type_);
+ void finalize(Type type_);
// set the type purely based on its contents.
void finalize();
@@ -288,7 +288,7 @@ public:
// set the type given you know its type, which is the case when parsing
// s-expression or binary, as explicit types are given. the only additional work
// this does is to set the type to unreachable in the cases that is needed.
- void finalize(WasmType type_);
+ void finalize(Type type_);
// set the type purely based on its contents.
void finalize();
@@ -345,8 +345,8 @@ public:
class FunctionType {
public:
Name name;
- WasmType result;
- std::vector<WasmType> params;
+ Type result;
+ std::vector<Type> params;
FunctionType() : result(none) {}
@@ -436,7 +436,7 @@ public:
bool isAtomic;
Expression* ptr;
Expression* value;
- WasmType valueType; // the store never returns a value
+ Type valueType; // the store never returns a value
void finalize();
};
@@ -478,7 +478,7 @@ class AtomicWait : public SpecificExpression<Expression::AtomicWaitId> {
Expression* ptr;
Expression* expected;
Expression* timeout;
- WasmType expectedType;
+ Type expectedType;
void finalize();
};
@@ -593,9 +593,9 @@ public:
class Function {
public:
Name name;
- WasmType result;
- std::vector<WasmType> params; // function locals are
- std::vector<WasmType> vars; // params plus vars
+ Type result;
+ std::vector<Type> params; // function locals are
+ std::vector<Type> vars; // params plus vars
Name type; // if null, it is implicit in params and result
Expression* body;
@@ -622,7 +622,7 @@ public:
Name getLocalName(Index index);
Index getLocalIndex(Name name);
Index getVarIndexBase();
- WasmType getLocalType(Index index);
+ Type getLocalType(Index index);
Name getLocalNameOrDefault(Index index);
Name getLocalNameOrGeneric(Index index);
@@ -644,7 +644,7 @@ public:
Name name, module, base; // name = module.base
ExternalKind kind;
Name functionType; // for Function imports
- WasmType globalType; // for Global imports
+ Type globalType; // for Global imports
};
class Export {
@@ -721,7 +721,7 @@ public:
class Global {
public:
Name name;
- WasmType type;
+ Type type;
Expression* init;
bool mutable_;
};
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index de89a7ac1..dca3d64b4 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -26,53 +26,53 @@
namespace wasm {
Literal Literal::castToF32() {
- assert(type == WasmType::i32);
+ assert(type == Type::i32);
Literal ret(i32);
- ret.type = WasmType::f32;
+ ret.type = Type::f32;
return ret;
}
Literal Literal::castToF64() {
- assert(type == WasmType::i64);
+ assert(type == Type::i64);
Literal ret(i64);
- ret.type = WasmType::f64;
+ ret.type = Type::f64;
return ret;
}
Literal Literal::castToI32() {
- assert(type == WasmType::f32);
+ assert(type == Type::f32);
Literal ret(i32);
- ret.type = WasmType::i32;
+ ret.type = Type::i32;
return ret;
}
Literal Literal::castToI64() {
- assert(type == WasmType::f64);
+ assert(type == Type::f64);
Literal ret(i64);
- ret.type = WasmType::i64;
+ ret.type = Type::i64;
return ret;
}
int64_t Literal::getInteger() const {
switch (type) {
- case WasmType::i32: return i32;
- case WasmType::i64: return i64;
+ case Type::i32: return i32;
+ case Type::i64: return i64;
default: abort();
}
}
double Literal::getFloat() const {
switch (type) {
- case WasmType::f32: return getf32();
- case WasmType::f64: return getf64();
+ case Type::f32: return getf32();
+ case Type::f64: return getf64();
default: abort();
}
}
int64_t Literal::getBits() const {
switch (type) {
- case WasmType::i32: case WasmType::f32: return i32;
- case WasmType::i64: case WasmType::f64: return i64;
+ case Type::i32: case Type::f32: return i32;
+ case Type::i64: case Type::f64: return i64;
default: abort();
}
}
@@ -80,11 +80,11 @@ int64_t Literal::getBits() const {
bool Literal::operator==(const Literal& other) const {
if (type != other.type) return false;
switch (type) {
- case WasmType::none: return true;
- case WasmType::i32: return i32 == other.i32;
- case WasmType::f32: return getf32() == other.getf32();
- case WasmType::i64: return i64 == other.i64;
- case WasmType::f64: return getf64() == other.getf64();
+ case Type::none: return true;
+ case Type::i32: return i32 == other.i32;
+ case Type::f32: return getf32() == other.getf32();
+ case Type::i64: return i64 == other.i64;
+ case Type::f64: return getf64() == other.getf64();
default: abort();
}
}
@@ -167,13 +167,13 @@ void Literal::printDouble(std::ostream& o, double d) {
std::ostream& operator<<(std::ostream& o, Literal literal) {
o << '(';
- prepareMinorColor(o) << printWasmType(literal.type) << ".const ";
+ prepareMinorColor(o) << printType(literal.type) << ".const ";
switch (literal.type) {
case none: o << "?"; break;
- case WasmType::i32: o << literal.i32; break;
- case WasmType::i64: o << literal.i64; break;
- case WasmType::f32: literal.printFloat(o, literal.getf32()); break;
- case WasmType::f64: literal.printDouble(o, literal.getf64()); break;
+ case Type::i32: o << literal.i32; break;
+ case Type::i64: o << literal.i64; break;
+ case Type::f32: literal.printFloat(o, literal.getf32()); break;
+ case Type::f64: literal.printDouble(o, literal.getf64()); break;
default: WASM_UNREACHABLE();
}
restoreNormalColor(o);
@@ -181,165 +181,165 @@ std::ostream& operator<<(std::ostream& o, Literal literal) {
}
Literal Literal::countLeadingZeroes() const {
- if (type == WasmType::i32) return Literal((int32_t)CountLeadingZeroes(i32));
- if (type == WasmType::i64) return Literal((int64_t)CountLeadingZeroes(i64));
+ if (type == Type::i32) return Literal((int32_t)CountLeadingZeroes(i32));
+ if (type == Type::i64) return Literal((int64_t)CountLeadingZeroes(i64));
WASM_UNREACHABLE();
}
Literal Literal::countTrailingZeroes() const {
- if (type == WasmType::i32) return Literal((int32_t)CountTrailingZeroes(i32));
- if (type == WasmType::i64) return Literal((int64_t)CountTrailingZeroes(i64));
+ if (type == Type::i32) return Literal((int32_t)CountTrailingZeroes(i32));
+ if (type == Type::i64) return Literal((int64_t)CountTrailingZeroes(i64));
WASM_UNREACHABLE();
}
Literal Literal::popCount() const {
- if (type == WasmType::i32) return Literal((int32_t)PopCount(i32));
- if (type == WasmType::i64) return Literal((int64_t)PopCount(i64));
+ if (type == Type::i32) return Literal((int32_t)PopCount(i32));
+ if (type == Type::i64) return Literal((int64_t)PopCount(i64));
WASM_UNREACHABLE();
}
Literal Literal::extendToSI64() const {
- assert(type == WasmType::i32);
+ assert(type == Type::i32);
return Literal((int64_t)i32);
}
Literal Literal::extendToUI64() const {
- assert(type == WasmType::i32);
+ assert(type == Type::i32);
return Literal((uint64_t)(uint32_t)i32);
}
Literal Literal::extendToF64() const {
- assert(type == WasmType::f32);
+ assert(type == Type::f32);
return Literal(double(getf32()));
}
Literal Literal::truncateToI32() const {
- assert(type == WasmType::i64);
+ assert(type == Type::i64);
return Literal((int32_t)i64);
}
Literal Literal::truncateToF32() const {
- assert(type == WasmType::f64);
+ assert(type == Type::f64);
return Literal(float(getf64()));
}
Literal Literal::convertSToF32() const {
- if (type == WasmType::i32) return Literal(float(i32));
- if (type == WasmType::i64) return Literal(float(i64));
+ if (type == Type::i32) return Literal(float(i32));
+ if (type == Type::i64) return Literal(float(i64));
WASM_UNREACHABLE();
}
Literal Literal::convertUToF32() const {
- if (type == WasmType::i32) return Literal(float(uint32_t(i32)));
- if (type == WasmType::i64) return Literal(float(uint64_t(i64)));
+ if (type == Type::i32) return Literal(float(uint32_t(i32)));
+ if (type == Type::i64) return Literal(float(uint64_t(i64)));
WASM_UNREACHABLE();
}
Literal Literal::convertSToF64() const {
- if (type == WasmType::i32) return Literal(double(i32));
- if (type == WasmType::i64) return Literal(double(i64));
+ if (type == Type::i32) return Literal(double(i32));
+ if (type == Type::i64) return Literal(double(i64));
WASM_UNREACHABLE();
}
Literal Literal::convertUToF64() const {
- if (type == WasmType::i32) return Literal(double(uint32_t(i32)));
- if (type == WasmType::i64) return Literal(double(uint64_t(i64)));
+ if (type == Type::i32) return Literal(double(uint32_t(i32)));
+ if (type == Type::i64) return Literal(double(uint64_t(i64)));
WASM_UNREACHABLE();
}
Literal Literal::neg() const {
switch (type) {
- case WasmType::i32: return Literal(i32 ^ 0x80000000);
- case WasmType::i64: return Literal(int64_t(i64 ^ 0x8000000000000000ULL));
- case WasmType::f32: return Literal(i32 ^ 0x80000000).castToF32();
- case WasmType::f64: return Literal(int64_t(i64 ^ 0x8000000000000000ULL)).castToF64();
+ case Type::i32: return Literal(i32 ^ 0x80000000);
+ case Type::i64: return Literal(int64_t(i64 ^ 0x8000000000000000ULL));
+ case Type::f32: return Literal(i32 ^ 0x80000000).castToF32();
+ case Type::f64: return Literal(int64_t(i64 ^ 0x8000000000000000ULL)).castToF64();
default: WASM_UNREACHABLE();
}
}
Literal Literal::abs() const {
switch (type) {
- case WasmType::i32: return Literal(i32 & 0x7fffffff);
- case WasmType::i64: return Literal(int64_t(i64 & 0x7fffffffffffffffULL));
- case WasmType::f32: return Literal(i32 & 0x7fffffff).castToF32();
- case WasmType::f64: return Literal(int64_t(i64 & 0x7fffffffffffffffULL)).castToF64();
+ case Type::i32: return Literal(i32 & 0x7fffffff);
+ case Type::i64: return Literal(int64_t(i64 & 0x7fffffffffffffffULL));
+ case Type::f32: return Literal(i32 & 0x7fffffff).castToF32();
+ case Type::f64: return Literal(int64_t(i64 & 0x7fffffffffffffffULL)).castToF64();
default: WASM_UNREACHABLE();
}
}
Literal Literal::ceil() const {
switch (type) {
- case WasmType::f32: return Literal(std::ceil(getf32()));
- case WasmType::f64: return Literal(std::ceil(getf64()));
+ case Type::f32: return Literal(std::ceil(getf32()));
+ case Type::f64: return Literal(std::ceil(getf64()));
default: WASM_UNREACHABLE();
}
}
Literal Literal::floor() const {
switch (type) {
- case WasmType::f32: return Literal(std::floor(getf32()));
- case WasmType::f64: return Literal(std::floor(getf64()));
+ case Type::f32: return Literal(std::floor(getf32()));
+ case Type::f64: return Literal(std::floor(getf64()));
default: WASM_UNREACHABLE();
}
}
Literal Literal::trunc() const {
switch (type) {
- case WasmType::f32: return Literal(std::trunc(getf32()));
- case WasmType::f64: return Literal(std::trunc(getf64()));
+ case Type::f32: return Literal(std::trunc(getf32()));
+ case Type::f64: return Literal(std::trunc(getf64()));
default: WASM_UNREACHABLE();
}
}
Literal Literal::nearbyint() const {
switch (type) {
- case WasmType::f32: return Literal(std::nearbyint(getf32()));
- case WasmType::f64: return Literal(std::nearbyint(getf64()));
+ case Type::f32: return Literal(std::nearbyint(getf32()));
+ case Type::f64: return Literal(std::nearbyint(getf64()));
default: WASM_UNREACHABLE();
}
}
Literal Literal::sqrt() const {
switch (type) {
- case WasmType::f32: return Literal(std::sqrt(getf32()));
- case WasmType::f64: return Literal(std::sqrt(getf64()));
+ case Type::f32: return Literal(std::sqrt(getf32()));
+ case Type::f64: return Literal(std::sqrt(getf64()));
default: WASM_UNREACHABLE();
}
}
Literal Literal::add(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) + uint32_t(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) + uint64_t(other.i64));
- case WasmType::f32: return Literal(getf32() + other.getf32());
- case WasmType::f64: return Literal(getf64() + other.getf64());
+ case Type::i32: return Literal(uint32_t(i32) + uint32_t(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) + uint64_t(other.i64));
+ case Type::f32: return Literal(getf32() + other.getf32());
+ case Type::f64: return Literal(getf64() + other.getf64());
default: WASM_UNREACHABLE();
}
}
Literal Literal::sub(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) - uint32_t(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) - uint64_t(other.i64));
- case WasmType::f32: return Literal(getf32() - other.getf32());
- case WasmType::f64: return Literal(getf64() - other.getf64());
+ case Type::i32: return Literal(uint32_t(i32) - uint32_t(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) - uint64_t(other.i64));
+ case Type::f32: return Literal(getf32() - other.getf32());
+ case Type::f64: return Literal(getf64() - other.getf64());
default: WASM_UNREACHABLE();
}
}
Literal Literal::mul(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) * uint32_t(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) * uint64_t(other.i64));
- case WasmType::f32: return Literal(getf32() * other.getf32());
- case WasmType::f64: return Literal(getf64() * other.getf64());
+ case Type::i32: return Literal(uint32_t(i32) * uint32_t(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) * uint64_t(other.i64));
+ case Type::f32: return Literal(getf32() * other.getf32());
+ case Type::f64: return Literal(getf64() * other.getf64());
default: WASM_UNREACHABLE();
}
}
Literal Literal::div(const Literal& other) const {
switch (type) {
- case WasmType::f32: {
+ case Type::f32: {
float lhs = getf32(), rhs = other.getf32();
float sign = std::signbit(lhs) == std::signbit(rhs) ? 0.f : -0.f;
switch (std::fpclassify(rhs)) {
@@ -359,7 +359,7 @@ Literal Literal::div(const Literal& other) const {
default: WASM_UNREACHABLE();
}
}
- case WasmType::f64: {
+ case Type::f64: {
double lhs = getf64(), rhs = other.getf64();
double sign = std::signbit(lhs) == std::signbit(rhs) ? 0. : -0.;
switch (std::fpclassify(rhs)) {
@@ -385,219 +385,219 @@ Literal Literal::div(const Literal& other) const {
Literal Literal::divS(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 / other.i32);
- case WasmType::i64: return Literal(i64 / other.i64);
+ case Type::i32: return Literal(i32 / other.i32);
+ case Type::i64: return Literal(i64 / other.i64);
default: WASM_UNREACHABLE();
}
}
Literal Literal::divU(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) / uint32_t(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) / uint64_t(other.i64));
+ case Type::i32: return Literal(uint32_t(i32) / uint32_t(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) / uint64_t(other.i64));
default: WASM_UNREACHABLE();
}
}
Literal Literal::remS(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 % other.i32);
- case WasmType::i64: return Literal(i64 % other.i64);
+ case Type::i32: return Literal(i32 % other.i32);
+ case Type::i64: return Literal(i64 % other.i64);
default: WASM_UNREACHABLE();
}
}
Literal Literal::remU(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) % uint32_t(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) % uint64_t(other.i64));
+ case Type::i32: return Literal(uint32_t(i32) % uint32_t(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) % uint64_t(other.i64));
default: WASM_UNREACHABLE();
}
}
Literal Literal::and_(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 & other.i32);
- case WasmType::i64: return Literal(i64 & other.i64);
+ case Type::i32: return Literal(i32 & other.i32);
+ case Type::i64: return Literal(i64 & other.i64);
default: WASM_UNREACHABLE();
}
}
Literal Literal::or_(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 | other.i32);
- case WasmType::i64: return Literal(i64 | other.i64);
+ case Type::i32: return Literal(i32 | other.i32);
+ case Type::i64: return Literal(i64 | other.i64);
default: WASM_UNREACHABLE();
}
}
Literal Literal::xor_(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 ^ other.i32);
- case WasmType::i64: return Literal(i64 ^ other.i64);
+ case Type::i32: return Literal(i32 ^ other.i32);
+ case Type::i64: return Literal(i64 ^ other.i64);
default: WASM_UNREACHABLE();
}
}
Literal Literal::shl(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) << shiftMask(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) << shiftMask(other.i64));
+ case Type::i32: return Literal(uint32_t(i32) << shiftMask(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) << shiftMask(other.i64));
default: WASM_UNREACHABLE();
}
}
Literal Literal::shrS(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 >> shiftMask(other.i32));
- case WasmType::i64: return Literal(i64 >> shiftMask(other.i64));
+ case Type::i32: return Literal(i32 >> shiftMask(other.i32));
+ case Type::i64: return Literal(i64 >> shiftMask(other.i64));
default: WASM_UNREACHABLE();
}
}
Literal Literal::shrU(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) >> shiftMask(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) >> shiftMask(other.i64));
+ case Type::i32: return Literal(uint32_t(i32) >> shiftMask(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) >> shiftMask(other.i64));
default: WASM_UNREACHABLE();
}
}
Literal Literal::rotL(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(RotateLeft(uint32_t(i32), uint32_t(other.i32)));
- case WasmType::i64: return Literal(RotateLeft(uint64_t(i64), uint64_t(other.i64)));
+ case Type::i32: return Literal(RotateLeft(uint32_t(i32), uint32_t(other.i32)));
+ case Type::i64: return Literal(RotateLeft(uint64_t(i64), uint64_t(other.i64)));
default: WASM_UNREACHABLE();
}
}
Literal Literal::rotR(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(RotateRight(uint32_t(i32), uint32_t(other.i32)));
- case WasmType::i64: return Literal(RotateRight(uint64_t(i64), uint64_t(other.i64)));
+ case Type::i32: return Literal(RotateRight(uint32_t(i32), uint32_t(other.i32)));
+ case Type::i64: return Literal(RotateRight(uint64_t(i64), uint64_t(other.i64)));
default: WASM_UNREACHABLE();
}
}
Literal Literal::eq(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 == other.i32);
- case WasmType::i64: return Literal(i64 == other.i64);
- case WasmType::f32: return Literal(getf32() == other.getf32());
- case WasmType::f64: return Literal(getf64() == other.getf64());
+ case Type::i32: return Literal(i32 == other.i32);
+ case Type::i64: return Literal(i64 == other.i64);
+ case Type::f32: return Literal(getf32() == other.getf32());
+ case Type::f64: return Literal(getf64() == other.getf64());
default: WASM_UNREACHABLE();
}
}
Literal Literal::ne(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 != other.i32);
- case WasmType::i64: return Literal(i64 != other.i64);
- case WasmType::f32: return Literal(getf32() != other.getf32());
- case WasmType::f64: return Literal(getf64() != other.getf64());
+ case Type::i32: return Literal(i32 != other.i32);
+ case Type::i64: return Literal(i64 != other.i64);
+ case Type::f32: return Literal(getf32() != other.getf32());
+ case Type::f64: return Literal(getf64() != other.getf64());
default: WASM_UNREACHABLE();
}
}
Literal Literal::ltS(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 < other.i32);
- case WasmType::i64: return Literal(i64 < other.i64);
+ case Type::i32: return Literal(i32 < other.i32);
+ case Type::i64: return Literal(i64 < other.i64);
default: WASM_UNREACHABLE();
}
}
Literal Literal::ltU(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) < uint32_t(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) < uint64_t(other.i64));
+ case Type::i32: return Literal(uint32_t(i32) < uint32_t(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) < uint64_t(other.i64));
default: WASM_UNREACHABLE();
}
}
Literal Literal::lt(const Literal& other) const {
switch (type) {
- case WasmType::f32: return Literal(getf32() < other.getf32());
- case WasmType::f64: return Literal(getf64() < other.getf64());
+ case Type::f32: return Literal(getf32() < other.getf32());
+ case Type::f64: return Literal(getf64() < other.getf64());
default: WASM_UNREACHABLE();
}
}
Literal Literal::leS(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 <= other.i32);
- case WasmType::i64: return Literal(i64 <= other.i64);
+ case Type::i32: return Literal(i32 <= other.i32);
+ case Type::i64: return Literal(i64 <= other.i64);
default: WASM_UNREACHABLE();
}
}
Literal Literal::leU(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) <= uint32_t(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) <= uint64_t(other.i64));
+ case Type::i32: return Literal(uint32_t(i32) <= uint32_t(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) <= uint64_t(other.i64));
default: WASM_UNREACHABLE();
}
}
Literal Literal::le(const Literal& other) const {
switch (type) {
- case WasmType::f32: return Literal(getf32() <= other.getf32());
- case WasmType::f64: return Literal(getf64() <= other.getf64());
+ case Type::f32: return Literal(getf32() <= other.getf32());
+ case Type::f64: return Literal(getf64() <= other.getf64());
default: WASM_UNREACHABLE();
}
}
Literal Literal::gtS(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 > other.i32);
- case WasmType::i64: return Literal(i64 > other.i64);
+ case Type::i32: return Literal(i32 > other.i32);
+ case Type::i64: return Literal(i64 > other.i64);
default: WASM_UNREACHABLE();
}
}
Literal Literal::gtU(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) > uint32_t(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) > uint64_t(other.i64));
+ case Type::i32: return Literal(uint32_t(i32) > uint32_t(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) > uint64_t(other.i64));
default: WASM_UNREACHABLE();
}
}
Literal Literal::gt(const Literal& other) const {
switch (type) {
- case WasmType::f32: return Literal(getf32() > other.getf32());
- case WasmType::f64: return Literal(getf64() > other.getf64());
+ case Type::f32: return Literal(getf32() > other.getf32());
+ case Type::f64: return Literal(getf64() > other.getf64());
default: WASM_UNREACHABLE();
}
}
Literal Literal::geS(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(i32 >= other.i32);
- case WasmType::i64: return Literal(i64 >= other.i64);
+ case Type::i32: return Literal(i32 >= other.i32);
+ case Type::i64: return Literal(i64 >= other.i64);
default: WASM_UNREACHABLE();
}
}
Literal Literal::geU(const Literal& other) const {
switch (type) {
- case WasmType::i32: return Literal(uint32_t(i32) >= uint32_t(other.i32));
- case WasmType::i64: return Literal(uint64_t(i64) >= uint64_t(other.i64));
+ case Type::i32: return Literal(uint32_t(i32) >= uint32_t(other.i32));
+ case Type::i64: return Literal(uint64_t(i64) >= uint64_t(other.i64));
default: WASM_UNREACHABLE();
}
}
Literal Literal::ge(const Literal& other) const {
switch (type) {
- case WasmType::f32: return Literal(getf32() >= other.getf32());
- case WasmType::f64: return Literal(getf64() >= other.getf64());
+ case Type::f32: return Literal(getf32() >= other.getf32());
+ case Type::f64: return Literal(getf64() >= other.getf64());
default: WASM_UNREACHABLE();
}
}
Literal Literal::min(const Literal& other) const {
switch (type) {
- case WasmType::f32: {
+ case Type::f32: {
auto l = getf32(), r = other.getf32();
if (l == r && l == 0) return Literal(std::signbit(l) ? l : r);
auto result = std::min(l, r);
@@ -606,7 +606,7 @@ Literal Literal::min(const Literal& other) const {
if (!lnan && !rnan) return Literal((int32_t)0x7fc00000).castToF32();
return Literal(lnan ? l : r).castToI32().or_(Literal(0xc00000)).castToF32();
}
- case WasmType::f64: {
+ case Type::f64: {
auto l = getf64(), r = other.getf64();
if (l == r && l == 0) return Literal(std::signbit(l) ? l : r);
auto result = std::min(l, r);
@@ -621,7 +621,7 @@ Literal Literal::min(const Literal& other) const {
Literal Literal::max(const Literal& other) const {
switch (type) {
- case WasmType::f32: {
+ case Type::f32: {
auto l = getf32(), r = other.getf32();
if (l == r && l == 0) return Literal(std::signbit(l) ? r : l);
auto result = std::max(l, r);
@@ -630,7 +630,7 @@ Literal Literal::max(const Literal& other) const {
if (!lnan && !rnan) return Literal((int32_t)0x7fc00000).castToF32();
return Literal(lnan ? l : r).castToI32().or_(Literal(0xc00000)).castToF32();
}
- case WasmType::f64: {
+ case Type::f64: {
auto l = getf64(), r = other.getf64();
if (l == r && l == 0) return Literal(std::signbit(l) ? r : l);
auto result = std::max(l, r);
@@ -646,8 +646,8 @@ Literal Literal::max(const Literal& other) const {
Literal Literal::copysign(const Literal& other) const {
// operate on bits directly, to avoid signalling bit being set on a float
switch (type) {
- case WasmType::f32: return Literal((i32 & 0x7fffffff) | (other.i32 & 0x80000000)).castToF32(); break;
- case WasmType::f64: return Literal((i64 & 0x7fffffffffffffffUL) | (other.i64 & 0x8000000000000000UL)).castToF64(); break;
+ case Type::f32: return Literal((i32 & 0x7fffffff) | (other.i32 & 0x80000000)).castToF32(); break;
+ case Type::f64: return Literal((i64 & 0x7fffffffffffffffUL) | (other.i64 & 0x8000000000000000UL)).castToF64(); break;
default: WASM_UNREACHABLE();
}
}
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 19f84f98c..188c2bc17 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -145,13 +145,13 @@ void WasmBinaryWriter::writeTypes() {
o << S32LEB(BinaryConsts::EncodedType::Func);
o << U32LEB(type->params.size());
for (auto param : type->params) {
- o << binaryWasmType(param);
+ o << binaryType(param);
}
if (type->result == none) {
o << U32LEB(0);
} else {
o << U32LEB(1);
- o << binaryWasmType(type->result);
+ o << binaryType(type->result);
}
}
finishSection(start);
@@ -188,7 +188,7 @@ void WasmBinaryWriter::writeImports() {
break;
}
case ExternalKind::Global:
- o << binaryWasmType(import->globalType);
+ o << binaryType(import->globalType);
o << U32LEB(0); // Mutable global's can't be imported for now.
break;
default: WASM_UNREACHABLE();
@@ -205,10 +205,10 @@ void WasmBinaryWriter::mapLocals(Function* function) {
for (auto type : function->vars) {
numLocalsByType[type]++;
}
- std::map<WasmType, size_t> currLocalsByType;
+ std::map<Type, size_t> currLocalsByType;
for (Index i = function->getVarIndexBase(); i < function->getNumLocals(); i++) {
size_t index = function->getVarIndexBase();
- WasmType type = function->getLocalType(i);
+ Type type = function->getLocalType(i);
currLocalsByType[type]++; // increment now for simplicity, must decrement it in returns
if (type == i32) {
mappedLocals[i] = index + currLocalsByType[i32] - 1;
@@ -273,10 +273,10 @@ void WasmBinaryWriter::writeFunctions() {
(numLocalsByType[f32] ? 1 : 0) +
(numLocalsByType[f64] ? 1 : 0)
);
- if (numLocalsByType[i32]) o << U32LEB(numLocalsByType[i32]) << binaryWasmType(i32);
- if (numLocalsByType[i64]) o << U32LEB(numLocalsByType[i64]) << binaryWasmType(i64);
- if (numLocalsByType[f32]) o << U32LEB(numLocalsByType[f32]) << binaryWasmType(f32);
- if (numLocalsByType[f64]) o << U32LEB(numLocalsByType[f64]) << binaryWasmType(f64);
+ if (numLocalsByType[i32]) o << U32LEB(numLocalsByType[i32]) << binaryType(i32);
+ if (numLocalsByType[i64]) o << U32LEB(numLocalsByType[i64]) << binaryType(i64);
+ if (numLocalsByType[f32]) o << U32LEB(numLocalsByType[f32]) << binaryType(f32);
+ if (numLocalsByType[f64]) o << U32LEB(numLocalsByType[f64]) << binaryType(f64);
recursePossibleBlockContents(function->body);
o << int8_t(BinaryConsts::End);
@@ -303,7 +303,7 @@ void WasmBinaryWriter::writeGlobals() {
o << U32LEB(wasm->globals.size());
for (auto& curr : wasm->globals) {
if (debug) std::cerr << "write one" << std::endl;
- o << binaryWasmType(curr->type);
+ o << binaryType(curr->type);
o << U32LEB(curr->mutable_);
writeExpression(curr->init);
o << int8_t(BinaryConsts::End);
@@ -628,7 +628,7 @@ static bool brokenTo(Block* block) {
void WasmBinaryWriter::visitBlock(Block *curr) {
if (debug) std::cerr << "zz node: Block" << std::endl;
o << int8_t(BinaryConsts::Block);
- o << binaryWasmType(curr->type != unreachable ? curr->type : none);
+ o << binaryType(curr->type != unreachable ? curr->type : none);
breakStack.push_back(curr->name);
Index i = 0;
for (auto* child : curr->list) {
@@ -678,7 +678,7 @@ void WasmBinaryWriter::visitIf(If *curr) {
}
recurse(curr->condition);
o << int8_t(BinaryConsts::If);
- o << binaryWasmType(curr->type != unreachable ? curr->type : none);
+ o << binaryType(curr->type != unreachable ? curr->type : none);
breakStack.push_back(IMPOSSIBLE_CONTINUE); // the binary format requires this; we have a block if we need one; TODO: optimize
recursePossibleBlockContents(curr->ifTrue); // TODO: emit block contents directly, if possible
breakStack.pop_back();
@@ -701,7 +701,7 @@ void WasmBinaryWriter::visitIf(If *curr) {
void WasmBinaryWriter::visitLoop(Loop *curr) {
if (debug) std::cerr << "zz node: Loop" << std::endl;
o << int8_t(BinaryConsts::Loop);
- o << binaryWasmType(curr->type != unreachable ? curr->type : none);
+ o << binaryType(curr->type != unreachable ? curr->type : none);
breakStack.push_back(curr->name);
recursePossibleBlockContents(curr->body);
breakStack.pop_back();
@@ -1478,7 +1478,7 @@ int64_t WasmBinaryBuilder::getS64LEB() {
return ret.value;
}
-WasmType WasmBinaryBuilder::getWasmType() {
+Type WasmBinaryBuilder::getType() {
int type = getS32LEB();
switch (type) {
// None only used for block signatures. TODO: Separate out?
@@ -1579,7 +1579,7 @@ void WasmBinaryBuilder::readSignatures() {
size_t numParams = getU32LEB();
if (debug) std::cerr << "num params: " << numParams << std::endl;
for (size_t j = 0; j < numParams; j++) {
- curr->params.push_back(getWasmType());
+ curr->params.push_back(getType());
}
auto numResults = getU32LEB();
if (numResults == 0) {
@@ -1588,7 +1588,7 @@ void WasmBinaryBuilder::readSignatures() {
if (numResults != 1) {
throw ParseException("signature must have 1 result");
}
- curr->result = getWasmType();
+ curr->result = getType();
}
curr->name = Name::fromInt(wasm.functionTypes.size());
wasm.addFunctionType(curr);
@@ -1661,7 +1661,7 @@ void WasmBinaryBuilder::readImports() {
break;
}
case ExternalKind::Global: {
- curr->globalType = getWasmType();
+ curr->globalType = getType();
auto globalMutable = getU32LEB();
// TODO: actually use the globalMutable flag. Currently mutable global
// imports is a future feature, to be implemented with thread support.
@@ -1717,7 +1717,7 @@ void WasmBinaryBuilder::readFunctions() {
size_t numLocalTypes = getU32LEB();
for (size_t t = 0; t < numLocalTypes; t++) {
auto num = getU32LEB();
- auto type = getWasmType();
+ auto type = getType();
while (num > 0) {
vars.emplace_back(addVar(), type);
num--;
@@ -1925,7 +1925,7 @@ void WasmBinaryBuilder::readGlobals() {
if (debug) std::cerr << "num: " << num << std::endl;
for (size_t i = 0; i < num; i++) {
if (debug) std::cerr << "read one" << std::endl;
- auto type = getWasmType();
+ auto type = getType();
auto mutable_ = getU32LEB();
if (bool(mutable_) != mutable_) throw ParseException("Global mutability must be 0 or 1");
auto* init = readExpression();
@@ -2302,7 +2302,7 @@ void WasmBinaryBuilder::pushBlockElements(Block* curr, size_t start, size_t end)
curr->list.push_back(item);
if (i < end - 1) {
// stacky&unreachable code may introduce elements that need to be dropped in non-final positions
- if (isConcreteWasmType(item->type)) {
+ if (isConcreteType(item->type)) {
curr->list.back() = Builder(wasm).makeDrop(item);
if (consumable == NONE) {
// this is the first, and hence consumable value. note the location
@@ -2331,7 +2331,7 @@ void WasmBinaryBuilder::visitBlock(Block *curr) {
// a common pattern that can be very highly nested.
std::vector<Block*> stack;
while (1) {
- curr->type = getWasmType();
+ curr->type = getType();
curr->name = getNextLabel();
breakStack.push_back({curr->name, curr->type != none});
stack.push_back(curr);
@@ -2367,7 +2367,7 @@ void WasmBinaryBuilder::visitBlock(Block *curr) {
}
}
-Expression* WasmBinaryBuilder::getBlockOrSingleton(WasmType type) {
+Expression* WasmBinaryBuilder::getBlockOrSingleton(Type type) {
Name label = getNextLabel();
breakStack.push_back({label, type != none && type != unreachable});
auto start = expressionStack.size();
@@ -2394,7 +2394,7 @@ Expression* WasmBinaryBuilder::getBlockOrSingleton(WasmType type) {
void WasmBinaryBuilder::visitIf(If *curr) {
if (debug) std::cerr << "zz node: If" << std::endl;
- curr->type = getWasmType();
+ curr->type = getType();
curr->condition = popNonVoidExpression();
curr->ifTrue = getBlockOrSingleton(curr->type);
if (lastSeparator == BinaryConsts::Else) {
@@ -2408,7 +2408,7 @@ void WasmBinaryBuilder::visitIf(If *curr) {
void WasmBinaryBuilder::visitLoop(Loop *curr) {
if (debug) std::cerr << "zz node: Loop" << std::endl;
- curr->type = getWasmType();
+ curr->type = getType();
curr->name = getNextLabel();
breakStack.push_back({curr->name, 0});
// find the expressions in the block, and create the body
@@ -2759,7 +2759,7 @@ bool WasmBinaryBuilder::maybeVisitAtomicWait(Expression*& out, uint8_t code) {
curr->ptr = popNonVoidExpression();
Address readAlign;
readMemoryAccess(readAlign, curr->offset);
- if (readAlign != getWasmTypeSize(curr->expectedType)) throw ParseException("Align of AtomicWait must match size");
+ if (readAlign != getTypeSize(curr->expectedType)) throw ParseException("Align of AtomicWait must match size");
curr->finalize();
out = curr;
return true;
@@ -2775,7 +2775,7 @@ bool WasmBinaryBuilder::maybeVisitAtomicWake(Expression*& out, uint8_t code) {
curr->ptr = popNonVoidExpression();
Address readAlign;
readMemoryAccess(readAlign, curr->offset);
- if (readAlign != getWasmTypeSize(curr->type)) throw ParseException("Align of AtomicWake must match size");
+ if (readAlign != getTypeSize(curr->type)) throw ParseException("Align of AtomicWake must match size");
curr->finalize();
out = curr;
return true;
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 0de3edf3f..5033047b0 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -377,13 +377,13 @@ void SExpressionWasmBuilder::preParseFunctionType(Element& s) {
functionCounter++;
FunctionType* type = nullptr;
functionTypes[name] = none;
- std::vector<WasmType> params;
+ std::vector<Type> params;
for (;i < s.size(); i++) {
Element& curr = *s[i];
IString id = curr[0]->str();
if (id == RESULT) {
if (curr.size() > 2) throw ParseException("invalid result arity", curr.line, curr.col);
- functionTypes[name] = stringToWasmType(curr[1]->str());
+ functionTypes[name] = stringToType(curr[1]->str());
} else if (id == TYPE) {
Name typeName = getFunctionTypeName(*curr[1]);
if (!wasm.getFunctionTypeOrNull(typeName)) throw ParseException("unknown function type", curr.line, curr.col);
@@ -393,10 +393,10 @@ void SExpressionWasmBuilder::preParseFunctionType(Element& s) {
Index j = 1;
if (curr[j]->dollared()) {
// dollared input symbols cannot be types
- params.push_back(stringToWasmType(curr[j + 1]->str(), true));
+ params.push_back(stringToType(curr[j + 1]->str(), true));
} else {
while (j < curr.size()) {
- params.push_back(stringToWasmType(curr[j++]->str(), true));
+ params.push_back(stringToType(curr[j++]->str(), true));
}
}
}
@@ -485,7 +485,7 @@ void SExpressionWasmBuilder::parseFunction(Element& s, bool preParseImport) {
std::vector<NameType> typeParams; // we may have both params and a type. store the type info here
std::vector<NameType> params;
std::vector<NameType> vars;
- WasmType result = none;
+ Type result = none;
Name type;
Block* autoBlock = nullptr; // we may need to add a block for the very top level
Name importModule, importBase;
@@ -511,16 +511,16 @@ void SExpressionWasmBuilder::parseFunction(Element& s, bool preParseImport) {
size_t j = 1;
while (j < curr.size()) {
IString name;
- WasmType type = none;
+ Type type = none;
if (!curr[j]->dollared()) { // dollared input symbols cannot be types
- type = stringToWasmType(curr[j]->str(), true);
+ type = stringToType(curr[j]->str(), true);
}
if (type != none) {
// a type, so an unnamed parameter
name = Name::fromInt(localIndex);
} else {
name = curr[j]->str();
- type = stringToWasmType(curr[j+1]->str());
+ type = stringToType(curr[j+1]->str());
j++;
}
j++;
@@ -534,7 +534,7 @@ void SExpressionWasmBuilder::parseFunction(Element& s, bool preParseImport) {
}
} else if (id == RESULT) {
if (curr.size() > 2) throw ParseException("invalid result arity", curr.line, curr.col);
- result = stringToWasmType(curr[1]->str());
+ result = stringToType(curr[1]->str());
} else if (id == TYPE) {
Name name = getFunctionTypeName(*curr[1]);
type = name;
@@ -543,7 +543,7 @@ void SExpressionWasmBuilder::parseFunction(Element& s, bool preParseImport) {
result = type->result;
for (size_t j = 0; j < type->params.size(); j++) {
IString name = Name::fromInt(j);
- WasmType currType = type->params[j];
+ Type currType = type->params[j];
typeParams.emplace_back(name, currType);
currLocalTypes[name] = currType;
}
@@ -614,7 +614,7 @@ void SExpressionWasmBuilder::parseFunction(Element& s, bool preParseImport) {
nameMapper.clear();
}
-WasmType SExpressionWasmBuilder::stringToWasmType(const char* str, bool allowError, bool prefix) {
+Type SExpressionWasmBuilder::stringToType(const char* str, bool allowError, bool prefix) {
if (str[0] == 'i') {
if (str[1] == '3' && str[2] == '2' && (prefix || str[3] == 0)) return i32;
if (str[1] == '6' && str[2] == '4' && (prefix || str[3] == 0)) return i64;
@@ -650,7 +650,7 @@ Expression* SExpressionWasmBuilder::makeExpression(Element& s) {
const char *dot = strchr(str, '.');
if (dot) {
// type.operation (e.g. i32.add)
- WasmType type = stringToWasmType(str, false, true);
+ Type type = stringToType(str, false, true);
// Local copy to index into op without bounds checking.
enum { maxNameSize = 15 };
char op[maxNameSize + 1] = {'\0'};
@@ -760,7 +760,7 @@ Expression* SExpressionWasmBuilder::makeExpression(Element& s) {
case 'r': {
if (op[1] == 'e') {
if (op[2] == 'm') return makeBinary(s, op[4] == 'u' ? BINARY_INT(RemU) : BINARY_INT(RemS), type);
- if (op[2] == 'i') return makeUnary(s, isWasmTypeFloat(type) ? (type == f32 ? UnaryOp::ReinterpretInt32 : UnaryOp::ReinterpretInt64) : (type == i32 ? UnaryOp::ReinterpretFloat32 : UnaryOp::ReinterpretFloat64), type);
+ if (op[2] == 'i') return makeUnary(s, isTypeFloat(type) ? (type == f32 ? UnaryOp::ReinterpretInt32 : UnaryOp::ReinterpretInt64) : (type == i32 ? UnaryOp::ReinterpretFloat32 : UnaryOp::ReinterpretFloat64), type);
}
if (op[1] == 'o' && op[2] == 't') {
return makeBinary(s, op[3] == 'l' ? BINARY_INT(RotL) : BINARY_INT(RotR), type);
@@ -882,7 +882,7 @@ Expression* SExpressionWasmBuilder::makeExpression(Element& s) {
abort_on("unrecognized input string for parsing");
}
-Expression* SExpressionWasmBuilder::makeBinary(Element& s, BinaryOp op, WasmType type) {
+Expression* SExpressionWasmBuilder::makeBinary(Element& s, BinaryOp op, Type type) {
auto ret = allocator.alloc<Binary>();
ret->op = op;
ret->left = parseExpression(s[1]);
@@ -892,7 +892,7 @@ Expression* SExpressionWasmBuilder::makeBinary(Element& s, BinaryOp op, WasmType
}
-Expression* SExpressionWasmBuilder::makeUnary(Element& s, UnaryOp op, WasmType type) {
+Expression* SExpressionWasmBuilder::makeUnary(Element& s, UnaryOp op, Type type) {
auto ret = allocator.alloc<Unary>();
ret->op = op;
ret->value = parseExpression(s[1]);
@@ -922,7 +922,7 @@ Expression* SExpressionWasmBuilder::makeUnary(Element& s, UnaryOp op, WasmType t
case ClzInt64:
case CtzInt64:
case PopcntInt64: {
- if (ret->value->type != unreachable && type != ret->value->type) throw ParseException(std::string("bad type for ") + getExpressionName(ret) + ": " + printWasmType(type) + " vs value type " + printWasmType(ret->value->type), s.line, s.col);
+ if (ret->value->type != unreachable && type != ret->value->type) throw ParseException(std::string("bad type for ") + getExpressionName(ret) + ": " + printType(type) + " vs value type " + printType(ret->value->type), s.line, s.col);
break;
}
case ExtendSInt32: case ExtendUInt32:
@@ -1069,7 +1069,7 @@ Expression* SExpressionWasmBuilder::makeBlock(Element& s) {
Name sName;
if (i < s.size() && s[i]->isStr()) {
// could be a name or a type
- if (s[i]->dollared() || stringToWasmType(s[i]->str(), true /* allowError */) == none) {
+ if (s[i]->dollared() || stringToType(s[i]->str(), true /* allowError */) == none) {
sName = s[i++]->str();
} else {
sName = "block";
@@ -1132,7 +1132,7 @@ Expression* SExpressionWasmBuilder::makeThenOrElse(Element& s) {
return ret;
}
-Expression* SExpressionWasmBuilder::makeConst(Element& s, WasmType type) {
+Expression* SExpressionWasmBuilder::makeConst(Element& s, Type type) {
auto ret = parseConst(s[1]->str(), type, allocator);
if (!ret) throw ParseException("bad const");
return ret;
@@ -1180,13 +1180,13 @@ static size_t parseMemAttributes(Element& s, Address* offset, Address* align, Ad
return i;
}
-Expression* SExpressionWasmBuilder::makeLoad(Element& s, WasmType type, bool isAtomic) {
+Expression* SExpressionWasmBuilder::makeLoad(Element& s, Type type, bool isAtomic) {
const char *extra = strchr(s[0]->c_str(), '.') + 5; // after "type.load"
if (isAtomic) extra += 7; // after "type.atomic.load"
auto* ret = allocator.alloc<Load>();
ret->isAtomic = isAtomic;
ret->type = type;
- ret->bytes = parseMemBytes(&extra, getWasmTypeSize(type));
+ ret->bytes = parseMemBytes(&extra, getTypeSize(type));
ret->signed_ = extra[0] && extra[1] == 's';
size_t i = parseMemAttributes(s, &ret->offset, &ret->align, ret->bytes);
ret->ptr = parseExpression(s[i]);
@@ -1194,13 +1194,13 @@ Expression* SExpressionWasmBuilder::makeLoad(Element& s, WasmType type, bool isA
return ret;
}
-Expression* SExpressionWasmBuilder::makeStore(Element& s, WasmType type, bool isAtomic) {
+Expression* SExpressionWasmBuilder::makeStore(Element& s, Type type, bool isAtomic) {
const char *extra = strchr(s[0]->c_str(), '.') + 6; // after "type.store"
if (isAtomic) extra += 7; // after "type.atomic.store"
auto ret = allocator.alloc<Store>();
ret->isAtomic = isAtomic;
ret->valueType = type;
- ret->bytes = parseMemBytes(&extra, getWasmTypeSize(type));
+ ret->bytes = parseMemBytes(&extra, getTypeSize(type));
size_t i = parseMemAttributes(s, &ret->offset, &ret->align, ret->bytes);
ret->ptr = parseExpression(s[i]);
@@ -1209,9 +1209,9 @@ Expression* SExpressionWasmBuilder::makeStore(Element& s, WasmType type, bool is
return ret;
}
-Expression* SExpressionWasmBuilder::makeAtomicRMWOrCmpxchg(Element& s, WasmType type) {
+Expression* SExpressionWasmBuilder::makeAtomicRMWOrCmpxchg(Element& s, Type type) {
const char* extra = strchr(s[0]->c_str(), '.') + 11; // afer "type.atomic.rmw"
- auto bytes = parseMemBytes(&extra, getWasmTypeSize(type));
+ auto bytes = parseMemBytes(&extra, getTypeSize(type));
extra = strchr(extra, '.'); // after the optional '_u' and before the opcode
if (!extra) throw ParseException("malformed atomic rmw instruction");
extra++; // after the '.'
@@ -1219,7 +1219,7 @@ Expression* SExpressionWasmBuilder::makeAtomicRMWOrCmpxchg(Element& s, WasmType
return makeAtomicRMW(s, type, bytes, extra);
}
-Expression* SExpressionWasmBuilder::makeAtomicRMW(Element& s, WasmType type, uint8_t bytes, const char* extra) {
+Expression* SExpressionWasmBuilder::makeAtomicRMW(Element& s, Type type, uint8_t bytes, const char* extra) {
auto ret = allocator.alloc<AtomicRMW>();
ret->type = type;
ret->bytes = bytes;
@@ -1239,7 +1239,7 @@ Expression* SExpressionWasmBuilder::makeAtomicRMW(Element& s, WasmType type, uin
return ret;
}
-Expression* SExpressionWasmBuilder::makeAtomicCmpxchg(Element& s, WasmType type, uint8_t bytes, const char* extra) {
+Expression* SExpressionWasmBuilder::makeAtomicCmpxchg(Element& s, Type type, uint8_t bytes, const char* extra) {
auto ret = allocator.alloc<AtomicCmpxchg>();
ret->type = type;
ret->bytes = bytes;
@@ -1253,7 +1253,7 @@ Expression* SExpressionWasmBuilder::makeAtomicCmpxchg(Element& s, WasmType type,
return ret;
}
-Expression* SExpressionWasmBuilder::makeAtomicWait(Element& s, WasmType type) {
+Expression* SExpressionWasmBuilder::makeAtomicWait(Element& s, Type type) {
auto ret = allocator.alloc<AtomicWait>();
ret->type = i32;
ret->expectedType = type;
@@ -1285,7 +1285,7 @@ Expression* SExpressionWasmBuilder::makeIf(Element& s) {
}
auto label = nameMapper.pushLabelName(sName);
// if signature
- WasmType type = parseOptionalResultType(s, i);
+ Type type = parseOptionalResultType(s, i);
ret->condition = parseExpression(s[i++]);
ret->ifTrue = parseExpression(*s[i++]);
if (i < s.size()) {
@@ -1305,7 +1305,7 @@ Expression* SExpressionWasmBuilder::makeIf(Element& s) {
}
-Expression* SExpressionWasmBuilder::makeMaybeBlock(Element& s, size_t i, WasmType type) {
+Expression* SExpressionWasmBuilder::makeMaybeBlock(Element& s, size_t i, Type type) {
Index stopAt = -1;
if (s.size() == i) return allocator.alloc<Nop>();
if (s.size() == i+1) return parseExpression(s[i]);
@@ -1320,14 +1320,14 @@ Expression* SExpressionWasmBuilder::makeMaybeBlock(Element& s, size_t i, WasmTyp
return ret;
}
-WasmType SExpressionWasmBuilder::parseOptionalResultType(Element& s, Index& i) {
+Type SExpressionWasmBuilder::parseOptionalResultType(Element& s, Index& i) {
if (s.size() == i)
return none;
// TODO(sbc): Remove support for old result syntax (bare streing) once the
// spec tests are updated.
if (s[i]->isStr())
- return stringToWasmType(s[i++]->str());
+ return stringToType(s[i++]->str());
Element& params = *s[i];
IString id = params[0]->str();
@@ -1335,7 +1335,7 @@ WasmType SExpressionWasmBuilder::parseOptionalResultType(Element& s, Index& i) {
return none;
i++;
- return stringToWasmType(params[1]->str());
+ return stringToType(params[1]->str());
}
Expression* SExpressionWasmBuilder::makeLoop(Element& s) {
@@ -1725,10 +1725,10 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
IString id = params[0]->str();
if (id == PARAM) {
for (size_t k = 1; k < params.size(); k++) {
- type->params.push_back(stringToWasmType(params[k]->str()));
+ type->params.push_back(stringToType(params[k]->str()));
}
} else if (id == RESULT) {
- type->result = stringToWasmType(params[1]->str());
+ type->result = stringToType(params[1]->str());
} else if (id == TYPE) {
IString name = params[1]->str();
if (!wasm.getFunctionTypeOrNull(name)) throw ParseException("bad function type for import");
@@ -1739,17 +1739,17 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
if (inner.size() > j+1) {
Element& result = *inner[j+1];
if (result[0]->str() != RESULT) throw ParseException("expected result");
- type->result = stringToWasmType(result[1]->str());
+ type->result = stringToType(result[1]->str());
}
}
im->functionType = ensureFunctionType(getSig(type.get()), &wasm)->name;
} else if (im->kind == ExternalKind::Global) {
if (inner[j]->isStr()) {
- im->globalType = stringToWasmType(inner[j]->str());
+ im->globalType = stringToType(inner[j]->str());
} else {
auto& inner2 = *inner[j];
if (inner2[0]->str() != MUT) throw ParseException("expected mut");
- im->globalType = stringToWasmType(inner2[1]->str());
+ im->globalType = stringToType(inner2[1]->str());
throw ParseException("cannot import a mutable global", s.line, s.col);
}
} else if (im->kind == ExternalKind::Table) {
@@ -1779,7 +1779,7 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) {
std::unique_ptr<Global> global = make_unique<Global>();
size_t i = 1;
- if (s[i]->dollared() && !(s[i]->isStr() && isWasmType(s[i]->str()))) {
+ if (s[i]->dollared() && !(s[i]->isStr() && isType(s[i]->str()))) {
global->name = s[i++]->str();
} else {
global->name = Name::fromInt(globalCounter);
@@ -1787,7 +1787,7 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) {
globalCounter++;
globalNames.push_back(global->name);
bool mutable_ = false;
- WasmType type = none;
+ Type type = none;
bool exported = false;
Name importModule, importBase;
while (i < s.size() && s[i]->isList()) {
@@ -1807,7 +1807,7 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) {
i++;
} else if (inner[0]->str() == MUT) {
mutable_ = true;
- type = stringToWasmType(inner[1]->str());
+ type = stringToType(inner[1]->str());
i++;
} else {
break;
@@ -1815,7 +1815,7 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) {
}
if (exported && mutable_) throw ParseException("cannot export a mutable global", s.line, s.col);
if (type == none) {
- type = stringToWasmType(s[i++]->str());
+ type = stringToType(s[i++]->str());
}
if (importModule.is()) {
// this is an import, actually
@@ -1949,11 +1949,11 @@ void SExpressionWasmBuilder::parseType(Element& s) {
Element& curr = *func[k];
if (curr[0]->str() == PARAM) {
for (size_t j = 1; j < curr.size(); j++) {
- type->params.push_back(stringToWasmType(curr[j]->str()));
+ type->params.push_back(stringToType(curr[j]->str()));
}
} else if (curr[0]->str() == RESULT) {
if (curr.size() > 2) throw ParseException("invalid result arity", curr.line, curr.col);
- type->result = stringToWasmType(curr[1]->str());
+ type->result = stringToType(curr[1]->str());
}
}
if (!type->name.is()) {
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index 1e48ce525..4b159b6e2 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -21,30 +21,30 @@
namespace wasm {
-const char* printWasmType(WasmType type) {
+const char* printType(Type type) {
switch (type) {
- case WasmType::none: return "none";
- case WasmType::i32: return "i32";
- case WasmType::i64: return "i64";
- case WasmType::f32: return "f32";
- case WasmType::f64: return "f64";
- case WasmType::unreachable: return "unreachable";
+ case Type::none: return "none";
+ case Type::i32: return "i32";
+ case Type::i64: return "i64";
+ case Type::f32: return "f32";
+ case Type::f64: return "f64";
+ case Type::unreachable: return "unreachable";
default: WASM_UNREACHABLE();
}
}
-unsigned getWasmTypeSize(WasmType type) {
+unsigned getTypeSize(Type type) {
switch (type) {
- case WasmType::none: abort();
- case WasmType::i32: return 4;
- case WasmType::i64: return 8;
- case WasmType::f32: return 4;
- case WasmType::f64: return 8;
+ case Type::none: abort();
+ case Type::i32: return 4;
+ case Type::i64: return 8;
+ case Type::f32: return 4;
+ case Type::f64: return 8;
default: WASM_UNREACHABLE();
}
}
-bool isWasmTypeFloat(WasmType type) {
+bool isTypeFloat(Type type) {
switch (type) {
case f32:
case f64: return true;
@@ -52,18 +52,18 @@ bool isWasmTypeFloat(WasmType type) {
}
}
-WasmType getWasmType(unsigned size, bool float_) {
- if (size < 4) return WasmType::i32;
- if (size == 4) return float_ ? WasmType::f32 : WasmType::i32;
- if (size == 8) return float_ ? WasmType::f64 : WasmType::i64;
+Type getType(unsigned size, bool float_) {
+ if (size < 4) return Type::i32;
+ if (size == 4) return float_ ? Type::f32 : Type::i32;
+ if (size == 8) return float_ ? Type::f64 : Type::i64;
abort();
}
-WasmType getReachableWasmType(WasmType a, WasmType b) {
+Type getReachableType(Type a, Type b) {
return a != unreachable ? a : b;
}
-bool isConcreteWasmType(WasmType type) {
+bool isConcreteType(Type type) {
return type != none && type != unreachable;
}
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 26b8c66b6..84dd43b20 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -153,7 +153,7 @@ struct ValidationInfo {
return true;
}
- void shouldBeIntOrUnreachable(WasmType ty, Expression* curr, const char* text, Function* func = nullptr) {
+ void shouldBeIntOrUnreachable(Type ty, Expression* curr, const char* text, Function* func = nullptr) {
switch (ty) {
case i32:
case i64:
@@ -176,16 +176,16 @@ struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> {
FunctionValidator(ValidationInfo* info) : info(*info) {}
struct BreakInfo {
- WasmType type;
+ Type type;
Index arity;
BreakInfo() {}
- BreakInfo(WasmType type, Index arity) : type(type), arity(arity) {}
+ BreakInfo(Type type, Index arity) : type(type), arity(arity) {}
};
std::map<Name, Expression*> breakTargets;
std::map<Expression*, BreakInfo> breakInfos;
- WasmType returnType = unreachable; // type used in returns
+ Type returnType = unreachable; // type used in returns
std::set<Name> labelNames; // Binaryen IR requires that label names must be unique - IR generators must ensure that
@@ -274,13 +274,13 @@ private:
return info.shouldBeUnequal(left, right, curr, text, getFunction());
}
- void shouldBeIntOrUnreachable(WasmType ty, Expression* curr, const char* text) {
+ void shouldBeIntOrUnreachable(Type ty, Expression* curr, const char* text) {
return info.shouldBeIntOrUnreachable(ty, curr, text, getFunction());
}
- void validateAlignment(size_t align, WasmType type, Index bytes, bool isAtomic,
+ void validateAlignment(size_t align, Type type, Index bytes, bool isAtomic,
Expression* curr);
- void validateMemBytes(uint8_t bytes, WasmType type, Expression* curr);
+ void validateMemBytes(uint8_t bytes, Type type, Expression* curr);
};
void FunctionValidator::noteLabelName(Name name) {
@@ -295,22 +295,22 @@ void FunctionValidator::visitBlock(Block *curr) {
noteLabelName(curr->name);
if (breakInfos.count(curr) > 0) {
auto& info = breakInfos[curr];
- if (isConcreteWasmType(curr->type)) {
+ if (isConcreteType(curr->type)) {
shouldBeTrue(info.arity != 0, curr, "break arities must be > 0 if block has a value");
} else {
shouldBeTrue(info.arity == 0, curr, "break arities must be 0 if block has no value");
}
// none or unreachable means a poison value that we should ignore - if consumed, it will error
- if (isConcreteWasmType(info.type) && isConcreteWasmType(curr->type)) {
+ if (isConcreteType(info.type) && isConcreteType(curr->type)) {
shouldBeEqual(curr->type, info.type, curr, "block+breaks must have right type if breaks return a value");
}
- if (isConcreteWasmType(curr->type) && info.arity && info.type != unreachable) {
+ if (isConcreteType(curr->type) && info.arity && info.type != unreachable) {
shouldBeEqual(curr->type, info.type, curr, "block+breaks must have right type if breaks have arity");
}
shouldBeTrue(info.arity != Index(-1), curr, "break arities must match");
if (curr->list.size() > 0) {
auto last = curr->list.back()->type;
- if (isConcreteWasmType(last) && info.type != unreachable) {
+ if (isConcreteType(last) && info.type != unreachable) {
shouldBeEqual(last, info.type, curr, "block+breaks must have right type if block ends with a reachable value");
}
if (last == none) {
@@ -322,24 +322,24 @@ void FunctionValidator::visitBlock(Block *curr) {
}
if (curr->list.size() > 1) {
for (Index i = 0; i < curr->list.size() - 1; i++) {
- if (!shouldBeTrue(!isConcreteWasmType(curr->list[i]->type), curr, "non-final block elements returning a value must be drop()ed (binaryen's autodrop option might help you)") && !info.quiet) {
+ if (!shouldBeTrue(!isConcreteType(curr->list[i]->type), curr, "non-final block elements returning a value must be drop()ed (binaryen's autodrop option might help you)") && !info.quiet) {
getStream() << "(on index " << i << ":\n" << curr->list[i] << "\n), type: " << curr->list[i]->type << "\n";
}
}
}
if (curr->list.size() > 0) {
auto backType = curr->list.back()->type;
- if (!isConcreteWasmType(curr->type)) {
- shouldBeFalse(isConcreteWasmType(backType), curr, "if block is not returning a value, final element should not flow out a value");
+ if (!isConcreteType(curr->type)) {
+ shouldBeFalse(isConcreteType(backType), curr, "if block is not returning a value, final element should not flow out a value");
} else {
- if (isConcreteWasmType(backType)) {
+ if (isConcreteType(backType)) {
shouldBeEqual(curr->type, backType, curr, "block with value and last element with value must match types");
} else {
shouldBeUnequal(backType, none, curr, "block with value must not have last element that is none");
}
}
}
- if (isConcreteWasmType(curr->type)) {
+ if (isConcreteType(curr->type)) {
shouldBeTrue(curr->list.size() > 0, curr, "block with a value must not be empty");
}
}
@@ -354,14 +354,14 @@ void FunctionValidator::visitLoop(Loop *curr) {
}
}
if (curr->type == none) {
- shouldBeFalse(isConcreteWasmType(curr->body->type), curr, "bad body for a loop that has no value");
+ shouldBeFalse(isConcreteType(curr->body->type), curr, "bad body for a loop that has no value");
}
}
void FunctionValidator::visitIf(If *curr) {
shouldBeTrue(curr->condition->type == unreachable || curr->condition->type == i32, curr, "if condition must be valid");
if (!curr->ifFalse) {
- shouldBeFalse(isConcreteWasmType(curr->ifTrue->type), curr, "if without else must not return a value in body");
+ shouldBeFalse(isConcreteType(curr->ifTrue->type), curr, "if without else must not return a value in body");
if (curr->condition->type != unreachable) {
shouldBeEqual(curr->type, none, curr, "if without else and reachable condition must be none");
}
@@ -375,11 +375,11 @@ void FunctionValidator::visitIf(If *curr) {
shouldBeEqual(curr->ifFalse->type, unreachable, curr, "unreachable if-else must have unreachable false");
}
}
- if (isConcreteWasmType(curr->ifTrue->type)) {
+ if (isConcreteType(curr->ifTrue->type)) {
shouldBeEqual(curr->type, curr->ifTrue->type, curr, "if type must match concrete ifTrue");
shouldBeEqualOrFirstIsUnreachable(curr->ifFalse->type, curr->ifTrue->type, curr, "other arm must match concrete ifTrue");
}
- if (isConcreteWasmType(curr->ifFalse->type)) {
+ if (isConcreteType(curr->ifFalse->type)) {
shouldBeEqual(curr->type, curr->ifFalse->type, curr, "if type must match concrete ifFalse");
shouldBeEqualOrFirstIsUnreachable(curr->ifTrue->type, curr->ifFalse->type, curr, "other arm must match concrete ifFalse");
}
@@ -387,7 +387,7 @@ void FunctionValidator::visitIf(If *curr) {
}
void FunctionValidator::noteBreak(Name name, Expression* value, Expression* curr) {
- WasmType valueType = none;
+ Type valueType = none;
Index arity = 0;
if (value) {
valueType = value->type;
@@ -473,7 +473,7 @@ void FunctionValidator::visitCallIndirect(CallIndirect *curr) {
void FunctionValidator::visitGetLocal(GetLocal* curr) {
shouldBeTrue(curr->index < getFunction()->getNumLocals(), curr, "get_local index must be small enough");
- shouldBeTrue(isConcreteWasmType(curr->type), curr, "get_local must have a valid type - check what you provided when you constructed the node");
+ shouldBeTrue(isConcreteType(curr->type), curr, "get_local must have a valid type - check what you provided when you constructed the node");
}
void FunctionValidator::visitSetLocal(SetLocal *curr) {
@@ -558,7 +558,7 @@ void FunctionValidator::visitAtomicWake(AtomicWake* curr) {
shouldBeEqualOrFirstIsUnreachable(curr->wakeCount->type, i32, curr, "AtomicWake wakeCount type must be i32");
}
-void FunctionValidator::validateMemBytes(uint8_t bytes, WasmType type, Expression* curr) {
+void FunctionValidator::validateMemBytes(uint8_t bytes, Type type, Expression* curr) {
switch (bytes) {
case 1:
case 2:
@@ -567,7 +567,7 @@ void FunctionValidator::validateMemBytes(uint8_t bytes, WasmType type, Expressio
// if we have a concrete type for the load, then we know the size of the mem operation and
// can validate it
if (type != unreachable) {
- shouldBeEqual(getWasmTypeSize(type), 8U, curr, "8-byte mem operations are only allowed with 8-byte wasm types");
+ shouldBeEqual(getTypeSize(type), 8U, curr, "8-byte mem operations are only allowed with 8-byte wasm types");
}
break;
}
@@ -764,7 +764,7 @@ void FunctionValidator::visitSelect(Select* curr) {
}
void FunctionValidator::visitDrop(Drop* curr) {
- shouldBeTrue(isConcreteWasmType(curr->value->type) || curr->value->type == unreachable, curr, "can only drop a valid value");
+ shouldBeTrue(isConcreteType(curr->value->type) || curr->value->type == unreachable, curr, "can only drop a valid value");
}
void FunctionValidator::visitReturn(Return* curr) {
@@ -840,7 +840,7 @@ static bool checkOffset(Expression* curr, Address add, Address max) {
return offset + add <= max;
}
-void FunctionValidator::validateAlignment(size_t align, WasmType type, Index bytes,
+void FunctionValidator::validateAlignment(size_t align, Type type, Index bytes,
bool isAtomic, Expression* curr) {
if (isAtomic) {
shouldBeEqual(align, (size_t)bytes, curr, "atomic accesses must have natural alignment");
@@ -891,9 +891,9 @@ static void validateBinaryenIR(Module& wasm, ValidationInfo& info) {
//
// The block has an added type, not derived from the ast itself, so it is
// ok for it to be either i32 or unreachable.
- if (!(isConcreteWasmType(oldType) && newType == unreachable)) {
+ if (!(isConcreteType(oldType) && newType == unreachable)) {
std::ostringstream ss;
- ss << "stale type found in " << (getFunction() ? getFunction()->name : Name("(global scope)")) << " on " << curr << "\n(marked as " << printWasmType(oldType) << ", should be " << printWasmType(newType) << ")\n";
+ ss << "stale type found in " << (getFunction() ? getFunction()->name : Name("(global scope)")) << " on " << curr << "\n(marked as " << printType(oldType) << ", should be " << printType(newType) << ")\n";
info.fail(ss.str(), curr, getFunction());
}
curr->type = oldType;
@@ -912,7 +912,7 @@ static void validateImports(Module& module, ValidationInfo& info) {
if (info.validateWeb) {
auto* functionType = module.getFunctionType(curr->functionType);
info.shouldBeUnequal(functionType->result, i64, curr->name, "Imported function must not have i64 return type");
- for (WasmType param : functionType->params) {
+ for (Type param : functionType->params) {
info.shouldBeUnequal(param, i64, curr->name, "Imported function must not have i64 parameters");
}
}
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 32a633926..cf847d5aa 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -107,7 +107,7 @@ const char* getExpressionName(Expression* curr) {
struct TypeSeeker : public PostWalker<TypeSeeker> {
Expression* target; // look for this one
Name targetName;
- std::vector<WasmType> types;
+ std::vector<Type> types;
TypeSeeker(Expression* target, Name targetName) : target(target), targetName(targetName) {
@@ -149,8 +149,8 @@ struct TypeSeeker : public PostWalker<TypeSeeker> {
}
};
-static WasmType mergeTypes(std::vector<WasmType>& types) {
- WasmType type = unreachable;
+static Type mergeTypes(std::vector<Type>& types) {
+ Type type = unreachable;
for (auto other : types) {
// once none, stop. it then indicates a poison value, that must not be consumed
// and ignore unreachable
@@ -177,7 +177,7 @@ static void handleUnreachable(Block* block) {
// if we are concrete, stop - even an unreachable child
// won't change that (since we have a break with a value,
// or the final child flows out a value)
- if (isConcreteWasmType(block->type)) return;
+ if (isConcreteType(block->type)) return;
// look for an unreachable child
for (auto* child : block->list) {
if (child->type == unreachable) {
@@ -190,7 +190,7 @@ static void handleUnreachable(Block* block) {
}
}
-void Block::finalize(WasmType type_) {
+void Block::finalize(Type type_) {
type = type_;
if (type == none && list.size() > 0) {
handleUnreachable(this);
@@ -209,7 +209,7 @@ void Block::finalize() {
// (return)
// (i32.const 10)
// )
- if (isConcreteWasmType(type)) return;
+ if (isConcreteType(type)) return;
// if we are unreachable, we are done
if (type == unreachable) return;
// we may still be unreachable if we have an unreachable
@@ -231,7 +231,7 @@ void Block::finalize() {
handleUnreachable(this);
}
-void If::finalize(WasmType type_) {
+void If::finalize(Type type_) {
type = type_;
if (type == none && (condition->type == unreachable || (ifFalse && ifTrue->type == unreachable && ifFalse->type == unreachable))) {
type = unreachable;
@@ -242,9 +242,9 @@ void If::finalize() {
if (ifFalse) {
if (ifTrue->type == ifFalse->type) {
type = ifTrue->type;
- } else if (isConcreteWasmType(ifTrue->type) && ifFalse->type == unreachable) {
+ } else if (isConcreteType(ifTrue->type) && ifFalse->type == unreachable) {
type = ifTrue->type;
- } else if (isConcreteWasmType(ifFalse->type) && ifTrue->type == unreachable) {
+ } else if (isConcreteType(ifFalse->type) && ifTrue->type == unreachable) {
type = ifFalse->type;
} else {
type = none;
@@ -265,7 +265,7 @@ void If::finalize() {
}
}
-void Loop::finalize(WasmType type_) {
+void Loop::finalize(Type type_) {
type = type_;
if (type == none && body->type == unreachable) {
type = unreachable;
@@ -613,7 +613,7 @@ Index Function::getVarIndexBase() {
return params.size();
}
-WasmType Function::getLocalType(Index index) {
+Type Function::getLocalType(Index index) {
if (isParam(index)) {
return params[index];
} else if (isVar(index)) {
diff --git a/src/wasm2asm.h b/src/wasm2asm.h
index 05896aacd..6a355c15c 100644
--- a/src/wasm2asm.h
+++ b/src/wasm2asm.h
@@ -135,14 +135,14 @@ public:
Ref processAsserts(Element& e, SExpressionWasmBuilder& sexpBuilder);
// Get a temp var.
- IString getTemp(WasmType type, Function* func) {
+ IString getTemp(Type type, Function* func) {
IString ret;
if (frees[type].size() > 0) {
ret = frees[type].back();
frees[type].pop_back();
} else {
size_t index = temps[type]++;
- ret = IString((std::string("wasm2asm_") + printWasmType(type) + "$" +
+ ret = IString((std::string("wasm2asm_") + printType(type) + "$" +
std::to_string(index)).c_str(), false);
}
if (func->localIndices.find(ret) == func->localIndices.end()) {
@@ -152,7 +152,7 @@ public:
}
// Free a temp var.
- void freeTemp(WasmType type, IString temp) {
+ void freeTemp(Type type, IString temp) {
frees[type].push_back(temp);
}
@@ -232,7 +232,7 @@ static Function* makeCtzFunc(MixedArena& allocator, UnaryOp op) {
BinaryOp xorOp = is32Bit ? XorInt32 : XorInt64;
UnaryOp clzOp = is32Bit ? ClzInt32 : ClzInt64;
UnaryOp eqzOp = is32Bit ? EqZInt32 : EqZInt64;
- WasmType argType = is32Bit ? i32 : i64;
+ Type argType = is32Bit ? i32 : i64;
Binary* xorExp = b.makeBinary(
xorOp,
b.makeGetLocal(0, i32),
@@ -275,7 +275,7 @@ static Function* makePopcntFunc(MixedArena& allocator, UnaryOp op) {
BinaryOp subOp = is32Bit ? SubInt32 : SubInt64;
BinaryOp andOp = is32Bit ? AndInt32 : AndInt64;
UnaryOp eqzOp = is32Bit ? EqZInt32 : EqZInt64;
- WasmType argType = is32Bit ? i32 : i64;
+ Type argType = is32Bit ? i32 : i64;
Name loopName("l");
Name blockName("b");
Break* brIf = b.makeBreak(
@@ -338,7 +338,7 @@ Function* makeRotFunc(MixedArena& allocator, BinaryOp op) {
BinaryOp orOp = is32Bit ? OrInt32 : OrInt64;
BinaryOp andOp = is32Bit ? AndInt32 : AndInt64;
BinaryOp subOp = is32Bit ? SubInt32 : SubInt64;
- WasmType argType = is32Bit ? i32 : i64;
+ Type argType = is32Bit ? i32 : i64;
Literal widthMask =
is32Bit ? Literal(int32_t(32 - 1)) : Literal(int64_t(64 - 1));
Literal width =
@@ -723,13 +723,13 @@ Ref Wasm2AsmBuilder::processFunctionBody(Function* func, IString result) {
// A scoped temporary variable.
struct ScopedTemp {
Wasm2AsmBuilder* parent;
- WasmType type;
+ Type type;
IString temp;
bool needFree;
// @param possible if provided, this is a variable we can use as our temp. it has already been
// allocated in a higher scope, and we can just assign to it as our result is
// going there anyhow.
- ScopedTemp(WasmType type, Wasm2AsmBuilder* parent, Function* func,
+ ScopedTemp(Type type, Wasm2AsmBuilder* parent, Function* func,
IString possible = NO_RESULT) : parent(parent), type(type) {
assert(possible != EXPRESSION_RESULT);
if (possible == NO_RESULT) {
@@ -767,7 +767,7 @@ Ref Wasm2AsmBuilder::processFunctionBody(Function* func, IString result) {
}
// this result is for an asm expression slot, but it might be a statement
- Ref visitForExpression(Expression* curr, WasmType type, IString& tempName) {
+ Ref visitForExpression(Expression* curr, Type type, IString& tempName) {
if (isStatement(curr)) {
ScopedTemp temp(type, parent, func);
tempName = temp.temp;
@@ -915,7 +915,7 @@ Ref Wasm2AsmBuilder::processFunctionBody(Function* func, IString result) {
return ret;
}
- Ref makeStatementizedCall(ExpressionList& operands, Ref ret, Ref theCall, IString result, WasmType type) {
+ Ref makeStatementizedCall(ExpressionList& operands, Ref ret, Ref theCall, IString result, Type type) {
std::vector<ScopedTemp*> temps; // TODO: utility class, with destructor?
for (auto& operand : operands) {
temps.push_back(new ScopedTemp(operand->type, parent, func));
@@ -1625,7 +1625,7 @@ Ref Wasm2AsmBuilder::makeAssertReturnFunc(SExpressionWasmBuilder& sexpBuilder,
}
} else if (e.size() == 3) {
Expression* expected = sexpBuilder.parseExpression(e[2]);
- WasmType resType = expected->type;
+ Type resType = expected->type;
actual->type = resType;
BinaryOp eqOp;
switch (resType) {