diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/binaryen-c.cpp | 1 | ||||
-rw-r--r-- | src/binaryen-c.h | 1 | ||||
-rw-r--r-- | src/ir/abstract.h | 4 | ||||
-rw-r--r-- | src/js/binaryen.js-post.js | 7 | ||||
-rw-r--r-- | src/literal.h | 2 | ||||
-rw-r--r-- | src/passes/FuncCastEmulation.cpp | 8 | ||||
-rw-r--r-- | src/passes/InstrumentLocals.cpp | 28 | ||||
-rw-r--r-- | src/wasm-builder.h | 4 | ||||
-rw-r--r-- | src/wasm-interpreter.h | 4 | ||||
-rw-r--r-- | src/wasm-type.h | 8 | ||||
-rw-r--r-- | src/wasm/literal.cpp | 26 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 6 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 26 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 18 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 4 |
15 files changed, 78 insertions, 69 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 93c8693c6..1845d39f3 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -144,6 +144,7 @@ BinaryenType BinaryenTypeExternref(void) { return Type::externref; } BinaryenType BinaryenTypeAnyref(void) { return Type::anyref; } BinaryenType BinaryenTypeEqref(void) { return Type::eqref; } BinaryenType BinaryenTypeI31ref(void) { return Type::i31ref; } +BinaryenType BinaryenTypeDataref(void) { return Type::dataref; } BinaryenType BinaryenTypeUnreachable(void) { return Type::unreachable; } BinaryenType BinaryenTypeAuto(void) { return uintptr_t(-1); } diff --git a/src/binaryen-c.h b/src/binaryen-c.h index 6337fadd8..f2d433fc4 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -103,6 +103,7 @@ BINARYEN_API BinaryenType BinaryenTypeExternref(void); BINARYEN_API BinaryenType BinaryenTypeAnyref(void); BINARYEN_API BinaryenType BinaryenTypeEqref(void); BINARYEN_API BinaryenType BinaryenTypeI31ref(void); +BINARYEN_API BinaryenType BinaryenTypeDataref(void); BINARYEN_API BinaryenType BinaryenTypeUnreachable(void); // Not a real type. Used as the last parameter to BinaryenBlock to let // the API figure out the type instead of providing one. diff --git a/src/ir/abstract.h b/src/ir/abstract.h index 4c8d556cb..e5dfd57e0 100644 --- a/src/ir/abstract.h +++ b/src/ir/abstract.h @@ -117,8 +117,8 @@ inline UnaryOp getUnary(Type type, Op op) { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: { return InvalidUnary; @@ -290,8 +290,8 @@ inline BinaryOp getBinary(Type type, Op op) { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: { return InvalidBinary; diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 1ae7b11b2..8c6730e9e 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -38,6 +38,7 @@ function initializeConstants() { ['anyref', 'Anyref'], ['eqref', 'Eqref'], ['i31ref', 'I31ref'], + ['dataref', 'Dataref'], ['unreachable', 'Unreachable'], ['auto', 'Auto'] ].forEach(entry => { @@ -2090,6 +2091,12 @@ function wrapModule(module, self = {}) { } }; + self['dataref'] = { + 'pop'() { + return Module['_BinaryenPop'](module, Module['dataref']); + } + }; + self['ref'] = { 'null'(type) { return Module['_BinaryenRefNull'](module, type); diff --git a/src/literal.h b/src/literal.h index c85701a48..e49946814 100644 --- a/src/literal.h +++ b/src/literal.h @@ -781,8 +781,8 @@ template<> struct less<wasm::Literal> { case wasm::Type::externref: case wasm::Type::anyref: case wasm::Type::eqref: - case wasm::Type::dataref: case wasm::Type::i31ref: + case wasm::Type::dataref: case wasm::Type::none: case wasm::Type::unreachable: return false; diff --git a/src/passes/FuncCastEmulation.cpp b/src/passes/FuncCastEmulation.cpp index 7f7721706..a9302fb65 100644 --- a/src/passes/FuncCastEmulation.cpp +++ b/src/passes/FuncCastEmulation.cpp @@ -65,8 +65,8 @@ static Expression* toABI(Expression* value, Module* module) { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: - case Type::i31ref: { + case Type::i31ref: + case Type::dataref: { WASM_UNREACHABLE("reference types cannot be converted to i64"); } case Type::none: { @@ -111,8 +111,8 @@ static Expression* fromABI(Expression* value, Type type, Module* module) { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: - case Type::i31ref: { + case Type::i31ref: + case Type::dataref: { WASM_UNREACHABLE("reference types cannot be converted from i64"); } case Type::none: { diff --git a/src/passes/InstrumentLocals.cpp b/src/passes/InstrumentLocals.cpp index cc1234fc5..85da3bd9b 100644 --- a/src/passes/InstrumentLocals.cpp +++ b/src/passes/InstrumentLocals.cpp @@ -55,25 +55,25 @@ Name get_i32("get_i32"); Name get_i64("get_i64"); Name get_f32("get_f32"); Name get_f64("get_f64"); +Name get_v128("get_v128"); Name get_funcref("get_funcref"); Name get_externref("get_externref"); Name get_anyref("get_anyref"); Name get_eqref("get_eqref"); -Name get_dataref("get_dataref"); Name get_i31ref("get_i31ref"); -Name get_v128("get_v128"); +Name get_dataref("get_dataref"); Name set_i32("set_i32"); Name set_i64("set_i64"); Name set_f32("set_f32"); Name set_f64("set_f64"); +Name set_v128("set_v128"); Name set_funcref("set_funcref"); Name set_externref("set_externref"); Name set_anyref("set_anyref"); Name set_eqref("set_eqref"); -Name set_dataref("set_dataref"); Name set_i31ref("set_i31ref"); -Name set_v128("set_v128"); +Name set_dataref("set_dataref"); struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { void visitLocalGet(LocalGet* curr) { @@ -107,12 +107,12 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { case Type::eqref: import = get_eqref; break; - case Type::dataref: - import = get_dataref; - break; case Type::i31ref: import = get_i31ref; break; + case Type::dataref: + import = get_dataref; + break; case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -167,12 +167,12 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { case Type::eqref: import = set_eqref; break; - case Type::dataref: - import = set_dataref; - break; case Type::i31ref: import = set_i31ref; break; + case Type::dataref: + import = set_dataref; + break; case Type::unreachable: return; // nothing to do here default: @@ -221,6 +221,10 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { curr, get_eqref, {Type::i32, Type::i32, Type::eqref}, Type::eqref); addImport( curr, set_eqref, {Type::i32, Type::i32, Type::eqref}, Type::eqref); + addImport( + curr, get_i31ref, {Type::i32, Type::i32, Type::i31ref}, Type::i31ref); + addImport( + curr, set_i31ref, {Type::i32, Type::i32, Type::i31ref}, Type::i31ref); addImport(curr, get_dataref, {Type::i32, Type::i32, Type::dataref}, @@ -229,10 +233,6 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { set_dataref, {Type::i32, Type::i32, Type::dataref}, Type::dataref); - addImport( - curr, get_i31ref, {Type::i32, Type::i32, Type::i31ref}, Type::i31ref); - addImport( - curr, set_i31ref, {Type::i32, Type::i32, Type::i31ref}, Type::i31ref); } } if (curr->features.hasSIMD()) { diff --git a/src/wasm-builder.h b/src/wasm-builder.h index 0bfa317d3..da74f47ef 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -1028,10 +1028,10 @@ public: case Type::anyref: case Type::eqref: return ExpressionManipulator::refNull(curr, curr->type); - case Type::dataref: - WASM_UNREACHABLE("TODO: dataref"); case Type::i31ref: return makeI31New(makeConst(0)); + case Type::dataref: + WASM_UNREACHABLE("TODO: dataref"); case Type::none: return ExpressionManipulator::nop(curr); case Type::unreachable: diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 1336a8d10..44173d395 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -2016,8 +2016,8 @@ public: case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -2075,8 +2075,8 @@ public: case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); diff --git a/src/wasm-type.h b/src/wasm-type.h index 6b3fdb08f..bf3dd69de 100644 --- a/src/wasm-type.h +++ b/src/wasm-type.h @@ -74,10 +74,10 @@ public: externref, anyref, eqref, - dataref, i31ref, + dataref, }; - static constexpr BasicType _last_basic_type = i31ref; + static constexpr BasicType _last_basic_type = dataref; Type() : id(none) {} @@ -295,10 +295,10 @@ public: ext, any, eq, - data, i31, + data, }; - static constexpr BasicHeapType _last_basic_type = i31; + static constexpr BasicHeapType _last_basic_type = data; // BasicHeapType can be implicitly upgraded to HeapType constexpr HeapType(BasicHeapType id) : id(id) {} diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 6d870ec55..dc6d90ef9 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -114,8 +114,8 @@ Literal::Literal(const Literal& other) : type(other.type) { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: WASM_UNREACHABLE("invalid type"); } } @@ -331,8 +331,8 @@ void Literal::getBits(uint8_t (&buf)[16]) const { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: WASM_UNREACHABLE("invalid type"); } } @@ -370,8 +370,8 @@ bool Literal::operator==(const Literal& other) const { case Type::funcref: case Type::externref: case Type::anyref: - case Type::dataref: case Type::eqref: + case Type::dataref: return compareRef(); case Type::unreachable: break; @@ -510,8 +510,8 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { case HeapType::i31: o << "i31ref(" << literal.geti31() << ")"; break; - case HeapType::data: case HeapType::func: + case HeapType::data: WASM_UNREACHABLE("type should have been handled above"); } } @@ -547,8 +547,8 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); } @@ -771,8 +771,8 @@ Literal Literal::eqz() const { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -795,8 +795,8 @@ Literal Literal::neg() const { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -819,8 +819,8 @@ Literal Literal::abs() const { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -960,8 +960,8 @@ Literal Literal::add(const Literal& other) const { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -984,8 +984,8 @@ Literal Literal::sub(const Literal& other) const { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -1079,8 +1079,8 @@ Literal Literal::mul(const Literal& other) const { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -1315,8 +1315,8 @@ Literal Literal::eq(const Literal& other) const { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -1339,8 +1339,8 @@ Literal Literal::ne(const Literal& other) const { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 5a78bfc42..cc289e7ec 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1413,12 +1413,12 @@ Type WasmBinaryBuilder::getType(int initial) { case BinaryConsts::EncodedType::nonnullable: // FIXME: for now, force all inputs to be nullable return Type(getHeapType(), Nullable); - case BinaryConsts::EncodedType::dataref: - // FIXME: for now, force all inputs to be nullable - return Type(HeapType::BasicHeapType::data, Nullable); case BinaryConsts::EncodedType::i31ref: // FIXME: for now, force all inputs to be nullable return Type(HeapType::BasicHeapType::i31, Nullable); + case BinaryConsts::EncodedType::dataref: + // FIXME: for now, force all inputs to be nullable + return Type(HeapType::BasicHeapType::data, Nullable); case BinaryConsts::EncodedType::rtt_n: { auto depth = getU32LEB(); auto heapType = getHeapType(); diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index d34698131..857c0143b 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -864,14 +864,14 @@ Type SExpressionWasmBuilder::stringToType(const char* str, if (strncmp(str, "eqref", 5) == 0 && (prefix || str[5] == 0)) { return Type::eqref; } - if (strncmp(str, "dataref", 7) == 0 && (prefix || str[7] == 0)) { - // FIXME: for now, force all inputs to be nullable - return Type(HeapType::BasicHeapType::data, Nullable); - } if (strncmp(str, "i31ref", 6) == 0 && (prefix || str[6] == 0)) { // FIXME: for now, force all inputs to be nullable return Type(HeapType::BasicHeapType::i31, Nullable); } + if (strncmp(str, "dataref", 7) == 0 && (prefix || str[7] == 0)) { + // FIXME: for now, force all inputs to be nullable + return Type(HeapType::BasicHeapType::data, Nullable); + } if (allowError) { return Type::none; } @@ -880,9 +880,10 @@ Type SExpressionWasmBuilder::stringToType(const char* str, HeapType SExpressionWasmBuilder::stringToHeapType(const char* str, bool prefix) { - if (str[0] == 'a') { - if (str[1] == 'n' && str[2] == 'y' && (prefix || str[3] == 0)) { - return HeapType::any; + if (str[0] == 'f') { + if (str[1] == 'u' && str[2] == 'n' && str[3] == 'c' && + (prefix || str[4] == 0)) { + return HeapType::func; } } if (str[0] == 'e') { @@ -894,17 +895,16 @@ HeapType SExpressionWasmBuilder::stringToHeapType(const char* str, return HeapType::ext; } } + if (str[0] == 'a') { + if (str[1] == 'n' && str[2] == 'y' && (prefix || str[3] == 0)) { + return HeapType::any; + } + } if (str[0] == 'i') { if (str[1] == '3' && str[2] == '1' && (prefix || str[3] == 0)) { return HeapType::i31; } } - if (str[0] == 'f') { - if (str[1] == 'u' && str[2] == 'n' && str[3] == 'c' && - (prefix || str[4] == 0)) { - return HeapType::func; - } - } if (str[0] == 'd') { if (str[1] == 'a' && str[2] == 't' && str[3] == 'a' && (prefix || str[4] == 0)) { diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index fc8f84f6f..b433c050c 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -306,8 +306,8 @@ struct TypeStore : Store<TypeInfo> { return Type::anyref; case HeapType::eq: return Type::eqref; - case HeapType::data: case HeapType::i31: + case HeapType::data: break; } } else { @@ -443,8 +443,8 @@ unsigned Type::getByteSize() const { case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: break; @@ -491,8 +491,8 @@ FeatureSet Type::getFeatures() const { switch (heapType.getBasic()) { case HeapType::BasicHeapType::any: case HeapType::BasicHeapType::eq: - case HeapType::BasicHeapType::data: case HeapType::BasicHeapType::i31: + case HeapType::BasicHeapType::data: return FeatureSet::ReferenceTypes | FeatureSet::GC; default: {} } @@ -544,10 +544,10 @@ HeapType Type::getHeapType() const { return HeapType::any; case Type::eqref: return HeapType::eq; - case Type::dataref: - return HeapType::data; case Type::i31ref: return HeapType::i31; + case Type::dataref: + return HeapType::data; } WASM_UNREACHABLE("Unexpected type"); } else { @@ -882,10 +882,10 @@ std::ostream& operator<<(std::ostream& os, Type type) { return os << "anyref"; case Type::eqref: return os << "eqref"; - case Type::dataref: - return os << "dataref"; case Type::i31ref: return os << "i31ref"; + case Type::dataref: + return os << "dataref"; } } return os << *getTypeInfo(type); @@ -974,10 +974,10 @@ std::ostream& operator<<(std::ostream& os, HeapType heapType) { return os << "any"; case HeapType::eq: return os << "eq"; - case HeapType::data: - return os << "data"; case HeapType::i31: return os << "i31"; + case HeapType::data: + return os << "data"; } } return os << *getHeapTypeInfo(heapType); diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index e4a70a347..7cddf5a86 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -1396,8 +1396,8 @@ void FunctionValidator::validateMemBytes(uint8_t bytes, case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: WASM_UNREACHABLE("unexpected type"); } @@ -2514,8 +2514,8 @@ void FunctionValidator::validateAlignment( case Type::externref: case Type::anyref: case Type::eqref: - case Type::dataref: case Type::i31ref: + case Type::dataref: case Type::none: WASM_UNREACHABLE("invalid type"); } |