decodetree: Allow multiple input files

While it would be possible to concatenate input files with make,
passing the original input files to decodetree.py allows us to
generate error messages which allows compilation environments
(read: emacs) to next-error to the correct input file.

Backports commit 6699ae6a8e74381583622502db8bd47fac381c9e from qemu
This commit is contained in:
Richard Henderson 2018-11-11 08:28:51 -05:00 committed by Lioncash
parent 4d49c004e4
commit 800c9db9c9
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -175,15 +175,15 @@ decode_function = 'decode'
re_ident = '[a-zA-Z][a-zA-Z0-9_]*' re_ident = '[a-zA-Z][a-zA-Z0-9_]*'
def error(lineno, *args): def error_with_file(file, lineno, *args):
"""Print an error message from file:line and args and exit.""" """Print an error message from file:line and args and exit."""
global output_file global output_file
global output_fd global output_fd
if lineno: if lineno:
r = '{0}:{1}: error:'.format(input_file, lineno) r = '{0}:{1}: error:'.format(file, lineno)
elif input_file: elif input_file:
r = '{0}: error:'.format(input_file) r = '{0}: error:'.format(file)
else: else:
r = 'error:' r = 'error:'
for a in args: for a in args:
@ -196,6 +196,10 @@ def error(lineno, *args):
exit(1) exit(1)
def error(lineno, *args):
error_with_file(input_file, lineno, args)
def output(*args): def output(*args):
global output_fd global output_fd
for a in args: for a in args:
@ -420,6 +424,7 @@ class General:
"""Common code between instruction formats and instruction patterns""" """Common code between instruction formats and instruction patterns"""
def __init__(self, name, lineno, base, fixb, fixm, udfm, fldm, flds): def __init__(self, name, lineno, base, fixb, fixm, udfm, fldm, flds):
self.name = name self.name = name
self.file = input_file
self.lineno = lineno self.lineno = lineno
self.base = base self.base = base
self.fixedbits = fixb self.fixedbits = fixb
@ -472,7 +477,7 @@ class Pattern(General):
global translate_prefix global translate_prefix
ind = str_indent(i) ind = str_indent(i)
arg = self.base.base.name arg = self.base.base.name
output(ind, '/* line ', str(self.lineno), ' */\n') output(ind, '/* ', self.file, ':', str(self.lineno), ' */\n')
if not extracted: if not extracted:
output(ind, self.base.extract_name(), '(&u.f_', arg, ', insn);\n') output(ind, self.base.extract_name(), '(&u.f_', arg, ', insn);\n')
for n, f in self.fields.items(): for n, f in self.fields.items():
@ -920,8 +925,9 @@ def build_tree(pats, outerbits, outermask):
if innermask == 0: if innermask == 0:
pnames = [] pnames = []
for p in pats: for p in pats:
pnames.append(p.name + ':' + str(p.lineno)) pnames.append(p.name + ':' + p.file + ':' + str(p.lineno))
error(pats[0].lineno, 'overlapping patterns:', pnames) error_with_file(pats[0].file, pats[0].lineno,
'overlapping patterns:', pnames)
fullmask = outermask | innermask fullmask = outermask | innermask
@ -1012,10 +1018,11 @@ def main():
if len(args) < 1: if len(args) < 1:
error(0, 'missing input file') error(0, 'missing input file')
input_file = args[0] for filename in args:
f = open(input_file, 'r') input_file = filename
parse_file(f) f = open(filename, 'r')
f.close() parse_file(f)
f.close()
t = build_tree(patterns, 0, 0) t = build_tree(patterns, 0, 0)
prop_format(t) prop_format(t)