#!/usr/bin/env python import sys f = open("op.txt", "r") lines = [line for line in f.readlines()] f.close() def get_match(x,y,z): q = y & 1 p = y >> 1 xx = -1 xz = None for line in lines: if line.strip() == "": continue if line.startswith("FOR x="): line = line[len("FOR x="):] xx = int(line) xz = None elif line.startswith("z="): line = line[len("z="):] xz = int(line) if xz == -1: xz = None else: if x != xx or (xz is not None and z != xz): continue line = line.strip() #if line.find("=") == -1: # continue line = line.strip() B_ok = True while line[1] == "=": n = line[0] v = int(line[2]) if n == "y": if y != v: B_ok = False elif n == "q": if q != v: B_ok = False elif n == "p": if p != v: B_ok = False else: assert(n in ["y", "q", "p"]) line = line[3:] assert(line[0] == "\t") line = line.strip() if not B_ok: continue return(line.replace("p", str(p)).replace("q", str(q)).replace("y", str(y)).replace("z", str(z)).replace("x", str(x))) pass opcode = 64 x = opcode >> 6 y = (opcode >> 3) & 7 z = opcode & 3 assert(get_match(x,y,z) is not None) for opcode in range(256): x = opcode >> 6 y = (opcode >> 3) & 7 z = opcode & 3 print "\telif opcode == 0x%X:\n\t\treturn self.%s)" % (opcode, get_match(x,y,z))