migrate code style to Black

This commit is contained in:
Julian Hammer
2021-03-11 12:02:45 +01:00
parent 1ebe5ecfbd
commit 6204c90934
33 changed files with 3045 additions and 2960 deletions

View File

@@ -3,18 +3,19 @@
import operator
import re
class BaseParser(object):
# Identifiers for operand types
COMMENT_ID = 'comment'
DIRECTIVE_ID = 'directive'
IMMEDIATE_ID = 'immediate'
LABEL_ID = 'label'
IDENTIFIER_ID = 'identifier'
MEMORY_ID = 'memory'
REGISTER_ID = 'register'
SEGMENT_EXT_ID = 'segment_extension'
INSTRUCTION_ID = 'instruction'
OPERANDS_ID = 'operands'
COMMENT_ID = "comment"
DIRECTIVE_ID = "directive"
IMMEDIATE_ID = "immediate"
LABEL_ID = "label"
IDENTIFIER_ID = "identifier"
MEMORY_ID = "memory"
REGISTER_ID = "register"
SEGMENT_EXT_ID = "segment_extension"
INSTRUCTION_ID = "instruction"
OPERANDS_ID = "operands"
_parser_constructed = False
def __init__(self):
@@ -27,15 +28,15 @@ class BaseParser(object):
"""Detect the ISA of the assembly based on the used registers and return the ISA code."""
# Check for the amount of registers in the code to determine the ISA
# 1) Check for xmm, ymm, zmm, rax, rbx, rcx, and rdx registers in x86
heuristics_x86ATT = [r'%[xyz]mm[0-9]', r'%[er][abcd]x[0-9]']
heuristics_x86ATT = [r"%[xyz]mm[0-9]", r"%[er][abcd]x[0-9]"]
# 2) check for v and z vector registers and x/w general-purpose registers
heuristics_aarch64 = [r'[vz][0-9][0-9]?\.[0-9][0-9]?[bhsd]', r'[wx][0-9]']
matches = {'x86': 0, 'aarch64': 0}
heuristics_aarch64 = [r"[vz][0-9][0-9]?\.[0-9][0-9]?[bhsd]", r"[wx][0-9]"]
matches = {"x86": 0, "aarch64": 0}
for h in heuristics_x86ATT:
matches['x86'] += len(re.findall(h, file_content))
matches["x86"] += len(re.findall(h, file_content))
for h in heuristics_aarch64:
matches['aarch64'] += len(re.findall(h, file_content))
matches["aarch64"] += len(re.findall(h, file_content))
return max(matches.items(), key=operator.itemgetter(1))[0]
@@ -50,9 +51,9 @@ class BaseParser(object):
"""
# Create instruction form list
asm_instructions = []
lines = file_content.split('\n')
lines = file_content.split("\n")
for i, line in enumerate(lines):
if line.strip() == '':
if line.strip() == "":
continue
asm_instructions.append(self.parse_line(line, i + 1 + start_line))
return asm_instructions