File: generate.py

package info (click to toggle)
pypy3 7.3.20%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 212,332 kB
  • sloc: python: 2,100,989; ansic: 540,684; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (53 lines) | stat: -rw-r--r-- 1,594 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import print_function

import sys, os
from rply.errors import ParsingError, LexingError
from rpython.jit.metainterp.ruleopt import parse, proof, codegen

def main(argv):
    here = os.path.dirname(__file__)
    def_file = os.path.join(here, "real.rules")
    out_file = os.path.join(here, "..", "optimizeopt", "autogenintrules.py")
    with open(def_file) as f:
        content = f.read()
    try:
        ast = proof.prove_source(content)
    except (ParsingError, LexingError) as e:
        pos = e.getsourcepos()
        print("Parse error in line %s:" % pos.lineno)
        line = content.splitlines()[pos.lineno - 1]
        print("    " + line)
        print("    " + " " * (pos.colno - 1) + "^")
        return -1
    except parse.TypeCheckError as e:
        print(e.format(content))
        return -2
    except proof.ProofProblem as e:
        print("_" * 60)
        print(e.format())
        return -3
    cgen = codegen.Codegen()
    result = cgen.generate_mixin(ast)
    with open(out_file, "w") as f:
        f.write("""# Generated by ruleopt/generate.py, don't edit!

import sys
from rpython.jit.metainterp.history import ConstInt
from rpython.jit.metainterp.optimizeopt.util import (
    get_box_replacement)
from rpython.jit.metainterp.resoperation import rop

from rpython.rlib.rarithmetic import LONG_BIT, r_uint, intmask, ovfcheck, uint_mul_high, highest_bit
MAXINT = sys.maxint
MININT = -sys.maxint - 1

""")
        f.write(result)



if __name__ == "__main__":
    try:
        sys.exit(main(sys.argv))
    except Exception:
        import pdb;pdb.xpm()