Skip to content

Commit

Permalink
Add except_ref type (#2081)
Browse files Browse the repository at this point in the history
This adds except_ref type, which is a part of the exception handling
proposal.
  • Loading branch information
aheejin committed May 8, 2019
1 parent da716eb commit 14a2869
Show file tree
Hide file tree
Showing 33 changed files with 157 additions and 9 deletions.
1 change: 1 addition & 0 deletions build-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export_function "_BinaryenTypeInt64"
export_function "_BinaryenTypeFloat32"
export_function "_BinaryenTypeFloat64"
export_function "_BinaryenTypeVec128"
export_function "_BinaryenTypeExceptRef"
export_function "_BinaryenTypeUnreachable"
export_function "_BinaryenTypeAuto"

Expand Down
6 changes: 6 additions & 0 deletions src/asmjs/asm_v_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ AsmType wasmToAsmType(Type type) {
return ASM_INT64;
case v128:
assert(false && "v128 not implemented yet");
case except_ref:
assert(false && "except_ref is not in asm2wasm");
case none:
return ASM_NONE;
case unreachable:
Expand All @@ -73,6 +75,8 @@ char getSig(Type type) {
return 'd';
case v128:
return 'V';
case except_ref:
return 'e';
case none:
return 'v';
case unreachable:
Expand Down Expand Up @@ -111,6 +115,8 @@ Type sigToType(char sig) {
return f64;
case 'V':
return v128;
case 'e':
return except_ref;
case 'v':
return none;
default:
Expand Down
5 changes: 5 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ BinaryenLiteral toBinaryenLiteral(Literal x) {
memcpy(&ret.v128, x.getv128Ptr(), 16);
break;
}

case Type::except_ref: // there's no except_ref literals
case Type::none:
case Type::unreachable:
WASM_UNREACHABLE();
Expand All @@ -85,6 +87,7 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) {
return Literal(x.i64).castToF64();
case Type::v128:
return Literal(x.v128);
case Type::except_ref: // there's no except_ref literals
case Type::none:
case Type::unreachable:
WASM_UNREACHABLE();
Expand Down Expand Up @@ -203,6 +206,7 @@ void printArg(std::ostream& setup, std::ostream& out, BinaryenLiteral arg) {
out << "BinaryenLiteralVec128(" << array << ")";
break;
}
case Type::except_ref: // there's no except_ref literals
case Type::none:
case Type::unreachable:
WASM_UNREACHABLE();
Expand Down Expand Up @@ -257,6 +261,7 @@ BinaryenType BinaryenTypeInt64(void) { return i64; }
BinaryenType BinaryenTypeFloat32(void) { return f32; }
BinaryenType BinaryenTypeFloat64(void) { return f64; }
BinaryenType BinaryenTypeVec128(void) { return v128; }
BinaryenType BinaryenTypeExceptRef(void) { return except_ref; }
BinaryenType BinaryenTypeUnreachable(void) { return unreachable; }
BinaryenType BinaryenTypeAuto(void) { return uint32_t(-1); }

Expand Down
1 change: 1 addition & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ BinaryenType BinaryenTypeInt64(void);
BinaryenType BinaryenTypeFloat32(void);
BinaryenType BinaryenTypeFloat64(void);
BinaryenType BinaryenTypeVec128(void);
BinaryenType BinaryenTypeExceptRef(void);
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.
Expand Down
2 changes: 2 additions & 0 deletions src/ir/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ inline UnaryOp getUnary(Type type, Op op) {
assert(false && "v128 not implemented yet");
WASM_UNREACHABLE();
}
case except_ref: // there's no unary instructions for except_ref
case none:
case unreachable: {
return InvalidUnary;
Expand Down Expand Up @@ -211,6 +212,7 @@ inline BinaryOp getBinary(Type type, Op op) {
assert(false && "v128 not implemented yet");
WASM_UNREACHABLE();
}
case except_ref: // there's no binary instructions for except_ref
case none:
case unreachable: {
return InvalidBinary;
Expand Down
1 change: 1 addition & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Module['i64'] = Module['_BinaryenTypeInt64']();
Module['f32'] = Module['_BinaryenTypeFloat32']();
Module['f64'] = Module['_BinaryenTypeFloat64']();
Module['v128'] = Module['_BinaryenTypeVec128']();
Module['except_ref'] = Module['_BinaryenTypeExceptRef']();
Module['unreachable'] = Module['_BinaryenTypeUnreachable']();
Module['auto'] = /* deprecated */ Module['undefined'] = Module['_BinaryenTypeAuto']();

Expand Down
2 changes: 2 additions & 0 deletions src/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Literal {
Literal(int32_t(0)),
Literal(int32_t(0)),
Literal(int32_t(0))}});
case Type::except_ref: // there's no except_ref literals
case none:
case unreachable:
WASM_UNREACHABLE();
Expand Down Expand Up @@ -429,6 +430,7 @@ template<> struct less<wasm::Literal> {
return a.reinterpreti64() < b.reinterpreti64();
case wasm::Type::v128:
return memcmp(a.getv128Ptr(), b.getv128Ptr(), 16) < 0;
case wasm::Type::except_ref: // except_ref is an opaque value
case wasm::Type::none:
case wasm::Type::unreachable:
return false;
Expand Down
1 change: 1 addition & 0 deletions src/parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) {
break;
}
case v128:
case except_ref: // there's no except_ref.const
WASM_UNREACHABLE();
case none:
case unreachable: {
Expand Down
4 changes: 4 additions & 0 deletions src/passes/ConstHoisting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ struct ConstHoisting : public WalkerPass<PostWalker<ConstHoisting>> {
// v128 not implemented yet
return false;
}
case except_ref: {
// except_ref cannot have literals
return false;
}
case none:
case unreachable: {
WASM_UNREACHABLE();
Expand Down
8 changes: 8 additions & 0 deletions src/passes/FuncCastEmulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ static Expression* toABI(Expression* value, Module* module) {
assert(false && "v128 not implemented yet");
WASM_UNREACHABLE();
}
case except_ref: {
assert(false && "except_ref cannot be converted to i64");
WASM_UNREACHABLE();
}
case none: {
// the value is none, but we need a value here
value = builder.makeSequence(value, LiteralUtils::makeZero(i64, *module));
Expand Down Expand Up @@ -104,6 +108,10 @@ static Expression* fromABI(Expression* value, Type type, Module* module) {
assert(false && "v128 not implemented yet");
WASM_UNREACHABLE();
}
case except_ref: {
assert(false && "except_ref cannot be converted from i64");
WASM_UNREACHABLE();
}
case none: {
value = builder.makeDrop(value);
}
Expand Down
4 changes: 4 additions & 0 deletions src/passes/InstrumentLocals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
break;
case v128:
assert(false && "v128 not implemented yet");
case except_ref:
assert(false && "not implemented yet");
case none:
WASM_UNREACHABLE();
case unreachable:
Expand Down Expand Up @@ -111,6 +113,8 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
break;
case v128:
assert(false && "v128 not implemented yet");
case except_ref:
assert(false && "except_ref not implemented yet");
case unreachable:
return; // nothing to do here
case none:
Expand Down
2 changes: 2 additions & 0 deletions src/shell-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
break;
case v128:
assert(false && "v128 not implemented yet");
case except_ref:
assert(false && "except_ref not implemented yet");
case none:
case unreachable:
WASM_UNREACHABLE();
Expand Down
36 changes: 34 additions & 2 deletions src/tools/fuzzing.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ high chance for set at start of loop
high chance of a tee in that case => loop var
*/

// TODO Complete except_ref type support. Its support is partialy implemented
// and the type is currently not generated in fuzzed programs yet.

#include "ir/memory-utils.h"
#include <ir/find_all.h>
#include <ir/literal-utils.h>
Expand Down Expand Up @@ -815,6 +818,7 @@ class TranslateToFuzzReader {
case f32:
case f64:
case v128:
case except_ref:
ret = _makeConcrete(type);
break;
case none:
Expand Down Expand Up @@ -1326,6 +1330,7 @@ class TranslateToFuzzReader {
return builder.makeLoad(
16, false, offset, pick(1, 2, 4, 8, 16), ptr, type);
}
case except_ref: // except_ref cannot be loaded from memory
case none:
case unreachable:
WASM_UNREACHABLE();
Expand All @@ -1334,7 +1339,8 @@ class TranslateToFuzzReader {
}

Expression* makeLoad(Type type) {
if (!allowMemory) {
// except_ref type cannot be stored in memory
if (!allowMemory || type == except_ref) {
return makeTrivial(type);
}
auto* ret = makeNonAtomicLoad(type);
Expand Down Expand Up @@ -1425,6 +1431,7 @@ class TranslateToFuzzReader {
return builder.makeStore(
16, offset, pick(1, 2, 4, 8, 16), ptr, value, type);
}
case except_ref: // except_ref cannot be stored in memory
case none:
case unreachable:
WASM_UNREACHABLE();
Expand All @@ -1433,7 +1440,8 @@ class TranslateToFuzzReader {
}

Expression* makeStore(Type type) {
if (!allowMemory) {
// except_ref type cannot be stored in memory
if (!allowMemory || type == except_ref) {
return makeTrivial(type);
}
auto* ret = makeNonAtomicStore(type);
Expand Down Expand Up @@ -1518,6 +1526,7 @@ class TranslateToFuzzReader {
case f64:
return Literal(getDouble());
case v128:
case except_ref: // except_ref cannot have literals
case none:
case unreachable:
WASM_UNREACHABLE();
Expand Down Expand Up @@ -1559,6 +1568,7 @@ class TranslateToFuzzReader {
case f64:
return Literal(double(small));
case v128:
case except_ref: // except_ref cannot have literals
case none:
case unreachable:
WASM_UNREACHABLE();
Expand Down Expand Up @@ -1623,6 +1633,7 @@ class TranslateToFuzzReader {
std::numeric_limits<uint64_t>::max()));
break;
case v128:
case except_ref: // except_ref cannot have literals
case none:
case unreachable:
WASM_UNREACHABLE();
Expand Down Expand Up @@ -1653,6 +1664,7 @@ class TranslateToFuzzReader {
value = Literal(double(int64_t(1) << upTo(64)));
break;
case v128:
case except_ref: // except_ref cannot have literals
case none:
case unreachable:
WASM_UNREACHABLE();
Expand All @@ -1676,6 +1688,12 @@ class TranslateToFuzzReader {
}

Expression* makeConst(Type type) {
if (type == except_ref) {
// There's no except_ref.const.
// TODO We should return a nullref once we implement instructions for
// reference types proposal.
assert(false && "except_ref const is not implemented yet");
}
auto* ret = wasm.allocator.alloc<Const>();
ret->value = makeLiteral(type);
ret->type = type;
Expand All @@ -1694,6 +1712,11 @@ class TranslateToFuzzReader {
// give up
return makeTrivial(type);
}
// There's no binary ops for except_ref
if (type == except_ref) {
makeTrivial(type);
}

switch (type) {
case i32: {
switch (getConcreteType()) {
Expand Down Expand Up @@ -1739,6 +1762,7 @@ class TranslateToFuzzReader {
AllTrueVecI64x2),
make(v128)});
}
case except_ref: // there's no unary ops for except_ref
case none:
case unreachable:
WASM_UNREACHABLE();
Expand Down Expand Up @@ -1869,6 +1893,7 @@ class TranslateToFuzzReader {
}
WASM_UNREACHABLE();
}
case except_ref: // there's no unary ops for except_ref
case none:
case unreachable:
WASM_UNREACHABLE();
Expand All @@ -1889,6 +1914,11 @@ class TranslateToFuzzReader {
// give up
return makeTrivial(type);
}
// There's no binary ops for except_ref
if (type == except_ref) {
makeTrivial(type);
}

switch (type) {
case i32: {
switch (upTo(4)) {
Expand Down Expand Up @@ -2076,6 +2106,7 @@ class TranslateToFuzzReader {
make(v128),
make(v128)});
}
case except_ref: // there's no binary ops for except_ref
case none:
case unreachable:
WASM_UNREACHABLE();
Expand Down Expand Up @@ -2269,6 +2300,7 @@ class TranslateToFuzzReader {
op = ExtractLaneVecF64x2;
break;
case v128:
case except_ref:
case none:
case unreachable:
WASM_UNREACHABLE();
Expand Down
1 change: 1 addition & 0 deletions src/tools/spec-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static std::string generateSpecWrapper(Module& wasm) {
case v128:
ret += "(v128.const i32x4 0 0 0 0)";
break;
case except_ref: // there's no except_ref.const
case none:
case unreachable:
WASM_UNREACHABLE();
Expand Down
15 changes: 10 additions & 5 deletions src/tools/wasm-reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ struct Reducer
fixed = builder->makeUnary(TruncSFloat64ToInt32, child);
break;
case v128:
continue; // v128 not implemented yet
case except_ref:
continue; // not implemented yet
case none:
case unreachable:
WASM_UNREACHABLE();
Expand All @@ -613,7 +614,8 @@ struct Reducer
fixed = builder->makeUnary(TruncSFloat64ToInt64, child);
break;
case v128:
continue; // v128 not implemented yet
case except_ref:
continue; // not implemented yet
case none:
case unreachable:
WASM_UNREACHABLE();
Expand All @@ -634,7 +636,8 @@ struct Reducer
fixed = builder->makeUnary(DemoteFloat64, child);
break;
case v128:
continue; // v128 not implemented yet
case except_ref:
continue; // not implemented yet
case none:
case unreachable:
WASM_UNREACHABLE();
Expand All @@ -655,15 +658,17 @@ struct Reducer
case f64:
WASM_UNREACHABLE();
case v128:
continue; // v128 not implemented yet
case except_ref:
continue; // not implemented yet
case none:
case unreachable:
WASM_UNREACHABLE();
}
break;
}
case v128:
continue; // v128 not implemented yet
case except_ref:
continue; // not implemented yet
case none:
case unreachable:
WASM_UNREACHABLE();
Expand Down
Loading

0 comments on commit 14a2869

Please sign in to comment.