formats = {}
patterns = []
allpatterns = []
+anyextern = False
translate_prefix = 'trans'
translate_scope = 'static '
return '{0}(insn, {1}, {2})'.format(extr, self.pos, self.len)
def __eq__(self, other):
- return self.sign == other.sign and self.sign == other.sign
+ return self.sign == other.sign and self.mask == other.mask
def __ne__(self, other):
return not self.__eq__(other)
class FunctionField:
- """Class representing a field passed through an expander"""
+ """Class representing a field passed through a function"""
def __init__(self, func, base):
self.mask = base.mask
self.sign = base.sign
# end FunctionField
+class ParameterField:
+ """Class representing a pseudo-field read from a function"""
+ def __init__(self, func):
+ self.mask = 0
+ self.sign = 0
+ self.func = func
+
+ def __str__(self):
+ return self.func
+
+ def str_extract(self):
+ return self.func + '(ctx)'
+
+ def __eq__(self, other):
+ return self.func == other.func
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+# end ParameterField
+
+
class Arguments:
"""Class representing the extracted fields of a format"""
def __init__(self, nm, flds, extern):
if width > insnwidth:
error(lineno, 'field too large')
- if len(subs) == 1:
- f = subs[0]
+ if len(subs) == 0:
+ if func:
+ f = ParameterField(func)
+ else:
+ error(lineno, 'field with no value')
else:
- mask = 0
- for s in subs:
- if mask & s.mask:
- error(lineno, 'field components overlap')
- mask |= s.mask
- f = MultiField(subs, mask)
- if func:
- f = FunctionField(func, f)
+ if len(subs) == 1:
+ f = subs[0]
+ else:
+ mask = 0
+ for s in subs:
+ if mask & s.mask:
+ error(lineno, 'field components overlap')
+ mask |= s.mask
+ f = MultiField(subs, mask)
+ if func:
+ f = FunctionField(func, f)
if name in fields:
error(lineno, 'duplicate field', name)
"""Parse one argument set from TOKS at LINENO"""
global arguments
global re_ident
+ global anyextern
flds = []
extern = False
for t in toks:
if re_fullmatch('!extern', t):
extern = True
+ anyextern = True
continue
if not re_fullmatch(re_ident, t):
error(lineno, 'invalid argument set token "{0}"'.format(t))
global insnmask
global decode_function
global variablewidth
+ global anyextern
decode_scope = 'static '
# A single translate function can be invoked for different patterns.
# Make sure that the argument sets are the same, and declare the
# function only once.
+ #
+ # If we're sharing formats, we're likely also sharing trans_* functions,
+ # but we can't tell which ones. Prevent issues from the compiler by
+ # suppressing redundant declaration warnings.
+ if anyextern:
+ output("#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE\n",
+ "# pragma GCC diagnostic push\n",
+ "# pragma GCC diagnostic ignored \"-Wredundant-decls\"\n",
+ "# ifdef __clang__\n"
+ "# pragma GCC diagnostic ignored \"-Wtypedef-redefinition\"\n",
+ "# endif\n",
+ "#endif\n\n")
+
out_pats = {}
for i in allpatterns:
if i.name in out_pats:
out_pats[i.name] = i
output('\n')
+ if anyextern:
+ output("#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE\n",
+ "# pragma GCC diagnostic pop\n",
+ "#endif\n\n")
+
for n in sorted(formats.keys()):
f = formats[n]
f.output_extract()