diff options
-rw-r--r-- | src/binaryen-c.cpp | 5 | ||||
-rw-r--r-- | src/binaryen-c.h | 5 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 2 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 3 |
4 files changed, 14 insertions, 1 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 5ae3b7a10..4dff289fb 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -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) { diff --git a/src/binaryen-c.h b/src/binaryen-c.h index b9343012c..a587e03ac 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -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; @@ -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. diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index ad499291a..4cbbb8fb5 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -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); diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 52b6cd6ed..a5fa729c8 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -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") |