diff options
author | Heejin Ahn <aheejin@gmail.com> | 2021-09-29 11:23:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-29 11:23:09 -0700 |
commit | 6b80ef6cccfd14b9b6620c5d41a148024d78576c (patch) | |
tree | 27f1a0cc96a512d6ed80f3f5b40e83de98e2e9f9 /test/example/relooper-fuzz1.c | |
parent | 414d54a28b749af6abcaec6b85c99cc69de6b7dd (diff) | |
download | binaryen-6b80ef6cccfd14b9b6620c5d41a148024d78576c.tar.gz binaryen-6b80ef6cccfd14b9b6620c5d41a148024d78576c.tar.bz2 binaryen-6b80ef6cccfd14b9b6620c5d41a148024d78576c.zip |
Clang-format c/cpp files in test directory (#4192)
This clang-formats c/cpp files in test/ directory, and updates
clang-format-diff.sh so that it does not ignore test/ directory anymore.
bigswitch.cpp is excluded from formatting, because there are big
commented-out code blocks, and apparently clang-format messes up
formatting in them. Also to make matters worse, different clang-format
versions do different things on those commented-out code blocks.
Diffstat (limited to 'test/example/relooper-fuzz1.c')
-rw-r--r-- | test/example/relooper-fuzz1.c | 370 |
1 files changed, 202 insertions, 168 deletions
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); |