diff options
-rw-r--r-- | src/binaryen-c.cpp | 39 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 9 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 6 |
3 files changed, 30 insertions, 24 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 20fefece0..89953e0ff 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -93,19 +93,7 @@ BinaryenType BinaryenFloat64(void) { return f64; } BinaryenModuleRef BinaryenModuleCreate(void) { if (tracing) { - std::cout << "// beginning a Binaryen API trace\n"; - std::cout << "#include <math.h>\n"; - std::cout << "#include <map>\n"; - std::cout << "#include \"src/binaryen-c.h\"\n"; - std::cout << "int main() {\n"; - std::cout << " std::map<size_t, BinaryenFunctionTypeRef> functionTypes;\n"; - std::cout << " std::map<size_t, BinaryenExpressionRef> expressions;\n"; - std::cout << " expressions[size_t(NULL)] = BinaryenExpressionRef(NULL);\n"; - std::cout << " std::map<size_t, BinaryenFunctionRef> functions;\n"; - std::cout << " std::map<size_t, RelooperBlockRef> relooperBlocks;\n"; - std::cout << " BinaryenModuleRef the_module = BinaryenModuleCreate();\n"; - std::cout << " RelooperRef the_relooper = NULL;\n"; - expressions[NULL] = 0; + std::cout << " the_module = BinaryenModuleCreate();\n"; } return new Module(); @@ -113,8 +101,6 @@ BinaryenModuleRef BinaryenModuleCreate(void) { void BinaryenModuleDispose(BinaryenModuleRef module) { if (tracing) { std::cout << " BinaryenModuleDispose(the_module);\n"; - std::cout << " return 0;\n"; - std::cout << "}\n"; } delete (Module*)module; @@ -967,6 +953,29 @@ BinaryenExpressionRef RelooperRenderAndDispose(RelooperRef relooper, RelooperBlo void BinaryenSetAPITracing(int on) { tracing = on; + + if (tracing) { + std::cout << "// beginning a Binaryen API trace\n"; + std::cout << "#include <math.h>\n"; + std::cout << "#include <map>\n"; + std::cout << "#include \"src/binaryen-c.h\"\n"; + std::cout << "int main() {\n"; + std::cout << " std::map<size_t, BinaryenFunctionTypeRef> functionTypes;\n"; + std::cout << " std::map<size_t, BinaryenExpressionRef> expressions;\n"; + std::cout << " expressions[size_t(NULL)] = BinaryenExpressionRef(NULL);\n"; + std::cout << " std::map<size_t, BinaryenFunctionRef> functions;\n"; + std::cout << " std::map<size_t, RelooperBlockRef> relooperBlocks;\n"; + std::cout << " BinaryenModuleRef the_module = BinaryenModuleCreate();\n"; + std::cout << " RelooperRef the_relooper = NULL;\n"; + expressions[NULL] = 0; + } else { + std::cout << " return 0;\n"; + std::cout << "}\n"; + functionTypes.clear(); + expressions.clear(); + functions.clear(); + relooperBlocks.clear(); + } } } // extern "C" diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 4f1d839c0..ddfffb0d7 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -53,15 +53,15 @@ BinaryenExpressionRef makeSomething(BinaryenModuleRef module) { // tests -void test_core() { - - // Core types - +void test_types() { printf("BinaryenNone: %d\n", BinaryenNone()); printf("BinaryenInt32: %d\n", BinaryenInt32()); printf("BinaryenInt64: %d\n", BinaryenInt64()); printf("BinaryenFloat32: %d\n", BinaryenFloat32()); printf("BinaryenFloat64: %d\n", BinaryenFloat64()); +} + +void test_core() { // Module creation @@ -507,6 +507,7 @@ void test_tracing() { } int main() { + test_types(); test_core(); test_relooper(); test_binaries(); diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index e6e266f02..9aab653ac 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -817,11 +817,6 @@ module loaded from binary form: ) ) validation: 0 -BinaryenNone: 0 -BinaryenInt32: 1 -BinaryenInt64: 2 -BinaryenFloat32: 3 -BinaryenFloat64: 4 // beginning a Binaryen API trace #include <math.h> #include <map> @@ -834,6 +829,7 @@ int main() { std::map<size_t, RelooperBlockRef> relooperBlocks; BinaryenModuleRef the_module = BinaryenModuleCreate(); RelooperRef the_relooper = NULL; + the_module = BinaryenModuleCreate(); expressions[1] = BinaryenConst(the_module, BinaryenLiteralInt32(1)); expressions[2] = BinaryenConst(the_module, BinaryenLiteralInt64(2)); expressions[3] = BinaryenConst(the_module, BinaryenLiteralFloat32(3.14)); |