summaryrefslogtreecommitdiff
path: root/src/binaryen-c.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/binaryen-c.cpp')
-rw-r--r--src/binaryen-c.cpp101
1 files changed, 89 insertions, 12 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index 82cbc4c1f..826193e06 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -64,13 +64,16 @@ BinaryenLiteral toBinaryenLiteral(Literal x) {
case Type::f64:
ret.i64 = x.reinterpreti64();
break;
- case Type::v128: {
+ case Type::v128:
memcpy(&ret.v128, x.getv128Ptr(), 16);
break;
- }
-
- case Type::anyref: // there's no anyref literals
- case Type::exnref: // there's no exnref literals
+ case Type::funcref:
+ ret.func = x.getFunc().c_str();
+ break;
+ case Type::nullref:
+ break;
+ case Type::anyref:
+ case Type::exnref:
case Type::none:
case Type::unreachable:
WASM_UNREACHABLE("unexpected type");
@@ -90,8 +93,12 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) {
return Literal(x.i64).castToF64();
case Type::v128:
return Literal(x.v128);
- case Type::anyref: // there's no anyref literals
- case Type::exnref: // there's no exnref literals
+ case Type::funcref:
+ return Literal::makeFuncref(x.func);
+ case Type::nullref:
+ return Literal::makeNullref();
+ case Type::anyref:
+ case Type::exnref:
case Type::none:
case Type::unreachable:
WASM_UNREACHABLE("unexpected type");
@@ -209,8 +216,14 @@ void printArg(std::ostream& setup, std::ostream& out, BinaryenLiteral arg) {
out << "BinaryenLiteralVec128(" << array << ")";
break;
}
- case Type::anyref: // there's no anyref literals
- case Type::exnref: // there's no exnref literals
+ case Type::funcref:
+ out << "BinaryenLiteralFuncref(" << arg.func << ")";
+ break;
+ case Type::nullref:
+ out << "BinaryenLiteralNullref()";
+ break;
+ case Type::anyref:
+ case Type::exnref:
case Type::none:
case Type::unreachable:
WASM_UNREACHABLE("unexpected type");
@@ -265,7 +278,9 @@ BinaryenType BinaryenTypeInt64(void) { return i64; }
BinaryenType BinaryenTypeFloat32(void) { return f32; }
BinaryenType BinaryenTypeFloat64(void) { return f64; }
BinaryenType BinaryenTypeVec128(void) { return v128; }
+BinaryenType BinaryenTypeFuncref(void) { return funcref; }
BinaryenType BinaryenTypeAnyref(void) { return anyref; }
+BinaryenType BinaryenTypeNullref(void) { return nullref; }
BinaryenType BinaryenTypeExnref(void) { return exnref; }
BinaryenType BinaryenTypeUnreachable(void) { return unreachable; }
BinaryenType BinaryenTypeAuto(void) { return uint32_t(-1); }
@@ -397,6 +412,15 @@ BinaryenExpressionId BinaryenMemoryCopyId(void) {
BinaryenExpressionId BinaryenMemoryFillId(void) {
return Expression::Id::MemoryFillId;
}
+BinaryenExpressionId BinaryenRefNullId(void) {
+ return Expression::Id::RefNullId;
+}
+BinaryenExpressionId BinaryenRefIsNullId(void) {
+ return Expression::Id::RefIsNullId;
+}
+BinaryenExpressionId BinaryenRefFuncId(void) {
+ return Expression::Id::RefFuncId;
+}
BinaryenExpressionId BinaryenTryId(void) { return Expression::Id::TryId; }
BinaryenExpressionId BinaryenThrowId(void) { return Expression::Id::ThrowId; }
BinaryenExpressionId BinaryenRethrowId(void) {
@@ -1330,17 +1354,22 @@ BinaryenExpressionRef BinaryenBinary(BinaryenModuleRef module,
BinaryenExpressionRef BinaryenSelect(BinaryenModuleRef module,
BinaryenExpressionRef condition,
BinaryenExpressionRef ifTrue,
- BinaryenExpressionRef ifFalse) {
+ BinaryenExpressionRef ifFalse,
+ BinaryenType type) {
auto* ret = ((Module*)module)->allocator.alloc<Select>();
if (tracing) {
- traceExpression(ret, "BinaryenSelect", condition, ifTrue, ifFalse);
+ traceExpression(ret, "BinaryenSelect", condition, ifTrue, ifFalse, type);
}
ret->condition = (Expression*)condition;
ret->ifTrue = (Expression*)ifTrue;
ret->ifFalse = (Expression*)ifFalse;
- ret->finalize();
+ if (type != BinaryenTypeAuto()) {
+ ret->finalize(Type(type));
+ } else {
+ ret->finalize();
+ }
return static_cast<Expression*>(ret);
}
BinaryenExpressionRef BinaryenDrop(BinaryenModuleRef module,
@@ -1695,6 +1724,32 @@ BinaryenExpressionRef BinaryenPop(BinaryenModuleRef module, BinaryenType type) {
return static_cast<Expression*>(ret);
}
+BinaryenExpressionRef BinaryenRefNull(BinaryenModuleRef module) {
+ auto* ret = Builder(*(Module*)module).makeRefNull();
+ if (tracing) {
+ traceExpression(ret, "BinaryenRefNull");
+ }
+ return static_cast<Expression*>(ret);
+}
+
+BinaryenExpressionRef BinaryenRefIsNull(BinaryenModuleRef module,
+ BinaryenExpressionRef value) {
+ auto* ret = Builder(*(Module*)module).makeRefIsNull((Expression*)value);
+ if (tracing) {
+ traceExpression(ret, "BinaryenRefIsNull", value);
+ }
+ return static_cast<Expression*>(ret);
+}
+
+BinaryenExpressionRef BinaryenRefFunc(BinaryenModuleRef module,
+ const char* func) {
+ auto* ret = Builder(*(Module*)module).makeRefFunc(func);
+ if (tracing) {
+ traceExpression(ret, "BinaryenRefFunc", StringLit(func));
+ }
+ return static_cast<Expression*>(ret);
+}
+
BinaryenExpressionRef BinaryenTry(BinaryenModuleRef module,
BinaryenExpressionRef body,
BinaryenExpressionRef catchBody) {
@@ -2964,6 +3019,28 @@ BinaryenExpressionRef BinaryenPushGetValue(BinaryenExpressionRef expr) {
assert(expression->is<Push>());
return static_cast<Push*>(expression)->value;
}
+// RefIsNull
+BinaryenExpressionRef BinaryenRefIsNullGetValue(BinaryenExpressionRef expr) {
+ if (tracing) {
+ std::cout << " BinaryenRefIsNullGetValue(expressions[" << expressions[expr]
+ << "]);\n";
+ }
+
+ auto* expression = (Expression*)expr;
+ assert(expression->is<RefIsNull>());
+ return static_cast<RefIsNull*>(expression)->value;
+}
+// RefFunc
+const char* BinaryenRefFuncGetFunc(BinaryenExpressionRef expr) {
+ if (tracing) {
+ std::cout << " BinaryenRefFuncGetFunc(expressions[" << expressions[expr]
+ << "]);\n";
+ }
+
+ auto* expression = (Expression*)expr;
+ assert(expression->is<RefFunc>());
+ return static_cast<RefFunc*>(expression)->func.c_str();
+}
// Try
BinaryenExpressionRef BinaryenTryGetBody(BinaryenExpressionRef expr) {
if (tracing) {