mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00
decodetree: More use of f-strings
Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
c7cefe6c66
commit
9f6e2b4d34
1 changed files with 23 additions and 27 deletions
|
@ -59,9 +59,9 @@ def error_with_file(file, lineno, *args):
|
||||||
|
|
||||||
prefix = ''
|
prefix = ''
|
||||||
if file:
|
if file:
|
||||||
prefix += '{0}:'.format(file)
|
prefix += f'{file}:'
|
||||||
if lineno:
|
if lineno:
|
||||||
prefix += '{0}:'.format(lineno)
|
prefix += f'{lineno}:'
|
||||||
if prefix:
|
if prefix:
|
||||||
prefix += ' '
|
prefix += ' '
|
||||||
print(prefix, end='error: ', file=sys.stderr)
|
print(prefix, end='error: ', file=sys.stderr)
|
||||||
|
@ -203,7 +203,7 @@ class Field:
|
||||||
extr = 'sextract32'
|
extr = 'sextract32'
|
||||||
else:
|
else:
|
||||||
extr = 'extract32'
|
extr = 'extract32'
|
||||||
return '{0}(insn, {1}, {2})'.format(extr, self.pos, self.len)
|
return f'{extr}(insn, {self.pos}, {self.len})'
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return self.sign == other.sign and self.mask == other.mask
|
return self.sign == other.sign and self.mask == other.mask
|
||||||
|
@ -227,11 +227,11 @@ class MultiField:
|
||||||
ret = '0'
|
ret = '0'
|
||||||
pos = 0
|
pos = 0
|
||||||
for f in reversed(self.subs):
|
for f in reversed(self.subs):
|
||||||
|
ext = f.str_extract()
|
||||||
if pos == 0:
|
if pos == 0:
|
||||||
ret = f.str_extract()
|
ret = ext
|
||||||
else:
|
else:
|
||||||
ret = 'deposit32({0}, {1}, {2}, {3})' \
|
ret = f'deposit32({ret}, {pos}, {32 - pos}, {ext})'
|
||||||
.format(ret, pos, 32 - pos, f.str_extract())
|
|
||||||
pos += f.len
|
pos += f.len
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -675,11 +675,11 @@ def parse_field(lineno, name, toks):
|
||||||
subtoks = t.split(':')
|
subtoks = t.split(':')
|
||||||
sign = False
|
sign = False
|
||||||
else:
|
else:
|
||||||
error(lineno, 'invalid field token "{0}"'.format(t))
|
error(lineno, f'invalid field token "{t}"')
|
||||||
po = int(subtoks[0])
|
po = int(subtoks[0])
|
||||||
le = int(subtoks[1])
|
le = int(subtoks[1])
|
||||||
if po + le > insnwidth:
|
if po + le > insnwidth:
|
||||||
error(lineno, 'field {0} too large'.format(t))
|
error(lineno, f'field {t} too large')
|
||||||
f = Field(sign, po, le)
|
f = Field(sign, po, le)
|
||||||
subs.append(f)
|
subs.append(f)
|
||||||
width += le
|
width += le
|
||||||
|
@ -724,9 +724,9 @@ def parse_arguments(lineno, name, toks):
|
||||||
anyextern = True
|
anyextern = True
|
||||||
continue
|
continue
|
||||||
if not re.fullmatch(re_C_ident, t):
|
if not re.fullmatch(re_C_ident, t):
|
||||||
error(lineno, 'invalid argument set token "{0}"'.format(t))
|
error(lineno, f'invalid argument set token "{t}"')
|
||||||
if t in flds:
|
if t in flds:
|
||||||
error(lineno, 'duplicate argument "{0}"'.format(t))
|
error(lineno, f'duplicate argument "{t}"')
|
||||||
flds.append(t)
|
flds.append(t)
|
||||||
|
|
||||||
if name in arguments:
|
if name in arguments:
|
||||||
|
@ -895,14 +895,14 @@ def parse_generic(lineno, parent_pat, name, toks):
|
||||||
flen = flen[1:]
|
flen = flen[1:]
|
||||||
shift = int(flen, 10)
|
shift = int(flen, 10)
|
||||||
if shift + width > insnwidth:
|
if shift + width > insnwidth:
|
||||||
error(lineno, 'field {0} exceeds insnwidth'.format(fname))
|
error(lineno, f'field {fname} exceeds insnwidth')
|
||||||
f = Field(sign, insnwidth - width - shift, shift)
|
f = Field(sign, insnwidth - width - shift, shift)
|
||||||
flds = add_field(lineno, flds, fname, f)
|
flds = add_field(lineno, flds, fname, f)
|
||||||
fixedbits <<= shift
|
fixedbits <<= shift
|
||||||
fixedmask <<= shift
|
fixedmask <<= shift
|
||||||
undefmask <<= shift
|
undefmask <<= shift
|
||||||
else:
|
else:
|
||||||
error(lineno, 'invalid token "{0}"'.format(t))
|
error(lineno, f'invalid token "{t}"')
|
||||||
width += shift
|
width += shift
|
||||||
|
|
||||||
if variablewidth and width < insnwidth and width % 8 == 0:
|
if variablewidth and width < insnwidth and width % 8 == 0:
|
||||||
|
@ -914,7 +914,7 @@ def parse_generic(lineno, parent_pat, name, toks):
|
||||||
|
|
||||||
# We should have filled in all of the bits of the instruction.
|
# We should have filled in all of the bits of the instruction.
|
||||||
elif not (is_format and width == 0) and width != insnwidth:
|
elif not (is_format and width == 0) and width != insnwidth:
|
||||||
error(lineno, 'definition has {0} bits'.format(width))
|
error(lineno, f'definition has {width} bits')
|
||||||
|
|
||||||
# Do not check for fields overlapping fields; one valid usage
|
# Do not check for fields overlapping fields; one valid usage
|
||||||
# is to be able to duplicate fields via import.
|
# is to be able to duplicate fields via import.
|
||||||
|
@ -932,8 +932,7 @@ def parse_generic(lineno, parent_pat, name, toks):
|
||||||
if arg:
|
if arg:
|
||||||
for f in flds.keys():
|
for f in flds.keys():
|
||||||
if f not in arg.fields:
|
if f not in arg.fields:
|
||||||
error(lineno, 'field {0} not in argument set {1}'
|
error(lineno, f'field {f} not in argument set {arg.name}')
|
||||||
.format(f, arg.name))
|
|
||||||
else:
|
else:
|
||||||
arg = infer_argument_set(flds)
|
arg = infer_argument_set(flds)
|
||||||
if name in formats:
|
if name in formats:
|
||||||
|
@ -960,13 +959,12 @@ def parse_generic(lineno, parent_pat, name, toks):
|
||||||
arg = fmt.base
|
arg = fmt.base
|
||||||
for f in flds.keys():
|
for f in flds.keys():
|
||||||
if f not in arg.fields:
|
if f not in arg.fields:
|
||||||
error(lineno, 'field {0} not in argument set {1}'
|
error(lineno, f'field {f} not in argument set {arg.name}')
|
||||||
.format(f, arg.name))
|
|
||||||
if f in fmt.fields.keys():
|
if f in fmt.fields.keys():
|
||||||
error(lineno, 'field {0} set by format and pattern'.format(f))
|
error(lineno, f'field {f} set by format and pattern')
|
||||||
for f in arg.fields:
|
for f in arg.fields:
|
||||||
if f not in flds.keys() and f not in fmt.fields.keys():
|
if f not in flds.keys() and f not in fmt.fields.keys():
|
||||||
error(lineno, 'field {0} not initialized'.format(f))
|
error(lineno, f'field {f} not initialized')
|
||||||
pat = Pattern(name, lineno, fmt, fixedbits, fixedmask,
|
pat = Pattern(name, lineno, fmt, fixedbits, fixedmask,
|
||||||
undefmask, fieldmask, flds, width)
|
undefmask, fieldmask, flds, width)
|
||||||
parent_pat.pats.append(pat)
|
parent_pat.pats.append(pat)
|
||||||
|
@ -1097,7 +1095,7 @@ def parse_file(f, parent_pat):
|
||||||
elif re.fullmatch(re_pat_ident, name):
|
elif re.fullmatch(re_pat_ident, name):
|
||||||
parse_generic(start_lineno, parent_pat, name, toks)
|
parse_generic(start_lineno, parent_pat, name, toks)
|
||||||
else:
|
else:
|
||||||
error(lineno, 'invalid token "{0}"'.format(name))
|
error(lineno, f'invalid token "{name}"')
|
||||||
toks = []
|
toks = []
|
||||||
|
|
||||||
if nesting != 0:
|
if nesting != 0:
|
||||||
|
@ -1131,9 +1129,8 @@ class SizeTree:
|
||||||
|
|
||||||
# If we need to load more bytes to test, do so now.
|
# If we need to load more bytes to test, do so now.
|
||||||
if extracted < self.width:
|
if extracted < self.width:
|
||||||
output(ind, 'insn = ', decode_function,
|
output(ind, f'insn = {decode_function}_load_bytes',
|
||||||
'_load_bytes(ctx, insn, {0}, {1});\n'
|
f'(ctx, insn, {extracted // 8}, {self.width // 8});\n')
|
||||||
.format(extracted // 8, self.width // 8));
|
|
||||||
extracted = self.width
|
extracted = self.width
|
||||||
|
|
||||||
# Attempt to aid the compiler in producing compact switch statements.
|
# Attempt to aid the compiler in producing compact switch statements.
|
||||||
|
@ -1184,9 +1181,8 @@ class SizeLeaf:
|
||||||
|
|
||||||
# If we need to load more bytes, do so now.
|
# If we need to load more bytes, do so now.
|
||||||
if extracted < self.width:
|
if extracted < self.width:
|
||||||
output(ind, 'insn = ', decode_function,
|
output(ind, f'insn = {decode_function}_load_bytes',
|
||||||
'_load_bytes(ctx, insn, {0}, {1});\n'
|
f'(ctx, insn, {extracted // 8}, {self.width // 8});\n')
|
||||||
.format(extracted // 8, self.width // 8));
|
|
||||||
extracted = self.width
|
extracted = self.width
|
||||||
output(ind, 'return insn;\n')
|
output(ind, 'return insn;\n')
|
||||||
# end SizeLeaf
|
# end SizeLeaf
|
||||||
|
@ -1220,7 +1216,7 @@ def build_size_tree(pats, width, outerbits, outermask):
|
||||||
for p in pats:
|
for p in pats:
|
||||||
pnames.append(p.name + ':' + p.file + ':' + str(p.lineno))
|
pnames.append(p.name + ':' + p.file + ':' + str(p.lineno))
|
||||||
error_with_file(pats[0].file, pats[0].lineno,
|
error_with_file(pats[0].file, pats[0].lineno,
|
||||||
'overlapping patterns size {0}:'.format(width), pnames)
|
f'overlapping patterns size {width}:', pnames)
|
||||||
|
|
||||||
bins = {}
|
bins = {}
|
||||||
for i in pats:
|
for i in pats:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue