diff --git a/osaca/parser/immediate.py b/osaca/parser/immediate.py index 742819c..10e77af 100644 --- a/osaca/parser/immediate.py +++ b/osaca/parser/immediate.py @@ -4,6 +4,8 @@ class ImmediateOperand(Operand): + WILDCARD = "*" + def __init__( self, identifier=None, @@ -69,3 +71,10 @@ def __eq__(self, other): and self._shift == other._shift ) return False + + def is_immediate_type(self, other, isa): + if isa == "aarch64": + if isinstance(other, ImmediateOperand): + return (self.imd_type == self.WILDCARD or self.imd_type == other.imd_type) and other.value is not None + elif isa == "x86": + return isinstance(other, ImmediateOperand) and other.imd_type == "int" diff --git a/osaca/semantics/hw_model.py b/osaca/semantics/hw_model.py index b0c0713..c4fb521 100644 --- a/osaca/semantics/hw_model.py +++ b/osaca/semantics/hw_model.py @@ -74,8 +74,8 @@ def __init__(self, arch=None, path_to_yaml=None, isa=None, lazy=False): if self._path in MachineModel._runtime_cache and not lazy: self._data = MachineModel._runtime_cache[self._path] # check if file is cached - #cached = self._get_cached(self._path) if not lazy else False - if False: + cached = self._get_cached(self._path) if not lazy else False + if cached: self._data = cached else: yaml = self._create_yaml_object() @@ -771,30 +771,8 @@ def _check_AArch64_operands(self, i_operand, operand): return False return operand.is_mem_type(i_operand, self._data["isa"].lower()) # immediate - if isinstance(i_operand, ImmediateOperand) and i_operand.imd_type == self.WILDCARD: - return isinstance(operand, ImmediateOperand) and (operand.value is not None) - - if isinstance(i_operand, ImmediateOperand) and i_operand.imd_type == "int": - return ( - isinstance(operand, ImmediateOperand) - and operand.imd_type == "int" - and operand.value is not None - ) - - if isinstance(i_operand, ImmediateOperand) and i_operand.imd_type == "float": - return ( - isinstance(operand, ImmediateOperand) - and operand.imd_type == "float" - and operand.value is not None - ) - - if isinstance(i_operand, ImmediateOperand) and i_operand.imd_type == "double": - return ( - isinstance(operand, ImmediateOperand) - and operand.imd_type == "double" - and operand.value is not None - ) - + if isinstance(i_operand, ImmediateOperand): + return i_operand.is_immediate_type(operand, self._data["isa"].lower()) # identifier if isinstance(operand, IdentifierOperand) or ( isinstance(operand, ImmediateOperand) and operand.identifier is not None @@ -812,9 +790,6 @@ def _check_AArch64_operands(self, i_operand, operand): def _check_x86_operands(self, i_operand, operand): """Check if the types of operand ``i_operand`` and ``operand`` match.""" - # if "class" in operand.name: - # compare two DB entries - # return self._compare_db_entries(i_operand, operand) # register if isinstance(operand, RegisterOperand): if not isinstance(i_operand, RegisterOperand): @@ -827,7 +802,7 @@ def _check_x86_operands(self, i_operand, operand): return operand.is_mem_type(i_operand, self._data["isa"].lower()) # immediate if isinstance(operand, ImmediateOperand): - return isinstance(i_operand, ImmediateOperand) and i_operand.imd_type == "int" + return operand.is_immediate_type(i_operand, self._data["isa"].lower()) # identifier (e.g., labels) if isinstance(operand, IdentifierOperand): return isinstance(i_operand, IdentifierOperand)