omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / qualification / om2 / oracle / s3s4 / oracle.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Independent oracle for seed/qualification/om2/sec/s3s4 (#748, ledger L836, lane QualPhaseB.FixRotUnroll). |
| 4 | # It models the documented semantics (contract omegese-om2.md sections 3-4, OMEGESE.md 9.3/9.4) of each |
| 5 | # fixture directly in Python integers; it never runs or reads output of any Omega compiler. |
| 6 | # Writes exp/<name>.out (exact expected stdout) and exp/exits.txt (<name> <exit status>), and checks that |
| 7 | # every rotation operand has w distinct rotations (so n+1, w-n and ROR-for-ROL mutants change a line). |
| 8 | # Usage: python3 oracle.py (from any directory; writes next to this file) |
| 9 | import os |
| 10 | |
| 11 | HERE = os.path.dirname(os.path.abspath(__file__)) |
| 12 | EXP = os.path.join(HERE, "exp") |
| 13 | os.makedirs(EXP, exist_ok=True) |
| 14 | M64 = (1 << 64) - 1 |
| 15 | EXITS = {} |
| 16 | |
| 17 | |
| 18 | class Trap(Exception): |
| 19 | def __init__(self, code): |
| 20 | self.code = code |
| 21 | |
| 22 | |
| 23 | def rotr(x, n, w): |
| 24 | if n >= w: |
| 25 | raise Trap(7) # contract section 3 line 79 |
| 26 | m = (1 << w) - 1 |
| 27 | return ((x >> n) | (x << (w - n))) & m if n else x |
| 28 | |
| 29 | |
| 30 | def rotl(x, n, w): |
| 31 | if n >= w: |
| 32 | raise Trap(7) |
| 33 | return rotr(x, (w - n) % w, w) |
| 34 | |
| 35 | |
| 36 | def sadd(a, b, bits): # signed add, trap 1 outside the type (OMEGESE 9.3) |
| 37 | r = a + b |
| 38 | if not -(1 << (bits - 1)) <= r < (1 << (bits - 1)): |
| 39 | raise Trap(1) |
| 40 | return r |
| 41 | |
| 42 | |
| 43 | def smul(a, b, bits): |
| 44 | r = a * b |
| 45 | if not -(1 << (bits - 1)) <= r < (1 << (bits - 1)): |
| 46 | raise Trap(1) |
| 47 | return r |
| 48 | |
| 49 | |
| 50 | def sdiv(a, b, bits): # round toward zero; /0 trap 2; min/-1 trap 1 |
| 51 | if b == 0: |
| 52 | raise Trap(2) |
| 53 | q = abs(a) // abs(b) |
| 54 | q = q if (a < 0) == (b < 0) else -q |
| 55 | if not -(1 << (bits - 1)) <= q < (1 << (bits - 1)): |
| 56 | raise Trap(1) |
| 57 | return q |
| 58 | |
| 59 | |
| 60 | def udiv(a, b): |
| 61 | if b == 0: |
| 62 | raise Trap(2) |
| 63 | return a // b |
| 64 | |
| 65 | |
| 66 | def urem(a, b): |
| 67 | if b == 0: |
| 68 | raise Trap(2) |
| 69 | return a % b |
| 70 | |
| 71 | |
| 72 | def conv(v, lo, hi): # conversion range check, trap 5 |
| 73 | if not lo <= v <= hi: |
| 74 | raise Trap(5) |
| 75 | return v |
| 76 | |
| 77 | |
| 78 | def shl64(x, n): |
| 79 | if not 0 <= n < 64: |
| 80 | raise Trap(7) |
| 81 | return (x << n) & M64 |
| 82 | |
| 83 | |
| 84 | def program(name, body): |
| 85 | """Run body(out) where out is a list of printed values; record stdout and exit status.""" |
| 86 | out = [] |
| 87 | try: |
| 88 | ex = body(out) |
| 89 | ex = 0 if ex is None else ex % 256 |
| 90 | except Trap as t: |
| 91 | ex = 100 + t.code |
| 92 | with open(os.path.join(EXP, name + ".out"), "w") as f: |
| 93 | f.write("".join("%d\n" % v for v in out)) |
| 94 | EXITS[name] = ex |
| 95 | |
| 96 | |
| 97 | XS = {8: (177, 3), 16: (45508, 5), 32: (4041331395, 13), 64: (9305357566071262703, 29)} |
| 98 | for w, (x, mid) in XS.items(): |
| 99 | assert len({rotr(x, n, w) for n in range(w)}) == w, (w, x) |
| 100 | |
| 101 | |
| 102 | def rot_values(out): |
| 103 | for w, (x, mid) in XS.items(): |
| 104 | ns = [0, 1, mid, w - 1] |
| 105 | for _path in ("const", "runtime"): |
| 106 | out += [rotr(x, n, w) for n in ns] |
| 107 | out += [rotl(x, n, w) for n in ns] |
| 108 | for n in range(w): |
| 109 | out += [rotr(x, n, w), rotl(x, n, w)] |
| 110 | |
| 111 | |
| 112 | program("rot-values", rot_values) |
| 113 | |
| 114 | ROT_TRAP = { # selector: (op, w, n) |
| 115 | "A": (rotr, 8, 8), "B": (rotl, 16, 16), "C": (rotr, 32, 32), "D": (rotl, 64, 64), |
| 116 | "E": (rotl, 8, 8), "F": (rotr, 16, 16), "G": (rotl, 32, 32), "H": (rotr, 64, 64), |
| 117 | "I": (rotr, 8, 9), "J": (rotl, 16, 65535), "K": (rotr, 32, 4294967295), |
| 118 | "L": (rotl, 64, M64), "M": (rotr, 32, 33), "N": (rotl, 64, 65), "O": (rotl, 8, 255), |
| 119 | "P": (rotr, 32, 31), |
| 120 | } |
| 121 | for sel, (op, w, n) in ROT_TRAP.items(): |
| 122 | program("rot-trap-" + sel, lambda out, op=op, w=w, n=n: out.append(op(XS[w][0], n, w))) |
| 123 | |
| 124 | |
| 125 | def unroll_sum(out): |
| 126 | h = 7 |
| 127 | for i in range(1): |
| 128 | h = (h * 1000003 + (i + 11)) & M64 |
| 129 | out.append(h) |
| 130 | s = 0 |
| 131 | for i in range(4): |
| 132 | s = (s * 131 + (i + 3)) & M64 |
| 133 | out.append(s) |
| 134 | a = [0] * 65 |
| 135 | t = c = 0 |
| 136 | for i in range(64): |
| 137 | t = (t * 6364136223846793005 + ((i + 1442695040888963407) & M64)) & M64 |
| 138 | c += 1 |
| 139 | a[i] = (i * 37 + 5) & 255 |
| 140 | out += [t, c] |
| 141 | q = 0 |
| 142 | for k in range(65): |
| 143 | q = (q * 257 + a[k]) & M64 |
| 144 | out.append(q) |
| 145 | |
| 146 | |
| 147 | program("unroll-sum", unroll_sum) |
| 148 | |
| 149 | |
| 150 | def unroll_nest(out): |
| 151 | m = [0] * 64 |
| 152 | f = 14695981039346656037 |
| 153 | for i in range(8): |
| 154 | for j in range(8): |
| 155 | f = ((f ^ (i * 8 + j)) * 1099511628211) & M64 |
| 156 | m[i * 8 + j] = i * 1000 + j |
| 157 | out.append(f) |
| 158 | g = 0 |
| 159 | for k in range(64): |
| 160 | g = (g * 3 + m[k]) & M64 |
| 161 | out.append(g) |
| 162 | |
| 163 | |
| 164 | program("unroll-nest", unroll_nest) |
| 165 | |
| 166 | |
| 167 | def unroll_nest_64x2(out): # erratum E7: 64 x 2 nested unroll, 128 copies |
| 168 | f, c = 1, 0 |
| 169 | for i in range(64): |
| 170 | for j in range(2): |
| 171 | f = (f * 31 + i * 2 + j) & M64 |
| 172 | c += 1 |
| 173 | out += [f, c] |
| 174 | |
| 175 | |
| 176 | program("unroll-nest-64x2", unroll_nest_64x2) |
| 177 | |
| 178 | |
| 179 | def nested_exit(stop): # erratum E7: break/continue of a rolled loop inside an unrolled body |
| 180 | def body(out): |
| 181 | s = 0 |
| 182 | for i in range(4): |
| 183 | for j in range(3): |
| 184 | if j == 1: |
| 185 | if stop: |
| 186 | break |
| 187 | continue |
| 188 | s += 1 |
| 189 | return s |
| 190 | return body |
| 191 | |
| 192 | |
| 193 | program("unroll-break-nested", nested_exit(True)) |
| 194 | program("unroll-continue-nested", nested_exit(False)) |
| 195 | |
| 196 | |
| 197 | def write_i_rolled(out): # for i ulong 4: body i = add i 1; pu i; then the for increments i |
| 198 | i = 0 |
| 199 | while i < 4: |
| 200 | i += 1 |
| 201 | out.append(i) |
| 202 | i += 1 |
| 203 | |
| 204 | |
| 205 | program("unroll-write-i-rolled", write_i_rolled) |
| 206 | |
| 207 | |
| 208 | def brk(out): |
| 209 | s = 0 |
| 210 | for i in range(4): |
| 211 | if i == 2: |
| 212 | break |
| 213 | s += 1 |
| 214 | return s |
| 215 | |
| 216 | |
| 217 | def cont(out): |
| 218 | s = 0 |
| 219 | for i in range(4): |
| 220 | if i == 2: |
| 221 | continue |
| 222 | s += 1 |
| 223 | return s |
| 224 | |
| 225 | |
| 226 | program("unroll-break-rolled", brk) |
| 227 | program("unroll-continue-rolled", cont) |
| 228 | |
| 229 | |
| 230 | def grow(a): |
| 231 | x, s, t, u = a, a + 1, a + 2, a + 3 |
| 232 | for i in range(64): |
| 233 | for j in range(64): |
| 234 | x = (x * 3 + (s + (i + j))) & M64 |
| 235 | s ^= x >> 7 |
| 236 | t = (t + s * x) & M64 |
| 237 | u ^= (t << 3) & M64 |
| 238 | x = (x + u * 5) & M64 |
| 239 | s = (s + (x ^ t)) & M64 |
| 240 | t ^= s >> 11 |
| 241 | u = (u + t * 9) & M64 |
| 242 | x ^= (u + s) & M64 |
| 243 | s = (s * (x + 1)) & M64 |
| 244 | t = (t + (u ^ 13)) & M64 |
| 245 | u ^= (s + t) & M64 |
| 246 | return x ^ s ^ (t ^ u) |
| 247 | |
| 248 | |
| 249 | program("unroll-growth-rolled", lambda out: grow(5) & 255) |
| 250 | |
| 251 | I32 = 32 |
| 252 | |
| 253 | |
| 254 | def mk(out, v, t): |
| 255 | out.append(t) |
| 256 | return v |
| 257 | |
| 258 | |
| 259 | def f_inl(a, b): |
| 260 | x = sadd(a, 1, I32) |
| 261 | return sdiv(x, b, I32) |
| 262 | |
| 263 | |
| 264 | def g_inl(a): |
| 265 | return 0 if a < 0 else smul(a, 2, I32) |
| 266 | |
| 267 | |
| 268 | INLINE = { |
| 269 | "A": lambda out: out.append(f_inl(mk(out, 10, 1), mk(out, 3, 2))), |
| 270 | "B": lambda out: out.append(f_inl(sdiv(1, 0, I32), sadd(2147483647, 1, I32))), |
| 271 | "C": lambda out: out.append(f_inl(sadd(2147483647, 1, I32), sdiv(1, 0, I32))), |
| 272 | "D": lambda out: out.append(f_inl(2147483647, 0)), |
| 273 | "E": lambda out: out.append(f_inl(5, 0)), |
| 274 | "F": lambda out: out.append(f_inl(mk(out, 1, 1), sdiv(1, 0, I32))), |
| 275 | "G": lambda out: out.append(f_inl(sdiv(1, 0, I32), mk(out, 1, 2))), |
| 276 | "H": lambda out: out.extend([g_inl(-5), g_inl(7)]), |
| 277 | "I": lambda out: out.append(g_inl(mk(out, 7, 3))), |
| 278 | } |
| 279 | for sel, fn in INLINE.items(): |
| 280 | program("inline-order-" + sel, fn) |
| 281 | |
| 282 | |
| 283 | def chain(n, a): |
| 284 | p = [3, 5, 7, 11, 13, 17] |
| 285 | |
| 286 | def f(k, a): |
| 287 | if k == n: |
| 288 | return (a * p[k - 1] + k) & M64 |
| 289 | return (f(k + 1, (a * p[k - 1]) & M64) + k) & M64 |
| 290 | |
| 291 | return f(1, a) |
| 292 | |
| 293 | |
| 294 | program("inline-depth4", lambda out: out.extend([chain(4, 2), chain(4, 1000)])) |
| 295 | program("inline-depth6", lambda out: out.extend([chain(6, 2), chain(6, 1000)])) |
| 296 | program("inline-new", lambda out: out.append(3)) |
| 297 | |
| 298 | |
| 299 | def tri(n): |
| 300 | return 0 if n == 0 else n + tri(n - 1) |
| 301 | |
| 302 | |
| 303 | program("inline-rec", lambda out: out.append(tri(10))) |
| 304 | |
| 305 | |
| 306 | def fold_guard(out): |
| 307 | out.append(sum(udiv(100, i) for i in range(4) if i != 0)) |
| 308 | out.append(sum(urem(101, i) for i in range(4) if i != 0)) |
| 309 | out.append(sum(sdiv(1000000, i, 64) for i in range(4) if i != 0)) |
| 310 | q = lambda a, b: 0 if b == 0 else udiv(a, b) |
| 311 | out += [q(100, 0), q(100, 7)] |
| 312 | |
| 313 | |
| 314 | program("fold-guard", fold_guard) |
| 315 | |
| 316 | |
| 317 | def ft_a(out): |
| 318 | out.append(999) |
| 319 | for i in range(4): |
| 320 | out.append(udiv(100, i)) |
| 321 | |
| 322 | |
| 323 | def ft_b(out): |
| 324 | for i in range(4): |
| 325 | out.append(sadd(2147483646, i, I32)) |
| 326 | |
| 327 | |
| 328 | def ft_c(out): |
| 329 | for i in range(4): |
| 330 | out.append(conv(254 + i, 0, 255)) |
| 331 | |
| 332 | |
| 333 | def ft_d(out): |
| 334 | for i in range(4): |
| 335 | out.append(shl64(1, 62 + i)) |
| 336 | |
| 337 | |
| 338 | def ft_e(out): |
| 339 | for i in range(4): |
| 340 | out.append(smul(1073741824, sadd(i, 1, I32), I32)) |
| 341 | |
| 342 | |
| 343 | def ft_f(out): |
| 344 | for i in range(4): |
| 345 | out.append(sadd(5, sdiv(-2147483648, sadd(i, -1, I32), I32), I32)) |
| 346 | |
| 347 | |
| 348 | def ft_g(out): |
| 349 | out.append(999) |
| 350 | for i in range(4): |
| 351 | out.append(urem(7, i)) |
| 352 | |
| 353 | |
| 354 | def ft_h(out): |
| 355 | out.append(conv(255, 0, 255)) |
| 356 | out.append(conv(256, 0, 255)) |
| 357 | |
| 358 | |
| 359 | def ft_i(out): |
| 360 | out.append(udiv(100, 4)) |
| 361 | out.append(udiv(100, 0)) |
| 362 | |
| 363 | |
| 364 | for sel, fn in zip("ABCDEFGHI", [ft_a, ft_b, ft_c, ft_d, ft_e, ft_f, ft_g, ft_h, ft_i]): |
| 365 | program("fold-trap-" + sel, fn) |
| 366 | |
| 367 | |
| 368 | def ce_sized(out): |
| 369 | a = [i * 10 + 1 for i in range(4)] |
| 370 | s = 0 |
| 371 | for i in range(4): |
| 372 | s = s * 100 + a[i] |
| 373 | t = 0 |
| 374 | for i in range(4): |
| 375 | t = t * 100 + a[3 - i] |
| 376 | out += [s, t] |
| 377 | |
| 378 | |
| 379 | program("ce-sized", ce_sized) |
| 380 | |
| 381 | |
| 382 | def vget(v, i): # unsized view read: index checked at run time, trap 3 |
| 383 | if not 0 <= i < len(v): |
| 384 | raise Trap(3) |
| 385 | return v[i] |
| 386 | |
| 387 | |
| 388 | B = [10 ** k for k in range(8)] |
| 389 | |
| 390 | |
| 391 | def sumv(out, v): |
| 392 | s = 0 |
| 393 | for i in range(5): |
| 394 | s = (s + vget(v, i)) & M64 |
| 395 | out.append(s) |
| 396 | return s |
| 397 | |
| 398 | |
| 399 | CE_VIEW = { |
| 400 | "A": lambda out: out.append(sumv(out, B[0:4])), |
| 401 | "B": lambda out: out.append(sumv(out, B[0:4])), |
| 402 | "C": lambda out: out.append(sumv(out, B[0:4])), |
| 403 | "D": lambda out: out.append(vget(B[0:4], 6)), |
| 404 | "E": lambda out: out.append(sumv(out, B[0:5])), |
| 405 | "F": lambda out: out.append(sumv(out, B[3:7])), |
| 406 | } |
| 407 | for sel, fn in CE_VIEW.items(): |
| 408 | program("ce-view-" + sel, fn) |
| 409 | |
| 410 | # ---- Mutant predictions (kill specs, README section M). Each model is the fixture run by a compiler |
| 411 | # with one deliberate fault; exp/mut/<name>.out is its predicted stdout and exp/mutants.txt lists |
| 412 | # "<mutant> <exit> <first differing stdout byte, 0-based, vs the correct expectation>". |
| 413 | os.makedirs(os.path.join(EXP, "mut"), exist_ok=True) |
| 414 | MUT = [] |
| 415 | |
| 416 | |
| 417 | def mutant(name, base, body): |
| 418 | program("mut/" + name, body) |
| 419 | with open(os.path.join(EXP, "mut", name + ".out"), "rb") as f: |
| 420 | m = f.read() |
| 421 | with open(os.path.join(EXP, base + ".out"), "rb") as f: |
| 422 | o = f.read() |
| 423 | d = next((i for i in range(min(len(m), len(o))) if m[i] != o[i]), None) |
| 424 | if d is None: |
| 425 | d = min(len(m), len(o)) if len(m) != len(o) else -1 |
| 426 | MUT.append("%s %d %d" % (name, EXITS.pop("mut/" + name), d)) |
| 427 | |
| 428 | |
| 429 | def unroll_sum_k(dk): # (a) every unrolled loop emits K+dk copies |
| 430 | def body(out): |
| 431 | h = 7 |
| 432 | for i in range(1 + dk): |
| 433 | h = (h * 1000003 + (i + 11)) & M64 |
| 434 | out.append(h) |
| 435 | s = 0 |
| 436 | for i in range(4 + dk): |
| 437 | s = (s * 131 + ((i + 3) & M64)) & M64 |
| 438 | out.append(s) |
| 439 | a = [0] * 65 |
| 440 | t = c = 0 |
| 441 | for i in range(64 + dk): |
| 442 | t = (t * 6364136223846793005 + ((i + 1442695040888963407) & M64)) & M64 |
| 443 | c += 1 |
| 444 | a[i] = (i * 37 + 5) & 255 |
| 445 | out += [t, c] |
| 446 | q = 0 |
| 447 | for k in range(65): |
| 448 | q = (q * 257 + a[k]) & M64 |
| 449 | out.append(q) |
| 450 | return body |
| 451 | |
| 452 | |
| 453 | mutant("unroll-sum-Kminus1", "unroll-sum", unroll_sum_k(-1)) |
| 454 | mutant("unroll-sum-Kplus1", "unroll-sum", unroll_sum_k(1)) |
| 455 | |
| 456 | |
| 457 | def rot_mut(kind, paths): # (b) faulty rotate lowering on the given paths ("const", "runtime") |
| 458 | def bad_r(x, n, w): |
| 459 | if kind == "nplus1": |
| 460 | return rotr(x, (n + 1) % w, w) |
| 461 | if kind == "wminusn": |
| 462 | return rotr(x, (w - n) % w, w) |
| 463 | return rotr(x, n, w) |
| 464 | |
| 465 | def bad_l(x, n, w): |
| 466 | if kind == "nplus1": |
| 467 | return rotl(x, (n + 1) % w, w) |
| 468 | if kind == "rorforrol": |
| 469 | return rotr(x, n, w) |
| 470 | return rotl(x, n, w) |
| 471 | |
| 472 | def body(out): |
| 473 | for w, (x, mid) in XS.items(): |
| 474 | ns = [0, 1, mid, w - 1] |
| 475 | for path in ("const", "runtime"): |
| 476 | r = bad_r if path in paths else rotr |
| 477 | l = bad_l if path in paths else rotl |
| 478 | out += [r(x, n, w) for n in ns] |
| 479 | out += [l(x, n, w) for n in ns] |
| 480 | r = bad_r if "runtime" in paths else rotr |
| 481 | l = bad_l if "runtime" in paths else rotl |
| 482 | for n in range(w): |
| 483 | out += [r(x, n, w), l(x, n, w)] |
| 484 | return body |
| 485 | |
| 486 | |
| 487 | for kind in ("nplus1", "wminusn", "rorforrol"): |
| 488 | for tag, paths in (("both", ("const", "runtime")), ("const", ("const",)), ("runtime", ("runtime",))): |
| 489 | mutant("rot-values-%s-%s" % (kind, tag), "rot-values", rot_mut(kind, paths)) |
| 490 | |
| 491 | # rotation range check dropped: RORV and the immediate use n mod w (no trap 7) |
| 492 | for sel, (op, w, n) in ROT_TRAP.items(): |
| 493 | if sel != "P": |
| 494 | mutant("rot-trap-%s-nocheck" % sel, "rot-trap-" + sel, |
| 495 | lambda out, op=op, w=w, n=n: out.append(op(XS[w][0], n % w, w))) |
| 496 | |
| 497 | |
| 498 | def sumv_nc(out, off): |
| 499 | s = 0 |
| 500 | for i in range(5): |
| 501 | s = (s + B[off + i]) & M64 |
| 502 | out.append(s) |
| 503 | return s |
| 504 | |
| 505 | |
| 506 | mutant("ce-view-A-nocheck", "ce-view-A", lambda out: out.append(sumv_nc(out, 0))) |
| 507 | mutant("ce-view-C-nocheck", "ce-view-C", lambda out: out.append(sumv_nc(out, 0))) |
| 508 | mutant("ce-view-D-nocheck", "ce-view-D", lambda out: out.append(B[6])) |
| 509 | mutant("ce-view-F-nocheck", "ce-view-F", lambda out: out.append(sumv_nc(out, 3))) |
| 510 | |
| 511 | |
| 512 | # (d) a trapping all-constant operation folded with AArch64 results instead of the trap: |
| 513 | # UDIV/SDIV by 0 give 0 (so rem gives the dividend), signed results wrap, a conversion truncates, |
| 514 | # a shift amount is taken mod 64. ps prints 7777 for a negative int. |
| 515 | def wrap32(v): |
| 516 | v &= 0xFFFFFFFF |
| 517 | return v - (1 << 32) if v >> 31 else v |
| 518 | |
| 519 | |
| 520 | def ps(out, v): |
| 521 | out.append(7777 if v < 0 else v) |
| 522 | |
| 523 | |
| 524 | FOLD_MUT = { |
| 525 | "A": lambda out: (out.append(999), [out.append(100 // i if i else 0) for i in range(4)]), |
| 526 | "B": lambda out: [ps(out, wrap32(2147483646 + i)) for i in range(4)], |
| 527 | "C": lambda out: [out.append((254 + i) & 255) for i in range(4)], |
| 528 | "D": lambda out: [out.append((1 << ((62 + i) % 64)) & M64) for i in range(4)], |
| 529 | "E": lambda out: [ps(out, wrap32(1073741824 * (i + 1))) for i in range(4)], |
| 530 | "F": lambda out: ft_f_mut(out), |
| 531 | "G": lambda out: (out.append(999), [out.append(7 % i if i else 7) for i in range(4)]), |
| 532 | "H": lambda out: (out.append(255), out.append(256 & 255)), |
| 533 | "I": lambda out: (out.append(25), out.append(0)), |
| 534 | } |
| 535 | |
| 536 | |
| 537 | def ft_f_mut(out): # i = 0: min / -1 wraps to min; i = 1: div by 0 folded to 0 |
| 538 | for i in range(4): |
| 539 | d = i - 1 |
| 540 | if d == 0: |
| 541 | q = 0 |
| 542 | elif d == -1: |
| 543 | q = wrap32(2147483648) |
| 544 | else: |
| 545 | q = sdiv(-2147483648, d, I32) |
| 546 | ps(out, wrap32(5 + q)) |
| 547 | |
| 548 | |
| 549 | for sel, fn in FOLD_MUT.items(): |
| 550 | mutant("fold-trap-%s-fold" % sel, "fold-trap-" + sel, lambda out, fn=fn: (fn(out), None)[1]) |
| 551 | |
| 552 | with open(os.path.join(EXP, "exits.txt"), "w") as f: |
| 553 | for k in sorted(EXITS): |
| 554 | f.write("%s %d\n" % (k, EXITS[k])) |
| 555 | with open(os.path.join(EXP, "mutants.txt"), "w") as f: |
| 556 | f.write("".join(m + "\n" for m in MUT)) |
| 557 | print("oracle: %d programs, %d mutant models written to %s" % (len(EXITS), len(MUT), EXP)) |