Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4088,15 +4088,15 @@ const char* BinaryenModuleGetDebugInfoFileName(BinaryenModuleRef module,
const char* BinaryenFunctionTypeGetName(BinaryenFunctionTypeRef ftype) {
if (tracing) {
std::cout << " BinaryenFunctionTypeGetName(functionsTypes["
<< functions[ftype] << "]);\n";
<< functionTypes[ftype] << "]);\n";
}

return ((FunctionType*)ftype)->name.c_str();
}
BinaryenIndex BinaryenFunctionTypeGetNumParams(BinaryenFunctionTypeRef ftype) {
if (tracing) {
std::cout << " BinaryenFunctionTypeGetNumParams(functionsTypes["
<< functions[ftype] << "]);\n";
<< functionTypes[ftype] << "]);\n";
}

return ((FunctionType*)ftype)->params.size();
Expand All @@ -4105,7 +4105,7 @@ BinaryenType BinaryenFunctionTypeGetParam(BinaryenFunctionTypeRef ftype,
BinaryenIndex index) {
if (tracing) {
std::cout << " BinaryenFunctionTypeGetParam(functionsTypes["
<< functions[ftype] << "], " << index << ");\n";
<< functionTypes[ftype] << "], " << index << ");\n";
}

auto* ft = (FunctionType*)ftype;
Expand All @@ -4115,7 +4115,7 @@ BinaryenType BinaryenFunctionTypeGetParam(BinaryenFunctionTypeRef ftype,
BinaryenType BinaryenFunctionTypeGetResult(BinaryenFunctionTypeRef ftype) {
if (tracing) {
std::cout << " BinaryenFunctionTypeGetResult(functionsTypes["
<< functions[ftype] << "]);\n";
<< functionTypes[ftype] << "]);\n";
}

return ((FunctionType*)ftype)->result;
Expand Down Expand Up @@ -4521,7 +4521,7 @@ RelooperBlockRef RelooperAddBlock(RelooperRef relooper,
}

R->AddBlock(ret);
return RelooperRef(ret);
return RelooperBlockRef(ret);
}

void RelooperAddBranch(RelooperBlockRef from,
Expand Down Expand Up @@ -4554,7 +4554,7 @@ RelooperBlockRef RelooperAddBlockWithSwitch(RelooperRef relooper,
}

R->AddBlock(ret);
return RelooperRef(ret);
return RelooperBlockRef(ret);
}

void RelooperAddBranchForSwitch(RelooperBlockRef from,
Expand Down
37 changes: 28 additions & 9 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
#define BINARYEN_API
#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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down