Skip to content

Commit 14a2869

Browse files
authored
Add except_ref type (#2081)
This adds except_ref type, which is a part of the exception handling proposal.
1 parent da716eb commit 14a2869

33 files changed

Lines changed: 157 additions & 9 deletions

build-js.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export_function "_BinaryenTypeInt64"
180180
export_function "_BinaryenTypeFloat32"
181181
export_function "_BinaryenTypeFloat64"
182182
export_function "_BinaryenTypeVec128"
183+
export_function "_BinaryenTypeExceptRef"
183184
export_function "_BinaryenTypeUnreachable"
184185
export_function "_BinaryenTypeAuto"
185186

src/asmjs/asm_v_wasm.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ AsmType wasmToAsmType(Type type) {
5353
return ASM_INT64;
5454
case v128:
5555
assert(false && "v128 not implemented yet");
56+
case except_ref:
57+
assert(false && "except_ref is not in asm2wasm");
5658
case none:
5759
return ASM_NONE;
5860
case unreachable:
@@ -73,6 +75,8 @@ char getSig(Type type) {
7375
return 'd';
7476
case v128:
7577
return 'V';
78+
case except_ref:
79+
return 'e';
7680
case none:
7781
return 'v';
7882
case unreachable:
@@ -111,6 +115,8 @@ Type sigToType(char sig) {
111115
return f64;
112116
case 'V':
113117
return v128;
118+
case 'e':
119+
return except_ref;
114120
case 'v':
115121
return none;
116122
default:

src/binaryen-c.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ BinaryenLiteral toBinaryenLiteral(Literal x) {
6666
memcpy(&ret.v128, x.getv128Ptr(), 16);
6767
break;
6868
}
69+
70+
case Type::except_ref: // there's no except_ref literals
6971
case Type::none:
7072
case Type::unreachable:
7173
WASM_UNREACHABLE();
@@ -85,6 +87,7 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) {
8587
return Literal(x.i64).castToF64();
8688
case Type::v128:
8789
return Literal(x.v128);
90+
case Type::except_ref: // there's no except_ref literals
8891
case Type::none:
8992
case Type::unreachable:
9093
WASM_UNREACHABLE();
@@ -203,6 +206,7 @@ void printArg(std::ostream& setup, std::ostream& out, BinaryenLiteral arg) {
203206
out << "BinaryenLiteralVec128(" << array << ")";
204207
break;
205208
}
209+
case Type::except_ref: // there's no except_ref literals
206210
case Type::none:
207211
case Type::unreachable:
208212
WASM_UNREACHABLE();
@@ -257,6 +261,7 @@ BinaryenType BinaryenTypeInt64(void) { return i64; }
257261
BinaryenType BinaryenTypeFloat32(void) { return f32; }
258262
BinaryenType BinaryenTypeFloat64(void) { return f64; }
259263
BinaryenType BinaryenTypeVec128(void) { return v128; }
264+
BinaryenType BinaryenTypeExceptRef(void) { return except_ref; }
260265
BinaryenType BinaryenTypeUnreachable(void) { return unreachable; }
261266
BinaryenType BinaryenTypeAuto(void) { return uint32_t(-1); }
262267

src/binaryen-c.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ BinaryenType BinaryenTypeInt64(void);
7474
BinaryenType BinaryenTypeFloat32(void);
7575
BinaryenType BinaryenTypeFloat64(void);
7676
BinaryenType BinaryenTypeVec128(void);
77+
BinaryenType BinaryenTypeExceptRef(void);
7778
BinaryenType BinaryenTypeUnreachable(void);
7879
// Not a real type. Used as the last parameter to BinaryenBlock to let
7980
// the API figure out the type instead of providing one.

src/ir/abstract.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ inline UnaryOp getUnary(Type type, Op op) {
8181
assert(false && "v128 not implemented yet");
8282
WASM_UNREACHABLE();
8383
}
84+
case except_ref: // there's no unary instructions for except_ref
8485
case none:
8586
case unreachable: {
8687
return InvalidUnary;
@@ -211,6 +212,7 @@ inline BinaryOp getBinary(Type type, Op op) {
211212
assert(false && "v128 not implemented yet");
212213
WASM_UNREACHABLE();
213214
}
215+
case except_ref: // there's no binary instructions for except_ref
214216
case none:
215217
case unreachable: {
216218
return InvalidBinary;

src/js/binaryen.js-post.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Module['i64'] = Module['_BinaryenTypeInt64']();
3737
Module['f32'] = Module['_BinaryenTypeFloat32']();
3838
Module['f64'] = Module['_BinaryenTypeFloat64']();
3939
Module['v128'] = Module['_BinaryenTypeVec128']();
40+
Module['except_ref'] = Module['_BinaryenTypeExceptRef']();
4041
Module['unreachable'] = Module['_BinaryenTypeUnreachable']();
4142
Module['auto'] = /* deprecated */ Module['undefined'] = Module['_BinaryenTypeAuto']();
4243

src/literal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Literal {
8080
Literal(int32_t(0)),
8181
Literal(int32_t(0)),
8282
Literal(int32_t(0))}});
83+
case Type::except_ref: // there's no except_ref literals
8384
case none:
8485
case unreachable:
8586
WASM_UNREACHABLE();
@@ -429,6 +430,7 @@ template<> struct less<wasm::Literal> {
429430
return a.reinterpreti64() < b.reinterpreti64();
430431
case wasm::Type::v128:
431432
return memcmp(a.getv128Ptr(), b.getv128Ptr(), 16) < 0;
433+
case wasm::Type::except_ref: // except_ref is an opaque value
432434
case wasm::Type::none:
433435
case wasm::Type::unreachable:
434436
return false;

src/parsing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) {
263263
break;
264264
}
265265
case v128:
266+
case except_ref: // there's no except_ref.const
266267
WASM_UNREACHABLE();
267268
case none:
268269
case unreachable: {

src/passes/ConstHoisting.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ struct ConstHoisting : public WalkerPass<PostWalker<ConstHoisting>> {
9595
// v128 not implemented yet
9696
return false;
9797
}
98+
case except_ref: {
99+
// except_ref cannot have literals
100+
return false;
101+
}
98102
case none:
99103
case unreachable: {
100104
WASM_UNREACHABLE();

src/passes/FuncCastEmulation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ static Expression* toABI(Expression* value, Module* module) {
6666
assert(false && "v128 not implemented yet");
6767
WASM_UNREACHABLE();
6868
}
69+
case except_ref: {
70+
assert(false && "except_ref cannot be converted to i64");
71+
WASM_UNREACHABLE();
72+
}
6973
case none: {
7074
// the value is none, but we need a value here
7175
value = builder.makeSequence(value, LiteralUtils::makeZero(i64, *module));
@@ -104,6 +108,10 @@ static Expression* fromABI(Expression* value, Type type, Module* module) {
104108
assert(false && "v128 not implemented yet");
105109
WASM_UNREACHABLE();
106110
}
111+
case except_ref: {
112+
assert(false && "except_ref cannot be converted from i64");
113+
WASM_UNREACHABLE();
114+
}
107115
case none: {
108116
value = builder.makeDrop(value);
109117
}

0 commit comments

Comments
 (0)