Minor cleanup of operand type and traits code in isa_parser.py.
arch/isa_parser.py: Minor cleanup of operand type and traits code: - build operand size map right away when types are defined instead of waiting to do it lazily - check that operand types have been defined before operands - don't use 'type' as a variable name - use isinstance() instead of checking for types directly --HG-- extra : convert_revision : 099c1ee8d490f9c38316749bf87209388c55c971
This commit is contained in:
parent
3cc6c59582
commit
8f2e096275
|
@ -326,12 +326,16 @@ def p_def_operand_types(t):
|
||||||
except Exception, exc:
|
except Exception, exc:
|
||||||
error(t.lineno(1),
|
error(t.lineno(1),
|
||||||
'error: %s in def operand_types block "%s".' % (exc, t[3]))
|
'error: %s in def operand_types block "%s".' % (exc, t[3]))
|
||||||
|
buildOperandSizeMap()
|
||||||
t[0] = GenCode() # contributes nothing to the output C++ file
|
t[0] = GenCode() # contributes nothing to the output C++ file
|
||||||
|
|
||||||
# Define the mapping from operand names to operand classes and other
|
# Define the mapping from operand names to operand classes and other
|
||||||
# traits. Stored in operandTraitsMap.
|
# traits. Stored in operandTraitsMap.
|
||||||
def p_def_operands(t):
|
def p_def_operands(t):
|
||||||
'def_operands : DEF OPERANDS CODELIT SEMI'
|
'def_operands : DEF OPERANDS CODELIT SEMI'
|
||||||
|
if not globals().has_key('operandSizeMap'):
|
||||||
|
error(t.lineno(1),
|
||||||
|
'error: operand types must be defined before operands')
|
||||||
s = 'global operandTraitsMap; operandTraitsMap = {' + t[3] + '}'
|
s = 'global operandTraitsMap; operandTraitsMap = {' + t[3] + '}'
|
||||||
try:
|
try:
|
||||||
exec s
|
exec s
|
||||||
|
@ -1081,20 +1085,20 @@ def buildOperandSizeMap():
|
||||||
for ext in operandTypeMap.keys():
|
for ext in operandTypeMap.keys():
|
||||||
(desc, size) = operandTypeMap[ext]
|
(desc, size) = operandTypeMap[ext]
|
||||||
if desc == 'signed int':
|
if desc == 'signed int':
|
||||||
type = 'int%d_t' % size
|
ctype = 'int%d_t' % size
|
||||||
is_signed = 1
|
is_signed = 1
|
||||||
elif desc == 'unsigned int':
|
elif desc == 'unsigned int':
|
||||||
type = 'uint%d_t' % size
|
ctype = 'uint%d_t' % size
|
||||||
is_signed = 0
|
is_signed = 0
|
||||||
elif desc == 'float':
|
elif desc == 'float':
|
||||||
is_signed = 1 # shouldn't really matter
|
is_signed = 1 # shouldn't really matter
|
||||||
if size == 32:
|
if size == 32:
|
||||||
type = 'float'
|
ctype = 'float'
|
||||||
elif size == 64:
|
elif size == 64:
|
||||||
type = 'double'
|
ctype = 'double'
|
||||||
if type == '':
|
if ctype == '':
|
||||||
error(0, 'Unrecognized type description "%s" in operandTypeMap')
|
error(0, 'Unrecognized type description "%s" in operandTypeMap')
|
||||||
operandSizeMap[ext] = (size, type, is_signed)
|
operandSizeMap[ext] = (size, ctype, is_signed)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Base class for operand traits. An instance of this class (or actually
|
# Base class for operand traits. An instance of this class (or actually
|
||||||
|
@ -1103,10 +1107,6 @@ def buildOperandSizeMap():
|
||||||
#
|
#
|
||||||
class OperandTraits:
|
class OperandTraits:
|
||||||
def __init__(self, dflt_ext, reg_spec, flags, sort_pri):
|
def __init__(self, dflt_ext, reg_spec, flags, sort_pri):
|
||||||
# Force construction of operandSizeMap from operandTypeMap
|
|
||||||
# if it hasn't happened yet
|
|
||||||
if not globals().has_key('operandSizeMap'):
|
|
||||||
buildOperandSizeMap()
|
|
||||||
self.dflt_ext = dflt_ext
|
self.dflt_ext = dflt_ext
|
||||||
(self.dflt_size, self.dflt_type, self.dflt_is_signed) = \
|
(self.dflt_size, self.dflt_type, self.dflt_is_signed) = \
|
||||||
operandSizeMap[dflt_ext]
|
operandSizeMap[dflt_ext]
|
||||||
|
@ -1119,13 +1119,13 @@ class OperandTraits:
|
||||||
if not flags:
|
if not flags:
|
||||||
# no flags specified (e.g., 'None')
|
# no flags specified (e.g., 'None')
|
||||||
self.flags = ( [], [], [] )
|
self.flags = ( [], [], [] )
|
||||||
elif type(flags) == StringType:
|
elif isinstance(flags, str):
|
||||||
# a single flag: assumed to be unconditional
|
# a single flag: assumed to be unconditional
|
||||||
self.flags = ( [ flags ], [], [] )
|
self.flags = ( [ flags ], [], [] )
|
||||||
elif type(flags) == ListType:
|
elif isinstance(flags, list):
|
||||||
# a list of flags: also assumed to be unconditional
|
# a list of flags: also assumed to be unconditional
|
||||||
self.flags = ( flags, [], [] )
|
self.flags = ( flags, [], [] )
|
||||||
elif type(flags) == TupleType:
|
elif isinstance(flags, tuple):
|
||||||
# it's a tuple: it should be a triple,
|
# it's a tuple: it should be a triple,
|
||||||
# but each item could be a single string or a list
|
# but each item could be a single string or a list
|
||||||
(uncond_flags, src_flags, dest_flags) = flags
|
(uncond_flags, src_flags, dest_flags) = flags
|
||||||
|
|
Loading…
Reference in a new issue