mirror of
https://github.com/RRZE-HPC/OSACA.git
synced 2025-12-16 09:00:05 +01:00
changed reg scale value to int and added prefix x for sp
This commit is contained in:
@@ -306,6 +306,8 @@ class ParserAArch64v81(BaseParser):
|
||||
):
|
||||
# TODO: discuss if ranges should be converted to lists
|
||||
return self.substitute_register_list(operand[self.REGISTER_ID])
|
||||
if self.REGISTER_ID in operand and operand[self.REGISTER_ID]['name'] == 'sp':
|
||||
return self.substitute_sp_register(operand[self.REGISTER_ID])
|
||||
# add value attribute to floating point immediates without exponent
|
||||
if self.IMMEDIATE_ID in operand:
|
||||
return self.substitute_immediate(operand[self.IMMEDIATE_ID])
|
||||
@@ -318,12 +320,16 @@ class ParserAArch64v81(BaseParser):
|
||||
offset = None if 'offset' not in memory_address else memory_address['offset']
|
||||
base = None if 'base' not in memory_address else memory_address['base']
|
||||
index = None if 'index' not in memory_address else memory_address['index']
|
||||
scale = '1'
|
||||
scale = 1
|
||||
if base is not None and 'name' in base and base['name'] == 'sp':
|
||||
base['prefix'] = 'x'
|
||||
if index is not None and 'name' in index and index['name'] == 'sp':
|
||||
index['prefix'] = 'x'
|
||||
valid_shift_ops = ['lsl', 'uxtw', 'sxtw']
|
||||
if 'index' in memory_address:
|
||||
if 'shift' in memory_address['index']:
|
||||
if memory_address['index']['shift_op'].lower() in valid_shift_ops:
|
||||
scale = str(2 ** int(memory_address['index']['shift']['value']))
|
||||
scale = 2 ** int(memory_address['index']['shift']['value'])
|
||||
new_dict = AttrDict({'offset': offset, 'base': base, 'index': index, 'scale': scale})
|
||||
if 'pre_indexed' in memory_address:
|
||||
new_dict['pre_indexed'] = True
|
||||
@@ -331,6 +337,11 @@ class ParserAArch64v81(BaseParser):
|
||||
new_dict['post_indexed'] = memory_address['post_indexed']
|
||||
return AttrDict({self.MEMORY_ID: new_dict})
|
||||
|
||||
def substitute_sp_register(self, register):
|
||||
reg = register
|
||||
reg['prefix'] = 'x'
|
||||
return AttrDict({self.REGISTER_ID: reg})
|
||||
|
||||
def substitute_register_list(self, register_list):
|
||||
# Remove unnecessarily created dictionary entries during parsing
|
||||
vlist = []
|
||||
|
||||
@@ -228,7 +228,7 @@ class ParserX86ATT(BaseParser):
|
||||
offset = None if 'offset' not in memory_address else memory_address['offset']
|
||||
base = None if 'base' not in memory_address else memory_address['base']
|
||||
index = None if 'index' not in memory_address else memory_address['index']
|
||||
scale = '1' if 'scale' not in memory_address else memory_address['scale']
|
||||
scale = 1 if 'scale' not in memory_address else int(memory_address['scale'])
|
||||
new_dict = AttrDict({'offset': offset, 'base': base, 'index': index, 'scale': scale})
|
||||
return AttrDict({self.MEMORY_ID: new_dict})
|
||||
|
||||
|
||||
@@ -107,10 +107,10 @@ class TestParserAArch64v81(unittest.TestCase):
|
||||
self.assertEqual(parsed_4.instruction, 'str')
|
||||
self.assertIsNone(parsed_4.operands.destination[0].memory.offset)
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.base.name, 'sp')
|
||||
self.assertIsNone(parsed_4.operands.destination[0].memory.base.prefix)
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.base.prefix, 'x')
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.index.name, '1')
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.index.prefix, 'x')
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.scale, '16')
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.scale, 16)
|
||||
self.assertEqual(parsed_4.operands.source[0].register.name, '28')
|
||||
self.assertEqual(parsed_4.operands.source[0].register.prefix, 'x')
|
||||
self.assertEqual(parsed_4.comment, '12.9')
|
||||
@@ -125,7 +125,7 @@ class TestParserAArch64v81(unittest.TestCase):
|
||||
self.assertEqual(parsed_5.operands.source[0].memory.base.name, '0')
|
||||
self.assertEqual(parsed_5.operands.source[0].memory.base.prefix, 'x')
|
||||
self.assertIsNone(parsed_5.operands.source[0].memory.index)
|
||||
self.assertEqual(parsed_5.operands.source[0].memory.scale, '1')
|
||||
self.assertEqual(parsed_5.operands.source[0].memory.scale, 1)
|
||||
|
||||
self.assertEqual(parsed_6.instruction, 'adrp')
|
||||
self.assertEqual(parsed_6.operands.destination[0].register.name, '0')
|
||||
@@ -181,7 +181,7 @@ class TestParserAArch64v81(unittest.TestCase):
|
||||
'shift_op': 'sxtw',
|
||||
'shift': {'value': '2'},
|
||||
},
|
||||
'scale': '4',
|
||||
'scale': 4,
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -201,7 +201,7 @@ class TestParserAArch64v81(unittest.TestCase):
|
||||
'offset': {'value': '2048'},
|
||||
'base': {'prefix': 'x', 'name': '26'},
|
||||
'index': None,
|
||||
'scale': '1',
|
||||
'scale': 1,
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -225,9 +225,9 @@ class TestParserAArch64v81(unittest.TestCase):
|
||||
{
|
||||
'memory': {
|
||||
'offset': {'value': '-16'},
|
||||
'base': {'name': 'sp', 'prefix': None},
|
||||
'base': {'name': 'sp', 'prefix': 'x'},
|
||||
'index': None,
|
||||
'scale': '1',
|
||||
'scale': 1,
|
||||
'pre_indexed': True,
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ class TestParserAArch64v81(unittest.TestCase):
|
||||
'offset': None,
|
||||
'base': {'prefix': 'x', 'name': '11'},
|
||||
'index': None,
|
||||
'scale': '1',
|
||||
'scale': 1,
|
||||
'post_indexed': {'value': '64'},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class TestParserX86ATT(unittest.TestCase):
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.offset.value, '-4')
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.base.name, 'rsp')
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.index.name, 'rax')
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.scale, '8')
|
||||
self.assertEqual(parsed_4.operands.destination[0].memory.scale, 8)
|
||||
self.assertEqual(parsed_4.operands.source[0].register.name, 'xmm4')
|
||||
self.assertEqual(parsed_4.comment, '12.9')
|
||||
|
||||
@@ -112,14 +112,14 @@ class TestParserX86ATT(unittest.TestCase):
|
||||
self.assertEqual(parsed_5.operands.destination[0].memory.offset.identifier.name, 'var')
|
||||
self.assertIsNone(parsed_5.operands.destination[0].memory.base)
|
||||
self.assertIsNone(parsed_5.operands.destination[0].memory.index)
|
||||
self.assertEqual(parsed_5.operands.destination[0].memory.scale, '1')
|
||||
self.assertEqual(parsed_5.operands.destination[0].memory.scale, 1)
|
||||
self.assertEqual(parsed_5.operands.source[0].register.name, 'ebx')
|
||||
|
||||
self.assertEqual(parsed_6.instruction, 'lea')
|
||||
self.assertIsNone(parsed_6.operands.source[0].memory.offset)
|
||||
self.assertIsNone(parsed_6.operands.source[0].memory.base)
|
||||
self.assertEqual(parsed_6.operands.source[0].memory.index.name, 'rax')
|
||||
self.assertEqual(parsed_6.operands.source[0].memory.scale, '8')
|
||||
self.assertEqual(parsed_6.operands.source[0].memory.scale, 8)
|
||||
self.assertEqual(parsed_6.operands.destination[0].register.name, 'rbx')
|
||||
|
||||
self.assertEqual(parsed_7.operands.source[0].immediate.value, '0x1')
|
||||
@@ -166,7 +166,7 @@ class TestParserX86ATT(unittest.TestCase):
|
||||
'offset': {'value': '2'},
|
||||
'base': {'name': 'rax'},
|
||||
'index': {'name': 'rax'},
|
||||
'scale': '1',
|
||||
'scale': 1,
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user