| 1 | from __future__ import print_function |
| 2 | |
| 3 | import sys, os |
| 4 | from rply.errors import ParsingError, LexingError |
| 5 | from rpython.jit.metainterp.ruleopt import parse, proof, codegen |
| 6 | |
| 7 | def main(argv): |
| 8 | here = os.path.dirname(__file__) |
| 9 | def_file = os.path.join(here, "real.rules") |
| 10 | out_file = os.path.join(here, "..", "optimizeopt", "autogenintrules.py") |
| 11 | with open(def_file) as f: |
| 12 | content = f.read() |
| 13 | try: |
| 14 | ast = proof.prove_source(content) |
| 15 | except (ParsingError, LexingError) as e: |
| 16 | pos = e.getsourcepos() |
| 17 | print("Parse error in line %s:" % pos.lineno) |
| 18 | line = content.splitlines()[pos.lineno - 1] |
| 19 | print(" " + line) |
| 20 | print(" " + " " * (pos.colno - 1) + "^") |
| 21 | return -1 |
| 22 | except parse.TypeCheckError as e: |
| 23 | print(e.format(content)) |
| 24 | return -2 |
| 25 | except proof.ProofProblem as e: |
| 26 | print("_" * 60) |
| 27 | print(e.format()) |
| 28 | return -3 |
| 29 | cgen = codegen.Codegen() |
| 30 | result = cgen.generate_mixin(ast) |
| 31 | with open(out_file, "w") as f: |
| 32 | f.write("""# Generated by ruleopt/generate.py, don't edit! |
| 33 | |
| 34 | import sys |
| 35 | from rpython.jit.metainterp.history import ConstInt |
| 36 | from rpython.jit.metainterp.optimizeopt.util import ( |
| 37 | get_box_replacement) |
| 38 | from rpython.jit.metainterp.resoperation import rop |
| 39 | |
| 40 | from rpython.rlib.rarithmetic import LONG_BIT, r_uint, intmask, ovfcheck, uint_mul_high, highest_bit |
| 41 | MAXINT = sys.maxint |
| 42 | MININT = -sys.maxint - 1 |
| 43 | |
| 44 | """) |
| 45 | f.write(result) |
| 46 | |
| 47 | |
| 48 | |
| 49 | if __name__ == "__main__": |
| 50 | try: |
| 51 | sys.exit(main(sys.argv)) |
| 52 | except Exception: |
| 53 | import pdb;pdb.xpm() |