diff options
Diffstat (limited to 'src/binaryen-c.h')
-rw-r--r-- | src/binaryen-c.h | 253 |
1 files changed, 244 insertions, 9 deletions
diff --git a/src/binaryen-c.h b/src/binaryen-c.h index 6bd61ed53..78866d189 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -68,15 +68,22 @@ typedef uint32_t BinaryenIndex; typedef uint32_t BinaryenType; -BinaryenType BinaryenNone(void); -BinaryenType BinaryenInt32(void); -BinaryenType BinaryenInt64(void); -BinaryenType BinaryenFloat32(void); -BinaryenType BinaryenFloat64(void); - +BinaryenType BinaryenTypeNone(void); +BinaryenType BinaryenTypeInt32(void); +BinaryenType BinaryenTypeInt64(void); +BinaryenType BinaryenTypeFloat32(void); +BinaryenType BinaryenTypeFloat64(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. -BinaryenType BinaryenUndefined(void); +BinaryenType BinaryenTypeAuto(void); + +WASM_DEPRECATED BinaryenType BinaryenNone(void); +WASM_DEPRECATED BinaryenType BinaryenInt32(void); +WASM_DEPRECATED BinaryenType BinaryenInt64(void); +WASM_DEPRECATED BinaryenType BinaryenFloat32(void); +WASM_DEPRECATED BinaryenType BinaryenFloat64(void); +WASM_DEPRECATED BinaryenType BinaryenUndefined(void); // Expression ids (call to get the value of each; you can cache them) @@ -382,8 +389,120 @@ BinaryenExpressionRef BinaryenAtomicWake(BinaryenModuleRef module, BinaryenExpre BinaryenExpressionId BinaryenExpressionGetId(BinaryenExpressionRef expr); // Gets the type of the specified expression. BinaryenType BinaryenExpressionGetType(BinaryenExpressionRef expr); -// Print an expression to stdout. Useful for debugging. +// Prints an expression to stdout. Useful for debugging. void BinaryenExpressionPrint(BinaryenExpressionRef expr); + +// Gets the name of the specified `Block` expression. May be `NULL`. +const char* BinaryenBlockGetName(BinaryenExpressionRef expr); +// Gets the number of nested child expressions within the specified `Block` expression. +BinaryenIndex BinaryenBlockGetNumChildren(BinaryenExpressionRef expr); +// Gets the nested child expression at the specified index within the specified `Block` expression. +BinaryenExpressionRef BinaryenBlockGetChild(BinaryenExpressionRef expr, BinaryenIndex index); + +// Gets the nested condition expression within the specified `If` expression. +BinaryenExpressionRef BinaryenIfGetCondition(BinaryenExpressionRef expr); +// Gets the nested ifTrue expression within the specified `If` expression. +BinaryenExpressionRef BinaryenIfGetIfTrue(BinaryenExpressionRef expr); +// Gets the nested ifFalse expression within the specified `If` expression. +BinaryenExpressionRef BinaryenIfGetIfFalse(BinaryenExpressionRef expr); + +// Gets the name of the specified `Loop` expression. May be `NULL`. +const char* BinaryenLoopGetName(BinaryenExpressionRef expr); +// Gets the nested body expression within the specified `Loop` expression. +BinaryenExpressionRef BinaryenLoopGetBody(BinaryenExpressionRef expr); + +// Gets the name of the specified `Break` expression. May be `NULL`. +const char* BinaryenBreakGetName(BinaryenExpressionRef expr); +// Gets the nested condition expression within the specified `Break` expression. Returns `NULL` if this is a `br` and not a `br_if`. +BinaryenExpressionRef BinaryenBreakGetCondition(BinaryenExpressionRef expr); +// Gets the nested value expression within the specified `Break` expression. May be `NULL`. +BinaryenExpressionRef BinaryenBreakGetValue(BinaryenExpressionRef expr); + +// Gets the number of names within the specified `Switch` expression. +BinaryenIndex BinaryenSwitchGetNumNames(BinaryenExpressionRef expr); +// Gets the name at the specified index within the specified `Switch` expression. +const char* BinaryenSwitchGetName(BinaryenExpressionRef expr, BinaryenIndex index); +// Gets the default name of the specified `Switch` expression. +const char* BinaryenSwitchGetDefaultName(BinaryenExpressionRef expr); +// Gets the nested condition expression within the specified `Switch` expression. +BinaryenExpressionRef BinaryenSwitchGetCondition(BinaryenExpressionRef expr); +// Gets the nested value expression within the specifiedd `Switch` expression. May be `NULL`. +BinaryenExpressionRef BinaryenSwitchGetValue(BinaryenExpressionRef expr); + +// Gets the name of the target of the specified `Call` expression. +const char* BinaryenCallGetTarget(BinaryenExpressionRef expr); +// Gets the number of nested operand expressions within the specified `Call` expression. +BinaryenIndex BinaryenCallGetNumOperands(BinaryenExpressionRef expr); +// Gets the nested operand expression at the specified index within the specified `Call` expression. +BinaryenExpressionRef BinaryenCallGetOperand(BinaryenExpressionRef expr, BinaryenIndex index); + +// Gets the name of the target of the specified `CallImport` expression. +const char* BinaryenCallImportGetTarget(BinaryenExpressionRef expr); +// Gets the number of nested operand expressions within the specified `CallImport` expression. +BinaryenIndex BinaryenCallImportGetNumOperands(BinaryenExpressionRef expr); +// Gets the nested operand expression at the specified index within the specified `CallImport` expression. +BinaryenExpressionRef BinaryenCallImportGetOperand(BinaryenExpressionRef expr, BinaryenIndex index); + +// Gets the nested target expression of the specified `CallIndirect` expression. +BinaryenExpressionRef BinaryenCallIndirectGetTarget(BinaryenExpressionRef expr); +// Gets the number of nested operand expressions within the specified `CallIndirect` expression. +BinaryenIndex BinaryenCallIndirectGetNumOperands(BinaryenExpressionRef expr); +// Gets the nested operand expression at the specified index within the specified `CallIndirect` expression. +BinaryenExpressionRef BinaryenCallIndirectGetOperand(BinaryenExpressionRef expr, BinaryenIndex index); + +// Gets the index of the specified `GetLocal` expression. +BinaryenIndex BinaryenGetLocalGetIndex(BinaryenExpressionRef expr); + +// Tests if the specified `SetLocal` expression performs a `tee_local` instead of a `set_local`. +int BinaryenSetLocalIsTee(BinaryenExpressionRef expr); +// Gets the index of the specified `SetLocal` expression. +BinaryenIndex BinaryenSetLocalGetIndex(BinaryenExpressionRef expr); +// Gets the nested value expression within the specified `SetLocal` expression. +BinaryenExpressionRef BinaryenSetLocalGetValue(BinaryenExpressionRef expr); + +// Gets the name of the specified `GetGlobal` expression. +const char* BinaryenGetGlobalGetName(BinaryenExpressionRef expr); + +// Gets the name of the specified `SetGlobal` expression. +const char* BinaryenSetGlobalGetName(BinaryenExpressionRef expr); +// Gets the nested value expression within the specified `SetLocal` expression. +BinaryenExpressionRef BinaryenSetGlobalGetValue(BinaryenExpressionRef expr); + +// Gets the operator of the specified `Host` expression. +BinaryenOp BinaryenHostGetOp(BinaryenExpressionRef expr); +// Gets the name operand of the specified `Host` expression. May be `NULL`. +const char* BinaryenHostGetNameOperand(BinaryenExpressionRef expr); +// Gets the number of nested operand expressions within the specified `Host` expression. +BinaryenIndex BinaryenHostGetNumOperands(BinaryenExpressionRef expr); +// Gets the nested operand expression at the specified index within the specified `Host` expression. +BinaryenExpressionRef BinaryenHostGetOperand(BinaryenExpressionRef expr, BinaryenIndex index); + +// Tests if the specified `Load` expression is atomic. +int BinaryenLoadIsAtomic(BinaryenExpressionRef expr); +// Tests if the specified `Load` expression is signed. +int BinaryenLoadIsSigned(BinaryenExpressionRef expr); +// Gets the offset of the specified `Load` expression. +uint32_t BinaryenLoadGetOffset(BinaryenExpressionRef expr); +// Gets the byte size of the specified `Load` expression. +uint32_t BinaryenLoadGetBytes(BinaryenExpressionRef expr); +// Gets the alignment of the specified `Load` expression. +uint32_t BinaryenLoadGetAlign(BinaryenExpressionRef expr); +// Gets the nested pointer expression within the specified `Load` expression. +BinaryenExpressionRef BinaryenLoadGetPtr(BinaryenExpressionRef expr); + +// Tests if the specified `Store` expression is atomic. +int BinaryenStoreIsAtomic(BinaryenExpressionRef expr); +// Gets the byte size of the specified `Store` expression. +uint32_t BinaryenStoreGetBytes(BinaryenExpressionRef expr); +// Gets the offset of the specified store expression. +uint32_t BinaryenStoreGetOffset(BinaryenExpressionRef expr); +// Gets the alignment of the specified `Store` expression. +uint32_t BinaryenStoreGetAlign(BinaryenExpressionRef expr); +// Gets the nested pointer expression within the specified `Store` expression. +BinaryenExpressionRef BinaryenStoreGetPtr(BinaryenExpressionRef expr); +// Gets the nested value expression within the specified `Store` expression. +BinaryenExpressionRef BinaryenStoreGetValue(BinaryenExpressionRef expr); + // Gets the 32-bit integer value of the specified `Const` expression. int32_t BinaryenConstGetValueI32(BinaryenExpressionRef expr); // Gets the 64-bit integer value of the specified `Const` expression. @@ -397,6 +516,67 @@ float BinaryenConstGetValueF32(BinaryenExpressionRef expr); // Gets the 64-bit float value of the specified `Const` expression. double BinaryenConstGetValueF64(BinaryenExpressionRef expr); +// Gets the operator of the specified `Unary` expression. +BinaryenOp BinaryenUnaryGetOp(BinaryenExpressionRef expr); +// Gets the nested value expression within the specified `Unary` expression. +BinaryenExpressionRef BinaryenUnaryGetValue(BinaryenExpressionRef expr); + +// Gets the operator of the specified `Binary` expression. +BinaryenOp BinaryenBinaryGetOp(BinaryenExpressionRef expr); +// Gets the nested left expression within the specified `Binary` expression. +BinaryenExpressionRef BinaryenBinaryGetLeft(BinaryenExpressionRef expr); +// Gets the nested right expression within the specified `Binary` expression. +BinaryenExpressionRef BinaryenBinaryGetRight(BinaryenExpressionRef expr); + +// Gets the nested ifTrue expression within the specified `Select` expression. +BinaryenExpressionRef BinaryenSelectGetIfTrue(BinaryenExpressionRef expr); +// Gets the nested ifFalse expression within the specified `Select` expression. +BinaryenExpressionRef BinaryenSelectGetIfFalse(BinaryenExpressionRef expr); +// Gets the nested condition expression within the specified `Select` expression. +BinaryenExpressionRef BinaryenSelectGetCondition(BinaryenExpressionRef expr); + +// Gets the nested value expression within the specified `Drop` expression. +BinaryenExpressionRef BinaryenDropGetValue(BinaryenExpressionRef expr); + +// Gets the nested value expression within the specified `Return` expression. +BinaryenExpressionRef BinaryenReturnGetValue(BinaryenExpressionRef expr); + +// Gets the operator of the specified `AtomicRMW` expression. +BinaryenOp BinaryenAtomicRMWGetOp(BinaryenExpressionRef expr); +// Gets the byte size of the specified `AtomicRMW` expression. +uint32_t BinaryenAtomicRMWGetBytes(BinaryenExpressionRef expr); +// Gets the offset of the specified `AtomicRMW` expression. +uint32_t BinaryenAtomicRMWGetOffset(BinaryenExpressionRef expr); +// Gets the nested pointer expression within the specified `AtomicRMW` expression. +BinaryenExpressionRef BinaryenAtomicRMWGetPtr(BinaryenExpressionRef expr); +// Gets the nested value expression within the specified `AtomicRMW` expression. +BinaryenExpressionRef BinaryenAtomicRMWGetValue(BinaryenExpressionRef expr); + +// Gets the byte size of the specified `AtomicCmpxchg` expression. +uint32_t BinaryenAtomicCmpxchgGetBytes(BinaryenExpressionRef expr); +// Gets the offset of the specified `AtomicCmpxchg` expression. +uint32_t BinaryenAtomicCmpxchgGetOffset(BinaryenExpressionRef expr); +// Gets the nested pointer expression within the specified `AtomicCmpxchg` expression. +BinaryenExpressionRef BinaryenAtomicCmpxchgGetPtr(BinaryenExpressionRef expr); +// Gets the nested expected value expression within the specified `AtomicCmpxchg` expression. +BinaryenExpressionRef BinaryenAtomicCmpxchgGetExpected(BinaryenExpressionRef expr); +// Gets the nested replacement value expression within the specified `AtomicCmpxchg` expression. +BinaryenExpressionRef BinaryenAtomicCmpxchgGetReplacement(BinaryenExpressionRef expr); + +// Gets the nested pointer expression within the specified `AtomicWait` expression. +BinaryenExpressionRef BinaryenAtomicWaitGetPtr(BinaryenExpressionRef expr); +// Gets the nested expected value expression within the specified `AtomicWait` expression. +BinaryenExpressionRef BinaryenAtomicWaitGetExpected(BinaryenExpressionRef expr); +// Gets the nested timeout expression within the specified `AtomicWait` expression. +BinaryenExpressionRef BinaryenAtomicWaitGetTimeout(BinaryenExpressionRef expr); +// Gets the expected type of the specified `AtomicWait` expression. +BinaryenType BinaryenAtomicWaitGetExpectedType(BinaryenExpressionRef expr); + +// Gets the nested pointer expression within the specified `AtomicWake` expression. +BinaryenExpressionRef BinaryenAtomicWakeGetPtr(BinaryenExpressionRef expr); +// Gets the nested wake count expression within the specified `AtomicWake` expression. +BinaryenExpressionRef BinaryenAtomicWakeGetWakeCount(BinaryenExpressionRef expr); + // Functions typedef void* BinaryenFunctionRef; @@ -500,10 +680,37 @@ BinaryenModuleRef BinaryenModuleRead(char* input, size_t inputSize); void BinaryenModuleInterpret(BinaryenModuleRef module); // +// ======== FunctionType Operations ======== +// + +// Gets the name of the specified `FunctionType`. +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 result type of the specified `FunctionType`. +BinaryenType BinaryenFunctionTypeGetResult(BinaryenFunctionTypeRef ftype); + +// // ========== Function Operations ========== // -// Gets the body of the function. +// 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. +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 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 body of the specified `Function`. BinaryenExpressionRef BinaryenFunctionGetBody(BinaryenFunctionRef func); // Runs the standard optimization passes on the function. @@ -513,6 +720,34 @@ void BinaryenFunctionOptimize(BinaryenFunctionRef func, BinaryenModuleRef module void BinaryenFunctionRunPasses(BinaryenFunctionRef func, BinaryenModuleRef module, const char **passes, BinaryenIndex numPasses); // +// ========== Import Operations ========== +// + +// Gets the external kind of the specified import. +BinaryenExternalKind BinaryenImportGetKind(BinaryenImportRef import); +// Gets the external module name of the specified import. +const char* BinaryenImportGetModule(BinaryenImportRef import); +// Gets the external base name of the specified import. +const char* BinaryenImportGetBase(BinaryenImportRef import); +// Gets the internal name of the specified import. +const char* BinaryenImportGetName(BinaryenImportRef import); +// Gets the type of the imported global, if referencing a `Global`. +BinaryenType BinaryenImportGetGlobalType(BinaryenImportRef import); +// Gets the name of the function type of the imported function, if referencing a `Function`. +const char* BinaryenImportGetFunctionType(BinaryenImportRef import); + +// +// ========== Export Operations ========== +// + +// Gets the external kind of the specified export. +BinaryenExternalKind BinaryenExportGetKind(BinaryenExportRef export_); +// Gets the external name of the specified export. +const char* BinaryenExportGetName(BinaryenExportRef export_); +// Gets the internal name of the specified export. +const char* BinaryenExportGetValue(BinaryenExportRef export_); + +// // ========== CFG / Relooper ========== // // General usage is (1) create a relooper, (2) create blocks, (3) add |