summaryrefslogtreecommitdiff
path: root/test/example/relooper-fuzz2.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/example/relooper-fuzz2.c')
-rw-r--r--test/example/relooper-fuzz2.c311
1 files changed, 173 insertions, 138 deletions
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));