summaryrefslogtreecommitdiff
path: root/src/binaryen-c.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/binaryen-c.h')
-rw-r--r--src/binaryen-c.h499
1 files changed, 365 insertions, 134 deletions
diff --git a/src/binaryen-c.h b/src/binaryen-c.h
index 7478a4642..9a57cac79 100644
--- a/src/binaryen-c.h
+++ b/src/binaryen-c.h
@@ -139,14 +139,14 @@ BinaryenExternalKind BinaryenExternalGlobal(void);
// Modules
//
// Modules contain lists of functions, imports, exports, function types. The
-// Add* methods create them on a module. The module owns them and will free their
-// memory when the module is disposed of.
+// Add* methods create them on a module. The module owns them and will free
+// their memory when the module is disposed of.
//
-// Expressions are also allocated inside modules, and freed with the module. They
-// are not created by Add* methods, since they are not added directly on the
-// module, instead, they are arguments to other expressions (and then they are
-// the children of that AST node), or to a function (and then they are the body
-// of that function).
+// Expressions are also allocated inside modules, and freed with the module.
+// They are not created by Add* methods, since they are not added directly on
+// the module, instead, they are arguments to other expressions (and then they
+// are the children of that AST node), or to a function (and then they are the
+// body of that function).
//
// A module can also contain a function table for indirect calls, a memory,
// and a start method.
@@ -162,7 +162,11 @@ typedef void* BinaryenFunctionTypeRef;
// Add a new function type. This is thread-safe.
// Note: name can be NULL, in which case we auto-generate a name
-BinaryenFunctionTypeRef BinaryenAddFunctionType(BinaryenModuleRef module, const char* name, BinaryenType result, BinaryenType* paramTypes, BinaryenIndex numParams);
+BinaryenFunctionTypeRef BinaryenAddFunctionType(BinaryenModuleRef module,
+ const char* name,
+ BinaryenType result,
+ BinaryenType* paramTypes,
+ BinaryenIndex numParams);
// Removes a function type.
void BinaryenRemoveFunctionType(BinaryenModuleRef module, const char* name);
@@ -485,20 +489,45 @@ typedef void* BinaryenExpressionRef;
// parameter indicates that the block's type shall be figured out
// automatically instead of explicitly providing it. This conforms
// to the behavior before the 'type' parameter has been introduced.
-BinaryenExpressionRef BinaryenBlock(BinaryenModuleRef module, const char* name, BinaryenExpressionRef* children, BinaryenIndex numChildren, BinaryenType type);
+BinaryenExpressionRef BinaryenBlock(BinaryenModuleRef module,
+ const char* name,
+ BinaryenExpressionRef* children,
+ BinaryenIndex numChildren,
+ BinaryenType type);
// If: ifFalse can be NULL
-BinaryenExpressionRef BinaryenIf(BinaryenModuleRef module, BinaryenExpressionRef condition, BinaryenExpressionRef ifTrue, BinaryenExpressionRef ifFalse);
-BinaryenExpressionRef BinaryenLoop(BinaryenModuleRef module, const char* in, BinaryenExpressionRef body);
+BinaryenExpressionRef BinaryenIf(BinaryenModuleRef module,
+ BinaryenExpressionRef condition,
+ BinaryenExpressionRef ifTrue,
+ BinaryenExpressionRef ifFalse);
+BinaryenExpressionRef BinaryenLoop(BinaryenModuleRef module,
+ const char* in,
+ BinaryenExpressionRef body);
// Break: value and condition can be NULL
-BinaryenExpressionRef BinaryenBreak(BinaryenModuleRef module, const char* name, BinaryenExpressionRef condition, BinaryenExpressionRef value);
+BinaryenExpressionRef BinaryenBreak(BinaryenModuleRef module,
+ const char* name,
+ BinaryenExpressionRef condition,
+ BinaryenExpressionRef value);
// Switch: value can be NULL
-BinaryenExpressionRef BinaryenSwitch(BinaryenModuleRef module, const char** names, BinaryenIndex numNames, const char* defaultName, BinaryenExpressionRef condition, BinaryenExpressionRef value);
+BinaryenExpressionRef BinaryenSwitch(BinaryenModuleRef module,
+ const char** names,
+ BinaryenIndex numNames,
+ const char* defaultName,
+ BinaryenExpressionRef condition,
+ BinaryenExpressionRef value);
// Call: Note the 'returnType' parameter. You must declare the
// type returned by the function being called, as that
// function might not have been created yet, so we don't
// know what it is.
-BinaryenExpressionRef BinaryenCall(BinaryenModuleRef module, const char* target, BinaryenExpressionRef* operands, BinaryenIndex numOperands, BinaryenType returnType);
-BinaryenExpressionRef BinaryenCallIndirect(BinaryenModuleRef module, BinaryenExpressionRef target, BinaryenExpressionRef* operands, BinaryenIndex numOperands, const char* type);
+BinaryenExpressionRef BinaryenCall(BinaryenModuleRef module,
+ const char* target,
+ BinaryenExpressionRef* operands,
+ BinaryenIndex numOperands,
+ BinaryenType returnType);
+BinaryenExpressionRef BinaryenCallIndirect(BinaryenModuleRef module,
+ BinaryenExpressionRef target,
+ BinaryenExpressionRef* operands,
+ BinaryenIndex numOperands,
+ const char* type);
// GetLocal: Note the 'type' parameter. It might seem redundant, since the
// local at that index must have a type. However, this API lets you
// build code "top-down": create a node, then its parents, and so
@@ -513,41 +542,134 @@ BinaryenExpressionRef BinaryenCallIndirect(BinaryenModuleRef module, BinaryenExp
// a var, that is, either a parameter to the function or a variable
// declared when you call BinaryenAddFunction. See BinaryenAddFunction
// for more details.
-BinaryenExpressionRef BinaryenGetLocal(BinaryenModuleRef module, BinaryenIndex index, BinaryenType type);
-BinaryenExpressionRef BinaryenSetLocal(BinaryenModuleRef module, BinaryenIndex index, BinaryenExpressionRef value);
-BinaryenExpressionRef BinaryenTeeLocal(BinaryenModuleRef module, BinaryenIndex index, BinaryenExpressionRef value);
-BinaryenExpressionRef BinaryenGetGlobal(BinaryenModuleRef module, const char* name, BinaryenType type);
-BinaryenExpressionRef BinaryenSetGlobal(BinaryenModuleRef module, const char* name, BinaryenExpressionRef value);
-// Load: align can be 0, in which case it will be the natural alignment (equal to bytes)
-BinaryenExpressionRef BinaryenLoad(BinaryenModuleRef module, uint32_t bytes, int8_t signed_, uint32_t offset, uint32_t align, BinaryenType type, BinaryenExpressionRef ptr);
-// Store: align can be 0, in which case it will be the natural alignment (equal to bytes)
-BinaryenExpressionRef BinaryenStore(BinaryenModuleRef module, uint32_t bytes, uint32_t offset, uint32_t align, BinaryenExpressionRef ptr, BinaryenExpressionRef value, BinaryenType type);
-BinaryenExpressionRef BinaryenConst(BinaryenModuleRef module, struct BinaryenLiteral value);
-BinaryenExpressionRef BinaryenUnary(BinaryenModuleRef module, BinaryenOp op, BinaryenExpressionRef value);
-BinaryenExpressionRef BinaryenBinary(BinaryenModuleRef module, BinaryenOp op, BinaryenExpressionRef left, BinaryenExpressionRef right);
-BinaryenExpressionRef BinaryenSelect(BinaryenModuleRef module, BinaryenExpressionRef condition, BinaryenExpressionRef ifTrue, BinaryenExpressionRef ifFalse);
-BinaryenExpressionRef BinaryenDrop(BinaryenModuleRef module, BinaryenExpressionRef value);
+BinaryenExpressionRef BinaryenGetLocal(BinaryenModuleRef module,
+ BinaryenIndex index,
+ BinaryenType type);
+BinaryenExpressionRef BinaryenSetLocal(BinaryenModuleRef module,
+ BinaryenIndex index,
+ BinaryenExpressionRef value);
+BinaryenExpressionRef BinaryenTeeLocal(BinaryenModuleRef module,
+ BinaryenIndex index,
+ BinaryenExpressionRef value);
+BinaryenExpressionRef BinaryenGetGlobal(BinaryenModuleRef module,
+ const char* name,
+ BinaryenType type);
+BinaryenExpressionRef BinaryenSetGlobal(BinaryenModuleRef module,
+ const char* name,
+ BinaryenExpressionRef value);
+// Load: align can be 0, in which case it will be the natural alignment (equal
+// to bytes)
+BinaryenExpressionRef BinaryenLoad(BinaryenModuleRef module,
+ uint32_t bytes,
+ int8_t signed_,
+ uint32_t offset,
+ uint32_t align,
+ BinaryenType type,
+ BinaryenExpressionRef ptr);
+// Store: align can be 0, in which case it will be the natural alignment (equal
+// to bytes)
+BinaryenExpressionRef BinaryenStore(BinaryenModuleRef module,
+ uint32_t bytes,
+ uint32_t offset,
+ uint32_t align,
+ BinaryenExpressionRef ptr,
+ BinaryenExpressionRef value,
+ BinaryenType type);
+BinaryenExpressionRef BinaryenConst(BinaryenModuleRef module,
+ struct BinaryenLiteral value);
+BinaryenExpressionRef BinaryenUnary(BinaryenModuleRef module,
+ BinaryenOp op,
+ BinaryenExpressionRef value);
+BinaryenExpressionRef BinaryenBinary(BinaryenModuleRef module,
+ BinaryenOp op,
+ BinaryenExpressionRef left,
+ BinaryenExpressionRef right);
+BinaryenExpressionRef BinaryenSelect(BinaryenModuleRef module,
+ BinaryenExpressionRef condition,
+ BinaryenExpressionRef ifTrue,
+ BinaryenExpressionRef ifFalse);
+BinaryenExpressionRef BinaryenDrop(BinaryenModuleRef module,
+ BinaryenExpressionRef value);
// Return: value can be NULL
-BinaryenExpressionRef BinaryenReturn(BinaryenModuleRef module, BinaryenExpressionRef value);
+BinaryenExpressionRef BinaryenReturn(BinaryenModuleRef module,
+ BinaryenExpressionRef value);
// Host: name may be NULL
-BinaryenExpressionRef BinaryenHost(BinaryenModuleRef module, BinaryenOp op, const char* name, BinaryenExpressionRef* operands, BinaryenIndex numOperands);
+BinaryenExpressionRef BinaryenHost(BinaryenModuleRef module,
+ BinaryenOp op,
+ const char* name,
+ BinaryenExpressionRef* operands,
+ BinaryenIndex numOperands);
BinaryenExpressionRef BinaryenNop(BinaryenModuleRef module);
BinaryenExpressionRef BinaryenUnreachable(BinaryenModuleRef module);
-BinaryenExpressionRef BinaryenAtomicLoad(BinaryenModuleRef module, uint32_t bytes, uint32_t offset, BinaryenType type, BinaryenExpressionRef ptr);
-BinaryenExpressionRef BinaryenAtomicStore(BinaryenModuleRef module, uint32_t bytes, uint32_t offset, BinaryenExpressionRef ptr, BinaryenExpressionRef value, BinaryenType type);
-BinaryenExpressionRef BinaryenAtomicRMW(BinaryenModuleRef module, BinaryenOp op, BinaryenIndex bytes, BinaryenIndex offset, BinaryenExpressionRef ptr, BinaryenExpressionRef value, BinaryenType type);
-BinaryenExpressionRef BinaryenAtomicCmpxchg(BinaryenModuleRef module, BinaryenIndex bytes, BinaryenIndex offset, BinaryenExpressionRef ptr, BinaryenExpressionRef expected, BinaryenExpressionRef replacement, BinaryenType type);
-BinaryenExpressionRef BinaryenAtomicWait(BinaryenModuleRef module, BinaryenExpressionRef ptr, BinaryenExpressionRef expected, BinaryenExpressionRef timeout, BinaryenType type);
-BinaryenExpressionRef BinaryenAtomicNotify(BinaryenModuleRef module, BinaryenExpressionRef ptr, BinaryenExpressionRef notifyCount);
-BinaryenExpressionRef BinaryenSIMDExtract(BinaryenModuleRef module, BinaryenOp op, BinaryenExpressionRef vec, uint8_t index);
-BinaryenExpressionRef BinaryenSIMDReplace(BinaryenModuleRef module, BinaryenOp op, BinaryenExpressionRef vec, uint8_t index, BinaryenExpressionRef value);
-BinaryenExpressionRef BinaryenSIMDShuffle(BinaryenModuleRef module, BinaryenExpressionRef left, BinaryenExpressionRef right, const uint8_t mask[16]);
-BinaryenExpressionRef BinaryenSIMDBitselect(BinaryenModuleRef module, BinaryenExpressionRef left, BinaryenExpressionRef right, BinaryenExpressionRef cond);
-BinaryenExpressionRef BinaryenSIMDShift(BinaryenModuleRef module, BinaryenOp op, BinaryenExpressionRef vec, BinaryenExpressionRef shift);
-BinaryenExpressionRef BinaryenMemoryInit(BinaryenModuleRef module, uint32_t segment, BinaryenExpressionRef dest, BinaryenExpressionRef offset, BinaryenExpressionRef size);
-BinaryenExpressionRef BinaryenDataDrop(BinaryenModuleRef module, uint32_t segment);
-BinaryenExpressionRef BinaryenMemoryCopy(BinaryenModuleRef module, BinaryenExpressionRef dest, BinaryenExpressionRef source, BinaryenExpressionRef size);
-BinaryenExpressionRef BinaryenMemoryFill(BinaryenModuleRef module, BinaryenExpressionRef dest, BinaryenExpressionRef value, BinaryenExpressionRef size);
+BinaryenExpressionRef BinaryenAtomicLoad(BinaryenModuleRef module,
+ uint32_t bytes,
+ uint32_t offset,
+ BinaryenType type,
+ BinaryenExpressionRef ptr);
+BinaryenExpressionRef BinaryenAtomicStore(BinaryenModuleRef module,
+ uint32_t bytes,
+ uint32_t offset,
+ BinaryenExpressionRef ptr,
+ BinaryenExpressionRef value,
+ BinaryenType type);
+BinaryenExpressionRef BinaryenAtomicRMW(BinaryenModuleRef module,
+ BinaryenOp op,
+ BinaryenIndex bytes,
+ BinaryenIndex offset,
+ BinaryenExpressionRef ptr,
+ BinaryenExpressionRef value,
+ BinaryenType type);
+BinaryenExpressionRef BinaryenAtomicCmpxchg(BinaryenModuleRef module,
+ BinaryenIndex bytes,
+ BinaryenIndex offset,
+ BinaryenExpressionRef ptr,
+ BinaryenExpressionRef expected,
+ BinaryenExpressionRef replacement,
+ BinaryenType type);
+BinaryenExpressionRef BinaryenAtomicWait(BinaryenModuleRef module,
+ BinaryenExpressionRef ptr,
+ BinaryenExpressionRef expected,
+ BinaryenExpressionRef timeout,
+ BinaryenType type);
+BinaryenExpressionRef BinaryenAtomicNotify(BinaryenModuleRef module,
+ BinaryenExpressionRef ptr,
+ BinaryenExpressionRef notifyCount);
+BinaryenExpressionRef BinaryenSIMDExtract(BinaryenModuleRef module,
+ BinaryenOp op,
+ BinaryenExpressionRef vec,
+ uint8_t index);
+BinaryenExpressionRef BinaryenSIMDReplace(BinaryenModuleRef module,
+ BinaryenOp op,
+ BinaryenExpressionRef vec,
+ uint8_t index,
+ BinaryenExpressionRef value);
+BinaryenExpressionRef BinaryenSIMDShuffle(BinaryenModuleRef module,
+ BinaryenExpressionRef left,
+ BinaryenExpressionRef right,
+ const uint8_t mask[16]);
+BinaryenExpressionRef BinaryenSIMDBitselect(BinaryenModuleRef module,
+ BinaryenExpressionRef left,
+ BinaryenExpressionRef right,
+ BinaryenExpressionRef cond);
+BinaryenExpressionRef BinaryenSIMDShift(BinaryenModuleRef module,
+ BinaryenOp op,
+ BinaryenExpressionRef vec,
+ BinaryenExpressionRef shift);
+BinaryenExpressionRef BinaryenMemoryInit(BinaryenModuleRef module,
+ uint32_t segment,
+ BinaryenExpressionRef dest,
+ BinaryenExpressionRef offset,
+ BinaryenExpressionRef size);
+BinaryenExpressionRef BinaryenDataDrop(BinaryenModuleRef module,
+ uint32_t segment);
+BinaryenExpressionRef BinaryenMemoryCopy(BinaryenModuleRef module,
+ BinaryenExpressionRef dest,
+ BinaryenExpressionRef source,
+ BinaryenExpressionRef size);
+BinaryenExpressionRef BinaryenMemoryFill(BinaryenModuleRef module,
+ BinaryenExpressionRef dest,
+ BinaryenExpressionRef value,
+ BinaryenExpressionRef size);
BinaryenExpressionId BinaryenExpressionGetId(BinaryenExpressionRef expr);
BinaryenType BinaryenExpressionGetType(BinaryenExpressionRef expr);
@@ -555,7 +677,8 @@ void BinaryenExpressionPrint(BinaryenExpressionRef expr);
const char* BinaryenBlockGetName(BinaryenExpressionRef expr);
BinaryenIndex BinaryenBlockGetNumChildren(BinaryenExpressionRef expr);
-BinaryenExpressionRef BinaryenBlockGetChild(BinaryenExpressionRef expr, BinaryenIndex index);
+BinaryenExpressionRef BinaryenBlockGetChild(BinaryenExpressionRef expr,
+ BinaryenIndex index);
BinaryenExpressionRef BinaryenIfGetCondition(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenIfGetIfTrue(BinaryenExpressionRef expr);
@@ -569,18 +692,21 @@ BinaryenExpressionRef BinaryenBreakGetCondition(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenBreakGetValue(BinaryenExpressionRef expr);
BinaryenIndex BinaryenSwitchGetNumNames(BinaryenExpressionRef expr);
-const char* BinaryenSwitchGetName(BinaryenExpressionRef expr, BinaryenIndex index);
+const char* BinaryenSwitchGetName(BinaryenExpressionRef expr,
+ BinaryenIndex index);
const char* BinaryenSwitchGetDefaultName(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenSwitchGetCondition(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenSwitchGetValue(BinaryenExpressionRef expr);
const char* BinaryenCallGetTarget(BinaryenExpressionRef expr);
BinaryenIndex BinaryenCallGetNumOperands(BinaryenExpressionRef expr);
-BinaryenExpressionRef BinaryenCallGetOperand(BinaryenExpressionRef expr, BinaryenIndex index);
+BinaryenExpressionRef BinaryenCallGetOperand(BinaryenExpressionRef expr,
+ BinaryenIndex index);
BinaryenExpressionRef BinaryenCallIndirectGetTarget(BinaryenExpressionRef expr);
BinaryenIndex BinaryenCallIndirectGetNumOperands(BinaryenExpressionRef expr);
-BinaryenExpressionRef BinaryenCallIndirectGetOperand(BinaryenExpressionRef expr, BinaryenIndex index);
+BinaryenExpressionRef BinaryenCallIndirectGetOperand(BinaryenExpressionRef expr,
+ BinaryenIndex index);
BinaryenIndex BinaryenGetLocalGetIndex(BinaryenExpressionRef expr);
@@ -596,7 +722,8 @@ BinaryenExpressionRef BinaryenSetGlobalGetValue(BinaryenExpressionRef expr);
BinaryenOp BinaryenHostGetOp(BinaryenExpressionRef expr);
const char* BinaryenHostGetNameOperand(BinaryenExpressionRef expr);
BinaryenIndex BinaryenHostGetNumOperands(BinaryenExpressionRef expr);
-BinaryenExpressionRef BinaryenHostGetOperand(BinaryenExpressionRef expr, BinaryenIndex index);
+BinaryenExpressionRef BinaryenHostGetOperand(BinaryenExpressionRef expr,
+ BinaryenIndex index);
int BinaryenLoadIsAtomic(BinaryenExpressionRef expr);
int BinaryenLoadIsSigned(BinaryenExpressionRef expr);
@@ -644,8 +771,10 @@ BinaryenExpressionRef BinaryenAtomicRMWGetValue(BinaryenExpressionRef expr);
uint32_t BinaryenAtomicCmpxchgGetBytes(BinaryenExpressionRef expr);
uint32_t BinaryenAtomicCmpxchgGetOffset(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenAtomicCmpxchgGetPtr(BinaryenExpressionRef expr);
-BinaryenExpressionRef BinaryenAtomicCmpxchgGetExpected(BinaryenExpressionRef expr);
-BinaryenExpressionRef BinaryenAtomicCmpxchgGetReplacement(BinaryenExpressionRef expr);
+BinaryenExpressionRef
+BinaryenAtomicCmpxchgGetExpected(BinaryenExpressionRef expr);
+BinaryenExpressionRef
+BinaryenAtomicCmpxchgGetReplacement(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenAtomicWaitGetPtr(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenAtomicWaitGetExpected(BinaryenExpressionRef expr);
@@ -653,7 +782,8 @@ BinaryenExpressionRef BinaryenAtomicWaitGetTimeout(BinaryenExpressionRef expr);
BinaryenType BinaryenAtomicWaitGetExpectedType(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenAtomicNotifyGetPtr(BinaryenExpressionRef expr);
-BinaryenExpressionRef BinaryenAtomicNotifyGetNotifyCount(BinaryenExpressionRef expr);
+BinaryenExpressionRef
+BinaryenAtomicNotifyGetNotifyCount(BinaryenExpressionRef expr);
BinaryenOp BinaryenSIMDExtractGetOp(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenSIMDExtractGetVec(BinaryenExpressionRef expr);
@@ -666,7 +796,7 @@ BinaryenExpressionRef BinaryenSIMDReplaceGetValue(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenSIMDShuffleGetLeft(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenSIMDShuffleGetRight(BinaryenExpressionRef expr);
-void BinaryenSIMDShuffleGetMask(BinaryenExpressionRef expr, uint8_t *mask);
+void BinaryenSIMDShuffleGetMask(BinaryenExpressionRef expr, uint8_t* mask);
BinaryenExpressionRef BinaryenSIMDBitselectGetLeft(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenSIMDBitselectGetRight(BinaryenExpressionRef expr);
@@ -703,48 +833,96 @@ typedef void* BinaryenFunctionRef;
// and then vars, so if you have one param it will be at index
// 0 (and written $0), and if you also have 2 vars they will be
// at indexes 1 and 2, etc., that is, they share an index space.
-BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module, const char* name, BinaryenFunctionTypeRef type, BinaryenType* varTypes, BinaryenIndex numVarTypes, BinaryenExpressionRef body);
+BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module,
+ const char* name,
+ BinaryenFunctionTypeRef type,
+ BinaryenType* varTypes,
+ BinaryenIndex numVarTypes,
+ BinaryenExpressionRef body);
// Gets a function reference by name.
-BinaryenFunctionRef BinaryenGetFunction(BinaryenModuleRef module, const char* name);
+BinaryenFunctionRef BinaryenGetFunction(BinaryenModuleRef module,
+ const char* name);
// Removes a function by name.
void BinaryenRemoveFunction(BinaryenModuleRef module, const char* name);
// Imports
-void BinaryenAddFunctionImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char* externalBaseName, BinaryenFunctionTypeRef functionType);
-void BinaryenAddTableImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char* externalBaseName);
-void BinaryenAddMemoryImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char* externalBaseName, uint8_t shared);
-void BinaryenAddGlobalImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char* externalBaseName, BinaryenType globalType);
+void BinaryenAddFunctionImport(BinaryenModuleRef module,
+ const char* internalName,
+ const char* externalModuleName,
+ const char* externalBaseName,
+ BinaryenFunctionTypeRef functionType);
+void BinaryenAddTableImport(BinaryenModuleRef module,
+ const char* internalName,
+ const char* externalModuleName,
+ const char* externalBaseName);
+void BinaryenAddMemoryImport(BinaryenModuleRef module,
+ const char* internalName,
+ const char* externalModuleName,
+ const char* externalBaseName,
+ uint8_t shared);
+void BinaryenAddGlobalImport(BinaryenModuleRef module,
+ const char* internalName,
+ const char* externalModuleName,
+ const char* externalBaseName,
+ BinaryenType globalType);
// Exports
typedef void* BinaryenExportRef;
-WASM_DEPRECATED BinaryenExportRef BinaryenAddExport(BinaryenModuleRef module, const char* internalName, const char* externalName);
-BinaryenExportRef BinaryenAddFunctionExport(BinaryenModuleRef module, const char* internalName, const char* externalName);
-BinaryenExportRef BinaryenAddTableExport(BinaryenModuleRef module, const char* internalName, const char* externalName);
-BinaryenExportRef BinaryenAddMemoryExport(BinaryenModuleRef module, const char* internalName, const char* externalName);
-BinaryenExportRef BinaryenAddGlobalExport(BinaryenModuleRef module, const char* internalName, const char* externalName);
+WASM_DEPRECATED BinaryenExportRef BinaryenAddExport(BinaryenModuleRef module,
+ const char* internalName,
+ const char* externalName);
+BinaryenExportRef BinaryenAddFunctionExport(BinaryenModuleRef module,
+ const char* internalName,
+ const char* externalName);
+BinaryenExportRef BinaryenAddTableExport(BinaryenModuleRef module,
+ const char* internalName,
+ const char* externalName);
+BinaryenExportRef BinaryenAddMemoryExport(BinaryenModuleRef module,
+ const char* internalName,
+ const char* externalName);
+BinaryenExportRef BinaryenAddGlobalExport(BinaryenModuleRef module,
+ const char* internalName,
+ const char* externalName);
void BinaryenRemoveExport(BinaryenModuleRef module, const char* externalName);
// Globals
typedef void* BinaryenGlobalRef;
-BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module, const char* name, BinaryenType type, int8_t mutable_, BinaryenExpressionRef init);
+BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module,
+ const char* name,
+ BinaryenType type,
+ int8_t mutable_,
+ BinaryenExpressionRef init);
void BinaryenRemoveGlobal(BinaryenModuleRef module, const char* name);
// Function table. One per module
-void BinaryenSetFunctionTable(BinaryenModuleRef module, BinaryenIndex initial, BinaryenIndex maximum, const char** funcNames, BinaryenIndex numFuncNames);
+void BinaryenSetFunctionTable(BinaryenModuleRef module,
+ BinaryenIndex initial,
+ BinaryenIndex maximum,
+ const char** funcNames,
+ BinaryenIndex numFuncNames);
// Memory. One per module
-// Each segment has data in segments, a start offset in segmentOffsets, and a size in segmentSizes.
-// exportName can be NULL
-void BinaryenSetMemory(BinaryenModuleRef module, BinaryenIndex initial, BinaryenIndex maximum, const char* exportName, const char** segments, int8_t* segmentPassive, BinaryenExpressionRef* segmentOffsets, BinaryenIndex* segmentSizes, BinaryenIndex numSegments, uint8_t shared);
+// Each segment has data in segments, a start offset in segmentOffsets, and a
+// size in segmentSizes. exportName can be NULL
+void BinaryenSetMemory(BinaryenModuleRef module,
+ BinaryenIndex initial,
+ BinaryenIndex maximum,
+ const char* exportName,
+ const char** segments,
+ int8_t* segmentPassive,
+ BinaryenExpressionRef* segmentOffsets,
+ BinaryenIndex* segmentSizes,
+ BinaryenIndex numSegments,
+ uint8_t shared);
// Start function. One per module
@@ -797,29 +975,41 @@ void BinaryenSetDebugInfo(int on);
// Runs the specified passes on the module. Uses the currently set global
// optimize and shrink level.
-void BinaryenModuleRunPasses(BinaryenModuleRef module, const char** passes, BinaryenIndex numPasses);
+void BinaryenModuleRunPasses(BinaryenModuleRef module,
+ const char** passes,
+ BinaryenIndex numPasses);
-// Auto-generate drop() operations where needed. This lets you generate code without
-// worrying about where they are needed. (It is more efficient to do it yourself,
-// but simpler to use autodrop).
+// Auto-generate drop() operations where needed. This lets you generate code
+// without worrying about where they are needed. (It is more efficient to do it
+// yourself, but simpler to use autodrop).
void BinaryenModuleAutoDrop(BinaryenModuleRef module);
-// Serialize a module into binary form. Uses the currently set global debugInfo option.
-// @return how many bytes were written. This will be less than or equal to outputSize
-size_t BinaryenModuleWrite(BinaryenModuleRef module, char* output, size_t outputSize);
+// Serialize a module into binary form. Uses the currently set global debugInfo
+// option.
+// @return how many bytes were written. This will be less than or equal to
+// outputSize
+size_t
+BinaryenModuleWrite(BinaryenModuleRef module, char* output, size_t outputSize);
typedef struct BinaryenBufferSizes {
size_t outputBytes;
size_t sourceMapBytes;
} BinaryenBufferSizes;
-// Serialize a module into binary form including its source map. Uses the currently set
-// global debugInfo option.
-// @returns how many bytes were written. This will be less than or equal to outputSize
-BinaryenBufferSizes BinaryenModuleWriteWithSourceMap(BinaryenModuleRef module, const char* url, char* output, size_t outputSize, char* sourceMap, size_t sourceMapSize);
-
-// Result structure of BinaryenModuleAllocateAndWrite. Contained buffers have been allocated
-// using malloc() and the user is expected to free() them manually once not needed anymore.
+// Serialize a module into binary form including its source map. Uses the
+// currently set global debugInfo option.
+// @returns how many bytes were written. This will be less than or equal to
+// outputSize
+BinaryenBufferSizes BinaryenModuleWriteWithSourceMap(BinaryenModuleRef module,
+ const char* url,
+ char* output,
+ size_t outputSize,
+ char* sourceMap,
+ size_t sourceMapSize);
+
+// Result structure of BinaryenModuleAllocateAndWrite. Contained buffers have
+// been allocated using malloc() and the user is expected to free() them
+// manually once not needed anymore.
typedef struct BinaryenModuleAllocateAndWriteResult {
void* binary;
size_t binaryBytes;
@@ -827,25 +1017,30 @@ typedef struct BinaryenModuleAllocateAndWriteResult {
} BinaryenModuleAllocateAndWriteResult;
// Serializes a module into binary form, optionally including its source map if
-// sourceMapUrl has been specified. Uses the currently set global debugInfo option.
-// Differs from BinaryenModuleWrite in that it implicitly allocates appropriate buffers
-// using malloc(), and expects the user to free() them manually once not needed anymore.
-BinaryenModuleAllocateAndWriteResult BinaryenModuleAllocateAndWrite(BinaryenModuleRef module, const char* sourceMapUrl);
+// sourceMapUrl has been specified. Uses the currently set global debugInfo
+// option. Differs from BinaryenModuleWrite in that it implicitly allocates
+// appropriate buffers using malloc(), and expects the user to free() them
+// manually once not needed anymore.
+BinaryenModuleAllocateAndWriteResult
+BinaryenModuleAllocateAndWrite(BinaryenModuleRef module,
+ const char* sourceMapUrl);
// Deserialize a module from binary form.
BinaryenModuleRef BinaryenModuleRead(char* input, size_t inputSize);
// Execute a module in the Binaryen interpreter. This will create an instance of
-// the module, run it in the interpreter - which means running the start method -
-// and then destroying the instance.
+// the module, run it in the interpreter - which means running the start method
+// - and then destroying the instance.
void BinaryenModuleInterpret(BinaryenModuleRef module);
// Adds a debug info file name to the module and returns its index.
-BinaryenIndex BinaryenModuleAddDebugInfoFileName(BinaryenModuleRef module, const char* filename);
+BinaryenIndex BinaryenModuleAddDebugInfoFileName(BinaryenModuleRef module,
+ const char* filename);
-// Gets the name of the debug info file at the specified index. Returns `NULL` if it
-// does not exist.
-const char* BinaryenModuleGetDebugInfoFileName(BinaryenModuleRef module, BinaryenIndex index);
+// Gets the name of the debug info file at the specified index. Returns `NULL`
+// if it does not exist.
+const char* BinaryenModuleGetDebugInfoFileName(BinaryenModuleRef module,
+ BinaryenIndex index);
//
// ======== FunctionType Operations ========
@@ -855,8 +1050,10 @@ const char* BinaryenModuleGetDebugInfoFileName(BinaryenModuleRef module, Binarye
const char* BinaryenFunctionTypeGetName(BinaryenFunctionTypeRef ftype);
// Gets the number of parameters of the specified `FunctionType`.
BinaryenIndex BinaryenFunctionTypeGetNumParams(BinaryenFunctionTypeRef ftype);
-// Gets the type of the parameter at the specified index of the specified `FunctionType`.
-BinaryenType BinaryenFunctionTypeGetParam(BinaryenFunctionTypeRef ftype, BinaryenIndex index);
+// Gets the type of the parameter at the specified index of the specified
+// `FunctionType`.
+BinaryenType BinaryenFunctionTypeGetParam(BinaryenFunctionTypeRef ftype,
+ BinaryenIndex index);
// Gets the result type of the specified `FunctionType`.
BinaryenType BinaryenFunctionTypeGetResult(BinaryenFunctionTypeRef ftype);
@@ -866,31 +1063,45 @@ BinaryenType BinaryenFunctionTypeGetResult(BinaryenFunctionTypeRef ftype);
// Gets the name of the specified `Function`.
const char* BinaryenFunctionGetName(BinaryenFunctionRef func);
-// Gets the name of the `FunctionType` associated with the specified `Function`. May be `NULL` if the signature is implicit.
+// Gets the name of the `FunctionType` associated with the specified `Function`.
+// May be `NULL` if the signature is implicit.
const char* BinaryenFunctionGetType(BinaryenFunctionRef func);
// Gets the number of parameters of the specified `Function`.
BinaryenIndex BinaryenFunctionGetNumParams(BinaryenFunctionRef func);
-// Gets the type of the parameter at the specified index of the specified `Function`.
-BinaryenType BinaryenFunctionGetParam(BinaryenFunctionRef func, BinaryenIndex index);
+// Gets the type of the parameter at the specified index of the specified
+// `Function`.
+BinaryenType BinaryenFunctionGetParam(BinaryenFunctionRef func,
+ BinaryenIndex index);
// Gets the result type of the specified `Function`.
BinaryenType BinaryenFunctionGetResult(BinaryenFunctionRef func);
// Gets the number of additional locals within the specified `Function`.
BinaryenIndex BinaryenFunctionGetNumVars(BinaryenFunctionRef func);
-// Gets the type of the additional local at the specified index within the specified `Function`.
-BinaryenType BinaryenFunctionGetVar(BinaryenFunctionRef func, BinaryenIndex index);
+// Gets the type of the additional local at the specified index within the
+// specified `Function`.
+BinaryenType BinaryenFunctionGetVar(BinaryenFunctionRef func,
+ BinaryenIndex index);
// Gets the body of the specified `Function`.
BinaryenExpressionRef BinaryenFunctionGetBody(BinaryenFunctionRef func);
// Runs the standard optimization passes on the function. Uses the currently set
// global optimize and shrink level.
-void BinaryenFunctionOptimize(BinaryenFunctionRef func, BinaryenModuleRef module);
+void BinaryenFunctionOptimize(BinaryenFunctionRef func,
+ BinaryenModuleRef module);
// Runs the specified passes on the function. Uses the currently set global
// optimize and shrink level.
-void BinaryenFunctionRunPasses(BinaryenFunctionRef func, BinaryenModuleRef module, const char** passes, BinaryenIndex numPasses);
-
-// Sets the debug location of the specified `Expression` within the specified `Function`.
-void BinaryenFunctionSetDebugLocation(BinaryenFunctionRef func, BinaryenExpressionRef expr, BinaryenIndex fileIndex, BinaryenIndex lineNumber, BinaryenIndex columnNumber);
+void BinaryenFunctionRunPasses(BinaryenFunctionRef func,
+ BinaryenModuleRef module,
+ const char** passes,
+ BinaryenIndex numPasses);
+
+// Sets the debug location of the specified `Expression` within the specified
+// `Function`.
+void BinaryenFunctionSetDebugLocation(BinaryenFunctionRef func,
+ BinaryenExpressionRef expr,
+ BinaryenIndex fileIndex,
+ BinaryenIndex lineNumber,
+ BinaryenIndex columnNumber);
//
// ========== Import Operations ==========
@@ -930,37 +1141,53 @@ typedef void* RelooperBlockRef;
RelooperRef RelooperCreate(BinaryenModuleRef module);
// Create a basic block that ends with nothing, or with some simple branching
-RelooperBlockRef RelooperAddBlock(RelooperRef relooper, BinaryenExpressionRef code);
+RelooperBlockRef RelooperAddBlock(RelooperRef relooper,
+ BinaryenExpressionRef code);
// Create a branch to another basic block
-// The branch can have code on it, that is executed as the branch happens. this is useful for phis. otherwise, code can be NULL
-void RelooperAddBranch(RelooperBlockRef from, RelooperBlockRef to, BinaryenExpressionRef condition, BinaryenExpressionRef code);
+// The branch can have code on it, that is executed as the branch happens. this
+// is useful for phis. otherwise, code can be NULL
+void RelooperAddBranch(RelooperBlockRef from,
+ RelooperBlockRef to,
+ BinaryenExpressionRef condition,
+ BinaryenExpressionRef code);
// Create a basic block that ends a switch on a condition
-RelooperBlockRef RelooperAddBlockWithSwitch(RelooperRef relooper, BinaryenExpressionRef code, BinaryenExpressionRef condition);
-
-// Create a switch-style branch to another basic block. The block's switch table will have these indexes going to that target
-void RelooperAddBranchForSwitch(RelooperBlockRef from, RelooperBlockRef to, BinaryenIndex* indexes, BinaryenIndex numIndexes, BinaryenExpressionRef code);
-
-// Generate structed wasm control flow from the CFG of blocks and branches that were created
-// on this relooper instance. This returns the rendered output, and also disposes of the
-// relooper and its blocks and branches, as they are no longer needed.
-// @param labelHelper To render irreducible control flow, we may need a helper variable to
-// guide us to the right target label. This value should be an index of
-// an i32 local variable that is free for us to use.
-BinaryenExpressionRef RelooperRenderAndDispose(RelooperRef relooper, RelooperBlockRef entry, BinaryenIndex labelHelper);
+RelooperBlockRef RelooperAddBlockWithSwitch(RelooperRef relooper,
+ BinaryenExpressionRef code,
+ BinaryenExpressionRef condition);
+
+// Create a switch-style branch to another basic block. The block's switch table
+// will have these indexes going to that target
+void RelooperAddBranchForSwitch(RelooperBlockRef from,
+ RelooperBlockRef to,
+ BinaryenIndex* indexes,
+ BinaryenIndex numIndexes,
+ BinaryenExpressionRef code);
+
+// Generate structed wasm control flow from the CFG of blocks and branches that
+// were created on this relooper instance. This returns the rendered output, and
+// also disposes of the relooper and its blocks and branches, as they are no
+// longer needed.
+// @param labelHelper To render irreducible control flow, we may need a helper
+// variable to guide us to the right target label. This value should be
+// an index of an i32 local variable that is free for us to use.
+BinaryenExpressionRef RelooperRenderAndDispose(RelooperRef relooper,
+ RelooperBlockRef entry,
+ BinaryenIndex labelHelper);
//
// ========= Other APIs =========
//
-// Sets whether API tracing is on or off. It is off by default. When on, each call
-// to an API method will print out C code equivalent to it, which is useful for
-// auto-generating standalone testcases from projects using the API.
-// When calling this to turn on tracing, the prelude of the full program is printed,
-// and when calling it to turn it off, the ending of the program is printed, giving
-// you the full compilable testcase.
-// TODO: compile-time option to enable/disable this feature entirely at build time?
+// Sets whether API tracing is on or off. It is off by default. When on, each
+// call to an API method will print out C code equivalent to it, which is useful
+// for auto-generating standalone testcases from projects using the API. When
+// calling this to turn on tracing, the prelude of the full program is printed,
+// and when calling it to turn it off, the ending of the program is printed,
+// giving you the full compilable testcase.
+// TODO: compile-time option to enable/disable this feature entirely at build
+// time?
void BinaryenSetAPITracing(int on);
//
@@ -968,11 +1195,15 @@ void BinaryenSetAPITracing(int on);
//
// Note that this function has been added because there is no better alternative
-// currently and is scheduled for removal once there is one. It takes the same set
-// of parameters as BinaryenAddFunctionType but instead of adding a new function
-// signature, it returns a pointer to the existing signature or NULL if there is no
-// such signature yet.
-BinaryenFunctionTypeRef BinaryenGetFunctionTypeBySignature(BinaryenModuleRef module, BinaryenType result, BinaryenType* paramTypes, BinaryenIndex numParams);
+// currently and is scheduled for removal once there is one. It takes the same
+// set of parameters as BinaryenAddFunctionType but instead of adding a new
+// function signature, it returns a pointer to the existing signature or NULL if
+// there is no such signature yet.
+BinaryenFunctionTypeRef
+BinaryenGetFunctionTypeBySignature(BinaryenModuleRef module,
+ BinaryenType result,
+ BinaryenType* paramTypes,
+ BinaryenIndex numParams);
#ifdef __cplusplus
} // extern "C"