summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-07-21 11:14:25 -0700
committerGitHub <noreply@github.com>2023-07-21 18:14:25 +0000
commit794a7ee41068ffe450bf904de504f2cad36d1f21 (patch)
tree189e38c991dd7273e9cf548923a987fe3f4eecab /src
parent0d79590340237214bccfca6a73ad11b3728f26fc (diff)
downloadbinaryen-794a7ee41068ffe450bf904de504f2cad36d1f21.tar.gz
binaryen-794a7ee41068ffe450bf904de504f2cad36d1f21.tar.bz2
binaryen-794a7ee41068ffe450bf904de504f2cad36d1f21.zip
C API: Add BinaryenAddFunctionWithHeapType which takes a heap type (#5829)
This is necessary for WasmGC producers using the C API, so that they can set the heap type of functions. Otherwise the heap type is set structurally using params and results in the old API. The old API is kept for backwards compatibility and convenience (for the structural case, which is all code before WasmGC basically). Fixes #5826
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-c.cpp37
-rw-r--r--src/binaryen-c.h9
2 files changed, 37 insertions, 9 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index d075115e7..dd2ad5c4a 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -4909,17 +4909,15 @@ void BinaryenStringSliceIterSetNum(BinaryenExpressionRef expr,
// Functions
-BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module,
- const char* name,
- BinaryenType params,
- BinaryenType results,
- BinaryenType* varTypes,
- BinaryenIndex numVarTypes,
- BinaryenExpressionRef body) {
+static BinaryenFunctionRef addFunctionInternal(BinaryenModuleRef module,
+ const char* name,
+ HeapType type,
+ BinaryenType* varTypes,
+ BinaryenIndex numVarTypes,
+ BinaryenExpressionRef body) {
auto* ret = new Function;
ret->setExplicitName(name);
- // TODO: Take a HeapType rather than params and results.
- ret->type = Signature(Type(params), Type(results));
+ ret->type = type;
for (BinaryenIndex i = 0; i < numVarTypes; i++) {
ret->vars.push_back(Type(varTypes[i]));
}
@@ -4934,6 +4932,27 @@ BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module,
return ret;
}
+
+BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module,
+ const char* name,
+ BinaryenType params,
+ BinaryenType results,
+ BinaryenType* varTypes,
+ BinaryenIndex numVarTypes,
+ BinaryenExpressionRef body) {
+ HeapType type = Signature(Type(params), Type(results));
+ return addFunctionInternal(module, name, type, varTypes, numVarTypes, body);
+}
+BinaryenFunctionRef
+BinaryenAddFunctionWithHeapType(BinaryenModuleRef module,
+ const char* name,
+ BinaryenHeapType type,
+ BinaryenType* varTypes,
+ BinaryenIndex numVarTypes,
+ BinaryenExpressionRef body) {
+ return addFunctionInternal(
+ module, name, HeapType(type), varTypes, numVarTypes, body);
+}
BinaryenFunctionRef BinaryenGetFunction(BinaryenModuleRef module,
const char* name) {
return ((Module*)module)->getFunctionOrNull(name);
diff --git a/src/binaryen-c.h b/src/binaryen-c.h
index 07c116aec..75acc20b0 100644
--- a/src/binaryen-c.h
+++ b/src/binaryen-c.h
@@ -2723,6 +2723,15 @@ BinaryenAddFunction(BinaryenModuleRef module,
BinaryenType* varTypes,
BinaryenIndex numVarTypes,
BinaryenExpressionRef body);
+// As BinaryenAddFunction, but takes a HeapType rather than params and results.
+// This lets you set the specific type of the function.
+BINARYEN_API BinaryenFunctionRef
+BinaryenAddFunctionWithHeapType(BinaryenModuleRef module,
+ const char* name,
+ BinaryenHeapType type,
+ BinaryenType* varTypes,
+ BinaryenIndex numVarTypes,
+ BinaryenExpressionRef body);
// Gets a function reference by name. Returns NULL if the function does not
// exist.
BINARYEN_API BinaryenFunctionRef BinaryenGetFunction(BinaryenModuleRef module,