Skip to content

Commit

Permalink
added prefetch operand
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesouza committed Mar 18, 2024
1 parent 4fd59eb commit 7830957
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions osaca/parser/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BaseParser(object):
segment_ext = "segment_extension"
mnemonic = "instruction"
operands = "operands"
prefetch = "prfop"
_parser_constructed = False

def __init__(self):
Expand Down
10 changes: 10 additions & 0 deletions osaca/parser/parser_AArch64.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from osaca.parser.immediate import ImmediateOperand
from osaca.parser.condition import ConditionOperand
from osaca.parser.flag import FlagOperand

Check failure on line 15 in osaca/parser/parser_AArch64.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/parser_AArch64.py#L15

'osaca.parser.flag.FlagOperand' imported but unused (F401)
from osaca.parser.prefetch import PrefetchOperand


class ParserAArch64(BaseParser):
Expand Down Expand Up @@ -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(
Expand Down
40 changes: 40 additions & 0 deletions osaca/parser/prefetch.py
Original file line number Diff line number Diff line change
@@ -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__()
13 changes: 11 additions & 2 deletions osaca/semantics/hw_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,

Check failure on line 264 in osaca/semantics/hw_model.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/semantics/hw_model.py#L264

Continuation line missing indentation or outdented (E122)
target=o["target"] if "target" in o else None,

Check failure on line 265 in osaca/semantics/hw_model.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/semantics/hw_model.py#L265

Continuation line missing indentation or outdented (E122)
policy=o["policy"] if "policy" in o else None,

Check failure on line 266 in osaca/semantics/hw_model.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/semantics/hw_model.py#L266

Continuation line missing indentation or outdented (E122)
)

Check failure on line 267 in osaca/semantics/hw_model.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/semantics/hw_model.py#L267

Continuation line missing indentation or outdented (E122)
)
else:
new_operands.append(o)

Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_parser_AArch64.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"]),

Check failure on line 237 in tests/test_parser_AArch64.py

View workflow job for this annotation

GitHub Actions / Flake8

tests/test_parser_AArch64.py#L237

Missing whitespace after ',' (E231)

Check failure on line 237 in tests/test_parser_AArch64.py

View workflow job for this annotation

GitHub Actions / Flake8

tests/test_parser_AArch64.py#L237

Missing whitespace after ',' (E231)
MemoryOperand(
offset=ImmediateOperand(value=2048),
base=RegisterOperand(prefix="x", name="26"),
Expand Down

0 comments on commit 7830957

Please sign in to comment.