diff options
35 files changed, 2408 insertions, 1703 deletions
diff --git a/scripts/clang-format-diff.sh b/scripts/clang-format-diff.sh index 01a813f2b..6c7144f58 100755 --- a/scripts/clang-format-diff.sh +++ b/scripts/clang-format-diff.sh @@ -12,13 +12,13 @@ else fi MERGE_BASE=$(git merge-base $BRANCH HEAD) -FORMAT_MSG=$(git clang-format $MERGE_BASE -q --diff -- src/) +FORMAT_MSG=$(git clang-format $MERGE_BASE -q --diff) if [ -n "$FORMAT_MSG" -a "$FORMAT_MSG" != "no modified files to format" ] then echo "Please run git clang-format before committing, or apply this diff:" echo # Run git clang-format again, this time without capruting stdout. This way # clang-format format the message nicely and add color. - git clang-format $MERGE_BASE -q --diff -- src/ + git clang-format $MERGE_BASE -q --diff exit 1 fi diff --git a/test/bigswitch.cpp b/test/bigswitch.cpp index 5b1f1baca..1e22f5c49 100644 --- a/test/bigswitch.cpp +++ b/test/bigswitch.cpp @@ -1,7 +1,9 @@ +#include "SDL/SDL_opengl.h" +#include <SDL.h> #include <stdio.h> #include <stdlib.h> -#include <SDL.h> -#include "SDL/SDL_opengl.h" + +// clang-format off const char *WWWGLEnumToString(GLenum e) { @@ -7943,4 +7945,3 @@ int main() { i = 3060; printf("%d: %s\n", i, WWWGLEnumToString(i)); } - diff --git a/test/calls.cpp b/test/calls.cpp index 0afb0eb69..8226263bc 100644 --- a/test/calls.cpp +++ b/test/calls.cpp @@ -2,23 +2,18 @@ extern "C" { -int inner(int x) { - return x*x + 2; -} +int inner(int x) { return x * x + 2; } -int EMSCRIPTEN_KEEPALIVE simple(int x) { - return inner(x); -} +int EMSCRIPTEN_KEEPALIVE simple(int x) { return inner(x); } int EMSCRIPTEN_KEEPALIVE fibo(int x) { - if (x == 0 || x == 1) return 1; - return fibo(x-1) + fibo(x-2); + if (x == 0 || x == 1) + return 1; + return fibo(x - 1) + fibo(x - 2); } int EMSCRIPTEN_KEEPALIVE run_script() { emscripten_run_script("Module.print('hello from called script')"); return emscripten_run_script_int("1+2+3+4-1"); } - } - diff --git a/test/control_flow.cpp b/test/control_flow.cpp index 504db2646..c2c51b24d 100644 --- a/test/control_flow.cpp +++ b/test/control_flow.cpp @@ -1,23 +1,26 @@ -#include <cmath> #include <algorithm> +#include <cmath> #include <emscripten.h> extern "C" { int EMSCRIPTEN_KEEPALIVE check_if(int x) { - if (x < 10) x++; + if (x < 10) + x++; return x; } int EMSCRIPTEN_KEEPALIVE check_loop(int x) { - while (x < 100) x *= 2; + while (x < 100) + x *= 2; return x; } int EMSCRIPTEN_KEEPALIVE check_loop_break(int x) { while (x < 100) { x *= 2; - if (x > 30) break; + if (x > 30) + break; x++; } return x; @@ -26,7 +29,8 @@ int EMSCRIPTEN_KEEPALIVE check_loop_break(int x) { int EMSCRIPTEN_KEEPALIVE check_loop_continue(int x) { while (x < 100) { x *= 2; - if (x > 30) continue; + if (x > 30) + continue; x++; } return x; @@ -35,9 +39,11 @@ int EMSCRIPTEN_KEEPALIVE check_loop_continue(int x) { int EMSCRIPTEN_KEEPALIVE check_do_loop(int x) { do { x *= 2; - if (x > 1000) break; + if (x > 1000) + break; x--; - if (x > 30) continue; + if (x > 30) + continue; x++; } while (x < 100); return x; @@ -46,9 +52,11 @@ int EMSCRIPTEN_KEEPALIVE check_do_loop(int x) { int EMSCRIPTEN_KEEPALIVE check_do_once(int x) { do { x *= 2; - if (x > 1000) break; + if (x > 1000) + break; x--; - if (x > 30) continue; + if (x > 30) + continue; x++; } while (0); return x; @@ -57,9 +65,11 @@ int EMSCRIPTEN_KEEPALIVE check_do_once(int x) { int EMSCRIPTEN_KEEPALIVE check_while_forever(int x) { while (1) { x *= 2; - if (x > 1000) break; + if (x > 1000) + break; x--; - if (x > 30) continue; + if (x > 30) + continue; x++; } return x; @@ -67,51 +77,72 @@ int EMSCRIPTEN_KEEPALIVE check_while_forever(int x) { int EMSCRIPTEN_KEEPALIVE check_switch(int x) { switch (x) { - case 1: return 10; - case 3: return 20; - case 5: return 30; - case 10: return 40; - case 11: return 50; - default: return 60; + case 1: + return 10; + case 3: + return 20; + case 5: + return 30; + case 10: + return 40; + case 11: + return 50; + default: + return 60; } return 70; } int EMSCRIPTEN_KEEPALIVE check_switch_nodefault(int x) { switch (x) { - case 1: return 10; - case 3: return 20; - case 5: return 30; - case 10: return 40; - case 11: return 50; + case 1: + return 10; + case 3: + return 20; + case 5: + return 30; + case 10: + return 40; + case 11: + return 50; } return 70; } int EMSCRIPTEN_KEEPALIVE check_switch_rdefault(int x) { switch (x) { - default: return -60; - case 1: return 10; - case 3: return 20; - case 5: return 30; - case 10: return 40; - case 11: return 50; + default: + return -60; + case 1: + return 10; + case 3: + return 20; + case 5: + return 30; + case 10: + return 40; + case 11: + return 50; } return 70; } int EMSCRIPTEN_KEEPALIVE check_switch_fallthrough(int x) { switch (x) { - case 1: return 10; + case 1: + return 10; case 2: - case 3: x++; - case 5: return x; - case 10: return 40; - case 11: return 50; - default: return 60; + case 3: + x++; + case 5: + return x; + case 10: + return 40; + case 11: + return 50; + default: + return 60; } return 70; } - } - diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 67a3a7b26..5db1d28dc 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -12,41 +12,73 @@ // kitchen sink, tests the full API - // helpers -static const uint8_t v128_bytes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - -BinaryenExpressionRef makeUnary(BinaryenModuleRef module, BinaryenOp op, BinaryenType inputType) { - if (inputType == BinaryenTypeInt32()) return BinaryenUnary(module, op, BinaryenConst(module, BinaryenLiteralInt32(-10))); - if (inputType == BinaryenTypeInt64()) return BinaryenUnary(module, op, BinaryenConst(module, BinaryenLiteralInt64(-22))); - if (inputType == BinaryenTypeFloat32()) return BinaryenUnary(module, op, BinaryenConst(module, BinaryenLiteralFloat32(-33.612f))); - if (inputType == BinaryenTypeFloat64()) return BinaryenUnary(module, op, BinaryenConst(module, BinaryenLiteralFloat64(-9005.841))); - if (inputType == BinaryenTypeVec128()) return BinaryenUnary(module, op, BinaryenConst(module, BinaryenLiteralVec128(v128_bytes))); +static const uint8_t v128_bytes[] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + +BinaryenExpressionRef +makeUnary(BinaryenModuleRef module, BinaryenOp op, BinaryenType inputType) { + if (inputType == BinaryenTypeInt32()) + return BinaryenUnary( + module, op, BinaryenConst(module, BinaryenLiteralInt32(-10))); + if (inputType == BinaryenTypeInt64()) + return BinaryenUnary( + module, op, BinaryenConst(module, BinaryenLiteralInt64(-22))); + if (inputType == BinaryenTypeFloat32()) + return BinaryenUnary( + module, op, BinaryenConst(module, BinaryenLiteralFloat32(-33.612f))); + if (inputType == BinaryenTypeFloat64()) + return BinaryenUnary( + module, op, BinaryenConst(module, BinaryenLiteralFloat64(-9005.841))); + if (inputType == BinaryenTypeVec128()) + return BinaryenUnary( + module, op, BinaryenConst(module, BinaryenLiteralVec128(v128_bytes))); abort(); } -BinaryenExpressionRef makeBinary(BinaryenModuleRef module, BinaryenOp op, BinaryenType type) { +BinaryenExpressionRef +makeBinary(BinaryenModuleRef module, BinaryenOp op, BinaryenType type) { if (type == BinaryenTypeInt32()) { - // use temp vars to ensure optimization doesn't change the order of operation in our trace recording - BinaryenExpressionRef temp = BinaryenConst(module, BinaryenLiteralInt32(-11)); - return BinaryenBinary(module, op, BinaryenConst(module, BinaryenLiteralInt32(-10)), temp); + // use temp vars to ensure optimization doesn't change the order of + // operation in our trace recording + BinaryenExpressionRef temp = + BinaryenConst(module, BinaryenLiteralInt32(-11)); + return BinaryenBinary( + module, op, BinaryenConst(module, BinaryenLiteralInt32(-10)), temp); } if (type == BinaryenTypeInt64()) { - BinaryenExpressionRef temp = BinaryenConst(module, BinaryenLiteralInt64(-23)); - return BinaryenBinary(module, op, BinaryenConst(module, BinaryenLiteralInt64(-22)), temp); + BinaryenExpressionRef temp = + BinaryenConst(module, BinaryenLiteralInt64(-23)); + return BinaryenBinary( + module, op, BinaryenConst(module, BinaryenLiteralInt64(-22)), temp); } if (type == BinaryenTypeFloat32()) { - BinaryenExpressionRef temp = BinaryenConst(module, BinaryenLiteralFloat32(-62.5f)); - return BinaryenBinary(module, op, BinaryenConst(module, BinaryenLiteralFloat32(-33.612f)), temp); + BinaryenExpressionRef temp = + BinaryenConst(module, BinaryenLiteralFloat32(-62.5f)); + return BinaryenBinary( + module, + op, + BinaryenConst(module, BinaryenLiteralFloat32(-33.612f)), + temp); } if (type == BinaryenTypeFloat64()) { - BinaryenExpressionRef temp = BinaryenConst(module, BinaryenLiteralFloat64(-9007.333)); - return BinaryenBinary(module, op, BinaryenConst(module, BinaryenLiteralFloat64(-9005.841)), temp); + BinaryenExpressionRef temp = + BinaryenConst(module, BinaryenLiteralFloat64(-9007.333)); + return BinaryenBinary( + module, + op, + BinaryenConst(module, BinaryenLiteralFloat64(-9005.841)), + temp); } if (type == BinaryenTypeVec128()) { - BinaryenExpressionRef temp = BinaryenConst(module, BinaryenLiteralVec128(v128_bytes)); - return BinaryenBinary(module, op, BinaryenConst(module, BinaryenLiteralVec128(v128_bytes)), temp); + BinaryenExpressionRef temp = + BinaryenConst(module, BinaryenLiteralVec128(v128_bytes)); + return BinaryenBinary( + module, + op, + BinaryenConst(module, BinaryenLiteralVec128(v128_bytes)), + temp); } abort(); } @@ -67,7 +99,8 @@ BinaryenExpressionRef makeFloat64(BinaryenModuleRef module, double x) { return BinaryenConst(module, BinaryenLiteralFloat64(x)); } -BinaryenExpressionRef makeVec128(BinaryenModuleRef module, uint8_t const *bytes) { +BinaryenExpressionRef makeVec128(BinaryenModuleRef module, + uint8_t const* bytes) { return BinaryenConst(module, BinaryenLiteralVec128(bytes)); } @@ -83,7 +116,8 @@ BinaryenExpressionRef makeSIMDExtract(BinaryenModuleRef module, BinaryenOp op) { return BinaryenSIMDExtract(module, op, makeVec128(module, v128_bytes), 0); } -BinaryenExpressionRef makeSIMDReplace(BinaryenModuleRef module, BinaryenOp op, BinaryenType type) { +BinaryenExpressionRef +makeSIMDReplace(BinaryenModuleRef module, BinaryenOp op, BinaryenType type) { BinaryenExpressionRef val; if (type == BinaryenTypeInt32()) { val = makeInt32(module, 42); @@ -100,13 +134,14 @@ BinaryenExpressionRef makeSIMDReplace(BinaryenModuleRef module, BinaryenOp op, B if (!val) { abort(); } - return BinaryenSIMDReplace(module, op, makeVec128(module, v128_bytes), 0, val); + return BinaryenSIMDReplace( + module, op, makeVec128(module, v128_bytes), 0, val); } BinaryenExpressionRef makeSIMDShuffle(BinaryenModuleRef module) { BinaryenExpressionRef left = makeVec128(module, v128_bytes); BinaryenExpressionRef right = makeVec128(module, v128_bytes); - return BinaryenSIMDShuffle(module, left, right, (uint8_t[16]) {}); + return BinaryenSIMDShuffle(module, left, right, (uint8_t[16]){}); } BinaryenExpressionRef makeSIMDTernary(BinaryenModuleRef module, BinaryenOp op) { @@ -251,13 +286,17 @@ void test_features() { printf("BinaryenFeatureMVP: %d\n", BinaryenFeatureMVP()); printf("BinaryenFeatureAtomics: %d\n", BinaryenFeatureAtomics()); printf("BinaryenFeatureBulkMemory: %d\n", BinaryenFeatureBulkMemory()); - printf("BinaryenFeatureMutableGlobals: %d\n", BinaryenFeatureMutableGlobals()); - printf("BinaryenFeatureNontrappingFPToInt: %d\n", BinaryenFeatureNontrappingFPToInt()); + printf("BinaryenFeatureMutableGlobals: %d\n", + BinaryenFeatureMutableGlobals()); + printf("BinaryenFeatureNontrappingFPToInt: %d\n", + BinaryenFeatureNontrappingFPToInt()); printf("BinaryenFeatureSignExt: %d\n", BinaryenFeatureSignExt()); printf("BinaryenFeatureSIMD128: %d\n", BinaryenFeatureSIMD128()); - printf("BinaryenFeatureExceptionHandling: %d\n", BinaryenFeatureExceptionHandling()); + printf("BinaryenFeatureExceptionHandling: %d\n", + BinaryenFeatureExceptionHandling()); printf("BinaryenFeatureTailCall: %d\n", BinaryenFeatureTailCall()); - printf("BinaryenFeatureReferenceTypes: %d\n", BinaryenFeatureReferenceTypes()); + printf("BinaryenFeatureReferenceTypes: %d\n", + BinaryenFeatureReferenceTypes()); printf("BinaryenFeatureMultivalue: %d\n", BinaryenFeatureMultivalue()); printf("BinaryenFeatureGC: %d\n", BinaryenFeatureGC()); printf("BinaryenFeatureMemory64: %d\n", BinaryenFeatureMemory64()); @@ -275,20 +314,30 @@ void test_core() { // Literals and consts - BinaryenExpressionRef constI32 = BinaryenConst(module, BinaryenLiteralInt32(1)), - constI64 = BinaryenConst(module, BinaryenLiteralInt64(2)), - constF32 = BinaryenConst(module, BinaryenLiteralFloat32(3.14f)), - constF64 = BinaryenConst(module, BinaryenLiteralFloat64(2.1828)), - constF32Bits = BinaryenConst(module, BinaryenLiteralFloat32Bits(0xffff1234)), - constF64Bits = BinaryenConst(module, BinaryenLiteralFloat64Bits(0xffff12345678abcdLL)), - constV128 = BinaryenConst(module, BinaryenLiteralVec128(v128_bytes)); - - const char* switchValueNames[] = { "the-value" }; - const char* switchBodyNames[] = { "the-nothing" }; - - BinaryenExpressionRef callOperands2[] = { makeInt32(module, 13), makeFloat64(module, 3.7) }; - BinaryenExpressionRef callOperands4[] = { makeInt32(module, 13), makeInt64(module, 37), makeFloat32(module, 1.3f), makeFloat64(module, 3.7) }; - BinaryenExpressionRef callOperands4b[] = { makeInt32(module, 13), makeInt64(module, 37), makeFloat32(module, 1.3f), makeFloat64(module, 3.7) }; + BinaryenExpressionRef + constI32 = BinaryenConst(module, BinaryenLiteralInt32(1)), + constI64 = BinaryenConst(module, BinaryenLiteralInt64(2)), + constF32 = BinaryenConst(module, BinaryenLiteralFloat32(3.14f)), + constF64 = BinaryenConst(module, BinaryenLiteralFloat64(2.1828)), + constF32Bits = + BinaryenConst(module, BinaryenLiteralFloat32Bits(0xffff1234)), + constF64Bits = + BinaryenConst(module, BinaryenLiteralFloat64Bits(0xffff12345678abcdLL)), + constV128 = BinaryenConst(module, BinaryenLiteralVec128(v128_bytes)); + + const char* switchValueNames[] = {"the-value"}; + const char* switchBodyNames[] = {"the-nothing"}; + + BinaryenExpressionRef callOperands2[] = {makeInt32(module, 13), + makeFloat64(module, 3.7)}; + BinaryenExpressionRef callOperands4[] = {makeInt32(module, 13), + makeInt64(module, 37), + makeFloat32(module, 1.3f), + makeFloat64(module, 3.7)}; + BinaryenExpressionRef callOperands4b[] = {makeInt32(module, 13), + makeInt64(module, 37), + makeFloat32(module, 1.3f), + makeFloat64(module, 3.7)}; BinaryenExpressionRef tupleElements4a[] = {makeInt32(module, 13), makeInt64(module, 37), makeFloat32(module, 1.3f), @@ -304,18 +353,30 @@ void test_core() { BinaryenTypeFloat64()}; BinaryenType iIfF = BinaryenTypeCreate(iIfF_, 4); - BinaryenExpressionRef temp1 = makeInt32(module, 1), temp2 = makeInt32(module, 2), temp3 = makeInt32(module, 3), - temp4 = makeInt32(module, 4), temp5 = makeInt32(module, 5), - temp6 = makeInt32(module, 0), temp7 = makeInt32(module, 1), - temp8 = makeInt32(module, 0), temp9 = makeInt32(module, 1), - temp10 = makeInt32(module, 1), temp11 = makeInt32(module, 3), temp12 = makeInt32(module, 5), - temp13 = makeInt32(module, 10), temp14 = makeInt32(module, 11), - temp15 = makeInt32(module, 110), temp16 = makeInt64(module, 111); - BinaryenExpressionRef externrefExpr = BinaryenRefNull(module, BinaryenTypeExternref()); - BinaryenExpressionRef funcrefExpr = BinaryenRefNull(module, BinaryenTypeFuncref()); + BinaryenExpressionRef temp1 = makeInt32(module, 1), + temp2 = makeInt32(module, 2), + temp3 = makeInt32(module, 3), + temp4 = makeInt32(module, 4), + temp5 = makeInt32(module, 5), + temp6 = makeInt32(module, 0), + temp7 = makeInt32(module, 1), + temp8 = makeInt32(module, 0), + temp9 = makeInt32(module, 1), + temp10 = makeInt32(module, 1), + temp11 = makeInt32(module, 3), + temp12 = makeInt32(module, 5), + temp13 = makeInt32(module, 10), + temp14 = makeInt32(module, 11), + temp15 = makeInt32(module, 110), + temp16 = makeInt64(module, 111); + BinaryenExpressionRef externrefExpr = + BinaryenRefNull(module, BinaryenTypeExternref()); + BinaryenExpressionRef funcrefExpr = + BinaryenRefNull(module, BinaryenTypeFuncref()); funcrefExpr = BinaryenRefFunc(module, "kitchen()sinker", BinaryenTypeFuncref()); - BinaryenExpressionRef i31refExpr = BinaryenI31New(module, makeInt32(module, 1)); + BinaryenExpressionRef i31refExpr = + BinaryenI31New(module, makeInt32(module, 1)); // Tags BinaryenAddTag(module, "a-tag", BinaryenTypeInt32(), BinaryenTypeNone()); @@ -893,9 +954,11 @@ void test_core() { BinaryenUnreachable(module), }; - BinaryenExpressionPrint(valueList[3]); // test printing a standalone expression + BinaryenExpressionPrint( + valueList[3]); // test printing a standalone expression - // Make the main body of the function. and one block with a return value, one without + // Make the main body of the function. and one block with a return value, one + // without BinaryenExpressionRef value = BinaryenBlock(module, "the-value", @@ -903,8 +966,9 @@ void test_core() { sizeof(valueList) / sizeof(BinaryenExpressionRef), BinaryenTypeAuto()); BinaryenExpressionRef droppedValue = BinaryenDrop(module, value); - BinaryenExpressionRef nothing = BinaryenBlock(module, "the-nothing", &droppedValue, 1, -1); - BinaryenExpressionRef bodyList[] = { nothing, makeInt32(module, 42) }; + BinaryenExpressionRef nothing = + BinaryenBlock(module, "the-nothing", &droppedValue, 1, -1); + BinaryenExpressionRef bodyList[] = {nothing, makeInt32(module, 42)}; BinaryenExpressionRef body = BinaryenBlock(module, "the-body", bodyList, 2, BinaryenTypeAuto()); @@ -915,8 +979,13 @@ void test_core() { // Globals - BinaryenAddGlobal(module, "a-global", BinaryenTypeInt32(), 0, makeInt32(module, 7)); - BinaryenAddGlobal(module, "a-mutable-global", BinaryenTypeFloat32(), 1, makeFloat32(module, 7.5)); + BinaryenAddGlobal( + module, "a-global", BinaryenTypeInt32(), 0, makeInt32(module, 7)); + BinaryenAddGlobal(module, + "a-mutable-global", + BinaryenTypeFloat32(), + 1, + makeFloat32(module, 7.5)); // Imports @@ -930,7 +999,7 @@ void test_core() { BinaryenAddFunctionExport(module, "kitchen()sinker", "kitchen_sinker"); // Function table. One per module - const char* funcNames[] = { BinaryenFunctionGetName(sinker) }; + const char* funcNames[] = {BinaryenFunctionGetName(sinker)}; BinaryenAddTable(module, "0", 1, 1, BinaryenTypeFuncref()); BinaryenAddActiveElementSegment( module, @@ -945,11 +1014,21 @@ void test_core() { // Memory. One per module - const char* segments[] = { "hello, world", "I am passive" }; + const char* segments[] = {"hello, world", "I am passive"}; bool segmentPassive[] = {false, true}; - BinaryenExpressionRef segmentOffsets[] = { BinaryenConst(module, BinaryenLiteralInt32(10)), NULL }; - BinaryenIndex segmentSizes[] = { 12, 12 }; - BinaryenSetMemory(module, 1, 256, "mem", segments, segmentPassive, segmentOffsets, segmentSizes, 2, 1); + BinaryenExpressionRef segmentOffsets[] = { + BinaryenConst(module, BinaryenLiteralInt32(10)), NULL}; + BinaryenIndex segmentSizes[] = {12, 12}; + BinaryenSetMemory(module, + 1, + 256, + "mem", + segments, + segmentPassive, + segmentOffsets, + segmentSizes, + 2, + 1); // Start function. One per module @@ -1002,13 +1081,13 @@ void test_unreachable() { } BinaryenExpressionRef makeCallCheck(BinaryenModuleRef module, int x) { - BinaryenExpressionRef callOperands[] = { makeInt32(module, x) }; + BinaryenExpressionRef callOperands[] = {makeInt32(module, x)}; return BinaryenCall(module, "check", callOperands, 1, BinaryenTypeNone()); } void test_relooper() { BinaryenModuleRef module = BinaryenModuleCreate(); - BinaryenType localTypes[] = { BinaryenTypeInt32() }; + BinaryenType localTypes[] = {BinaryenTypeInt32()}; BinaryenAddFunctionImport(module, "check", @@ -1019,7 +1098,8 @@ void test_relooper() { { // trivial: just one block RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block = RelooperAddBlock(relooper, makeCallCheck(module, 1337)); + RelooperBlockRef block = + RelooperAddBlock(relooper, makeCallCheck(module, 1337)); BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block, 0); BinaryenFunctionRef sinker = BinaryenAddFunction(module, "just-one-block", @@ -1031,9 +1111,12 @@ void test_relooper() { } { // two blocks RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperAddBranch(block0, block1, NULL, NULL); // no condition, no code on branch + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperAddBranch( + block0, block1, NULL, NULL); // no condition, no code on branch BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0); BinaryenFunctionRef sinker = BinaryenAddFunction(module, "two-blocks", @@ -1045,9 +1128,12 @@ void test_relooper() { } { // two blocks with code between them RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperAddBranch(block0, block1, NULL, makeDroppedInt32(module, 77)); // code on branch + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperAddBranch( + block0, block1, NULL, makeDroppedInt32(module, 77)); // code on branch BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0); BinaryenFunctionRef sinker = BinaryenAddFunction(module, "two-blocks-plus-code", @@ -1059,8 +1145,10 @@ void test_relooper() { } { // two blocks in a loop RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); RelooperAddBranch(block0, block1, NULL, NULL); RelooperAddBranch(block1, block0, NULL, NULL); BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0); @@ -1074,8 +1162,10 @@ void test_relooper() { } { // two blocks in a loop with codes RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); RelooperAddBranch(block0, block1, NULL, makeDroppedInt32(module, 33)); RelooperAddBranch(block1, block0, NULL, makeDroppedInt32(module, -66)); BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0); @@ -1089,9 +1179,12 @@ void test_relooper() { } { // split RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperBlockRef block2 = RelooperAddBlock(relooper, makeCallCheck(module, 2)); + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block2 = + RelooperAddBlock(relooper, makeCallCheck(module, 2)); RelooperAddBranch(block0, block1, makeInt32(module, 55), NULL); RelooperAddBranch(block0, block2, NULL, NULL); BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0); @@ -1105,9 +1198,12 @@ void test_relooper() { } { // split + code RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperBlockRef block2 = RelooperAddBlock(relooper, makeCallCheck(module, 2)); + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block2 = + RelooperAddBlock(relooper, makeCallCheck(module, 2)); BinaryenExpressionRef temp = makeDroppedInt32(module, 10); RelooperAddBranch(block0, block1, makeInt32(module, 55), temp); RelooperAddBranch(block0, block2, NULL, makeDroppedInt32(module, 20)); @@ -1122,9 +1218,12 @@ void test_relooper() { } { // if RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperBlockRef block2 = RelooperAddBlock(relooper, makeCallCheck(module, 2)); + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block2 = + RelooperAddBlock(relooper, makeCallCheck(module, 2)); RelooperAddBranch(block0, block1, makeInt32(module, 55), NULL); RelooperAddBranch(block0, block2, NULL, NULL); RelooperAddBranch(block1, block2, NULL, NULL); @@ -1139,9 +1238,12 @@ void test_relooper() { } { // if + code RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperBlockRef block2 = RelooperAddBlock(relooper, makeCallCheck(module, 2)); + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block2 = + RelooperAddBlock(relooper, makeCallCheck(module, 2)); BinaryenExpressionRef temp = makeDroppedInt32(module, -1); RelooperAddBranch(block0, block1, makeInt32(module, 55), temp); RelooperAddBranch(block0, block2, NULL, makeDroppedInt32(module, -2)); @@ -1157,10 +1259,14 @@ void test_relooper() { } { // if-else RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperBlockRef block2 = RelooperAddBlock(relooper, makeCallCheck(module, 2)); - RelooperBlockRef block3 = RelooperAddBlock(relooper, makeCallCheck(module, 3)); + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block2 = + RelooperAddBlock(relooper, makeCallCheck(module, 2)); + RelooperBlockRef block3 = + RelooperAddBlock(relooper, makeCallCheck(module, 3)); RelooperAddBranch(block0, block1, makeInt32(module, 55), NULL); RelooperAddBranch(block0, block2, NULL, NULL); RelooperAddBranch(block1, block3, NULL, NULL); @@ -1176,9 +1282,12 @@ void test_relooper() { } { // loop+tail RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperBlockRef block2 = RelooperAddBlock(relooper, makeCallCheck(module, 2)); + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block2 = + RelooperAddBlock(relooper, makeCallCheck(module, 2)); RelooperAddBranch(block0, block1, NULL, NULL); RelooperAddBranch(block1, block0, makeInt32(module, 10), NULL); RelooperAddBranch(block1, block2, NULL, NULL); @@ -1193,13 +1302,20 @@ void test_relooper() { } { // nontrivial loop + phi to head RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperBlockRef block2 = RelooperAddBlock(relooper, makeCallCheck(module, 2)); - RelooperBlockRef block3 = RelooperAddBlock(relooper, makeCallCheck(module, 3)); - RelooperBlockRef block4 = RelooperAddBlock(relooper, makeCallCheck(module, 4)); - RelooperBlockRef block5 = RelooperAddBlock(relooper, makeCallCheck(module, 5)); - RelooperBlockRef block6 = RelooperAddBlock(relooper, makeCallCheck(module, 6)); + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block2 = + RelooperAddBlock(relooper, makeCallCheck(module, 2)); + RelooperBlockRef block3 = + RelooperAddBlock(relooper, makeCallCheck(module, 3)); + RelooperBlockRef block4 = + RelooperAddBlock(relooper, makeCallCheck(module, 4)); + RelooperBlockRef block5 = + RelooperAddBlock(relooper, makeCallCheck(module, 5)); + RelooperBlockRef block6 = + RelooperAddBlock(relooper, makeCallCheck(module, 6)); RelooperAddBranch(block0, block1, NULL, makeDroppedInt32(module, 10)); RelooperAddBranch(block1, block2, makeInt32(module, -2), NULL); RelooperAddBranch(block1, block6, NULL, makeDroppedInt32(module, 20)); @@ -1222,17 +1338,24 @@ void test_relooper() { { // switch RelooperRef relooper = RelooperCreate(module); BinaryenExpressionRef temp = makeInt32(module, -99); - RelooperBlockRef block0 = RelooperAddBlockWithSwitch(relooper, makeCallCheck(module, 0), temp); - // TODO: this example is not very good, the blocks should end in a |return| as otherwise they - // fall through to each other. A relooper block should end in something that stops control - // flow, if it doesn't have branches going out - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperBlockRef block2 = RelooperAddBlock(relooper, makeCallCheck(module, 2)); - RelooperBlockRef block3 = RelooperAddBlock(relooper, makeCallCheck(module, 3)); - BinaryenIndex to_block1[] = { 2, 5 }; + RelooperBlockRef block0 = + RelooperAddBlockWithSwitch(relooper, makeCallCheck(module, 0), temp); + // TODO: this example is not very good, the blocks should end in a |return| + // as otherwise they + // fall through to each other. A relooper block should end in + // something that stops control flow, if it doesn't have branches + // going out + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block2 = + RelooperAddBlock(relooper, makeCallCheck(module, 2)); + RelooperBlockRef block3 = + RelooperAddBlock(relooper, makeCallCheck(module, 3)); + BinaryenIndex to_block1[] = {2, 5}; RelooperAddBranchForSwitch(block0, block1, to_block1, 2, NULL); - BinaryenIndex to_block2[] = { 4 }; - RelooperAddBranchForSwitch(block0, block2, to_block2, 1, makeDroppedInt32(module, 55)); + BinaryenIndex to_block2[] = {4}; + RelooperAddBranchForSwitch( + block0, block2, to_block2, 1, makeDroppedInt32(module, 55)); RelooperAddBranchForSwitch(block0, block3, NULL, 0, NULL); BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0); BinaryenFunctionRef sinker = BinaryenAddFunction(module, @@ -1245,15 +1368,25 @@ void test_relooper() { } { // duff's device RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef block0 = RelooperAddBlock(relooper, makeCallCheck(module, 0)); - RelooperBlockRef block1 = RelooperAddBlock(relooper, makeCallCheck(module, 1)); - RelooperBlockRef block2 = RelooperAddBlock(relooper, makeCallCheck(module, 2)); + RelooperBlockRef block0 = + RelooperAddBlock(relooper, makeCallCheck(module, 0)); + RelooperBlockRef block1 = + RelooperAddBlock(relooper, makeCallCheck(module, 1)); + RelooperBlockRef block2 = + RelooperAddBlock(relooper, makeCallCheck(module, 2)); RelooperAddBranch(block0, block1, makeInt32(module, 10), NULL); RelooperAddBranch(block0, block2, NULL, NULL); RelooperAddBranch(block1, block2, NULL, NULL); RelooperAddBranch(block2, block1, NULL, NULL); - BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 3); // use $3 as the helper var - BinaryenType localTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32(), BinaryenTypeInt64(), BinaryenTypeInt32(), BinaryenTypeFloat32(), BinaryenTypeFloat64(), BinaryenTypeInt32() }; + BinaryenExpressionRef body = + RelooperRenderAndDispose(relooper, block0, 3); // use $3 as the helper var + BinaryenType localTypes[] = {BinaryenTypeInt32(), + BinaryenTypeInt32(), + BinaryenTypeInt64(), + BinaryenTypeInt32(), + BinaryenTypeFloat32(), + BinaryenTypeFloat64(), + BinaryenTypeInt32()}; BinaryenFunctionRef sinker = BinaryenAddFunction(module, "duffs-device", @@ -1266,8 +1399,11 @@ void test_relooper() { { // return in a block RelooperRef relooper = RelooperCreate(module); - BinaryenExpressionRef listList[] = { makeCallCheck(module, 42), BinaryenReturn(module, makeInt32(module, 1337)) }; - BinaryenExpressionRef list = BinaryenBlock(module, "the-list", listList, 2, -1); + BinaryenExpressionRef listList[] = { + makeCallCheck(module, 42), + BinaryenReturn(module, makeInt32(module, 1337))}; + BinaryenExpressionRef list = + BinaryenBlock(module, "the-list", listList, 2, -1); RelooperBlockRef block = RelooperAddBlock(relooper, list); BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block, 0); BinaryenFunctionRef sinker = BinaryenAddFunction(module, @@ -1304,10 +1440,11 @@ void test_binaries() { BinaryenType ii = BinaryenTypeCreate(ii_, 2); BinaryenExpressionRef x = BinaryenLocalGet(module, 0, BinaryenTypeInt32()), y = BinaryenLocalGet(module, 1, BinaryenTypeInt32()); - BinaryenExpressionRef add = BinaryenBinary(module, BinaryenAddInt32(), x, y); + BinaryenExpressionRef add = + BinaryenBinary(module, BinaryenAddInt32(), x, y); BinaryenFunctionRef adder = BinaryenAddFunction( module, "adder", ii, BinaryenTypeInt32(), NULL, 0, add); - BinaryenSetDebugInfo(1); // include names section + BinaryenSetDebugInfo(1); // include names section size = BinaryenModuleWrite(module, buffer, 1024); // write out the module BinaryenSetDebugInfo(0); BinaryenModuleDispose(module); @@ -1328,22 +1465,21 @@ void test_binaries() { BinaryenModuleWriteText(module, buffer, 1024); printf("module s-expr printed (in memory):\n%s\n", buffer); - // writ the s-expr representation to a pointer which is managed by the // caller - char *text = BinaryenModuleAllocateAndWriteText(module); + char* text = BinaryenModuleAllocateAndWriteText(module); printf("module s-expr printed (in memory, caller-owned):\n%s\n", text); free(text); - BinaryenModuleDispose(module); } void test_interpret() { - // create a simple module with a start method that prints a number, and interpret it, printing that number. + // create a simple module with a start method that prints a number, and + // interpret it, printing that number. BinaryenModuleRef module = BinaryenModuleCreate(); - BinaryenType iparams[2] = { BinaryenTypeInt32() }; + BinaryenType iparams[2] = {BinaryenTypeInt32()}; BinaryenAddFunctionImport(module, "print-i32", "spectest", @@ -1351,8 +1487,9 @@ void test_interpret() { BinaryenTypeInt32(), BinaryenTypeNone()); - BinaryenExpressionRef callOperands[] = { makeInt32(module, 1234) }; - BinaryenExpressionRef call = BinaryenCall(module, "print-i32", callOperands, 1, BinaryenTypeNone()); + BinaryenExpressionRef callOperands[] = {makeInt32(module, 1234)}; + BinaryenExpressionRef call = + BinaryenCall(module, "print-i32", callOperands, 1, BinaryenTypeNone()); BinaryenFunctionRef starter = BinaryenAddFunction( module, "starter", BinaryenTypeNone(), BinaryenTypeNone(), NULL, 0, call); BinaryenSetStart(module, starter); @@ -1368,7 +1505,7 @@ void test_nonvalid() { { BinaryenModuleRef module = BinaryenModuleCreate(); - BinaryenType localTypes[] = { BinaryenTypeInt32() }; + BinaryenType localTypes[] = {BinaryenTypeInt32()}; BinaryenFunctionRef func = BinaryenAddFunction( module, "func", @@ -1387,18 +1524,18 @@ void test_nonvalid() { } void test_color_status() { - int i; + int i; - // save old state - const int old_state = BinaryenAreColorsEnabled(); + // save old state + const int old_state = BinaryenAreColorsEnabled(); - // Check that we can set the state to both {0, 1} - for(i = 0; i <= 1; i++){ - BinaryenSetColorsEnabled(i); - assert(BinaryenAreColorsEnabled() == i); - } + // Check that we can set the state to both {0, 1} + for (i = 0; i <= 1; i++) { + BinaryenSetColorsEnabled(i); + assert(BinaryenAreColorsEnabled() == i); + } - BinaryenSetColorsEnabled(old_state); + BinaryenSetColorsEnabled(old_state); } void test_for_each() { @@ -1428,7 +1565,7 @@ void test_for_each() { 0, BinaryenNop(module)); { - for (i = 0; i < BinaryenGetNumFunctions(module) ; i++) { + for (i = 0; i < BinaryenGetNumFunctions(module); i++) { assert(BinaryenGetFunctionByIndex(module, i) == fns[i]); } @@ -1437,37 +1574,49 @@ void test_for_each() { exps[1] = BinaryenAddFunctionExport(module, "fn1", "export1"); exps[2] = BinaryenAddFunctionExport(module, "fn2", "export2"); - for (i = 0; i < BinaryenGetNumExports(module) ; i++) { + for (i = 0; i < BinaryenGetNumExports(module); i++) { assert(BinaryenGetExportByIndex(module, i) == exps[i]); } - const char* segments[] = { "hello, world", "segment data 2" }; - const uint32_t expected_offsets[] = { 10, 125 }; + const char* segments[] = {"hello, world", "segment data 2"}; + const uint32_t expected_offsets[] = {10, 125}; bool segmentPassive[] = {false, false}; - BinaryenIndex segmentSizes[] = { 12, 14 }; + BinaryenIndex segmentSizes[] = {12, 14}; BinaryenExpressionRef segmentOffsets[] = { BinaryenConst(module, BinaryenLiteralInt32(expected_offsets[0])), - BinaryenGlobalGet(module, "a-global", BinaryenTypeInt32()) - }; - BinaryenSetMemory(module, 1, 256, "mem", segments, segmentPassive, segmentOffsets, segmentSizes, 2, 0); - BinaryenAddGlobal(module, "a-global", BinaryenTypeInt32(), 0, makeInt32(module, expected_offsets[1])); - - for (i = 0; i < BinaryenGetNumMemorySegments(module) ; i++) { + BinaryenGlobalGet(module, "a-global", BinaryenTypeInt32())}; + BinaryenSetMemory(module, + 1, + 256, + "mem", + segments, + segmentPassive, + segmentOffsets, + segmentSizes, + 2, + 0); + BinaryenAddGlobal(module, + "a-global", + BinaryenTypeInt32(), + 0, + makeInt32(module, expected_offsets[1])); + + for (i = 0; i < BinaryenGetNumMemorySegments(module); i++) { char out[15] = {}; - assert(BinaryenGetMemorySegmentByteOffset(module, i) == expected_offsets[i]); + assert(BinaryenGetMemorySegmentByteOffset(module, i) == + expected_offsets[i]); assert(BinaryenGetMemorySegmentByteLength(module, i) == segmentSizes[i]); BinaryenCopyMemorySegmentData(module, i, out); assert(0 == strcmp(segments[i], out)); } } { - const char* funcNames[] = { - BinaryenFunctionGetName(fns[0]), - BinaryenFunctionGetName(fns[1]), - BinaryenFunctionGetName(fns[2]) - }; - BinaryenExpressionRef constExprRef = BinaryenConst(module, BinaryenLiteralInt32(0)); + const char* funcNames[] = {BinaryenFunctionGetName(fns[0]), + BinaryenFunctionGetName(fns[1]), + BinaryenFunctionGetName(fns[2])}; + BinaryenExpressionRef constExprRef = + BinaryenConst(module, BinaryenLiteralInt32(0)); BinaryenAddTable(module, "0", 1, 1, BinaryenTypeFuncref()); BinaryenAddActiveElementSegment( module, "0", "0", funcNames, 3, constExprRef); diff --git a/test/example/c-api-relooper-unreachable-if.cpp b/test/example/c-api-relooper-unreachable-if.cpp index babafac5a..e8bfc43bc 100644 --- a/test/example/c-api-relooper-unreachable-if.cpp +++ b/test/example/c-api-relooper-unreachable-if.cpp @@ -1,9 +1,9 @@ // beginning a Binaryen API trace +#include "binaryen-c.h" #include <cassert> -#include <math.h> #include <map> -#include "binaryen-c.h" +#include <math.h> int main() { std::map<size_t, BinaryenExpressionRef> expressions; @@ -15,11 +15,20 @@ int main() { expressions[size_t(NULL)] = BinaryenExpressionRef(NULL); BinaryenModuleAutoDrop(the_module); { - const char* segments[] = { 0 }; + const char* segments[] = {0}; bool segmentPassive[] = {false}; - BinaryenExpressionRef segmentOffsets[] = { 0 }; - BinaryenIndex segmentSizes[] = { 0 }; - BinaryenSetMemory(the_module, 256, 256, "memory", segments, segmentPassive, segmentOffsets, segmentSizes, 0, 0); + BinaryenExpressionRef segmentOffsets[] = {0}; + BinaryenIndex segmentSizes[] = {0}; + BinaryenSetMemory(the_module, + 256, + 256, + "memory", + segments, + segmentPassive, + segmentOffsets, + segmentSizes, + 0, + 0); } the_relooper = RelooperCreate(the_module); expressions[1] = BinaryenLocalGet(the_module, 0, BinaryenTypeInt32()); @@ -28,15 +37,18 @@ int main() { the_module, 4, 0, 0, expressions[2], expressions[1], BinaryenTypeInt32()); expressions[4] = BinaryenReturn(the_module, expressions[0]); { - BinaryenExpressionRef children[] = { expressions[3], expressions[4] }; - expressions[5] = BinaryenBlock(the_module, "bb0", children, 2, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[3], expressions[4]}; + expressions[5] = + BinaryenBlock(the_module, "bb0", children, 2, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[5]); expressions[6] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[7] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[6]); + expressions[7] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[6]); expressions[8] = BinaryenLocalSet(the_module, 0, expressions[7]); relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[8]); - RelooperAddBranch(relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); + RelooperAddBranch( + relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); expressions[9] = RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 1); { BinaryenType varTypes[] = { @@ -49,7 +61,8 @@ int main() { 3, expressions[9]); } - BinaryenAddFunctionExport(the_module, "tinycore::eh_personality", "tinycore::eh_personality"); + BinaryenAddFunctionExport( + the_module, "tinycore::eh_personality", "tinycore::eh_personality"); the_relooper = RelooperCreate(the_module); expressions[10] = BinaryenLocalGet(the_module, 0, BinaryenTypeInt32()); expressions[11] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); @@ -57,16 +70,20 @@ int main() { the_module, 4, 0, 0, expressions[11], expressions[10], BinaryenTypeInt32()); expressions[13] = BinaryenReturn(the_module, expressions[0]); { - BinaryenExpressionRef children[] = { expressions[12], expressions[13] }; - expressions[14] = BinaryenBlock(the_module, "bb0", children, 2, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[12], expressions[13]}; + expressions[14] = + BinaryenBlock(the_module, "bb0", children, 2, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[14]); expressions[15] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[16] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[15]); + expressions[16] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[15]); expressions[17] = BinaryenLocalSet(the_module, 0, expressions[16]); relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[17]); - RelooperAddBranch(relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); - expressions[18] = RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 1); + RelooperAddBranch( + relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); + expressions[18] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 1); { BinaryenType varTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32(), BinaryenTypeInt64()}; @@ -78,26 +95,34 @@ int main() { 3, expressions[18]); } - BinaryenAddFunctionExport(the_module, "tinycore::eh_unwind_resume", "tinycore::eh_unwind_resume"); + BinaryenAddFunctionExport( + the_module, "tinycore::eh_unwind_resume", "tinycore::eh_unwind_resume"); the_relooper = RelooperCreate(the_module); { - BinaryenExpressionRef children[] = { 0 }; - expressions[19] = BinaryenBlock(the_module, "bb0", children, 0, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {0}; + expressions[19] = + BinaryenBlock(the_module, "bb0", children, 0, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[19]); { - BinaryenExpressionRef children[] = { 0 }; - expressions[20] = BinaryenBlock(the_module, "bb1", children, 0, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {0}; + expressions[20] = + BinaryenBlock(the_module, "bb1", children, 0, BinaryenTypeAuto()); } relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[20]); - RelooperAddBranch(relooperBlocks[0], relooperBlocks[1], expressions[0], expressions[0]); - RelooperAddBranch(relooperBlocks[1], relooperBlocks[1], expressions[0], expressions[0]); + RelooperAddBranch( + relooperBlocks[0], relooperBlocks[1], expressions[0], expressions[0]); + RelooperAddBranch( + relooperBlocks[1], relooperBlocks[1], expressions[0], expressions[0]); expressions[21] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[22] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[21]); + expressions[22] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[21]); expressions[23] = BinaryenLocalSet(the_module, 0, expressions[22]); relooperBlocks[2] = RelooperAddBlock(the_relooper, expressions[23]); - RelooperAddBranch(relooperBlocks[2], relooperBlocks[0], expressions[0], expressions[0]); - expressions[24] = RelooperRenderAndDispose(the_relooper, relooperBlocks[2], 1); + RelooperAddBranch( + relooperBlocks[2], relooperBlocks[0], expressions[0], expressions[0]); + expressions[24] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[2], 1); { BinaryenType varTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32(), BinaryenTypeInt64()}; @@ -109,7 +134,8 @@ int main() { 3, expressions[24]); } - BinaryenAddFunctionExport(the_module, "tinycore::panic_fmt", "tinycore::panic_fmt"); + BinaryenAddFunctionExport( + the_module, "tinycore::panic_fmt", "tinycore::panic_fmt"); the_relooper = RelooperCreate(the_module); expressions[25] = BinaryenLocalGet(the_module, 0, BinaryenTypeInt32()); expressions[26] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); @@ -117,16 +143,20 @@ int main() { the_module, 4, 0, 0, expressions[26], expressions[25], BinaryenTypeInt32()); expressions[28] = BinaryenReturn(the_module, expressions[0]); { - BinaryenExpressionRef children[] = { expressions[27], expressions[28] }; - expressions[29] = BinaryenBlock(the_module, "bb0", children, 2, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[27], expressions[28]}; + expressions[29] = + BinaryenBlock(the_module, "bb0", children, 2, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[29]); expressions[30] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[31] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[30]); + expressions[31] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[30]); expressions[32] = BinaryenLocalSet(the_module, 0, expressions[31]); relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[32]); - RelooperAddBranch(relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); - expressions[33] = RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 1); + RelooperAddBranch( + relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); + expressions[33] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 1); { BinaryenType varTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32(), BinaryenTypeInt64()}; @@ -138,7 +168,9 @@ int main() { 3, expressions[33]); } - BinaryenAddFunctionExport(the_module, "tinycore::rust_eh_register_frames", "tinycore::rust_eh_register_frames"); + BinaryenAddFunctionExport(the_module, + "tinycore::rust_eh_register_frames", + "tinycore::rust_eh_register_frames"); the_relooper = RelooperCreate(the_module); expressions[34] = BinaryenLocalGet(the_module, 0, BinaryenTypeInt32()); expressions[35] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); @@ -146,16 +178,20 @@ int main() { the_module, 4, 0, 0, expressions[35], expressions[34], BinaryenTypeInt32()); expressions[37] = BinaryenReturn(the_module, expressions[0]); { - BinaryenExpressionRef children[] = { expressions[36], expressions[37] }; - expressions[38] = BinaryenBlock(the_module, "bb0", children, 2, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[36], expressions[37]}; + expressions[38] = + BinaryenBlock(the_module, "bb0", children, 2, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[38]); expressions[39] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[40] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[39]); + expressions[40] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[39]); expressions[41] = BinaryenLocalSet(the_module, 0, expressions[40]); relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[41]); - RelooperAddBranch(relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); - expressions[42] = RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 1); + RelooperAddBranch( + relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); + expressions[42] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 1); { BinaryenType varTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32(), BinaryenTypeInt64()}; @@ -167,7 +203,9 @@ int main() { 3, expressions[42]); } - BinaryenAddFunctionExport(the_module, "tinycore::rust_eh_unregister_frames", "tinycore::rust_eh_unregister_frames"); + BinaryenAddFunctionExport(the_module, + "tinycore::rust_eh_unregister_frames", + "tinycore::rust_eh_unregister_frames"); the_relooper = RelooperCreate(the_module); expressions[43] = BinaryenLocalGet(the_module, 0, BinaryenTypeInt32()); expressions[44] = BinaryenLocalSet(the_module, 1, expressions[43]); @@ -181,12 +219,15 @@ int main() { BinaryenTypeNone()); expressions[47] = BinaryenLocalGet(the_module, 2, BinaryenTypeInt32()); { - BinaryenExpressionRef operands[] = { expressions[47] }; - expressions[48] = BinaryenCall(the_module, "print_i32", operands, 1, BinaryenTypeNone()); + BinaryenExpressionRef operands[] = {expressions[47]}; + expressions[48] = + BinaryenCall(the_module, "print_i32", operands, 1, BinaryenTypeNone()); } { - BinaryenExpressionRef children[] = { expressions[44], expressions[46], expressions[48] }; - expressions[49] = BinaryenBlock(the_module, "bb0", children, 3, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = { + expressions[44], expressions[46], expressions[48]}; + expressions[49] = + BinaryenBlock(the_module, "bb0", children, 3, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[49]); expressions[50] = BinaryenLocalGet(the_module, 3, BinaryenTypeInt32()); @@ -195,17 +236,22 @@ int main() { the_module, 4, 0, 0, expressions[51], expressions[50], BinaryenTypeInt32()); expressions[53] = BinaryenReturn(the_module, expressions[0]); { - BinaryenExpressionRef children[] = { expressions[52], expressions[53] }; - expressions[54] = BinaryenBlock(the_module, "bb1", children, 2, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[52], expressions[53]}; + expressions[54] = + BinaryenBlock(the_module, "bb1", children, 2, BinaryenTypeAuto()); } relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[54]); - RelooperAddBranch(relooperBlocks[0], relooperBlocks[1], expressions[0], expressions[0]); + RelooperAddBranch( + relooperBlocks[0], relooperBlocks[1], expressions[0], expressions[0]); expressions[55] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[56] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[55]); + expressions[56] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[55]); expressions[57] = BinaryenLocalSet(the_module, 3, expressions[56]); relooperBlocks[2] = RelooperAddBlock(the_relooper, expressions[57]); - RelooperAddBranch(relooperBlocks[2], relooperBlocks[0], expressions[0], expressions[0]); - expressions[58] = RelooperRenderAndDispose(the_relooper, relooperBlocks[2], 4); + RelooperAddBranch( + relooperBlocks[2], relooperBlocks[0], expressions[0], expressions[0]); + expressions[58] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[2], 4); { BinaryenType varTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32(), @@ -230,18 +276,22 @@ int main() { expressions[64] = BinaryenConst(the_module, BinaryenLiteralInt32(2)); expressions[65] = BinaryenUnary(the_module, 22, expressions[63]); expressions[66] = BinaryenUnary(the_module, 22, expressions[64]); - expressions[67] = BinaryenBinary(the_module, 25, expressions[65], expressions[66]); + expressions[67] = + BinaryenBinary(the_module, 25, expressions[65], expressions[66]); expressions[68] = BinaryenLocalSet(the_module, 8, expressions[67]); expressions[69] = BinaryenLocalGet(the_module, 8, BinaryenTypeInt64()); expressions[70] = BinaryenUnary(the_module, 24, expressions[69]); expressions[71] = BinaryenConst(the_module, BinaryenLiteralInt64(32)); expressions[72] = BinaryenLocalGet(the_module, 8, BinaryenTypeInt64()); - expressions[73] = BinaryenBinary(the_module, 36, expressions[72], expressions[71]); + expressions[73] = + BinaryenBinary(the_module, 36, expressions[72], expressions[71]); expressions[74] = BinaryenUnary(the_module, 24, expressions[73]); expressions[75] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[76] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[75]); + expressions[76] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[75]); expressions[77] = BinaryenConst(the_module, BinaryenLiteralInt32(128)); - expressions[78] = BinaryenBinary(the_module, 1, expressions[76], expressions[77]); + expressions[78] = + BinaryenBinary(the_module, 1, expressions[76], expressions[77]); expressions[79] = BinaryenLocalTee(the_module, 3, expressions[78], BinaryenTypeInt32()); expressions[80] = BinaryenStore( @@ -252,12 +302,19 @@ int main() { expressions[83] = BinaryenStore( the_module, 4, 4, 0, expressions[81], expressions[74], BinaryenTypeInt32()); { - BinaryenExpressionRef children[] = { expressions[60], expressions[62], expressions[68], expressions[80], expressions[82], expressions[83] }; - expressions[84] = BinaryenBlock(the_module, "bb0", children, 6, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[60], + expressions[62], + expressions[68], + expressions[80], + expressions[82], + expressions[83]}; + expressions[84] = + BinaryenBlock(the_module, "bb0", children, 6, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[84]); expressions[85] = BinaryenLocalGet(the_module, 3, BinaryenTypeInt32()); - expressions[86] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[85]); + expressions[86] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[85]); expressions[87] = BinaryenLocalSet(the_module, 1, expressions[86]); expressions[88] = BinaryenLocalGet(the_module, 1, BinaryenTypeInt32()); expressions[89] = BinaryenLocalSet(the_module, 4, expressions[88]); @@ -270,22 +327,33 @@ int main() { expressions[95] = BinaryenLocalGet(the_module, 5, BinaryenTypeInt32()); expressions[96] = BinaryenReturn(the_module, expressions[95]); { - BinaryenExpressionRef children[] = { expressions[87], expressions[89], expressions[91], expressions[94], expressions[96] }; - expressions[97] = BinaryenBlock(the_module, "bb1", children, 5, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[87], + expressions[89], + expressions[91], + expressions[94], + expressions[96]}; + expressions[97] = + BinaryenBlock(the_module, "bb1", children, 5, BinaryenTypeAuto()); } relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[97]); expressions[98] = BinaryenLocalGet(the_module, 3, BinaryenTypeInt32()); - expressions[99] = BinaryenLoad(the_module, 4, 0, 8, 0, BinaryenTypeInt32(), expressions[98]); - RelooperAddBranch(relooperBlocks[0], relooperBlocks[1], expressions[99], expressions[0]); + expressions[99] = + BinaryenLoad(the_module, 4, 0, 8, 0, BinaryenTypeInt32(), expressions[98]); + RelooperAddBranch( + relooperBlocks[0], relooperBlocks[1], expressions[99], expressions[0]); expressions[100] = BinaryenUnreachable(the_module); relooperBlocks[2] = RelooperAddBlock(the_relooper, expressions[100]); - RelooperAddBranch(relooperBlocks[0], relooperBlocks[2], expressions[0], expressions[0]); + RelooperAddBranch( + relooperBlocks[0], relooperBlocks[2], expressions[0], expressions[0]); expressions[101] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[102] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[101]); + expressions[102] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[101]); expressions[103] = BinaryenLocalSet(the_module, 6, expressions[102]); relooperBlocks[3] = RelooperAddBlock(the_relooper, expressions[103]); - RelooperAddBranch(relooperBlocks[3], relooperBlocks[0], expressions[0], expressions[0]); - expressions[104] = RelooperRenderAndDispose(the_relooper, relooperBlocks[3], 7); + RelooperAddBranch( + relooperBlocks[3], relooperBlocks[0], expressions[0], expressions[0]); + expressions[104] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[3], 7); { BinaryenType varTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32(), @@ -309,31 +377,37 @@ int main() { expressions[105] = BinaryenLocalGet(the_module, 0, BinaryenTypeInt32()); expressions[106] = BinaryenLocalSet(the_module, 2, expressions[105]); { - BinaryenExpressionRef operands[] = { 0 }; - expressions[107] = BinaryenCall(the_module, "real_main", operands, 0, BinaryenTypeInt32()); + BinaryenExpressionRef operands[] = {0}; + expressions[107] = + BinaryenCall(the_module, "real_main", operands, 0, BinaryenTypeInt32()); } expressions[108] = BinaryenLocalSet(the_module, 4, expressions[107]); { - BinaryenExpressionRef children[] = { expressions[106], expressions[108] }; - expressions[109] = BinaryenBlock(the_module, "bb0", children, 2, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[106], expressions[108]}; + expressions[109] = + BinaryenBlock(the_module, "bb0", children, 2, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[109]); expressions[110] = BinaryenLocalGet(the_module, 4, BinaryenTypeInt32()); expressions[111] = BinaryenConst(the_module, BinaryenLiteralInt32(3)); expressions[112] = BinaryenUnary(the_module, 22, expressions[110]); expressions[113] = BinaryenUnary(the_module, 22, expressions[111]); - expressions[114] = BinaryenBinary(the_module, 25, expressions[112], expressions[113]); + expressions[114] = + BinaryenBinary(the_module, 25, expressions[112], expressions[113]); expressions[115] = BinaryenLocalSet(the_module, 11, expressions[114]); expressions[116] = BinaryenLocalGet(the_module, 11, BinaryenTypeInt64()); expressions[117] = BinaryenUnary(the_module, 24, expressions[116]); expressions[118] = BinaryenConst(the_module, BinaryenLiteralInt64(32)); expressions[119] = BinaryenLocalGet(the_module, 11, BinaryenTypeInt64()); - expressions[120] = BinaryenBinary(the_module, 36, expressions[119], expressions[118]); + expressions[120] = + BinaryenBinary(the_module, 36, expressions[119], expressions[118]); expressions[121] = BinaryenUnary(the_module, 24, expressions[120]); expressions[122] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[123] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[122]); + expressions[123] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[122]); expressions[124] = BinaryenConst(the_module, BinaryenLiteralInt32(128)); - expressions[125] = BinaryenBinary(the_module, 1, expressions[123], expressions[124]); + expressions[125] = + BinaryenBinary(the_module, 1, expressions[123], expressions[124]); expressions[126] = BinaryenLocalTee(the_module, 5, expressions[125], BinaryenTypeInt32()); expressions[127] = BinaryenStore(the_module, @@ -359,23 +433,29 @@ int main() { expressions[121], BinaryenTypeInt32()); { - BinaryenExpressionRef children[] = { expressions[115], expressions[127], expressions[129], expressions[130] }; - expressions[131] = BinaryenBlock(the_module, "bb1", children, 4, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = { + expressions[115], expressions[127], expressions[129], expressions[130]}; + expressions[131] = + BinaryenBlock(the_module, "bb1", children, 4, BinaryenTypeAuto()); } relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[131]); expressions[132] = BinaryenLocalGet(the_module, 5, BinaryenTypeInt32()); - expressions[133] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[132]); + expressions[133] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[132]); expressions[134] = BinaryenLocalSet(the_module, 3, expressions[133]); expressions[135] = BinaryenLocalGet(the_module, 3, BinaryenTypeInt32()); expressions[136] = BinaryenLocalSet(the_module, 6, expressions[135]); expressions[137] = BinaryenLocalGet(the_module, 6, BinaryenTypeInt32()); { - BinaryenExpressionRef operands[] = { expressions[137] }; - expressions[138] = BinaryenCall(the_module, "wasm::print_i32", operands, 1, BinaryenTypeNone()); + BinaryenExpressionRef operands[] = {expressions[137]}; + expressions[138] = BinaryenCall( + the_module, "wasm::print_i32", operands, 1, BinaryenTypeNone()); } { - BinaryenExpressionRef children[] = { expressions[134], expressions[136], expressions[138] }; - expressions[139] = BinaryenBlock(the_module, "bb2", children, 3, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = { + expressions[134], expressions[136], expressions[138]}; + expressions[139] = + BinaryenBlock(the_module, "bb2", children, 3, BinaryenTypeAuto()); } relooperBlocks[2] = RelooperAddBlock(the_relooper, expressions[139]); expressions[140] = BinaryenLocalGet(the_module, 3, BinaryenTypeInt32()); @@ -394,24 +474,34 @@ int main() { expressions[147] = BinaryenLocalGet(the_module, 8, BinaryenTypeInt32()); expressions[148] = BinaryenReturn(the_module, expressions[147]); { - BinaryenExpressionRef children[] = { expressions[141], expressions[143], expressions[146], expressions[148] }; - expressions[149] = BinaryenBlock(the_module, "bb3", children, 4, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = { + expressions[141], expressions[143], expressions[146], expressions[148]}; + expressions[149] = + BinaryenBlock(the_module, "bb3", children, 4, BinaryenTypeAuto()); } relooperBlocks[3] = RelooperAddBlock(the_relooper, expressions[149]); - RelooperAddBranch(relooperBlocks[0], relooperBlocks[1], expressions[0], expressions[0]); + RelooperAddBranch( + relooperBlocks[0], relooperBlocks[1], expressions[0], expressions[0]); expressions[150] = BinaryenLocalGet(the_module, 5, BinaryenTypeInt32()); - expressions[151] = BinaryenLoad(the_module, 4, 0, 8, 0, BinaryenTypeInt32(), expressions[150]); - RelooperAddBranch(relooperBlocks[1], relooperBlocks[2], expressions[151], expressions[0]); + expressions[151] = + BinaryenLoad(the_module, 4, 0, 8, 0, BinaryenTypeInt32(), expressions[150]); + RelooperAddBranch( + relooperBlocks[1], relooperBlocks[2], expressions[151], expressions[0]); expressions[152] = BinaryenUnreachable(the_module); relooperBlocks[4] = RelooperAddBlock(the_relooper, expressions[152]); - RelooperAddBranch(relooperBlocks[1], relooperBlocks[4], expressions[0], expressions[0]); - RelooperAddBranch(relooperBlocks[2], relooperBlocks[3], expressions[0], expressions[0]); + RelooperAddBranch( + relooperBlocks[1], relooperBlocks[4], expressions[0], expressions[0]); + RelooperAddBranch( + relooperBlocks[2], relooperBlocks[3], expressions[0], expressions[0]); expressions[153] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[154] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[153]); + expressions[154] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[153]); expressions[155] = BinaryenLocalSet(the_module, 9, expressions[154]); relooperBlocks[5] = RelooperAddBlock(the_relooper, expressions[155]); - RelooperAddBranch(relooperBlocks[5], relooperBlocks[0], expressions[0], expressions[0]); - expressions[156] = RelooperRenderAndDispose(the_relooper, relooperBlocks[5], 10); + RelooperAddBranch( + relooperBlocks[5], relooperBlocks[0], expressions[0], expressions[0]); + expressions[156] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[5], 10); { BinaryenType varTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32(), @@ -435,11 +525,20 @@ int main() { } BinaryenAddFunctionExport(the_module, "main", "main"); { - const char* segments[] = { 0 }; - BinaryenExpressionRef segmentOffsets[] = { 0 }; + const char* segments[] = {0}; + BinaryenExpressionRef segmentOffsets[] = {0}; bool segmentPassive[] = {false}; - BinaryenIndex segmentSizes[] = { 0 }; - BinaryenSetMemory(the_module, 1, 1, NULL, segments, segmentPassive, segmentOffsets, segmentSizes, 0, 0); + BinaryenIndex segmentSizes[] = {0}; + BinaryenSetMemory(the_module, + 1, + 1, + NULL, + segments, + segmentPassive, + segmentOffsets, + segmentSizes, + 0, + 0); } expressions[157] = BinaryenConst(the_module, BinaryenLiteralInt32(65535)); expressions[158] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); @@ -453,14 +552,15 @@ int main() { expressions[160] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); expressions[161] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); { - BinaryenExpressionRef operands[] = { expressions[160], expressions[161] }; + BinaryenExpressionRef operands[] = {expressions[160], expressions[161]}; expressions[162] = BinaryenCall(the_module, "main", operands, 2, BinaryenTypeInt32()); } expressions[163] = BinaryenDrop(the_module, expressions[162]); { - BinaryenExpressionRef children[] = { expressions[159], expressions[163] }; - expressions[164] = BinaryenBlock(the_module, NULL, children, 2, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[159], expressions[163]}; + expressions[164] = + BinaryenBlock(the_module, NULL, children, 2, BinaryenTypeAuto()); } BinaryenAddFunctionExport(the_module, "__wasm_start", "rust_entry"); { @@ -487,18 +587,22 @@ int main() { expressions[174] = BinaryenLocalGet(the_module, 5, BinaryenTypeInt32()); expressions[175] = BinaryenUnary(the_module, 22, expressions[173]); expressions[176] = BinaryenUnary(the_module, 22, expressions[174]); - expressions[177] = BinaryenBinary(the_module, 25, expressions[175], expressions[176]); + expressions[177] = + BinaryenBinary(the_module, 25, expressions[175], expressions[176]); expressions[178] = BinaryenLocalSet(the_module, 10, expressions[177]); expressions[179] = BinaryenLocalGet(the_module, 10, BinaryenTypeInt64()); expressions[180] = BinaryenUnary(the_module, 24, expressions[179]); expressions[181] = BinaryenConst(the_module, BinaryenLiteralInt64(32)); expressions[182] = BinaryenLocalGet(the_module, 10, BinaryenTypeInt64()); - expressions[183] = BinaryenBinary(the_module, 36, expressions[182], expressions[181]); + expressions[183] = + BinaryenBinary(the_module, 36, expressions[182], expressions[181]); expressions[184] = BinaryenUnary(the_module, 24, expressions[183]); expressions[185] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[186] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[185]); + expressions[186] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[185]); expressions[187] = BinaryenConst(the_module, BinaryenLiteralInt32(128)); - expressions[188] = BinaryenBinary(the_module, 1, expressions[186], expressions[187]); + expressions[188] = + BinaryenBinary(the_module, 1, expressions[186], expressions[187]); expressions[189] = BinaryenLocalTee(the_module, 6, expressions[188], BinaryenTypeInt32()); expressions[190] = BinaryenStore(the_module, @@ -524,12 +628,21 @@ int main() { expressions[184], BinaryenTypeInt32()); { - BinaryenExpressionRef children[] = { expressions[166], expressions[168], expressions[170], expressions[172], expressions[178], expressions[190], expressions[192], expressions[193] }; - expressions[194] = BinaryenBlock(the_module, "bb0", children, 8, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[166], + expressions[168], + expressions[170], + expressions[172], + expressions[178], + expressions[190], + expressions[192], + expressions[193]}; + expressions[194] = + BinaryenBlock(the_module, "bb0", children, 8, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[194]); expressions[195] = BinaryenLocalGet(the_module, 6, BinaryenTypeInt32()); - expressions[196] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[195]); + expressions[196] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[195]); expressions[197] = BinaryenLocalSet(the_module, 7, expressions[196]); expressions[198] = BinaryenLocalGet(the_module, 8, BinaryenTypeInt32()); expressions[199] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); @@ -543,22 +656,30 @@ int main() { expressions[201] = BinaryenLocalGet(the_module, 7, BinaryenTypeInt32()); expressions[202] = BinaryenReturn(the_module, expressions[201]); { - BinaryenExpressionRef children[] = { expressions[197], expressions[200], expressions[202] }; - expressions[203] = BinaryenBlock(the_module, "bb1", children, 3, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = { + expressions[197], expressions[200], expressions[202]}; + expressions[203] = + BinaryenBlock(the_module, "bb1", children, 3, BinaryenTypeAuto()); } relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[203]); expressions[204] = BinaryenLocalGet(the_module, 6, BinaryenTypeInt32()); - expressions[205] = BinaryenLoad(the_module, 4, 0, 8, 0, BinaryenTypeInt32(), expressions[204]); - RelooperAddBranch(relooperBlocks[0], relooperBlocks[1], expressions[205], expressions[0]); + expressions[205] = + BinaryenLoad(the_module, 4, 0, 8, 0, BinaryenTypeInt32(), expressions[204]); + RelooperAddBranch( + relooperBlocks[0], relooperBlocks[1], expressions[205], expressions[0]); expressions[206] = BinaryenUnreachable(the_module); relooperBlocks[2] = RelooperAddBlock(the_relooper, expressions[206]); - RelooperAddBranch(relooperBlocks[0], relooperBlocks[2], expressions[0], expressions[0]); + RelooperAddBranch( + relooperBlocks[0], relooperBlocks[2], expressions[0], expressions[0]); expressions[207] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[208] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[207]); + expressions[208] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[207]); expressions[209] = BinaryenLocalSet(the_module, 8, expressions[208]); relooperBlocks[3] = RelooperAddBlock(the_relooper, expressions[209]); - RelooperAddBranch(relooperBlocks[3], relooperBlocks[0], expressions[0], expressions[0]); - expressions[210] = RelooperRenderAndDispose(the_relooper, relooperBlocks[3], 9); + RelooperAddBranch( + relooperBlocks[3], relooperBlocks[0], expressions[0], expressions[0]); + expressions[210] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[3], 9); { BinaryenType varTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32(), @@ -579,7 +700,9 @@ int main() { 9, expressions[210]); } - BinaryenAddFunctionExport(the_module, "_isize_as_tinycore::Add_::add", "_isize_as_tinycore::Add_::add"); + BinaryenAddFunctionExport(the_module, + "_isize_as_tinycore::Add_::add", + "_isize_as_tinycore::Add_::add"); the_relooper = RelooperCreate(the_module); expressions[211] = BinaryenLocalGet(the_module, 0, BinaryenTypeInt32()); expressions[212] = BinaryenLocalSet(the_module, 1, expressions[211]); @@ -600,16 +723,24 @@ int main() { expressions[221] = BinaryenLocalGet(the_module, 3, BinaryenTypeInt32()); expressions[222] = BinaryenReturn(the_module, expressions[221]); { - BinaryenExpressionRef children[] = { expressions[212], expressions[214], expressions[217], expressions[220], expressions[222] }; - expressions[223] = BinaryenBlock(the_module, "bb0", children, 5, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[212], + expressions[214], + expressions[217], + expressions[220], + expressions[222]}; + expressions[223] = + BinaryenBlock(the_module, "bb0", children, 5, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[223]); expressions[224] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[225] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[224]); + expressions[225] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[224]); expressions[226] = BinaryenLocalSet(the_module, 4, expressions[225]); relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[226]); - RelooperAddBranch(relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); - expressions[227] = RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 5); + RelooperAddBranch( + relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); + expressions[227] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 5); { BinaryenType varTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32(), @@ -625,7 +756,8 @@ int main() { 6, expressions[227]); } - BinaryenAddFunctionExport(the_module, "_bool_as_tinycore::Not_::not", "_bool_as_tinycore::Not_::not"); + BinaryenAddFunctionExport( + the_module, "_bool_as_tinycore::Not_::not", "_bool_as_tinycore::Not_::not"); the_relooper = RelooperCreate(the_module); expressions[228] = BinaryenLocalGet(the_module, 0, BinaryenTypeInt32()); expressions[229] = BinaryenLocalSet(the_module, 2, expressions[228]); @@ -637,7 +769,8 @@ int main() { expressions[235] = BinaryenLocalSet(the_module, 5, expressions[234]); expressions[236] = BinaryenLocalGet(the_module, 4, BinaryenTypeInt32()); expressions[237] = BinaryenLocalGet(the_module, 5, BinaryenTypeInt32()); - expressions[238] = BinaryenBinary(the_module, 15, expressions[236], expressions[237]); + expressions[238] = + BinaryenBinary(the_module, 15, expressions[236], expressions[237]); expressions[239] = BinaryenLocalSet(the_module, 6, expressions[238]); expressions[240] = BinaryenLocalGet(the_module, 7, BinaryenTypeInt32()); expressions[241] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); @@ -651,16 +784,26 @@ int main() { expressions[243] = BinaryenLocalGet(the_module, 6, BinaryenTypeInt32()); expressions[244] = BinaryenReturn(the_module, expressions[243]); { - BinaryenExpressionRef children[] = { expressions[229], expressions[231], expressions[233], expressions[235], expressions[239], expressions[242], expressions[244] }; - expressions[245] = BinaryenBlock(the_module, "bb0", children, 7, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[229], + expressions[231], + expressions[233], + expressions[235], + expressions[239], + expressions[242], + expressions[244]}; + expressions[245] = + BinaryenBlock(the_module, "bb0", children, 7, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[245]); expressions[246] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[247] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[246]); + expressions[247] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[246]); expressions[248] = BinaryenLocalSet(the_module, 7, expressions[247]); relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[248]); - RelooperAddBranch(relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); - expressions[249] = RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 8); + RelooperAddBranch( + relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); + expressions[249] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 8); { BinaryenType varTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32(), @@ -680,7 +823,9 @@ int main() { 8, expressions[249]); } - BinaryenAddFunctionExport(the_module, "_i16_as_tinycore::PartialEq_::eq", "_i16_as_tinycore::PartialEq_::eq"); + BinaryenAddFunctionExport(the_module, + "_i16_as_tinycore::PartialEq_::eq", + "_i16_as_tinycore::PartialEq_::eq"); the_relooper = RelooperCreate(the_module); expressions[250] = BinaryenLocalGet(the_module, 0, BinaryenTypeInt64()); expressions[251] = BinaryenLocalSet(the_module, 2, expressions[250]); @@ -692,7 +837,8 @@ int main() { expressions[257] = BinaryenLocalSet(the_module, 5, expressions[256]); expressions[258] = BinaryenLocalGet(the_module, 4, BinaryenTypeInt64()); expressions[259] = BinaryenLocalGet(the_module, 5, BinaryenTypeInt64()); - expressions[260] = BinaryenBinary(the_module, 40, expressions[258], expressions[259]); + expressions[260] = + BinaryenBinary(the_module, 40, expressions[258], expressions[259]); expressions[261] = BinaryenLocalSet(the_module, 6, expressions[260]); expressions[262] = BinaryenLocalGet(the_module, 7, BinaryenTypeInt64()); expressions[263] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); @@ -706,16 +852,26 @@ int main() { expressions[265] = BinaryenLocalGet(the_module, 6, BinaryenTypeInt32()); expressions[266] = BinaryenReturn(the_module, expressions[265]); { - BinaryenExpressionRef children[] = { expressions[251], expressions[253], expressions[255], expressions[257], expressions[261], expressions[264], expressions[266] }; - expressions[267] = BinaryenBlock(the_module, "bb0", children, 7, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[251], + expressions[253], + expressions[255], + expressions[257], + expressions[261], + expressions[264], + expressions[266]}; + expressions[267] = + BinaryenBlock(the_module, "bb0", children, 7, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[267]); expressions[268] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); - expressions[269] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt64(), expressions[268]); + expressions[269] = + BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt64(), expressions[268]); expressions[270] = BinaryenLocalSet(the_module, 7, expressions[269]); relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[270]); - RelooperAddBranch(relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); - expressions[271] = RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 8); + RelooperAddBranch( + relooperBlocks[1], relooperBlocks[0], expressions[0], expressions[0]); + expressions[271] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[1], 8); { BinaryenType varTypes[] = {BinaryenTypeInt64(), BinaryenTypeInt64(), @@ -735,7 +891,9 @@ int main() { 8, expressions[271]); } - BinaryenAddFunctionExport(the_module, "_i64_as_tinycore::PartialEq_::eq", "_i64_as_tinycore::PartialEq_::eq"); + BinaryenAddFunctionExport(the_module, + "_i64_as_tinycore::PartialEq_::eq", + "_i64_as_tinycore::PartialEq_::eq"); assert(BinaryenModuleValidate(the_module)); BinaryenModuleDispose(the_module); expressions.clear(); diff --git a/test/example/c-api-unused-mem.cpp b/test/example/c-api-unused-mem.cpp index 2121d8bde..1231f5695 100644 --- a/test/example/c-api-unused-mem.cpp +++ b/test/example/c-api-unused-mem.cpp @@ -1,10 +1,10 @@ // beginning a Binaryen API trace +#include "binaryen-c.h" #include <cassert> -#include <stdio.h> -#include <math.h> #include <map> -#include "binaryen-c.h" +#include <math.h> +#include <stdio.h> int main() { std::map<size_t, BinaryenExpressionRef> expressions; @@ -16,16 +16,26 @@ int main() { expressions[size_t(NULL)] = BinaryenExpressionRef(NULL); BinaryenModuleAutoDrop(the_module); { - const char* segments[] = { 0 }; + const char* segments[] = {0}; bool segmentPassive[] = {false}; - BinaryenExpressionRef segmentOffsets[] = { 0 }; - BinaryenIndex segmentSizes[] = { 0 }; - BinaryenSetMemory(the_module, 256, 256, "memory", segments, segmentPassive, segmentOffsets, segmentSizes, 0, 0); + BinaryenExpressionRef segmentOffsets[] = {0}; + BinaryenIndex segmentSizes[] = {0}; + BinaryenSetMemory(the_module, + 256, + 256, + "memory", + segments, + segmentPassive, + segmentOffsets, + segmentSizes, + 0, + 0); } the_relooper = RelooperCreate(the_module); { - BinaryenExpressionRef children[] = { 0 }; - expressions[1] = BinaryenBlock(the_module, "bb0", children, 0, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {0}; + expressions[1] = + BinaryenBlock(the_module, "bb0", children, 0, BinaryenTypeAuto()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[1]); expressions[2] = BinaryenLocalGet(the_module, 0, BinaryenTypeInt32()); @@ -34,18 +44,22 @@ int main() { the_module, 4, 0, 0, expressions[3], expressions[2], BinaryenTypeInt32()); expressions[5] = BinaryenReturn(the_module, expressions[0]); { - BinaryenExpressionRef children[] = { expressions[4], expressions[5] }; - expressions[6] = BinaryenBlock(the_module, "bb1", children, 2, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[4], expressions[5]}; + expressions[6] = + BinaryenBlock(the_module, "bb1", children, 2, BinaryenTypeAuto()); } relooperBlocks[1] = RelooperAddBlock(the_relooper, expressions[6]); - RelooperAddBranch(relooperBlocks[0], relooperBlocks[1], expressions[0], expressions[0]); + RelooperAddBranch( + relooperBlocks[0], relooperBlocks[1], expressions[0], expressions[0]); expressions[7] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); expressions[8] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[7]); expressions[9] = BinaryenLocalSet(the_module, 0, expressions[8]); relooperBlocks[2] = RelooperAddBlock(the_relooper, expressions[9]); - RelooperAddBranch(relooperBlocks[2], relooperBlocks[0], expressions[0], expressions[0]); - expressions[10] = RelooperRenderAndDispose(the_relooper, relooperBlocks[2], 1); + RelooperAddBranch( + relooperBlocks[2], relooperBlocks[0], expressions[0], expressions[0]); + expressions[10] = + RelooperRenderAndDispose(the_relooper, relooperBlocks[2], 1); { BinaryenType varTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32(), BinaryenTypeInt64()}; @@ -59,23 +73,34 @@ int main() { } BinaryenAddFunctionExport(the_module, "main", "main"); { - const char* segments[] = { 0 }; + const char* segments[] = {0}; bool segmentPassive[] = {false}; - BinaryenExpressionRef segmentOffsets[] = { 0 }; - BinaryenIndex segmentSizes[] = { 0 }; - BinaryenSetMemory(the_module, 1024, 1024, NULL, segments, segmentPassive, segmentOffsets, segmentSizes, 0, 0); + BinaryenExpressionRef segmentOffsets[] = {0}; + BinaryenIndex segmentSizes[] = {0}; + BinaryenSetMemory(the_module, + 1024, + 1024, + NULL, + segments, + segmentPassive, + segmentOffsets, + segmentSizes, + 0, + 0); } expressions[11] = BinaryenConst(the_module, BinaryenLiteralInt32(65535)); expressions[12] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); expressions[13] = BinaryenStore( the_module, 4, 0, 0, expressions[12], expressions[11], BinaryenTypeInt32()); { - BinaryenExpressionRef operands[] = { 0 }; - expressions[14] = BinaryenCall(the_module, "main", operands, 0, BinaryenTypeNone()); + BinaryenExpressionRef operands[] = {0}; + expressions[14] = + BinaryenCall(the_module, "main", operands, 0, BinaryenTypeNone()); } { - BinaryenExpressionRef children[] = { expressions[13], expressions[14] }; - expressions[15] = BinaryenBlock(the_module, NULL, children, 2, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = {expressions[13], expressions[14]}; + expressions[15] = + BinaryenBlock(the_module, NULL, children, 2, BinaryenTypeAuto()); } BinaryenAddFunctionExport(the_module, "__wasm_start", "rust_entry"); { diff --git a/test/example/cpp-threads.cpp b/test/example/cpp-threads.cpp index e59bd5243..af392b5ab 100644 --- a/test/example/cpp-threads.cpp +++ b/test/example/cpp-threads.cpp @@ -24,7 +24,8 @@ void worker() { // Create the add function // Note: no additional local variables - // Note: no basic blocks here, we are an AST. The function body is just an expression node. + // Note: no basic blocks here, we are an AST. The function body is just an + // expression node. BinaryenFunctionRef adder = BinaryenAddFunction(module, "adder", ii, BinaryenTypeInt32(), NULL, 0, ret); diff --git a/test/example/cpp-unit.cpp b/test/example/cpp-unit.cpp index 41096a43a..961013bc3 100644 --- a/test/example/cpp-unit.cpp +++ b/test/example/cpp-unit.cpp @@ -12,15 +12,15 @@ using namespace wasm; using namespace Bits; -#define RESET "\x1b[0m" +#define RESET "\x1b[0m" -#define FG_BLACK "\x1b[30m" -#define FG_RED "\x1b[31m" -#define FG_GREEN "\x1b[32m" +#define FG_BLACK "\x1b[30m" +#define FG_RED "\x1b[31m" +#define FG_GREEN "\x1b[32m" #define FG_YELLOW "\x1b[33m" -#define BG_BLACK "\x1b[40m" -#define BG_RED "\x1b[41m" +#define BG_BLACK "\x1b[40m" +#define BG_RED "\x1b[41m" static int failsCount = 0; @@ -28,20 +28,16 @@ template<typename T, typename U> void assert_equal_(T a, U b, int line, const char* file) { if (a != b) { std::cerr << '\n' - << BG_RED FG_BLACK << "î‚° ASSERTION ERROR " - << ++failsCount << " " - << RESET FG_RED << "î‚°\n" - << FG_RED << " Actual: " << a << '\n' - << FG_GREEN << " Expected: " << b << "\n\n" - << FG_YELLOW << " Line: " << line << '\n' - << FG_YELLOW << " File: " << file << '\n' - << RESET << std::endl; - - std::cout << "actual: " << a - << ", expected: " << b - << ", line " << line - << ", file " << file - << std::endl; + << BG_RED FG_BLACK << "î‚° ASSERTION ERROR " << ++failsCount + << " " << RESET FG_RED << "î‚°\n" + << FG_RED << " Actual: " << a << '\n' + << FG_GREEN << " Expected: " << b << "\n\n" + << FG_YELLOW << " Line: " << line << '\n' + << FG_YELLOW << " File: " << file << '\n' + << RESET << std::endl; + + std::cout << "actual: " << a << ", expected: " << b << ", line " << line + << ", file " << file << std::endl; } } @@ -60,7 +56,7 @@ void test_bits() { c0.type = Type::i32; c1.type = Type::i32; - b.type = Type::i32; + b.type = Type::i32; c0.value = Literal(int32_t(0)); assert_equal(getMaxBits(&c0), 0); @@ -128,17 +124,17 @@ void test_bits() { c0.value = Literal(int32_t(0)); c1.value = Literal(int32_t(0xF)); assert_equal(getMaxBits(&b), 0); - c0.value = Literal(int32_t( 1)); - c1.value = Literal(int32_t( 2)); + c0.value = Literal(int32_t(1)); + c1.value = Literal(int32_t(2)); assert_equal(getMaxBits(&b), 0); c0.value = Literal(int32_t(0xFF)); c1.value = Literal(int32_t(0xFF)); assert_equal(getMaxBits(&b), 1); c0.value = Literal(int32_t(-1)); - c1.value = Literal(int32_t( 1)); + c1.value = Literal(int32_t(1)); assert_equal(getMaxBits(&b), 32); c0.value = Literal(int32_t(-1)); - c1.value = Literal(int32_t( 2)); + c1.value = Literal(int32_t(2)); assert_equal(getMaxBits(&b), 32); c0.value = Literal(int32_t(0x7FFFFFFF)); c1.value = Literal(int32_t(3)); @@ -156,22 +152,21 @@ void test_bits() { c1.value = Literal(int32_t(-2)); assert_equal(getMaxBits(&b), 32); - b.op = DivUInt32; c0.value = Literal(uint32_t(0)); c1.value = Literal(uint32_t(0xF)); assert_equal(getMaxBits(&b), 0); - c0.value = Literal(uint32_t( 1)); - c1.value = Literal(uint32_t( 2)); + c0.value = Literal(uint32_t(1)); + c1.value = Literal(uint32_t(2)); assert_equal(getMaxBits(&b), 0); c0.value = Literal(uint32_t(0xFF)); c1.value = Literal(uint32_t(0xFF)); assert_equal(getMaxBits(&b), 1); c0.value = Literal(uint32_t(-1)); - c1.value = Literal(uint32_t( 1)); + c1.value = Literal(uint32_t(1)); assert_equal(getMaxBits(&b), 32); c0.value = Literal(uint32_t(-1)); - c1.value = Literal(uint32_t( 2)); + c1.value = Literal(uint32_t(2)); assert_equal(getMaxBits(&b), 31); c0.value = Literal(uint32_t(0x7FFFFFFF)); c1.value = Literal(uint32_t(3)); @@ -196,11 +191,11 @@ void test_bits() { c0.value = Literal(int32_t(0)); c1.value = Literal(int32_t(-1)); assert_equal(getMaxBits(&b), 0); - c0.value = Literal(int32_t( 1)); - c1.value = Literal(int32_t( 2)); + c0.value = Literal(int32_t(1)); + c1.value = Literal(int32_t(2)); assert_equal(getMaxBits(&b), 1); c0.value = Literal(int32_t(-1)); - c1.value = Literal(int32_t( 2)); + c1.value = Literal(int32_t(2)); assert_equal(getMaxBits(&b), 32); c0.value = Literal(int32_t(3)); c1.value = Literal(int32_t(-1)); @@ -216,11 +211,11 @@ void test_bits() { c0.value = Literal(uint32_t(0)); c1.value = Literal(uint32_t(-1)); assert_equal(getMaxBits(&b), 0); - c0.value = Literal(uint32_t( 1)); - c1.value = Literal(uint32_t( 2)); + c0.value = Literal(uint32_t(1)); + c1.value = Literal(uint32_t(2)); assert_equal(getMaxBits(&b), 1); c0.value = Literal(uint32_t(-1)); - c1.value = Literal(uint32_t( 2)); + c1.value = Literal(uint32_t(2)); assert_equal(getMaxBits(&b), 1); c0.value = Literal(uint32_t(3)); c1.value = Literal(uint32_t(-1)); @@ -286,7 +281,7 @@ void test_bits() { c0.type = Type::i64; c1.type = Type::i64; - b.type = Type::i64; + b.type = Type::i64; c0.value = Literal(int64_t(0)); assert_equal(getMaxBits(&c0), 0); @@ -354,17 +349,17 @@ void test_bits() { c0.value = Literal(int64_t(0)); c1.value = Literal(int64_t(0xF)); assert_equal(getMaxBits(&b), 0); - c0.value = Literal(int64_t( 1)); - c1.value = Literal(int64_t( 2)); + c0.value = Literal(int64_t(1)); + c1.value = Literal(int64_t(2)); assert_equal(getMaxBits(&b), 0); c0.value = Literal(int64_t(0xFF)); c1.value = Literal(int64_t(0xFF)); assert_equal(getMaxBits(&b), 1); c0.value = Literal(int64_t(-1)); - c1.value = Literal(int64_t( 1)); + c1.value = Literal(int64_t(1)); assert_equal(getMaxBits(&b), 64); c0.value = Literal(int64_t(-1)); - c1.value = Literal(int64_t( 2)); + c1.value = Literal(int64_t(2)); assert_equal(getMaxBits(&b), 64); c0.value = Literal(int64_t(0x7FFFFFFFFFFFFFFF)); c1.value = Literal(int64_t(3)); @@ -380,17 +375,17 @@ void test_bits() { c0.value = Literal(uint64_t(0)); c1.value = Literal(uint64_t(0xF)); assert_equal(getMaxBits(&b), 0); - c0.value = Literal(uint64_t( 1)); - c1.value = Literal(uint64_t( 2)); + c0.value = Literal(uint64_t(1)); + c1.value = Literal(uint64_t(2)); assert_equal(getMaxBits(&b), 0); c0.value = Literal(uint64_t(0xFF)); c1.value = Literal(uint64_t(0xFF)); assert_equal(getMaxBits(&b), 1); c0.value = Literal(uint64_t(-1)); - c1.value = Literal(uint64_t( 1)); + c1.value = Literal(uint64_t(1)); assert_equal(getMaxBits(&b), 64); c0.value = Literal(uint64_t(-1)); - c1.value = Literal(uint64_t( 2)); + c1.value = Literal(uint64_t(2)); assert_equal(getMaxBits(&b), 63); c0.value = Literal(uint64_t(0x7FFFFFFFFFFFFFFF)); c1.value = Literal(uint64_t(3)); @@ -409,11 +404,11 @@ void test_bits() { c0.value = Literal(int64_t(0)); c1.value = Literal(int64_t(-1)); assert_equal(getMaxBits(&b), 0); - c0.value = Literal(int64_t( 1)); - c1.value = Literal(int64_t( 2)); + c0.value = Literal(int64_t(1)); + c1.value = Literal(int64_t(2)); assert_equal(getMaxBits(&b), 1); c0.value = Literal(int64_t(-1)); - c1.value = Literal(int64_t( 2)); + c1.value = Literal(int64_t(2)); assert_equal(getMaxBits(&b), 64); c0.value = Literal(int64_t(3)); c1.value = Literal(int64_t(-1)); @@ -429,11 +424,11 @@ void test_bits() { c0.value = Literal(uint64_t(0)); c1.value = Literal(uint64_t(-1)); assert_equal(getMaxBits(&b), 0); - c0.value = Literal(uint64_t( 1)); - c1.value = Literal(uint64_t( 2)); + c0.value = Literal(uint64_t(1)); + c1.value = Literal(uint64_t(2)); assert_equal(getMaxBits(&b), 1); c0.value = Literal(uint64_t(-1)); - c1.value = Literal(uint64_t( 2)); + c1.value = Literal(uint64_t(2)); assert_equal(getMaxBits(&b), 1); c0.value = Literal(uint64_t(3)); c1.value = Literal(uint64_t(-1)); diff --git a/test/example/relooper-fuzz.c b/test/example/relooper-fuzz.c index 4a6330e6e..d953d9cf2 100644 --- a/test/example/relooper-fuzz.c +++ b/test/example/relooper-fuzz.c @@ -14,49 +14,89 @@ int main() { // check() // if the end, halt - BinaryenExpressionRef halter = BinaryenIf(module, - BinaryenBinary(module, + BinaryenExpressionRef halter = BinaryenIf( + module, + BinaryenBinary( + module, BinaryenEqInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4 * 27)) // jumps of 4 bytes - ), + ), BinaryenUnreachable(module), - NULL - ); + NULL); // increment index - BinaryenExpressionRef incer = BinaryenStore(module, - 4, 0, 0, + BinaryenExpressionRef incer = BinaryenStore( + module, + 4, + 0, + 0, BinaryenConst(module, BinaryenLiteralInt32(4)), BinaryenBinary(module, - BinaryenAddInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenTypeInt32() - ); + BinaryenAddInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4))), + BinaryenConst(module, BinaryenLiteralInt32(4))), + BinaryenTypeInt32()); // optionally, print the return value - BinaryenExpressionRef args[] = { - BinaryenBinary(module, - BinaryenSubInt32(), - BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenExpressionRef args[] = {BinaryenBinary( + module, + BinaryenSubInt32(), + BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenLoad( + module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))) - ) - ) - }; + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))))}; BinaryenExpressionRef debugger; - if (1) debugger = BinaryenCall(module, "print", args, 1, BinaryenTypeNone()); - else debugger = BinaryenNop(module); - - // return the decision. need to subtract 4 that we just added, and add 8 since that's where we start, so overall offset 4 - BinaryenExpressionRef returner = BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))) - ); - BinaryenExpressionRef checkBodyList[] = { halter, incer, debugger, returner }; - BinaryenExpressionRef checkBody = BinaryenBlock(module, NULL, checkBodyList, sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), BinaryenTypeAuto()); + if (1) + debugger = BinaryenCall(module, "print", args, 1, BinaryenTypeNone()); + else + debugger = BinaryenNop(module); + + // return the decision. need to subtract 4 that we just added, and add 8 since + // that's where we start, so overall offset 4 + BinaryenExpressionRef returner = + BinaryenLoad(module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))); + BinaryenExpressionRef checkBodyList[] = {halter, incer, debugger, returner}; + BinaryenExpressionRef checkBody = + BinaryenBlock(module, + NULL, + checkBodyList, + sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), + BinaryenTypeAuto()); BinaryenAddFunction(module, "check", BinaryenTypeNone(), @@ -69,106 +109,144 @@ int main() { RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef b0; { - BinaryenExpressionRef args[] = { BinaryenConst(module, BinaryenLiteralInt32(0)) }; + BinaryenExpressionRef args[] = { + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32())) - }; - b0 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b0 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b1; { - BinaryenExpressionRef args[] = { BinaryenConst(module, BinaryenLiteralInt32(1)) }; + BinaryenExpressionRef args[] = { + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32())) - }; - b1 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b1 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b2; { - BinaryenExpressionRef args[] = { BinaryenConst(module, BinaryenLiteralInt32(2)) }; + BinaryenExpressionRef args[] = { + BinaryenConst(module, BinaryenLiteralInt32(2))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32())) - }; - b2 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b2 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b3; { - BinaryenExpressionRef args[] = { BinaryenConst(module, BinaryenLiteralInt32(3)) }; + BinaryenExpressionRef args[] = { + BinaryenConst(module, BinaryenLiteralInt32(3))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32())) - }; - b3 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b3 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b4; { - BinaryenExpressionRef args[] = { BinaryenConst(module, BinaryenLiteralInt32(4)) }; + BinaryenExpressionRef args[] = { + BinaryenConst(module, BinaryenLiteralInt32(4))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32())) - }; - b4 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b4 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b5; { - BinaryenExpressionRef args[] = { BinaryenConst(module, BinaryenLiteralInt32(5)) }; + BinaryenExpressionRef args[] = { + BinaryenConst(module, BinaryenLiteralInt32(5))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32())) - }; - b5 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b5 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b6; { - BinaryenExpressionRef args[] = { BinaryenConst(module, BinaryenLiteralInt32(6)) }; + BinaryenExpressionRef args[] = { + BinaryenConst(module, BinaryenLiteralInt32(6))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32())) - }; - b6 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b6 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b7; { - BinaryenExpressionRef args[] = { BinaryenConst(module, BinaryenLiteralInt32(7)) }; + BinaryenExpressionRef args[] = { + BinaryenConst(module, BinaryenLiteralInt32(7))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32())) - }; - b7 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b7 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b8; { - BinaryenExpressionRef args[] = { BinaryenConst(module, BinaryenLiteralInt32(8)) }; + BinaryenExpressionRef args[] = { + BinaryenConst(module, BinaryenLiteralInt32(8))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32())) - }; - b8 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b8 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } - RelooperAddBranch(b0, b5, BinaryenBinary(module, - BinaryenEqInt32(), - BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(2)) - ), - BinaryenConst(module, BinaryenLiteralInt32(0)) - ), NULL); + RelooperAddBranch( + b0, + b5, + BinaryenBinary( + module, + BinaryenEqInt32(), + BinaryenBinary(module, + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(2))), + BinaryenConst(module, BinaryenLiteralInt32(0))), + NULL); RelooperAddBranch(b0, b8, NULL, NULL); @@ -176,49 +254,61 @@ int main() { RelooperAddBranch(b2, b5, NULL, NULL); - RelooperAddBranch(b3, b5, BinaryenBinary(module, - BinaryenEqInt32(), - BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(2)) - ), - BinaryenConst(module, BinaryenLiteralInt32(0)) - ), NULL); + RelooperAddBranch( + b3, + b5, + BinaryenBinary( + module, + BinaryenEqInt32(), + BinaryenBinary(module, + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(2))), + BinaryenConst(module, BinaryenLiteralInt32(0))), + NULL); RelooperAddBranch(b3, b8, NULL, NULL); - RelooperAddBranch(b4, b4, BinaryenBinary(module, - BinaryenEqInt32(), - BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(3)) - ), - BinaryenConst(module, BinaryenLiteralInt32(0)) - ), NULL); - - RelooperAddBranch(b4, b5, BinaryenBinary(module, - BinaryenEqInt32(), - BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(3)) - ), - BinaryenConst(module, BinaryenLiteralInt32(1)) - ), NULL); + RelooperAddBranch( + b4, + b4, + BinaryenBinary( + module, + BinaryenEqInt32(), + BinaryenBinary(module, + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(3))), + BinaryenConst(module, BinaryenLiteralInt32(0))), + NULL); + + RelooperAddBranch( + b4, + b5, + BinaryenBinary( + module, + BinaryenEqInt32(), + BinaryenBinary(module, + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(3))), + BinaryenConst(module, BinaryenLiteralInt32(1))), + NULL); RelooperAddBranch(b4, b2, NULL, NULL); - RelooperAddBranch(b5, b4, BinaryenBinary(module, - BinaryenEqInt32(), - BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(2)) - ), - BinaryenConst(module, BinaryenLiteralInt32(0)) - ), NULL); + RelooperAddBranch( + b5, + b4, + BinaryenBinary( + module, + BinaryenEqInt32(), + BinaryenBinary(module, + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(2))), + BinaryenConst(module, BinaryenLiteralInt32(0))), + NULL); RelooperAddBranch(b5, b5, NULL, NULL); @@ -230,33 +320,40 @@ int main() { BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, b0, 1); - int decisions[] = { 89, 12, 78, 149, 118, 179, 127, 80, 21, 34, 119, 98, 38, 29, 36, 147, 13, 55, 166, 16, 143, 52, 130, 150, 176, 91, 34 }; - int numDecisions = sizeof(decisions)/sizeof(int); + int decisions[] = {89, 12, 78, 149, 118, 179, 127, 80, 21, + 34, 119, 98, 38, 29, 36, 147, 13, 55, + 166, 16, 143, 52, 130, 150, 176, 91, 34}; + int numDecisions = sizeof(decisions) / sizeof(int); - BinaryenExpressionRef full[numDecisions + 1]; // write out all the decisions, then the body of the function + BinaryenExpressionRef full[numDecisions + 1]; // write out all the decisions, + // then the body of the function { int i; for (i = 0; i < numDecisions; i++) { - full[i] = BinaryenStore(module, - 4, 0, 0, - BinaryenConst(module, BinaryenLiteralInt32(8 + 4 * i)), - BinaryenConst(module, BinaryenLiteralInt32(decisions[i])), - BinaryenTypeInt32() - ); + full[i] = + BinaryenStore(module, + 4, + 0, + 0, + BinaryenConst(module, BinaryenLiteralInt32(8 + 4 * i)), + BinaryenConst(module, BinaryenLiteralInt32(decisions[i])), + BinaryenTypeInt32()); } } full[numDecisions] = body; - BinaryenExpressionRef all = BinaryenBlock(module, NULL, full, numDecisions + 1, BinaryenTypeAuto()); + BinaryenExpressionRef all = + BinaryenBlock(module, NULL, full, numDecisions + 1, BinaryenTypeAuto()); - BinaryenType localTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32() }; // state, free-for-label + BinaryenType localTypes[] = {BinaryenTypeInt32(), + BinaryenTypeInt32()}; // state, free-for-label BinaryenFunctionRef theMain = BinaryenAddFunction( module, "main", BinaryenTypeNone(), BinaryenTypeNone(), localTypes, 2, all); BinaryenSetStart(module, theMain); // import - BinaryenType iparams[] = { BinaryenTypeInt32() }; + BinaryenType iparams[] = {BinaryenTypeInt32()}; BinaryenAddFunctionImport(module, "print", "spectest", diff --git a/test/example/relooper-fuzz1.c b/test/example/relooper-fuzz1.c index f4a049697..9e49fbcd3 100644 --- a/test/example/relooper-fuzz1.c +++ b/test/example/relooper-fuzz1.c @@ -12,59 +12,89 @@ int main() { // check() // if the end, halt - BinaryenExpressionRef halter = BinaryenIf(module, - BinaryenBinary(module, + BinaryenExpressionRef halter = BinaryenIf( + module, + BinaryenBinary( + module, BinaryenEqInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4 * 30)) // jumps of 4 bytes - ), + ), BinaryenUnreachable(module), - NULL - ); + NULL); // increment index - BinaryenExpressionRef incer = BinaryenStore(module, - 4, 0, 0, + BinaryenExpressionRef incer = BinaryenStore( + module, + 4, + 0, + 0, BinaryenConst(module, BinaryenLiteralInt32(4)), BinaryenBinary(module, - BinaryenAddInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenAddInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4))), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenTypeInt32() - ); + BinaryenTypeInt32()); // optionally, print the return value - BinaryenExpressionRef args[] = { - BinaryenBinary(module, - BinaryenSubInt32(), - BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenExpressionRef args[] = {BinaryenBinary( + module, + BinaryenSubInt32(), + BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenLoad( + module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ) - ) - }; + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))))}; BinaryenExpressionRef debugger; - if (1) debugger = BinaryenCall(module, "print", args, 1, - BinaryenTypeNone()); - else debugger = BinaryenNop(module); + if (1) + debugger = BinaryenCall(module, "print", args, 1, BinaryenTypeNone()); + else + debugger = BinaryenNop(module); // return the decision. need to subtract 4 that we just added, // and add 8 since that's where we start, so overall offset 4 - BinaryenExpressionRef returner = BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ); - BinaryenExpressionRef checkBodyList[] = { halter, incer, debugger, - returner }; - BinaryenExpressionRef checkBody = BinaryenBlock(module, - NULL, checkBodyList, sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), - BinaryenTypeAuto() - ); + BinaryenExpressionRef returner = + BinaryenLoad(module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))); + BinaryenExpressionRef checkBodyList[] = {halter, incer, debugger, returner}; + BinaryenExpressionRef checkBody = + BinaryenBlock(module, + NULL, + checkBodyList, + sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), + BinaryenTypeAuto()); BinaryenAddFunction(module, "check", BinaryenTypeNone(), @@ -77,219 +107,222 @@ int main() { RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef b0; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b0 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, - BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b0 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b1; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b1 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, - BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b1 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b2; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(2)) - }; + BinaryenConst(module, BinaryenLiteralInt32(2))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b2 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, - BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b2 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b3; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(3)) - }; + BinaryenConst(module, BinaryenLiteralInt32(3))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b3 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, - BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b3 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b4; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(4)) - }; + BinaryenConst(module, BinaryenLiteralInt32(4))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b4 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, - BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b4 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b5; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(5)) - }; + BinaryenConst(module, BinaryenLiteralInt32(5))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b5 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, - BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b5 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b6; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(6)) - }; + BinaryenConst(module, BinaryenLiteralInt32(6))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b6 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, - BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b6 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b7; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(7)) - }; + BinaryenConst(module, BinaryenLiteralInt32(7))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b7 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, - BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b7 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b8; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(8)) - }; + BinaryenConst(module, BinaryenLiteralInt32(8))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b8 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, - BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b8 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } RelooperBlockRef b9; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(9)) - }; + BinaryenConst(module, BinaryenLiteralInt32(9))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b9 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, - BinaryenTypeAuto())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b9 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeAuto())); } - RelooperAddBranch(b0, b2, BinaryenBinary(module, - BinaryenEqInt32(), - BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenConst(module, BinaryenLiteralInt32(0)) - ), NULL); - - RelooperAddBranch(b0, b7, BinaryenBinary(module, - BinaryenEqInt32(), - BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenConst(module, BinaryenLiteralInt32(2)) - ), NULL); + RelooperAddBranch( + b0, + b2, + BinaryenBinary( + module, + BinaryenEqInt32(), + BinaryenBinary(module, + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(4))), + BinaryenConst(module, BinaryenLiteralInt32(0))), + NULL); + + RelooperAddBranch( + b0, + b7, + BinaryenBinary( + module, + BinaryenEqInt32(), + BinaryenBinary(module, + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(4))), + BinaryenConst(module, BinaryenLiteralInt32(2))), + NULL); RelooperAddBranch(b0, b3, NULL, NULL); - RelooperAddBranch(b2, b3, BinaryenBinary(module, - BinaryenEqInt32(), - BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(2)) - ), - BinaryenConst(module, BinaryenLiteralInt32(0)) - ), NULL); + RelooperAddBranch( + b2, + b3, + BinaryenBinary( + module, + BinaryenEqInt32(), + BinaryenBinary(module, + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(2))), + BinaryenConst(module, BinaryenLiteralInt32(0))), + NULL); RelooperAddBranch(b2, b9, NULL, NULL); RelooperAddBranch(b3, b3, NULL, NULL); - RelooperAddBranch(b7, b2, BinaryenBinary(module, - BinaryenEqInt32(), - BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(3)) - ), - BinaryenConst(module, BinaryenLiteralInt32(0)) - ), NULL); + RelooperAddBranch( + b7, + b2, + BinaryenBinary( + module, + BinaryenEqInt32(), + BinaryenBinary(module, + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(3))), + BinaryenConst(module, BinaryenLiteralInt32(0))), + NULL); RelooperAddBranch(b7, b9, NULL, NULL); BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, b0, 1); - int decisions[] = { 67, 131, 49, 36, 112, 161, 62, 166, 16, 88, 176, 152, 161, 194, 117, 180, 60, 166, 55, 183, 150, 73, 196, 143, 76, 182, 97, 140, 126, 3 }; - int numDecisions = sizeof(decisions)/sizeof(int); + int decisions[] = {67, 131, 49, 36, 112, 161, 62, 166, 16, 88, + 176, 152, 161, 194, 117, 180, 60, 166, 55, 183, + 150, 73, 196, 143, 76, 182, 97, 140, 126, 3}; + int numDecisions = sizeof(decisions) / sizeof(int); // write out all the decisions, then the body of the function BinaryenExpressionRef full[numDecisions + 1]; @@ -297,21 +330,22 @@ int main() { { int i; for (i = 0; i < numDecisions; i++) { - full[i] = BinaryenStore(module, - 4, 0, 0, - BinaryenConst(module, BinaryenLiteralInt32(8 + 4 * i)), - BinaryenConst(module, BinaryenLiteralInt32(decisions[i])), - BinaryenTypeInt32() - ); + full[i] = + BinaryenStore(module, + 4, + 0, + 0, + BinaryenConst(module, BinaryenLiteralInt32(8 + 4 * i)), + BinaryenConst(module, BinaryenLiteralInt32(decisions[i])), + BinaryenTypeInt32()); } } full[numDecisions] = body; - BinaryenExpressionRef all = BinaryenBlock(module, NULL, full, - numDecisions + 1, - BinaryenTypeAuto()); + BinaryenExpressionRef all = + BinaryenBlock(module, NULL, full, numDecisions + 1, BinaryenTypeAuto()); // locals: state, free-for-label - BinaryenType localTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32() }; + BinaryenType localTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32()}; BinaryenFunctionRef theMain = BinaryenAddFunction( module, "main", BinaryenTypeNone(), BinaryenTypeNone(), localTypes, 2, all); BinaryenSetStart(module, theMain); diff --git a/test/example/relooper-fuzz2.c b/test/example/relooper-fuzz2.c index 217aaf9fa..a48b86e2a 100644 --- a/test/example/relooper-fuzz2.c +++ b/test/example/relooper-fuzz2.c @@ -12,59 +12,89 @@ int main() { // check() // if the end, halt - BinaryenExpressionRef halter = BinaryenIf(module, - BinaryenBinary(module, + BinaryenExpressionRef halter = BinaryenIf( + module, + BinaryenBinary( + module, BinaryenGeUInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4 * 27)) // jumps of 4 bytes - ), + ), BinaryenUnreachable(module), - NULL - ); + NULL); // increment index - BinaryenExpressionRef incer = BinaryenStore(module, - 4, 0, 0, + BinaryenExpressionRef incer = BinaryenStore( + module, + 4, + 0, + 0, BinaryenConst(module, BinaryenLiteralInt32(4)), BinaryenBinary(module, - BinaryenAddInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenAddInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4))), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenTypeInt32() - ); + BinaryenTypeInt32()); // optionally, print the return value - BinaryenExpressionRef args[] = { - BinaryenBinary(module, - BinaryenSubInt32(), - BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenExpressionRef args[] = {BinaryenBinary( + module, + BinaryenSubInt32(), + BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenLoad( + module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ) - ) - }; + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))))}; BinaryenExpressionRef debugger; - if (1) debugger = BinaryenCall(module, "print", args, 1, - BinaryenTypeNone()); - else debugger = BinaryenNop(module); + if (1) + debugger = BinaryenCall(module, "print", args, 1, BinaryenTypeNone()); + else + debugger = BinaryenNop(module); // return the decision. need to subtract 4 that we just added, // and add 8 since that's where we start, so overall offset 4 - BinaryenExpressionRef returner = BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ); - BinaryenExpressionRef checkBodyList[] = { halter, incer, debugger, - returner }; - BinaryenExpressionRef checkBody = BinaryenBlock(module, - NULL, checkBodyList, sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), - BinaryenTypeInt32() - ); + BinaryenExpressionRef returner = + BinaryenLoad(module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))); + BinaryenExpressionRef checkBodyList[] = {halter, incer, debugger, returner}; + BinaryenExpressionRef checkBody = + BinaryenBlock(module, + NULL, + checkBodyList, + sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), + BinaryenTypeInt32()); BinaryenAddFunction(module, "check", BinaryenTypeNone(), @@ -77,168 +107,159 @@ int main() { RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef b0; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b0 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b0 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b1; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b1 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b1 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b2; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b2 = RelooperAddBlockWithSwitch(relooper, + b2 = RelooperAddBlockWithSwitch( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()), BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(2)) - ) - ); - + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(2)))); } RelooperBlockRef b3; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b3 = RelooperAddBlockWithSwitch(relooper, + b3 = RelooperAddBlockWithSwitch( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()), BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(1)) - ) - ); - + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(1)))); } RelooperBlockRef b4; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(4)) - }; + BinaryenConst(module, BinaryenLiteralInt32(4))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b4 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b4 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b5; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b5 = RelooperAddBlockWithSwitch(relooper, + b5 = RelooperAddBlockWithSwitch( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()), BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(1)) - ) - ); - + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(1)))); } RelooperBlockRef b6; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(6)) - }; + BinaryenConst(module, BinaryenLiteralInt32(6))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b6 = RelooperAddBlockWithSwitch(relooper, + b6 = RelooperAddBlockWithSwitch( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()), BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(3)) - ) - ); - + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(3)))); } RelooperBlockRef b7; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b7 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b7 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b8; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b8 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b8 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperAddBranch( @@ -288,7 +309,10 @@ int main() { BinaryenTypeInt32())); { - BinaryenIndex values[] = { 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86 }; + BinaryenIndex values[] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, + 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, + 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, + 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86}; RelooperAddBranchForSwitch( b2, b7, @@ -440,7 +464,10 @@ int main() { BinaryenTypeInt32())); { - BinaryenIndex values[] = { 0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108 }; + BinaryenIndex values[] = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, + 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, + 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, + 90, 93, 96, 99, 102, 105, 108}; RelooperAddBranchForSwitch( b6, b1, @@ -467,7 +494,11 @@ int main() { } { - BinaryenIndex values[] = { 1,4,7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58,61,64,67,70,73,76,79,82,85,88,91,94,97,100,103,106,109,112,115,118,121,124,127,130,133,136,139,142,145,148,151,154,157,160 }; + BinaryenIndex values[] = { + 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, + 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, + 85, 88, 91, 94, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124, + 127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160}; RelooperAddBranchForSwitch( b6, b7, @@ -595,8 +626,10 @@ int main() { BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, b0, 1); - int decisions[] = { 5, 111, 119, 17, 179, 41, 32, 3, 171, 126, 13, 95, 70, 91, 9, 140, 99, 161, 38, 87, 153, 117, 140, 11, 157, 48, 4 }; - int numDecisions = sizeof(decisions)/sizeof(int); + int decisions[] = {5, 111, 119, 17, 179, 41, 32, 3, 171, + 126, 13, 95, 70, 91, 9, 140, 99, 161, + 38, 87, 153, 117, 140, 11, 157, 48, 4}; + int numDecisions = sizeof(decisions) / sizeof(int); // write out all the decisions, then the body of the function BinaryenExpressionRef full[numDecisions + 1]; @@ -604,21 +637,22 @@ int main() { { int i; for (i = 0; i < numDecisions; i++) { - full[i] = BinaryenStore(module, - 4, 0, 0, - BinaryenConst(module, BinaryenLiteralInt32(8 + 4 * i)), - BinaryenConst(module, BinaryenLiteralInt32(decisions[i])), - BinaryenTypeInt32() - ); + full[i] = + BinaryenStore(module, + 4, + 0, + 0, + BinaryenConst(module, BinaryenLiteralInt32(8 + 4 * i)), + BinaryenConst(module, BinaryenLiteralInt32(decisions[i])), + BinaryenTypeInt32()); } } full[numDecisions] = body; - BinaryenExpressionRef all = BinaryenBlock(module, NULL, full, - numDecisions + 1, - BinaryenTypeNone()); + BinaryenExpressionRef all = + BinaryenBlock(module, NULL, full, numDecisions + 1, BinaryenTypeNone()); // locals: state, free-for-label - BinaryenType localTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32() }; + BinaryenType localTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32()}; BinaryenFunctionRef theMain = BinaryenAddFunction( module, "main", BinaryenTypeNone(), BinaryenTypeNone(), localTypes, 2, all); BinaryenSetStart(module, theMain); @@ -635,7 +669,8 @@ int main() { BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0); // optionally, optimize - if (0) BinaryenModuleOptimize(module); + if (0) + BinaryenModuleOptimize(module); assert(BinaryenModuleValidate(module)); diff --git a/test/example/relooper-merge1.c b/test/example/relooper-merge1.c index 68796a6f6..491839f36 100644 --- a/test/example/relooper-merge1.c +++ b/test/example/relooper-merge1.c @@ -12,59 +12,89 @@ int main() { // check() // if the end, halt - BinaryenExpressionRef halter = BinaryenIf(module, - BinaryenBinary(module, + BinaryenExpressionRef halter = BinaryenIf( + module, + BinaryenBinary( + module, BinaryenGeUInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4 * 12)) // jumps of 4 bytes - ), + ), BinaryenUnreachable(module), - NULL - ); + NULL); // increment index - BinaryenExpressionRef incer = BinaryenStore(module, - 4, 0, 0, + BinaryenExpressionRef incer = BinaryenStore( + module, + 4, + 0, + 0, BinaryenConst(module, BinaryenLiteralInt32(4)), BinaryenBinary(module, - BinaryenAddInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenAddInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4))), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenTypeInt32() - ); + BinaryenTypeInt32()); // optionally, print the return value - BinaryenExpressionRef args[] = { - BinaryenBinary(module, - BinaryenSubInt32(), - BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenExpressionRef args[] = {BinaryenBinary( + module, + BinaryenSubInt32(), + BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenLoad( + module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ) - ) - }; + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))))}; BinaryenExpressionRef debugger; - if (1) debugger = BinaryenCall(module, "print", args, 1, - BinaryenTypeNone()); - else debugger = BinaryenNop(module); + if (1) + debugger = BinaryenCall(module, "print", args, 1, BinaryenTypeNone()); + else + debugger = BinaryenNop(module); // return the decision. need to subtract 4 that we just added, // and add 8 since that's where we start, so overall offset 4 - BinaryenExpressionRef returner = BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ); - BinaryenExpressionRef checkBodyList[] = { halter, incer, debugger, - returner }; - BinaryenExpressionRef checkBody = BinaryenBlock(module, - NULL, checkBodyList, sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), - BinaryenTypeInt32() - ); + BinaryenExpressionRef returner = + BinaryenLoad(module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))); + BinaryenExpressionRef checkBodyList[] = {halter, incer, debugger, returner}; + BinaryenExpressionRef checkBody = + BinaryenBlock(module, + NULL, + checkBodyList, + sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), + BinaryenTypeInt32()); BinaryenAddFunction(module, "check", BinaryenTypeNone(), @@ -77,100 +107,99 @@ int main() { RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef b0; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b0 = RelooperAddBlockWithSwitch(relooper, + b0 = RelooperAddBlockWithSwitch( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()), BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(1)) - ) - ); - + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(1)))); } RelooperBlockRef b1; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b1 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b1 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b2; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b2 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b2 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b3; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b3 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b3 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b4; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b4 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b4 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } // Separate branch for each. // In this testcase, target blocks have identical contents (print 1), // and branches have no phi codes, and no loops. { - BinaryenIndex indexes[] = { 1, 4, 9 }; + BinaryenIndex indexes[] = {1, 4, 9}; RelooperAddBranchForSwitch(b0, b1, indexes, 3, NULL); } { - BinaryenIndex indexes[] = { 3, 6 }; + BinaryenIndex indexes[] = {3, 6}; RelooperAddBranchForSwitch(b0, b2, indexes, 2, NULL); } { - BinaryenIndex indexes[] = { 5, 25, 125 }; + BinaryenIndex indexes[] = {5, 25, 125}; RelooperAddBranchForSwitch(b0, b3, indexes, 3, NULL); } RelooperAddBranchForSwitch(b0, b4, NULL, 0, NULL); @@ -178,7 +207,7 @@ int main() { BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, b0, 1); // locals: state, free-for-label - BinaryenType localTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32() }; + BinaryenType localTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32()}; BinaryenFunctionRef theMain = BinaryenAddFunction(module, "main", BinaryenTypeNone(), @@ -197,10 +226,11 @@ int main() { BinaryenTypeNone()); // memory - BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0); + BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0); // optionally, optimize - if (0) BinaryenModuleOptimize(module); + if (0) + BinaryenModuleOptimize(module); assert(BinaryenModuleValidate(module)); diff --git a/test/example/relooper-merge2.c b/test/example/relooper-merge2.c index c4ac11a14..ed5fc0f4d 100644 --- a/test/example/relooper-merge2.c +++ b/test/example/relooper-merge2.c @@ -12,59 +12,89 @@ int main() { // check() // if the end, halt - BinaryenExpressionRef halter = BinaryenIf(module, - BinaryenBinary(module, + BinaryenExpressionRef halter = BinaryenIf( + module, + BinaryenBinary( + module, BinaryenGeUInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4 * 12)) // jumps of 4 bytes - ), + ), BinaryenUnreachable(module), - NULL - ); + NULL); // increment index - BinaryenExpressionRef incer = BinaryenStore(module, - 4, 0, 0, + BinaryenExpressionRef incer = BinaryenStore( + module, + 4, + 0, + 0, BinaryenConst(module, BinaryenLiteralInt32(4)), BinaryenBinary(module, - BinaryenAddInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenAddInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4))), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenTypeInt32() - ); + BinaryenTypeInt32()); // optionally, print the return value - BinaryenExpressionRef args[] = { - BinaryenBinary(module, - BinaryenSubInt32(), - BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenExpressionRef args[] = {BinaryenBinary( + module, + BinaryenSubInt32(), + BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenLoad( + module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ) - ) - }; + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))))}; BinaryenExpressionRef debugger; - if (1) debugger = BinaryenCall(module, "print", args, 1, - BinaryenTypeNone()); - else debugger = BinaryenNop(module); + if (1) + debugger = BinaryenCall(module, "print", args, 1, BinaryenTypeNone()); + else + debugger = BinaryenNop(module); // return the decision. need to subtract 4 that we just added, // and add 8 since that's where we start, so overall offset 4 - BinaryenExpressionRef returner = BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ); - BinaryenExpressionRef checkBodyList[] = { halter, incer, debugger, - returner }; - BinaryenExpressionRef checkBody = BinaryenBlock(module, - NULL, checkBodyList, sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), - BinaryenTypeInt32() - ); + BinaryenExpressionRef returner = + BinaryenLoad(module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))); + BinaryenExpressionRef checkBodyList[] = {halter, incer, debugger, returner}; + BinaryenExpressionRef checkBody = + BinaryenBlock(module, + NULL, + checkBodyList, + sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), + BinaryenTypeInt32()); BinaryenAddFunction(module, "check", BinaryenTypeNone(), @@ -77,120 +107,122 @@ int main() { RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef b0; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b0 = RelooperAddBlockWithSwitch(relooper, + b0 = RelooperAddBlockWithSwitch( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()), BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(1)) - ) - ); - + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(1)))); } RelooperBlockRef b1; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b1 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b1 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b2; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b2 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b2 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b3; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b3 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b3 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b4; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b4 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b4 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } // Separate branch for each. // In this testcase, target blocks have identical contents (print 1), // and branches have identical phis. { - BinaryenIndex indexes[] = { 1, 4, 9 }; - RelooperAddBranchForSwitch(b0, b1, indexes, 3, - BinaryenDrop(module, - BinaryenConst(module, BinaryenLiteralInt32(4)) - ) - ); + BinaryenIndex indexes[] = {1, 4, 9}; + RelooperAddBranchForSwitch( + b0, + b1, + indexes, + 3, + BinaryenDrop(module, BinaryenConst(module, BinaryenLiteralInt32(4)))); } { - BinaryenIndex indexes[] = { 3, 6 }; - RelooperAddBranchForSwitch(b0, b2, indexes, 2, - BinaryenDrop(module, - BinaryenConst(module, BinaryenLiteralInt32(4)) - ) - ); + BinaryenIndex indexes[] = {3, 6}; + RelooperAddBranchForSwitch( + b0, + b2, + indexes, + 2, + BinaryenDrop(module, BinaryenConst(module, BinaryenLiteralInt32(4)))); } { - BinaryenIndex indexes[] = { 5, 25, 125 }; - RelooperAddBranchForSwitch(b0, b3, indexes, 3, - BinaryenDrop(module, - BinaryenConst(module, BinaryenLiteralInt32(4)) - ) - ); + BinaryenIndex indexes[] = {5, 25, 125}; + RelooperAddBranchForSwitch( + b0, + b3, + indexes, + 3, + BinaryenDrop(module, BinaryenConst(module, BinaryenLiteralInt32(4)))); } RelooperAddBranchForSwitch(b0, b4, NULL, 0, NULL); BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, b0, 1); // locals: state, free-for-label - BinaryenType localTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32() }; + BinaryenType localTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32()}; BinaryenFunctionRef theMain = BinaryenAddFunction(module, "main", BinaryenTypeNone(), @@ -212,7 +244,8 @@ int main() { BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0); // optionally, optimize - if (0) BinaryenModuleOptimize(module); + if (0) + BinaryenModuleOptimize(module); assert(BinaryenModuleValidate(module)); diff --git a/test/example/relooper-merge3.c b/test/example/relooper-merge3.c index 276ab3c3c..655b4d22b 100644 --- a/test/example/relooper-merge3.c +++ b/test/example/relooper-merge3.c @@ -12,59 +12,89 @@ int main() { // check() // if the end, halt - BinaryenExpressionRef halter = BinaryenIf(module, - BinaryenBinary(module, + BinaryenExpressionRef halter = BinaryenIf( + module, + BinaryenBinary( + module, BinaryenGeUInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4 * 12)) // jumps of 4 bytes - ), + ), BinaryenUnreachable(module), - NULL - ); + NULL); // increment index - BinaryenExpressionRef incer = BinaryenStore(module, - 4, 0, 0, + BinaryenExpressionRef incer = BinaryenStore( + module, + 4, + 0, + 0, BinaryenConst(module, BinaryenLiteralInt32(4)), BinaryenBinary(module, - BinaryenAddInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenAddInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4))), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenTypeInt32() - ); + BinaryenTypeInt32()); // optionally, print the return value - BinaryenExpressionRef args[] = { - BinaryenBinary(module, - BinaryenSubInt32(), - BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenExpressionRef args[] = {BinaryenBinary( + module, + BinaryenSubInt32(), + BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenLoad( + module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ) - ) - }; + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))))}; BinaryenExpressionRef debugger; - if (1) debugger = BinaryenCall(module, "print", args, 1, - BinaryenTypeNone()); - else debugger = BinaryenNop(module); + if (1) + debugger = BinaryenCall(module, "print", args, 1, BinaryenTypeNone()); + else + debugger = BinaryenNop(module); // return the decision. need to subtract 4 that we just added, // and add 8 since that's where we start, so overall offset 4 - BinaryenExpressionRef returner = BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ); - BinaryenExpressionRef checkBodyList[] = { halter, incer, debugger, - returner }; - BinaryenExpressionRef checkBody = BinaryenBlock(module, - NULL, checkBodyList, sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), - BinaryenTypeInt32() - ); + BinaryenExpressionRef returner = + BinaryenLoad(module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))); + BinaryenExpressionRef checkBodyList[] = {halter, incer, debugger, returner}; + BinaryenExpressionRef checkBody = + BinaryenBlock(module, + NULL, + checkBodyList, + sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), + BinaryenTypeInt32()); BinaryenAddFunction(module, "check", BinaryenTypeNone(), @@ -77,99 +107,98 @@ int main() { RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef b0; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b0 = RelooperAddBlockWithSwitch(relooper, + b0 = RelooperAddBlockWithSwitch( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()), BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(1)) - ) - ); - + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(1)))); } RelooperBlockRef b1; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b1 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b1 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b2; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b2 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b2 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b3; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(2)) - }; + BinaryenConst(module, BinaryenLiteralInt32(2))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b3 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b3 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b4; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(3)) - }; + BinaryenConst(module, BinaryenLiteralInt32(3))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b4 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b4 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } // Separate branch for each. // In this testcase, two blocks out of 4 can be merged. { - BinaryenIndex indexes[] = { 1, 4, 9 }; + BinaryenIndex indexes[] = {1, 4, 9}; RelooperAddBranchForSwitch(b0, b1, indexes, 3, NULL); } { - BinaryenIndex indexes[] = { 3, 6 }; + BinaryenIndex indexes[] = {3, 6}; RelooperAddBranchForSwitch(b0, b2, indexes, 2, NULL); } { - BinaryenIndex indexes[] = { 5 }; + BinaryenIndex indexes[] = {5}; RelooperAddBranchForSwitch(b0, b3, indexes, 1, NULL); } RelooperAddBranchForSwitch(b0, b4, NULL, 0, NULL); @@ -177,7 +206,7 @@ int main() { BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, b0, 1); // locals: state, free-for-label - BinaryenType localTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32() }; + BinaryenType localTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32()}; BinaryenFunctionRef theMain = BinaryenAddFunction(module, "main", BinaryenTypeNone(), @@ -199,7 +228,8 @@ int main() { BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0); // optionally, optimize - if (0) BinaryenModuleOptimize(module); + if (0) + BinaryenModuleOptimize(module); assert(BinaryenModuleValidate(module)); diff --git a/test/example/relooper-merge4.c b/test/example/relooper-merge4.c index b168a2db6..2e5624421 100644 --- a/test/example/relooper-merge4.c +++ b/test/example/relooper-merge4.c @@ -12,59 +12,89 @@ int main() { // check() // if the end, halt - BinaryenExpressionRef halter = BinaryenIf(module, - BinaryenBinary(module, + BinaryenExpressionRef halter = BinaryenIf( + module, + BinaryenBinary( + module, BinaryenGeUInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4 * 12)) // jumps of 4 bytes - ), + ), BinaryenUnreachable(module), - NULL - ); + NULL); // increment index - BinaryenExpressionRef incer = BinaryenStore(module, - 4, 0, 0, + BinaryenExpressionRef incer = BinaryenStore( + module, + 4, + 0, + 0, BinaryenConst(module, BinaryenLiteralInt32(4)), BinaryenBinary(module, - BinaryenAddInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenAddInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4))), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenTypeInt32() - ); + BinaryenTypeInt32()); // optionally, print the return value - BinaryenExpressionRef args[] = { - BinaryenBinary(module, - BinaryenSubInt32(), - BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenExpressionRef args[] = {BinaryenBinary( + module, + BinaryenSubInt32(), + BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenLoad( + module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ) - ) - }; + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))))}; BinaryenExpressionRef debugger; - if (1) debugger = BinaryenCall(module, "print", args, 1, - BinaryenTypeNone()); - else debugger = BinaryenNop(module); + if (1) + debugger = BinaryenCall(module, "print", args, 1, BinaryenTypeNone()); + else + debugger = BinaryenNop(module); // return the decision. need to subtract 4 that we just added, // and add 8 since that's where we start, so overall offset 4 - BinaryenExpressionRef returner = BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ); - BinaryenExpressionRef checkBodyList[] = { halter, incer, debugger, - returner }; - BinaryenExpressionRef checkBody = BinaryenBlock(module, - NULL, checkBodyList, sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), - BinaryenTypeInt32() - ); + BinaryenExpressionRef returner = + BinaryenLoad(module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))); + BinaryenExpressionRef checkBodyList[] = {halter, incer, debugger, returner}; + BinaryenExpressionRef checkBody = + BinaryenBlock(module, + NULL, + checkBodyList, + sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), + BinaryenTypeInt32()); BinaryenAddFunction(module, "check", BinaryenTypeNone(), @@ -77,99 +107,98 @@ int main() { RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef b0; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b0 = RelooperAddBlockWithSwitch(relooper, + b0 = RelooperAddBlockWithSwitch( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()), BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(1)) - ) - ); - + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(1)))); } RelooperBlockRef b1; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b1 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b1 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b2; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b2 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b2 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b3; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(2)) - }; + BinaryenConst(module, BinaryenLiteralInt32(2))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b3 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b3 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b4; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(3)) - }; + BinaryenConst(module, BinaryenLiteralInt32(3))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b4 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b4 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } // Separate branch for each. // In this testcase, two blocks out of 4 can be merged. { - BinaryenIndex indexes[] = { 1, 4, 9 }; + BinaryenIndex indexes[] = {1, 4, 9}; RelooperAddBranchForSwitch(b0, b4, indexes, 3, NULL); } { - BinaryenIndex indexes[] = { 3, 6 }; + BinaryenIndex indexes[] = {3, 6}; RelooperAddBranchForSwitch(b0, b2, indexes, 2, NULL); } { - BinaryenIndex indexes[] = { 5 }; + BinaryenIndex indexes[] = {5}; RelooperAddBranchForSwitch(b0, b3, indexes, 1, NULL); } RelooperAddBranchForSwitch(b0, b1, NULL, 0, NULL); @@ -177,7 +206,7 @@ int main() { BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, b0, 1); // locals: state, free-for-label - BinaryenType localTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32() }; + BinaryenType localTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32()}; BinaryenFunctionRef theMain = BinaryenAddFunction(module, "main", BinaryenTypeNone(), @@ -199,7 +228,8 @@ int main() { BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0); // optionally, optimize - if (0) BinaryenModuleOptimize(module); + if (0) + BinaryenModuleOptimize(module); assert(BinaryenModuleValidate(module)); diff --git a/test/example/relooper-merge5.c b/test/example/relooper-merge5.c index deee2afee..41a36c102 100644 --- a/test/example/relooper-merge5.c +++ b/test/example/relooper-merge5.c @@ -12,59 +12,89 @@ int main() { // check() // if the end, halt - BinaryenExpressionRef halter = BinaryenIf(module, - BinaryenBinary(module, + BinaryenExpressionRef halter = BinaryenIf( + module, + BinaryenBinary( + module, BinaryenGeUInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4 * 12)) // jumps of 4 bytes - ), + ), BinaryenUnreachable(module), - NULL - ); + NULL); // increment index - BinaryenExpressionRef incer = BinaryenStore(module, - 4, 0, 0, + BinaryenExpressionRef incer = BinaryenStore( + module, + 4, + 0, + 0, BinaryenConst(module, BinaryenLiteralInt32(4)), BinaryenBinary(module, - BinaryenAddInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenAddInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4))), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenTypeInt32() - ); + BinaryenTypeInt32()); // optionally, print the return value - BinaryenExpressionRef args[] = { - BinaryenBinary(module, - BinaryenSubInt32(), - BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenExpressionRef args[] = {BinaryenBinary( + module, + BinaryenSubInt32(), + BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenLoad( + module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ) - ) - }; + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))))}; BinaryenExpressionRef debugger; - if (1) debugger = BinaryenCall(module, "print", args, 1, - BinaryenTypeNone()); - else debugger = BinaryenNop(module); + if (1) + debugger = BinaryenCall(module, "print", args, 1, BinaryenTypeNone()); + else + debugger = BinaryenNop(module); // return the decision. need to subtract 4 that we just added, // and add 8 since that's where we start, so overall offset 4 - BinaryenExpressionRef returner = BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ); - BinaryenExpressionRef checkBodyList[] = { halter, incer, debugger, - returner }; - BinaryenExpressionRef checkBody = BinaryenBlock(module, - NULL, checkBodyList, sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), - BinaryenTypeInt32() - ); + BinaryenExpressionRef returner = + BinaryenLoad(module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))); + BinaryenExpressionRef checkBodyList[] = {halter, incer, debugger, returner}; + BinaryenExpressionRef checkBody = + BinaryenBlock(module, + NULL, + checkBodyList, + sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), + BinaryenTypeInt32()); BinaryenAddFunction(module, "check", BinaryenTypeNone(), @@ -77,107 +107,106 @@ int main() { RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef b0; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b0 = RelooperAddBlockWithSwitch(relooper, + b0 = RelooperAddBlockWithSwitch( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()), BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(1)) - ) - ); - + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(1)))); } RelooperBlockRef b1; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b1 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b1 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b2; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b2 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b2 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b3; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(2)) - }; + BinaryenConst(module, BinaryenLiteralInt32(2))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b3 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b3 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b4; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(3)) - }; + BinaryenConst(module, BinaryenLiteralInt32(3))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b4 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b4 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } // Separate branch for each. // In this testcase, two blocks out of 4 can be merged. RelooperAddBranchForSwitch(b0, b1, NULL, 0, NULL); { - BinaryenIndex indexes[] = { 1, 4, 9 }; + BinaryenIndex indexes[] = {1, 4, 9}; RelooperAddBranchForSwitch(b0, b4, indexes, 3, NULL); } { - BinaryenIndex indexes[] = { 3, 6 }; + BinaryenIndex indexes[] = {3, 6}; RelooperAddBranchForSwitch(b0, b2, indexes, 2, NULL); } { - BinaryenIndex indexes[] = { 5 }; + BinaryenIndex indexes[] = {5}; RelooperAddBranchForSwitch(b0, b3, indexes, 1, NULL); } BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, b0, 1); // locals: state, free-for-label - BinaryenType localTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32() }; + BinaryenType localTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32()}; BinaryenFunctionRef theMain = BinaryenAddFunction(module, "main", BinaryenTypeNone(), @@ -199,7 +228,8 @@ int main() { BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0); // optionally, optimize - if (0) BinaryenModuleOptimize(module); + if (0) + BinaryenModuleOptimize(module); assert(BinaryenModuleValidate(module)); diff --git a/test/example/relooper-merge6.c b/test/example/relooper-merge6.c index a9b26e8e1..23e639cb1 100644 --- a/test/example/relooper-merge6.c +++ b/test/example/relooper-merge6.c @@ -12,59 +12,89 @@ int main() { // check() // if the end, halt - BinaryenExpressionRef halter = BinaryenIf(module, - BinaryenBinary(module, + BinaryenExpressionRef halter = BinaryenIf( + module, + BinaryenBinary( + module, BinaryenGeUInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4 * 12)) // jumps of 4 bytes - ), + ), BinaryenUnreachable(module), - NULL - ); + NULL); // increment index - BinaryenExpressionRef incer = BinaryenStore(module, - 4, 0, 0, + BinaryenExpressionRef incer = BinaryenStore( + module, + 4, + 0, + 0, BinaryenConst(module, BinaryenLiteralInt32(4)), BinaryenBinary(module, - BinaryenAddInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), + BinaryenAddInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4))), BinaryenConst(module, BinaryenLiteralInt32(4))), - BinaryenConst(module, BinaryenLiteralInt32(4)) - ), - BinaryenTypeInt32() - ); + BinaryenTypeInt32()); // optionally, print the return value - BinaryenExpressionRef args[] = { - BinaryenBinary(module, - BinaryenSubInt32(), - BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenExpressionRef args[] = {BinaryenBinary( + module, + BinaryenSubInt32(), + BinaryenConst(module, BinaryenLiteralInt32(0)), + BinaryenLoad( + module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ) - ) - }; + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))))}; BinaryenExpressionRef debugger; - if (1) debugger = BinaryenCall(module, "print", args, 1, - BinaryenTypeNone()); - else debugger = BinaryenNop(module); + if (1) + debugger = BinaryenCall(module, "print", args, 1, BinaryenTypeNone()); + else + debugger = BinaryenNop(module); // return the decision. need to subtract 4 that we just added, // and add 8 since that's where we start, so overall offset 4 - BinaryenExpressionRef returner = BinaryenLoad(module, - 4, 0, 4, 0, BinaryenTypeInt32(), - BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), - BinaryenConst(module, BinaryenLiteralInt32(4))) - ); - BinaryenExpressionRef checkBodyList[] = { halter, incer, debugger, - returner }; - BinaryenExpressionRef checkBody = BinaryenBlock(module, - NULL, checkBodyList, sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), - BinaryenTypeInt32() - ); + BinaryenExpressionRef returner = + BinaryenLoad(module, + 4, + 0, + 4, + 0, + BinaryenTypeInt32(), + BinaryenLoad(module, + 4, + 0, + 0, + 0, + BinaryenTypeInt32(), + BinaryenConst(module, BinaryenLiteralInt32(4)))); + BinaryenExpressionRef checkBodyList[] = {halter, incer, debugger, returner}; + BinaryenExpressionRef checkBody = + BinaryenBlock(module, + NULL, + checkBodyList, + sizeof(checkBodyList) / sizeof(BinaryenExpressionRef), + BinaryenTypeInt32()); BinaryenAddFunction(module, "check", BinaryenTypeNone(), @@ -77,98 +107,109 @@ int main() { RelooperRef relooper = RelooperCreate(module); - RelooperBlockRef b0; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(0)) - }; + BinaryenConst(module, BinaryenLiteralInt32(0))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b0 = RelooperAddBlockWithSwitch(relooper, + b0 = RelooperAddBlockWithSwitch( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()), BinaryenBinary(module, - BinaryenRemUInt32(), - BinaryenLocalGet(module, 0, BinaryenTypeInt32()), - BinaryenConst(module, BinaryenLiteralInt32(1)) - ) - ); - + BinaryenRemUInt32(), + BinaryenLocalGet(module, 0, BinaryenTypeInt32()), + BinaryenConst(module, BinaryenLiteralInt32(1)))); } RelooperBlockRef b1; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b1 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b1 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b2; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; - - b2 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; + b2 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b3; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b3 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b3 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } RelooperBlockRef b4; { BinaryenExpressionRef args[] = { - BinaryenConst(module, BinaryenLiteralInt32(1)) - }; + BinaryenConst(module, BinaryenLiteralInt32(1))}; BinaryenExpressionRef list[] = { BinaryenCall(module, "print", args, 1, BinaryenTypeNone()), - BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0, - BinaryenTypeInt32())) - }; + BinaryenLocalSet( + module, + 0, + BinaryenCall(module, "check", NULL, 0, BinaryenTypeInt32()))}; - b4 = RelooperAddBlock(relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); + b4 = RelooperAddBlock( + relooper, BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone())); } // Separate branch for each. // In this testcase, we can merge multiple consecutive blocks with phis. - RelooperAddBranch(b0, b1, NULL, BinaryenDrop(module, BinaryenConst(module, BinaryenLiteralInt32(10)))); - RelooperAddBranch(b1, b2, NULL, BinaryenDrop(module, BinaryenConst(module, BinaryenLiteralInt32(11)))); + RelooperAddBranch( + b0, + b1, + NULL, + BinaryenDrop(module, BinaryenConst(module, BinaryenLiteralInt32(10)))); + RelooperAddBranch( + b1, + b2, + NULL, + BinaryenDrop(module, BinaryenConst(module, BinaryenLiteralInt32(11)))); RelooperAddBranch(b2, b3, NULL, NULL); - RelooperAddBranch(b3, b4, NULL, BinaryenDrop(module, BinaryenConst(module, BinaryenLiteralInt32(12)))); + RelooperAddBranch( + b3, + b4, + NULL, + BinaryenDrop(module, BinaryenConst(module, BinaryenLiteralInt32(12)))); BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, b0, 1); // locals: state, free-for-label - BinaryenType localTypes[] = { BinaryenTypeInt32(), BinaryenTypeInt32() }; + BinaryenType localTypes[] = {BinaryenTypeInt32(), BinaryenTypeInt32()}; BinaryenFunctionRef theMain = BinaryenAddFunction(module, "main", BinaryenTypeNone(), @@ -190,7 +231,8 @@ int main() { BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0); // optionally, optimize - if (0) BinaryenModuleOptimize(module); + if (0) + BinaryenModuleOptimize(module); assert(BinaryenModuleValidate(module)); diff --git a/test/example/small_vector.cpp b/test/example/small_vector.cpp index 732cbfac3..cb2e22e79 100644 --- a/test/example/small_vector.cpp +++ b/test/example/small_vector.cpp @@ -1,12 +1,11 @@ -#include <iostream> #include <cassert> +#include <iostream> #include "support/small_vector.h" using namespace wasm; -template<typename T> -void test() { +template<typename T> void test() { { T t; // build up @@ -65,4 +64,3 @@ int main() { test<SmallVector<int, 10>>(); std::cout << "ok.\n"; } - diff --git a/test/fannkuch.cpp b/test/fannkuch.cpp index f615ba2f8..86791a98d 100644 --- a/test/fannkuch.cpp +++ b/test/fannkuch.cpp @@ -9,151 +9,144 @@ * Modified for emscripten by azakai */ -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> struct worker_args { - int i, n; - struct worker_args *next; + int i, n; + struct worker_args* next; }; -int -fannkuch_worker(void *_arg) -{ - struct worker_args *args = (worker_args*)_arg; - int *perm1, *count, *perm; - int maxflips, flips, i, n, r, j, k, tmp; - - maxflips = 0; - n = args->n; - perm1 = (int*)malloc(n * sizeof(int)); - perm = (int*)malloc(n * sizeof(int)); - count = (int*)malloc(n * sizeof(int)); - for (i = 0; i < n; i++) - perm1[i] = i; - perm1[args->i] = n - 1; - perm1[n - 1] = args->i; - r = n; - - for (;;) { - for (; r > 1; r--) - count[r - 1] = r; - if (perm1[0] != 0 && perm1[n - 1] != n - 1) { - for (i = 0; i < n; i++) - perm[i] = perm1[i]; - flips = 0; - k = perm[0]; - do { - for (i = 1, j = k - 1; i < j; i++, j--) { - tmp = perm[i]; - perm[i] = perm[j]; - perm[j] = tmp; - } - flips++; - tmp = perm[k]; - perm[k] = k; - k = tmp; - } while (k); - if (maxflips < flips) - maxflips = flips; +int fannkuch_worker(void* _arg) { + struct worker_args* args = (worker_args*)_arg; + int *perm1, *count, *perm; + int maxflips, flips, i, n, r, j, k, tmp; + + maxflips = 0; + n = args->n; + perm1 = (int*)malloc(n * sizeof(int)); + perm = (int*)malloc(n * sizeof(int)); + count = (int*)malloc(n * sizeof(int)); + for (i = 0; i < n; i++) + perm1[i] = i; + perm1[args->i] = n - 1; + perm1[n - 1] = args->i; + r = n; + + for (;;) { + for (; r > 1; r--) + count[r - 1] = r; + if (perm1[0] != 0 && perm1[n - 1] != n - 1) { + for (i = 0; i < n; i++) + perm[i] = perm1[i]; + flips = 0; + k = perm[0]; + do { + for (i = 1, j = k - 1; i < j; i++, j--) { + tmp = perm[i]; + perm[i] = perm[j]; + perm[j] = tmp; + } + flips++; + tmp = perm[k]; + perm[k] = k; + k = tmp; + } while (k); + if (maxflips < flips) + maxflips = flips; + } + for (;;) { + if (r >= n - 1) { + free(perm1); + free(perm); + free(count); + return maxflips; } - for (;;) { - if (r >= n - 1) { - free(perm1); - free(perm); - free(count); - return maxflips; - } - - { - int p0 = perm1[0]; - for (i = 0; i < r; i++) - perm1[i] = perm1[i + 1]; - perm1[i] = p0; - } - if (--count[r] > 0) - break; - r++; + + { + int p0 = perm1[0]; + for (i = 0; i < r; i++) + perm1[i] = perm1[i + 1]; + perm1[i] = p0; } - } + if (--count[r] > 0) + break; + r++; + } + } } -static int -fannkuch(int n) -{ - struct worker_args *args, *targs; - int showmax = 30; - int *perm1, *count, i, r, maxflips, flips; - - args = NULL; - for (i = 0; i < n - 1; i++) { - targs = (worker_args*)malloc(sizeof(struct worker_args)); - targs->i = i; - targs->n = n; - targs->next = args; - args = targs; - } - - perm1 = (int*)malloc(n * sizeof(int)); - count = (int*)malloc(n * sizeof(int)); - - for (i = 0; i < n; i++) - perm1[i] = i; - - r = n; - for (;;) { - if (showmax) { - for (i = 0; i < n; i++) - printf("%d", perm1[i] + 1); - printf("\n"); - showmax--; - } else - goto cleanup; - - for (; r > 1; r--) - count[r - 1] = r; - - for (;;) { - if (r == n) - goto cleanup; - { - int p0 = perm1[0]; - for (i = 0; i < r; i++) - perm1[i] = perm1[i + 1]; - perm1[i] = p0; - } - if (--count[r] > 0) - break; - - r++; +static int fannkuch(int n) { + struct worker_args *args, *targs; + int showmax = 30; + int *perm1, *count, i, r, maxflips, flips; + + args = NULL; + for (i = 0; i < n - 1; i++) { + targs = (worker_args*)malloc(sizeof(struct worker_args)); + targs->i = i; + targs->n = n; + targs->next = args; + args = targs; + } + + perm1 = (int*)malloc(n * sizeof(int)); + count = (int*)malloc(n * sizeof(int)); + + for (i = 0; i < n; i++) + perm1[i] = i; + + r = n; + for (;;) { + if (showmax) { + for (i = 0; i < n; i++) + printf("%d", perm1[i] + 1); + printf("\n"); + showmax--; + } else + goto cleanup; + + for (; r > 1; r--) + count[r - 1] = r; + + for (;;) { + if (r == n) + goto cleanup; + { + int p0 = perm1[0]; + for (i = 0; i < r; i++) + perm1[i] = perm1[i + 1]; + perm1[i] = p0; } - } - - cleanup: - free(perm1); - free(count); - maxflips = 0; - while (args != NULL) { - flips = (int)fannkuch_worker(args); - if (maxflips < flips) - maxflips = flips; - targs = args; - args = args->next; - free(targs); - } - return maxflips; + if (--count[r] > 0) + break; + + r++; + } + } + +cleanup: + free(perm1); + free(count); + maxflips = 0; + while (args != NULL) { + flips = (int)fannkuch_worker(args); + if (maxflips < flips) + maxflips = flips; + targs = args; + args = args->next; + free(targs); + } + return maxflips; } -int -main(int argc, char **argv) -{ - int n = argc > 1 ? atoi(argv[1]) : 0; - - if (n < 1) { - printf("Wrong argument.\n"); - return 1; - } - printf("Pfannkuchen(%d) = %d.\n", n, fannkuch(n)); - return 0; -} +int main(int argc, char** argv) { + int n = argc > 1 ? atoi(argv[1]) : 0; + if (n < 1) { + printf("Wrong argument.\n"); + return 1; + } + printf("Pfannkuchen(%d) = %d.\n", n, fannkuch(n)); + return 0; +} diff --git a/test/fasta.cpp b/test/fasta.cpp index 1b52e1b27..4216665ea 100644 --- a/test/fasta.cpp +++ b/test/fasta.cpp @@ -8,8 +8,7 @@ #include <string.h> // limit output, so we do not benchmark speed of printing -void puts_limited(char *x) -{ +void puts_limited(char* x) { static int left = 550; int len = strlen(x); if (len <= left) { @@ -26,173 +25,175 @@ void puts_limited(char *x) } struct Random { - enum { IM = 139968, IA = 3877, IC = 29573 }; - Random() : last(42) {} - float get( float max = 1.0f ) { - last = ( last * IA + IC ) % IM; - return max * last / IM; - } + enum { IM = 139968, IA = 3877, IC = 29573 }; + Random() : last(42) {} + float get(float max = 1.0f) { + last = (last * IA + IC) % IM; + return max * last / IM; + } + protected: - unsigned int last; + unsigned int last; } rng; struct IUB { - int c; - double p; - unsigned int pi; + int c; + double p; + unsigned int pi; }; struct Cumulative { - enum { slots = 512, }; - - Cumulative( IUB *start ) { - double p = 0; - for ( IUB *iter = start; iter->c; ++iter ) { - p += iter->p; - iter->p = p < 1.0 ? p : 1.0; - iter->pi = (unsigned int )( iter->p * slots ); + enum { + slots = 512, + }; + + Cumulative(IUB* start) { + double p = 0; + for (IUB* iter = start; iter->c; ++iter) { + p += iter->p; + iter->p = p < 1.0 ? p : 1.0; + iter->pi = (unsigned int)(iter->p * slots); + } + + for (unsigned int i = 0; i <= slots; i++) { + while (i > start->pi && start->pi != 0) { + ++start; } - for ( unsigned int i = 0; i <= slots; i++ ) { - while ( i > start->pi && start->pi != 0) { - ++start; - } - - table[i] = start; - } - } + table[i] = start; + } + } - const char operator[] ( float pct ) const { - IUB *iter = table[(unsigned int )( pct * slots )]; - while ( iter->p < pct ) - ++iter; - return iter->c; - } + const char operator[](float pct) const { + IUB* iter = table[(unsigned int)(pct * slots)]; + while (iter->p < pct) + ++iter; + return iter->c; + } protected: - IUB *table[slots + 1]; + IUB* table[slots + 1]; }; static const size_t lineLength = 60; struct LineBuffer { - LineBuffer() : lastN(0) {} - LineBuffer &genrand( Cumulative &table, size_t N ) { - //assert(N <= lineLength); - for ( size_t i = 0; i < N; i++ ) - buffer[i] = table[rng.get()]; - buffer[N] = '\n'; - buffer[N+1] = '\0'; - lastN = N + 1; - return *this; - } - void writeline() { puts_limited(buffer); } + LineBuffer() : lastN(0) {} + LineBuffer& genrand(Cumulative& table, size_t N) { + // assert(N <= lineLength); + for (size_t i = 0; i < N; i++) + buffer[i] = table[rng.get()]; + buffer[N] = '\n'; + buffer[N + 1] = '\0'; + lastN = N + 1; + return *this; + } + void writeline() { puts_limited(buffer); } + protected: - char buffer[lineLength + 2]; - size_t lastN; + char buffer[lineLength + 2]; + size_t lastN; }; struct RotatingString { - RotatingString( const char *in ) : pos(0) { - size = strlen( in ); - buffer = new char[size + lineLength]; - memcpy( buffer, in, size ); - memcpy( buffer + size, in, lineLength ); - } - ~RotatingString() { delete[] buffer; } - void write( size_t bytes ) { - char* temp = new char[bytes+2]; - memcpy(temp, buffer + pos, bytes); - temp[bytes] = '\n'; - temp[bytes] = '\0'; - puts_limited(temp); - delete temp; - pos += bytes; - if ( pos > size ) - pos -= size; - } + RotatingString(const char* in) : pos(0) { + size = strlen(in); + buffer = new char[size + lineLength]; + memcpy(buffer, in, size); + memcpy(buffer + size, in, lineLength); + } + ~RotatingString() { delete[] buffer; } + void write(size_t bytes) { + char* temp = new char[bytes + 2]; + memcpy(temp, buffer + pos, bytes); + temp[bytes] = '\n'; + temp[bytes] = '\0'; + puts_limited(temp); + delete temp; + pos += bytes; + if (pos > size) + pos -= size; + } + protected: - char *buffer; - size_t size, pos; + char* buffer; + size_t size, pos; }; -template< class Output > -void makeFasta( const char *id, const char *desc, size_t N, Output &output ) { - while ( N ) { - const size_t bytes = N < lineLength ? N : lineLength; - output.writeline( bytes ); - N -= bytes; - } +template<class Output> +void makeFasta(const char* id, const char* desc, size_t N, Output& output) { + while (N) { + const size_t bytes = N < lineLength ? N : lineLength; + output.writeline(bytes); + N -= bytes; + } } struct Repeater { - Repeater( const char *alu ) : rot(alu) {} - void writeline( size_t bytes ) { rot.write( bytes ); } - void run( const char *id, const char *desc, size_t N ) { - makeFasta( id, desc, N, *this ); - } + Repeater(const char* alu) : rot(alu) {} + void writeline(size_t bytes) { rot.write(bytes); } + void run(const char* id, const char* desc, size_t N) { + makeFasta(id, desc, N, *this); + } + protected: - RotatingString rot; + RotatingString rot; }; struct Randomized { - Randomized( IUB *start ) : table(start) {} - void writeline( size_t bytes ) { line.genrand(table, bytes).writeline(); } - void run( const char *id, const char *desc, size_t N ) { - makeFasta( id, desc, N, *this ); - } + Randomized(IUB* start) : table(start) {} + void writeline(size_t bytes) { line.genrand(table, bytes).writeline(); } + void run(const char* id, const char* desc, size_t N) { + makeFasta(id, desc, N, *this); + } + protected: - Cumulative table; - LineBuffer line; + Cumulative table; + LineBuffer line; }; IUB iub[] = { - { 'a', 0.27, 0 }, - { 'c', 0.12, 0 }, - { 'g', 0.12, 0 }, - { 't', 0.27, 0 }, - - { 'B', 0.02, 0 }, - { 'D', 0.02, 0 }, - { 'H', 0.02, 0 }, - { 'K', 0.02, 0 }, - { 'M', 0.02, 0 }, - { 'N', 0.02, 0 }, - { 'R', 0.02, 0 }, - { 'S', 0.02, 0 }, - { 'V', 0.02, 0 }, - { 'W', 0.02, 0 }, - { 'Y', 0.02, 0 }, - { 0, 0, 0 }, + {'a', 0.27, 0}, + {'c', 0.12, 0}, + {'g', 0.12, 0}, + {'t', 0.27, 0}, + + {'B', 0.02, 0}, + {'D', 0.02, 0}, + {'H', 0.02, 0}, + {'K', 0.02, 0}, + {'M', 0.02, 0}, + {'N', 0.02, 0}, + {'R', 0.02, 0}, + {'S', 0.02, 0}, + {'V', 0.02, 0}, + {'W', 0.02, 0}, + {'Y', 0.02, 0}, + {0, 0, 0}, }; IUB homosapiens[] = { - { 'a', 0.3029549426680, 0 }, - { 'c', 0.1979883004921, 0 }, - { 'g', 0.1975473066391, 0 }, - { 't', 0.3015094502008, 0 }, - { 0, 0, 0 }, + {'a', 0.3029549426680, 0}, + {'c', 0.1979883004921, 0}, + {'g', 0.1975473066391, 0}, + {'t', 0.3015094502008, 0}, + {0, 0, 0}, }; -static const char alu[] = - "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG" - "GGAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGA" - "GACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAA" - "AATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAAT" - "CCCAGCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAAC" - "CCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTG" - "CACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"; - -int main( int argc, const char *argv[] ) { - const size_t n = ( argc > 1 ) ? atoi( argv[1] ) : 512; - - Repeater(alu) - .run( "ONE", "Homo sapiens alu", n*2 ); - Randomized(iub) - .run( "TWO", "IUB ambiguity codes", n*3 ); - Randomized(homosapiens) - .run( "THREE", "Homo sapiens frequency", n*5 ); - - return 0; -} +static const char alu[] = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG" + "GGAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGA" + "GACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAA" + "AATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAAT" + "CCCAGCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAAC" + "CCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTG" + "CACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"; + +int main(int argc, const char* argv[]) { + const size_t n = (argc > 1) ? atoi(argv[1]) : 512; + Repeater(alu).run("ONE", "Homo sapiens alu", n * 2); + Randomized(iub).run("TWO", "IUB ambiguity codes", n * 3); + Randomized(homosapiens).run("THREE", "Homo sapiens frequency", n * 5); + + return 0; +} diff --git a/test/float_ops.cpp b/test/float_ops.cpp index 9e4d68bae..5976ceb63 100644 --- a/test/float_ops.cpp +++ b/test/float_ops.cpp @@ -1,5 +1,5 @@ -#include <cmath> #include <algorithm> +#include <cmath> #include <emscripten.h> extern "C" { @@ -13,7 +13,9 @@ double EMSCRIPTEN_KEEPALIVE dadd(double x, double y) { return x + y; } double EMSCRIPTEN_KEEPALIVE dsub(double x, double y) { return x - y; } double EMSCRIPTEN_KEEPALIVE dmul(double x, double y) { return x * y; } double EMSCRIPTEN_KEEPALIVE ddiv(double x, double y) { return x / y; } -double EMSCRIPTEN_KEEPALIVE dcopysign(double x, double y) { return std::copysign(x, y); } +double EMSCRIPTEN_KEEPALIVE dcopysign(double x, double y) { + return std::copysign(x, y); +} double EMSCRIPTEN_KEEPALIVE dmin(double x, double y) { return std::min(x, y); } double EMSCRIPTEN_KEEPALIVE dmax(double x, double y) { return std::max(x, y); } @@ -68,6 +70,4 @@ int EMSCRIPTEN_KEEPALIVE float_to_uint(float d) { unsigned x = d; return x; } - } - diff --git a/test/grow_memory.cpp b/test/grow_memory.cpp index b8f732f7a..22703e048 100644 --- a/test/grow_memory.cpp +++ b/test/grow_memory.cpp @@ -1,20 +1,15 @@ +#include <emscripten.h> #include <stdio.h> #include <stdlib.h> -#include <emscripten.h> volatile int writeOnly; int main() { - EM_ASM({ - assert(HEAPU8.length === 16*1024*1024); - }); + EM_ASM({ assert(HEAPU8.length == = 16 * 1024 * 1024); }); for (int i = 0; i < 20; i++) { printf("alloc 1MB: %d\n", i); - writeOnly = (int)malloc(1024*1024); + writeOnly = (int)malloc(1024 * 1024); } - EM_ASM({ - assert(HEAPU8.length > 16*1024*1024); - }); + EM_ASM({ assert(HEAPU8.length > 16 * 1024 * 1024); }); printf("ok.\n"); } - diff --git a/test/hello_libcxx.cpp b/test/hello_libcxx.cpp index 445c5513b..25abee0e2 100644 --- a/test/hello_libcxx.cpp +++ b/test/hello_libcxx.cpp @@ -1,8 +1,6 @@ #include <iostream> -int main() -{ +int main() { std::cout << "hello, world!" << std::endl; return 0; } - diff --git a/test/hello_world.c b/test/hello_world.c index eb47ea813..ce0cca463 100644 --- a/test/hello_world.c +++ b/test/hello_world.c @@ -1,7 +1,6 @@ -#include<stdio.h> +#include <stdio.h> int main() { printf("hello, world!\n"); return 0; } - diff --git a/test/int_ops.c b/test/int_ops.c index 2e4a9b17d..045127dec 100644 --- a/test/int_ops.c +++ b/test/int_ops.c @@ -11,10 +11,12 @@ int EMSCRIPTEN_KEEPALIVE sdiv(int x, int y) { return x / y; } unsigned EMSCRIPTEN_KEEPALIVE udiv(unsigned x, unsigned y) { return x / y; } int EMSCRIPTEN_KEEPALIVE srem(int x, int y) { return x % y; } unsigned EMSCRIPTEN_KEEPALIVE urem(unsigned x, unsigned y) { return x % y; } -int EMSCRIPTEN_KEEPALIVE and(int x, int y) { return x & y; } -int EMSCRIPTEN_KEEPALIVE or(int x, int y) { return x | y; } -int EMSCRIPTEN_KEEPALIVE xor(int x, int y) { return x ^ y; } -int EMSCRIPTEN_KEEPALIVE shl(int x, int y) { return x << y; } +int EMSCRIPTEN_KEEPALIVE and (int x, int y) { return x & y; } +int EMSCRIPTEN_KEEPALIVE or (int x, int y) { return x | y; } +int EMSCRIPTEN_KEEPALIVE xor + (int x, int y) { return x ^ y; } int EMSCRIPTEN_KEEPALIVE shl(int x, int y) { + return x << y; +} int EMSCRIPTEN_KEEPALIVE sshr(int x, int y) { return x >> y; } unsigned EMSCRIPTEN_KEEPALIVE ushr(unsigned x, unsigned y) { return x >> y; } @@ -29,4 +31,3 @@ int EMSCRIPTEN_KEEPALIVE gts(int x, int y) { return x > y; } int EMSCRIPTEN_KEEPALIVE gtu(unsigned x, unsigned y) { return x > y; } int EMSCRIPTEN_KEEPALIVE ges(int x, int y) { return x >= y; } int EMSCRIPTEN_KEEPALIVE geu(unsigned x, unsigned y) { return x >= y; } - diff --git a/test/linker/baz.c b/test/linker/baz.c index 02759782d..256a0e368 100644 --- a/test/linker/baz.c +++ b/test/linker/baz.c @@ -1,2 +1 @@ -void baz() { -} +void baz() {} diff --git a/test/linker/foo.c b/test/linker/foo.c index 187032ae2..cb4b940cd 100644 --- a/test/linker/foo.c +++ b/test/linker/foo.c @@ -1,3 +1 @@ -int foo() { - return 43; -} +int foo() { return 43; } diff --git a/test/linker/main.c b/test/linker/main.c index d70bc7033..57efdde58 100644 --- a/test/linker/main.c +++ b/test/linker/main.c @@ -1,6 +1,4 @@ -int foo() { - return 42; -} +int foo() { return 42; } void bar(); diff --git a/test/lld/em_asm_O0.c b/test/lld/em_asm_O0.c index b00c75be2..6351f81b5 100644 --- a/test/lld/em_asm_O0.c +++ b/test/lld/em_asm_O0.c @@ -1,6 +1,6 @@ #include <emscripten.h> -int main(int argc, char **argv) { +int main(int argc, char** argv) { EM_ASM({ Module.print("Hello world"); }); int ret = EM_ASM_INT({ return $0 + $1; }, 20, 30); EM_ASM({ Module.print("Got " + $0); }, 42); diff --git a/test/lld/init.c b/test/lld/init.c index 3a9311e3c..d59f70e1e 100644 --- a/test/lld/init.c +++ b/test/lld/init.c @@ -1,15 +1,7 @@ volatile int x, y; -__attribute__((constructor)) -void init_x() { - x = 14; -} +__attribute__((constructor)) void init_x() { x = 14; } -__attribute__((constructor)) -void init_y() { - y = 144; -} +__attribute__((constructor)) void init_y() { y = 144; } -int main() { - return x + y; -} +int main() { return x + y; } diff --git a/test/lld/recursive.c b/test/lld/recursive.c index c0cdaa425..351b90bcb 100644 --- a/test/lld/recursive.c +++ b/test/lld/recursive.c @@ -3,10 +3,9 @@ int printf(const char* fmt, ...); -__attribute__((noinline)) -int foo(int a, int b) { - printf("%d:%d\n", a, b); - return a + b; +__attribute__((noinline)) int foo(int a, int b) { + printf("%d:%d\n", a, b); + return a + b; } int main() { diff --git a/test/lld/reserved_func_ptr.cpp b/test/lld/reserved_func_ptr.cpp index f40613ea0..31ee08ada 100644 --- a/test/lld/reserved_func_ptr.cpp +++ b/test/lld/reserved_func_ptr.cpp @@ -1,9 +1,9 @@ -int atoi(const char *nptr); +int atoi(const char* nptr); void address_taken_func(int a, int b, int c) {} void address_taken_func2(int a, int b, int c) {} -int main(int argc, char **argv) { +int main(int argc, char** argv) { int fp_v = atoi(argv[1]); int fp_vi = atoi(argv[2]); int fp_iii = atoi(argv[3]); @@ -20,9 +20,9 @@ int main(int argc, char **argv) { void (*f_vi)(int) = reinterpret_cast<void (*)(int)>(fp_vi); int (*f_iii)(int, int) = reinterpret_cast<int (*)(int, int)>(fp_iii); float (*f_fffi)(float, float, int) = - reinterpret_cast<float (*)(float, float, int)>(fp_fffi); + reinterpret_cast<float (*)(float, float, int)>(fp_fffi); double (*f_ddi)(double, int) = - reinterpret_cast<double (*)(double, int)>(fp_ddi); + reinterpret_cast<double (*)(double, int)>(fp_ddi); f_v(); f_vi(3); diff --git a/test/mem.cpp b/test/mem.cpp index e45149df1..eac12b311 100644 --- a/test/mem.cpp +++ b/test/mem.cpp @@ -1,5 +1,5 @@ -#include <stdint.h> #include <emscripten.h> +#include <stdint.h> extern "C" { @@ -14,21 +14,35 @@ int EMSCRIPTEN_KEEPALIVE loadu32(size_t addr) { return ((uint32_t*)addr)[0]; } double EMSCRIPTEN_KEEPALIVE loadf32(size_t addr) { return ((float*)addr)[0]; } double EMSCRIPTEN_KEEPALIVE loadf64(size_t addr) { return ((double*)addr)[0]; } -void EMSCRIPTEN_KEEPALIVE storei8(size_t addr, int8_t v) { ((int8_t*)addr)[0] = v; } -void EMSCRIPTEN_KEEPALIVE storei16(size_t addr, int16_t v) { ((int16_t*)addr)[0] = v; } -void EMSCRIPTEN_KEEPALIVE storei32(size_t addr, int32_t v) { ((int32_t*)addr)[0] = v; } +void EMSCRIPTEN_KEEPALIVE storei8(size_t addr, int8_t v) { + ((int8_t*)addr)[0] = v; +} +void EMSCRIPTEN_KEEPALIVE storei16(size_t addr, int16_t v) { + ((int16_t*)addr)[0] = v; +} +void EMSCRIPTEN_KEEPALIVE storei32(size_t addr, int32_t v) { + ((int32_t*)addr)[0] = v; +} -void EMSCRIPTEN_KEEPALIVE storeu8(size_t addr, uint8_t v) { ((uint8_t*)addr)[0] = v; } -void EMSCRIPTEN_KEEPALIVE storeu16(size_t addr, uint16_t v) { ((uint16_t*)addr)[0] = v; } -void EMSCRIPTEN_KEEPALIVE storeu32(size_t addr, uint32_t v) { ((uint32_t*)addr)[0] = v; } +void EMSCRIPTEN_KEEPALIVE storeu8(size_t addr, uint8_t v) { + ((uint8_t*)addr)[0] = v; +} +void EMSCRIPTEN_KEEPALIVE storeu16(size_t addr, uint16_t v) { + ((uint16_t*)addr)[0] = v; +} +void EMSCRIPTEN_KEEPALIVE storeu32(size_t addr, uint32_t v) { + ((uint32_t*)addr)[0] = v; +} -void EMSCRIPTEN_KEEPALIVE storef32(size_t addr, float v) { ((float*)addr)[0] = v; } -void EMSCRIPTEN_KEEPALIVE storef64(size_t addr, double v) { ((double*)addr)[0] = v; } +void EMSCRIPTEN_KEEPALIVE storef32(size_t addr, float v) { + ((float*)addr)[0] = v; +} +void EMSCRIPTEN_KEEPALIVE storef64(size_t addr, double v) { + ((double*)addr)[0] = v; +} int* EMSCRIPTEN_KEEPALIVE get_stack() { int t; return &t; } - } - diff --git a/test/printf.c b/test/printf.c index ca1b1797f..c5454201d 100644 --- a/test/printf.c +++ b/test/printf.c @@ -1,20 +1,24 @@ #include <stdio.h> int main() { - int a = 12345; - unsigned b = 123456; - long c = 1234567; - unsigned long d = 12345678; - long long e = 1234567891011; - unsigned long long f = 123456789101112; + int a = 12345; + unsigned b = 123456; + long c = 1234567; + unsigned long d = 12345678; + long long e = 1234567891011; + unsigned long long f = 123456789101112; - printf( - "int a = %d\n" - "unsigned b = %u\n" - "long c = %ld\n" - "unsigned long d = %lu\n" - "long long e = %lld\n" - "unsigned long long f = %llu\n" - , a, b, c, d, e, f); - return 0; + printf("int a = %d\n" + "unsigned b = %u\n" + "long c = %ld\n" + "unsigned long d = %lu\n" + "long long e = %lld\n" + "unsigned long long f = %llu\n", + a, + b, + c, + d, + e, + f); + return 0; } |