Skip to content

Commit

Permalink
Merge pull request #108 from MarkusBuettner/fix_x86_memory_segments
Browse files Browse the repository at this point in the history
Update parsing of x86 memory segments
  • Loading branch information
JanLJL authored Aug 13, 2024
2 parents bc8d0c7 + 0e69fa1 commit 628bdf6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions osaca/parser/parser_x86att.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def construct_parser(self):
joinString="::",
).setResultsName("name")
+ pp.Optional(relocation).setResultsName("relocation")
+ pp.Optional(pp.Suppress(pp.Optional(pp.Literal("+"))) + decimal_number).setResultsName("offset")
).setResultsName("identifier")
# Label
label_rest = pp.Word(pp.alphanums + "$_.+-()")
Expand Down Expand Up @@ -106,13 +107,13 @@ def construct_parser(self):
^ pp.Word(pp.nums)
^ pp.Group(
pp.Optional(offset.setResultsName("offset"))
+ pp.Literal("(")
+ pp.Optional(pp.Literal("(")
+ pp.Optional(self.register.setResultsName("base"))

Check failure on line 111 in osaca/parser/parser_x86att.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/parser_x86att.py#L111

Continuation line under-indented for visual indent (E128)
+ pp.Optional(pp.Suppress(pp.Literal(",")))

Check failure on line 112 in osaca/parser/parser_x86att.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/parser_x86att.py#L112

Continuation line under-indented for visual indent (E128)
+ pp.Optional(self.register.setResultsName("index"))

Check failure on line 113 in osaca/parser/parser_x86att.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/parser_x86att.py#L113

Continuation line under-indented for visual indent (E128)
+ pp.Optional(pp.Suppress(pp.Literal(",")))

Check failure on line 114 in osaca/parser/parser_x86att.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/parser_x86att.py#L114

Continuation line under-indented for visual indent (E128)
+ pp.Optional(scale.setResultsName("scale"))

Check failure on line 115 in osaca/parser/parser_x86att.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/parser_x86att.py#L115

Continuation line under-indented for visual indent (E128)
+ pp.Literal(")")
+ pp.Literal(")"))

Check failure on line 116 in osaca/parser/parser_x86att.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/parser_x86att.py#L116

Continuation line under-indented for visual indent (E128)
)
)
memory_segmentation = (
Expand Down
27 changes: 27 additions & 0 deletions tests/test_parser_x86att.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def test_parse_instruction(self):
instr5 = "mov %ebx,var(,1)"
instr6 = "lea (,%rax,8),%rbx"
instr7 = "vinsertf128 $0x1, %xmm0, %ymm1, %ymm1"
instr8 = "cmpb $0, %fs:var@TPOFF"
instr9 = "movq %rdi, %fs:var@TPOFF-8(%rcx)"
instr10 = "movq $624, %fs:var@TPOFF+4992"

parsed_1 = self.parser.parse_instruction(instr1)
parsed_2 = self.parser.parse_instruction(instr2)
Expand All @@ -120,6 +123,9 @@ def test_parse_instruction(self):
parsed_5 = self.parser.parse_instruction(instr5)
parsed_6 = self.parser.parse_instruction(instr6)
parsed_7 = self.parser.parse_instruction(instr7)
parsed_8 = self.parser.parse_instruction(instr8)
parsed_9 = self.parser.parse_instruction(instr9)
parsed_10 = self.parser.parse_instruction(instr10)

self.assertEqual(parsed_1.mnemonic, "vcvtsi2ss")
self.assertEqual(parsed_1.operands[0].name, "edx")
Expand Down Expand Up @@ -162,6 +168,27 @@ def test_parse_instruction(self):
self.assertEqual(parsed_7.operands[2].name, "ymm1")
self.assertEqual(parsed_7.operands[3].name, "ymm1")

self.assertEqual(parsed_8.mnemonic, "cmpb")
self.assertEqual(parsed_8.operands[0].value, 0)
self.assertEqual(parsed_8.operands[1].base.name, "fs")
self.assertEqual(parsed_8.operands[1].segment_ext[0]['offset']['identifier']['name'], "var")
self.assertEqual(parsed_8.operands[1].segment_ext[0]['offset']['identifier']['relocation'], "@TPOFF")

self.assertEqual(parsed_9.mnemonic, "movq")
self.assertEqual(parsed_9.operands[0].name, "rdi")
self.assertEqual(parsed_9.operands[1].base.name, "fs")
self.assertEqual(parsed_9.operands[1].segment_ext[0]['offset']['identifier']['name'], "var")
self.assertEqual(parsed_9.operands[1].segment_ext[0]['offset']['identifier']['relocation'], "@TPOFF")
self.assertEqual(parsed_9.operands[1].segment_ext[0]['offset']['identifier']['offset'][0], "-8")
self.assertEqual(parsed_9.operands[1].segment_ext[0]['base']['name'], "rcx")

self.assertEqual(parsed_10.mnemonic, "movq")
self.assertEqual(parsed_10.operands[0].value, 624)
self.assertEqual(parsed_10.operands[1].base.name, "fs")
self.assertEqual(parsed_10.operands[1].segment_ext[0]['offset']['identifier']['name'], "var")
self.assertEqual(parsed_10.operands[1].segment_ext[0]['offset']['identifier']['relocation'], "@TPOFF")
self.assertEqual(parsed_10.operands[1].segment_ext[0]['offset']['identifier']['offset'][0], "4992")

def test_parse_line(self):
line_comment = "# -- Begin main"
line_label = "..B1.7: # Preds ..B1.6"
Expand Down

0 comments on commit 628bdf6

Please sign in to comment.