diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-08-16 17:02:43 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-08-21 17:09:16 -0700 |
commit | d705c37e34ad11b01ad33e7c985818a14623dff7 (patch) | |
tree | bb1a48ff1208f5a4efda08d6f2a5c1827e55a0b3 /src/relooper/fuzzer.py | |
parent | ab506b38dbb9acb2db4f1a1b8c1608cc57409a6b (diff) |
emit switches in relooper1.5.6
Diffstat (limited to 'src/relooper/fuzzer.py')
-rw-r--r-- | src/relooper/fuzzer.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/relooper/fuzzer.py b/src/relooper/fuzzer.py index 5f6bae3d..50846d10 100644 --- a/src/relooper/fuzzer.py +++ b/src/relooper/fuzzer.py @@ -26,13 +26,13 @@ while True: pass # parts - entry = '''print('entry'); var label; var state; var decisions = %s; var index = 0; function check() { if (index == decisions.length) throw 'HALT'; return decisions[index++] }''' % str(decisions) + entry = '''print('entry'); var label; var state; var modded; var decisions = %s; var index = 0; function check() { if (index == decisions.length) throw 'HALT'; return decisions[index++] }''' % str(decisions) slow = entry + '\n' for i in range(len(branches[0])): if i > 0: slow += 'else ' b = branches[0] - slow += 'if (state %% %d == %d) { label = %d; }\n' % (len(b)+1, i, b[i]) # TODO: split range 1-n into these options + slow += 'if (modded == %d) { label = %d; }\n' % (i, b[i]) # TODO: split range 1-n into these options if len(branches[0]): slow += 'else ' slow += 'label = %d;\n' % defaults[0] @@ -51,26 +51,35 @@ int main() { ''' for i in range(1, num): - slow += ' case %d: print(%d); state = check(); \n' % (i, i) + slow += ' case %d: print(%d); state = check(); modded = state %% %d\n' % (i, i, len(branches[i])+1) b = branches[i] for j in range(len(b)): - slow += ' if (state %% %d == %d) { label = %d; break }\n' % (len(b)+1, j, b[j]) # TODO: split range 1-n into these options + slow += ' if (modded == %d) { label = %d; break }\n' % (j, b[j]) # TODO: split range 1-n into these options slow += ' label = %d; break\n' % defaults[i] + branch_vars = [] for i in range(num): + branch_var = '"modded"' if len(branches[i]) > 0 and not (len(branches[i]) == 1 and random.random() < 0.5) else 'NULL' + branch_vars.append(branch_var) + if i == 0: fast += ''' - Block *b%d = new Block("%s"); -''' % (i, entry) + Block *b%d = new Block("%s", %s); +''' % (i, entry, branch_var) else: - fast += ''' Block *b%d = new Block("print(%d); state = check();%s"); -''' % (i, i, '// ' + ('.' * int(random.expovariate(0.5/num)))) + fast += ''' Block *b%d = new Block("print(%d); state = check(); modded = state %% %d; %s", %s); +''' % (i, i, len(branches[i])+1, '// ' + ('.' * int(random.expovariate(0.5/num))), branch_var) for i in range(num): + branch_var = branch_vars[i] b = branches[i] for j in range(len(b)): - fast += ''' b%d->AddBranchTo(b%d, "state %% %d == %d"); -''' % (i, b[j], len(b)+1, j) + if branch_var == 'NULL': + fast += ''' b%d->AddBranchTo(b%d, "modded == %d"); +''' % (i, b[j], j) + else: + fast += ''' b%d->AddBranchTo(b%d, "case %d:"); +''' % (i, b[j], j) fast += ''' b%d->AddBranchTo(b%d, NULL); ''' % (i, defaults[i]) |