mirror of
https://github.com/RRZE-HPC/OSACA.git
synced 2026-01-06 03:00:11 +01:00
enhanced x86 parser for directives
This commit is contained in:
@@ -188,9 +188,9 @@ def insert_byte_marker(args):
|
||||
from kerncraft.incore_model import asm_instrumentation
|
||||
except ImportError:
|
||||
print(
|
||||
"Module kerncraft not installed. Use 'pip install --user "
|
||||
"kerncraft' for installation.\nFor more information see "
|
||||
"https://github.com/RRZE-HPC/kerncraft",
|
||||
'Module kerncraft not installed. Use \'pip install --user '
|
||||
'kerncraft\' for installation.\nFor more information see '
|
||||
'https://github.com/RRZE-HPC/kerncraft',
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import re
|
||||
import string
|
||||
|
||||
import pyparsing as pp
|
||||
@@ -108,23 +109,19 @@ class ParserX86ATT(BaseParser):
|
||||
).setResultsName(self.MEMORY_ID)
|
||||
|
||||
# Directive
|
||||
directive_option = pp.Combine(
|
||||
pp.Word('#@.', exact=1) + pp.Word(pp.printables, excludeChars=',')
|
||||
)
|
||||
directive_parameter = (
|
||||
pp.quotedString
|
||||
^ directive_option
|
||||
^ identifier
|
||||
^ hex_number
|
||||
^ decimal_number
|
||||
^ self.register
|
||||
^ pp.Group(pp.Word(pp.alphanums + '_').setResultsName('name'))
|
||||
^ (
|
||||
pp.Word(pp.printables, excludeChars=',#')
|
||||
+ pp.Optional(pp.Suppress(pp.Literal(',')))
|
||||
)
|
||||
^ pp.Suppress(pp.Literal(','))
|
||||
)
|
||||
commaSeparatedList = pp.delimitedList(pp.Optional(directive_parameter), delim=',')
|
||||
self.directive = pp.Group(
|
||||
pp.Literal('.')
|
||||
+ pp.Word(pp.alphanums + '_').setResultsName('name')
|
||||
+ commaSeparatedList.setResultsName('parameters')
|
||||
# + pp.ZeroOrMore(directive_parameter).setResultsName('parameters')
|
||||
+ pp.ZeroOrMore(directive_parameter).setResultsName('parameters')
|
||||
+ pp.Optional(self.comment)
|
||||
).setResultsName(self.DIRECTIVE_ID)
|
||||
|
||||
@@ -277,8 +274,18 @@ class ParserX86ATT(BaseParser):
|
||||
return self.process_immediate(operand[self.IMMEDIATE_ID])
|
||||
if self.LABEL_ID in operand:
|
||||
return self.process_label(operand[self.LABEL_ID])
|
||||
if self.DIRECTIVE_ID in operand:
|
||||
return self.process_directive(operand[self.DIRECTIVE_ID])
|
||||
return operand
|
||||
|
||||
def process_directive(self, directive):
|
||||
directive_new = {'name': directive['name'], 'parameters': []}
|
||||
if 'parameters' in directive:
|
||||
directive_new['parameters'] = directive['parameters']
|
||||
if 'comment' in directive:
|
||||
directive_new['comment'] = directive['comment']
|
||||
return AttrDict({self.DIRECTIVE_ID: directive_new})
|
||||
|
||||
def process_memory_address(self, memory_address):
|
||||
"""Post-process memory address operand"""
|
||||
# Remove unecessarily created dictionary entries during memory address parsing
|
||||
|
||||
@@ -47,18 +47,26 @@ class TestParserX86ATT(unittest.TestCase):
|
||||
self.assertEqual(len(self._get_directive(self.parser, '\t.align\t16,0x90').parameters), 2)
|
||||
self.assertEqual(
|
||||
self._get_directive(self.parser, '\t.set\tL$set$0,LECIE1-LSCIE1').parameters,
|
||||
[{'name': 'L$set$0'}, {'name': 'LECIE1-LSCIE1'}])
|
||||
['L$set$0', 'LECIE1-LSCIE1'],
|
||||
)
|
||||
self.assertEqual(
|
||||
self._get_directive(
|
||||
self.parser,
|
||||
'\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support'
|
||||
).parameters,
|
||||
[{'name': v} for v in
|
||||
['__TEXT', '__eh_frame', 'coalesced', 'no_toc+strip_static_syms+live_support']])
|
||||
'\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support',
|
||||
).parameters,
|
||||
[
|
||||
'__TEXT',
|
||||
'__eh_frame',
|
||||
'coalesced',
|
||||
'no_toc+strip_static_syms+live_support',
|
||||
],
|
||||
)
|
||||
self.assertEqual(
|
||||
self._get_directive(
|
||||
self.parser, '\t.section\t__TEXT,__literal16,16byte_literals').parameters,
|
||||
[{'name': v} for v in ['__TEXT', '__literal16', '16byte_literals']])
|
||||
self.parser, '\t.section\t__TEXT,__literal16,16byte_literals'
|
||||
).parameters,
|
||||
['__TEXT', '__literal16', '16byte_literals'],
|
||||
)
|
||||
self.assertEqual(
|
||||
self._get_directive(self.parser, '\t.align\t16,0x90').parameters[1], '0x90'
|
||||
)
|
||||
@@ -169,7 +177,7 @@ class TestParserX86ATT(unittest.TestCase):
|
||||
instruction_form_3 = {
|
||||
'instruction': None,
|
||||
'operands': [],
|
||||
'directive': {'name': 'quad', 'parameters': [{'name': '.2.3_2__kmpc_loc_pack.2'}]},
|
||||
'directive': {'name': 'quad', 'parameters': ['.2.3_2__kmpc_loc_pack.2']},
|
||||
'comment': 'qed',
|
||||
'label': None,
|
||||
'line': '.quad .2.3_2__kmpc_loc_pack.2 #qed',
|
||||
@@ -186,9 +194,7 @@ class TestParserX86ATT(unittest.TestCase):
|
||||
'scale': 1,
|
||||
}
|
||||
},
|
||||
{
|
||||
'register': {'name': 'ecx'}
|
||||
}
|
||||
{'register': {'name': 'ecx'}},
|
||||
],
|
||||
'directive': None,
|
||||
'comment': '12.9',
|
||||
|
||||
Reference in New Issue
Block a user