Skip to content

Commit

Permalink
add BinaryenExpressionPrint to c api (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken authored Jun 24, 2016
1 parent 51e7034 commit ed4e614
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ BinaryenExpressionRef BinaryenUnreachable(BinaryenModuleRef module) {
return static_cast<Expression*>(((Module*)module)->allocator.alloc<Unreachable>());
}

void BinaryenExpressionPrint(BinaryenExpressionRef expr) {
WasmPrinter::printExpression((Expression*)expr, std::cout);
std::cout << '\n';
}

// Functions

BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module, const char* name, BinaryenFunctionTypeRef type, BinaryenType* localTypes, BinaryenIndex numLocalTypes, BinaryenExpressionRef body) {
Expand Down
5 changes: 4 additions & 1 deletion src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ BinaryenExpressionRef BinaryenHost(BinaryenModuleRef module, BinaryenOp op, cons
BinaryenExpressionRef BinaryenNop(BinaryenModuleRef module);
BinaryenExpressionRef BinaryenUnreachable(BinaryenModuleRef module);

// Print an expression to stdout. Useful for debugging.
void BinaryenExpressionPrint(BinaryenExpressionRef expr);

// Functions

typedef void* BinaryenFunctionRef;
Expand Down Expand Up @@ -324,7 +327,7 @@ void BinaryenSetStart(BinaryenModuleRef module, BinaryenFunctionRef start);
// ========== Module Operations ==========
//

// Print a module to stdout.
// Print a module to stdout. Useful for debugging.
void BinaryenModulePrint(BinaryenModuleRef module);

// Validate a module, showing errors on problems.
Expand Down
2 changes: 2 additions & 0 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ void test_core() {
BinaryenUnreachable(module),
};

BinaryenExpressionPrint(valueList[3]); // test printing a standalone expression

// Make the main body of the function. and one block with a return value, one without
BinaryenExpressionRef value = BinaryenBlock(module, "the-value", valueList, sizeof(valueList) / sizeof(BinaryenExpressionRef));
BinaryenExpressionRef nothing = BinaryenBlock(module, "the-nothing", &value, 1);
Expand Down
3 changes: 3 additions & 0 deletions test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ BinaryenInt32: 1
BinaryenInt64: 2
BinaryenFloat32: 3
BinaryenFloat64: 4
(f32.neg
(f32.const -33.61199951171875)
)
(module
(memory 1 256
(segment 10 "hello, world")
Expand Down

0 comments on commit ed4e614

Please sign in to comment.