Changeset 2340de6 in buchla-68k for misc/gen-x.py
- Timestamp:
- 07/10/2017 09:06:56 PM (7 years ago)
- Branches:
- master
- Children:
- 4aa78b2
- Parents:
- 526a993
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
misc/gen-x.py
r526a993 r2340de6 3 3 from sys import stdout 4 4 from pycparser import c_ast, parse_file, c_generator 5 from re import escape, subn, search 5 6 6 7 cross_gcc = "/opt/cross-m68k/bin/m68k-none-elf-gcc" … … 77 78 def get_typs(self): 78 79 return self.typs 80 81 def fix(text, path): 82 with open(path, "r") as f: 83 cont = f.read() 84 85 (pat, n) = subn(r"\[[0-9]+\]", "[@]", text[7:]) 86 87 if n == 0: 88 return text 89 90 rex = escape(pat). \ 91 replace("\@", "([0-9A-Z_]+)"). \ 92 replace("\ ", "[\t\n ]+") 93 94 m = search(rex, cont) 95 96 if not m: 97 raise Exception("error while matching {}".format(re)) 98 99 pats = pat.split("@") 100 vals = m.groups() 101 102 if len(pats) != len(vals) + 1: 103 raise Exception("length mismatch: {} vs. {}". \ 104 format(len(pats), len(vals))) 105 106 out = pats[0] 107 pats = pats[1:] 108 109 while len(pats) > 0: 110 out += vals[0] + pats[0] 111 vals = vals[1:] 112 pats = pats[1:] 113 114 return "extern " + out 79 115 80 116 gen = c_generator.CGenerator() … … 130 166 decl.init = None 131 167 132 toks = gen.visit(decl).split(" ") 168 text = gen.visit(decl) 169 text = fix(text, decl.coord.file) 170 171 toks = text.split(" ") 133 172 alig = "" 134 173
Note:
See TracChangeset
for help on using the changeset viewer.