From 78309574acfc345a2ecee78865c34c86b95dde78 Mon Sep 17 00:00:00 2001 From: stefandesouza Date: Mon, 18 Mar 2024 22:29:39 +0100 Subject: [PATCH] added prefetch operand --- osaca/parser/base_parser.py | 1 + osaca/parser/parser_AArch64.py | 10 +++++++++ osaca/parser/prefetch.py | 40 ++++++++++++++++++++++++++++++++++ osaca/semantics/hw_model.py | 13 +++++++++-- tests/test_parser_AArch64.py | 3 ++- 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 osaca/parser/prefetch.py diff --git a/osaca/parser/base_parser.py b/osaca/parser/base_parser.py index b83ea15..3ac2124 100644 --- a/osaca/parser/base_parser.py +++ b/osaca/parser/base_parser.py @@ -17,6 +17,7 @@ class BaseParser(object): segment_ext = "segment_extension" mnemonic = "instruction" operands = "operands" + prefetch = "prfop" _parser_constructed = False def __init__(self): diff --git a/osaca/parser/parser_AArch64.py b/osaca/parser/parser_AArch64.py index 1dce190..e858732 100644 --- a/osaca/parser/parser_AArch64.py +++ b/osaca/parser/parser_AArch64.py @@ -13,6 +13,7 @@ from osaca.parser.immediate import ImmediateOperand from osaca.parser.condition import ConditionOperand from osaca.parser.flag import FlagOperand +from osaca.parser.prefetch import PrefetchOperand class ParserAArch64(BaseParser): @@ -389,8 +390,17 @@ def process_operand(self, operand): return self.process_directive_operand(operand[self.directive_id]) if self.condition_id in operand: return self.process_condition(operand[self.condition_id]) + if self.prefetch in operand: + return self.process_prefetch_operand(operand[self.prefetch]) return operand + def process_prefetch_operand(self, operand): + return PrefetchOperand( + type_id=operand["type"] if "type" in operand else None, + target=operand["target"] if "target" in operand else None, + policy=operand["policy"] if "policy" in operand else None, + ) + def process_directive_operand(self, operand): return ( DirectiveOperand( diff --git a/osaca/parser/prefetch.py b/osaca/parser/prefetch.py new file mode 100644 index 0000000..5455c4d --- /dev/null +++ b/osaca/parser/prefetch.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +from osaca.parser.operand import Operand + + +class PrefetchOperand(Operand): + def __init__(self, type_id=None, target=None, policy=None): + self._type_id = type_id + self._target = target + self._policy = policy + + @property + def type_id(self): + return self._type_id + + @type_id.setter + def type_id(self, type_id): + self._type_id = type_id + + @property + def target(self): + return self._target + + @target.setter + def target(self, target): + self._target = target + + @property + def policy(self): + return self._policy + + @policy.setter + def policy(self, policy): + self._policy = policy + + def __str__(self): + return f"Label(type_id={self._type_id},target={self._target},policy={self._policy})" + + def __repr__(self): + return self.__str__() diff --git a/osaca/semantics/hw_model.py b/osaca/semantics/hw_model.py index 0a2dd0e..c3e19a1 100644 --- a/osaca/semantics/hw_model.py +++ b/osaca/semantics/hw_model.py @@ -21,6 +21,7 @@ from osaca.parser.identifier import IdentifierOperand from osaca.parser.condition import ConditionOperand from osaca.parser.flag import FlagOperand +from osaca.parser.prefetch import PrefetchOperand from ruamel.yaml.compat import StringIO @@ -257,6 +258,14 @@ def operand_to_class(self, o, new_operands): destination=o["destination"] if "destination" in o else False, ) ) + elif o["class"] == "prfop": + new_operands.append( + PrefetchOperand( + type_id=o["type"] if "type" in o else None, + target=o["target"] if "target" in o else None, + policy=o["policy"] if "policy" in o else None, + ) + ) else: new_operands.append(o) @@ -798,8 +807,8 @@ def _check_AArch64_operands(self, i_operand, operand): ): return isinstance(i_operand, IdentifierOperand) # prefetch option - if not isinstance(operand, Operand) and "prfop" in operand: - return i_operand["class"] == "prfop" + if isinstance(operand, PrefetchOperand): + return isinstance(i_operand, PrefetchOperand) # condition if isinstance(operand, ConditionOperand): if isinstance(i_operand, ConditionOperand): diff --git a/tests/test_parser_AArch64.py b/tests/test_parser_AArch64.py index 161ea6a..aebe58d 100755 --- a/tests/test_parser_AArch64.py +++ b/tests/test_parser_AArch64.py @@ -14,6 +14,7 @@ from osaca.parser.register import RegisterOperand from osaca.parser.immediate import ImmediateOperand from osaca.parser.identifier import IdentifierOperand +from osaca.parser.prefetch import PrefetchOperand class TestParserAArch64(unittest.TestCase): @@ -233,7 +234,7 @@ def test_parse_line(self): instruction_form_5 = InstructionForm( mnemonic="prfm", operands=[ - {"prfop": {"type": ["PLD"], "target": ["L1"], "policy": ["KEEP"]}}, + PrefetchOperand(type_id=["PLD"],target=["L1"],policy=["KEEP"]), MemoryOperand( offset=ImmediateOperand(value=2048), base=RegisterOperand(prefix="x", name="26"),