summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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,