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.h37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/binaryen-c.h b/src/binaryen-c.h
index b5d023400..046a56363 100644
--- a/src/binaryen-c.h
+++ b/src/binaryen-c.h
@@ -65,6 +65,16 @@
#endif
#ifdef __cplusplus
+#define BINARYEN_REF(NAME) \
+ namespace wasm { \
+ class NAME; \
+ }; \
+ typedef class wasm::NAME* Binaryen##NAME##Ref;
+#else
+#define BINARYEN_REF(NAME) typedef struct Binaryen##NAME* Binaryen##NAME##Ref;
+#endif
+
+#ifdef __cplusplus
extern "C" {
#endif
@@ -198,14 +208,14 @@ BINARYEN_API BinaryenFeatures BinaryenFeatureAll(void);
// A module can also contain a function table for indirect calls, a memory,
// and a start method.
-typedef void* BinaryenModuleRef;
+BINARYEN_REF(Module);
BINARYEN_API BinaryenModuleRef BinaryenModuleCreate(void);
BINARYEN_API void BinaryenModuleDispose(BinaryenModuleRef module);
// Function types
-typedef void* BinaryenFunctionTypeRef;
+BINARYEN_REF(FunctionType);
// Add a new function type. This is thread-safe.
// Note: name can be NULL, in which case we auto-generate a name
@@ -574,7 +584,7 @@ BINARYEN_API BinaryenOp BinaryenWidenLowUVecI16x8ToVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenWidenHighUVecI16x8ToVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenSwizzleVec8x16(void);
-typedef void* BinaryenExpressionRef;
+BINARYEN_REF(Expression);
// Block: name can be NULL. Specifying BinaryenUndefined() as the 'type'
// parameter indicates that the block's type shall be figured out
@@ -1060,7 +1070,7 @@ BinaryenPushGetValue(BinaryenExpressionRef expr);
// Functions
-typedef void* BinaryenFunctionRef;
+BINARYEN_REF(Function);
// Adds a function to the module. This is thread-safe.
// @varTypes: the types of variables. In WebAssembly, vars share
@@ -1123,7 +1133,7 @@ BINARYEN_API void BinaryenAddEventImport(BinaryenModuleRef module,
// Exports
-typedef void* BinaryenExportRef;
+BINARYEN_REF(Export);
WASM_DEPRECATED BinaryenExportRef BinaryenAddExport(BinaryenModuleRef module,
const char* internalName,
@@ -1145,7 +1155,7 @@ BINARYEN_API void BinaryenRemoveExport(BinaryenModuleRef module,
// Globals
-typedef void* BinaryenGlobalRef;
+BINARYEN_REF(Global);
BINARYEN_API BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module,
const char* name,
@@ -1160,7 +1170,7 @@ BINARYEN_API void BinaryenRemoveGlobal(BinaryenModuleRef module,
// Events
-typedef void* BinaryenEventRef;
+BINARYEN_REF(Event);
BINARYEN_API BinaryenEventRef BinaryenAddEvent(BinaryenModuleRef module,
const char* name,
@@ -1495,8 +1505,17 @@ BINARYEN_API void BinaryenAddCustomSection(BinaryenModuleRef module,
// For more details, see src/cfg/Relooper.h and
// https://github.com/WebAssembly/binaryen/wiki/Compiling-to-WebAssembly-with-Binaryen#cfg-api
-typedef void* RelooperRef;
-typedef void* RelooperBlockRef;
+#ifdef __cplusplus
+namespace CFG {
+struct Relooper;
+struct Block;
+} // namespace CFG
+typedef struct CFG::Relooper* RelooperRef;
+typedef struct CFG::Block* RelooperBlockRef;
+#else
+typedef struct Relooper* RelooperRef;
+typedef struct RelooperBlock* RelooperBlockRef;
+#endif
// Create a relooper instance
BINARYEN_API RelooperRef RelooperCreate(BinaryenModuleRef module);