flake8 standards

This commit is contained in:
stefandesouza
2023-12-03 21:04:58 +01:00
parent cef7f8098d
commit cac4a0ebf2
17 changed files with 88 additions and 99 deletions

View File

@@ -13,6 +13,7 @@ class BaseParser(object):
IDENTIFIER_ID = "identifier"
MEMORY_ID = "memory"
REGISTER_ID = "register"
CONDITION_ID = "condition"
segment_ext_id = "segment_extension"
instruction_id = "instruction"
operands_id = "operands"

View File

@@ -1,7 +1,5 @@
#!/usr/bin/env python3
from osaca.parser.directive import DirectiveOperand
class instructionForm:
def __init__(

View File

@@ -291,7 +291,7 @@ class ParserAArch64(BaseParser):
try:
result = self.process_operand(self.label.parseString(line, parseAll=True).asDict())
instruction_form.label = result.name
if result.comment != None:
if result.comment is not None:
instruction_form.comment = " ".join(result.comment)
except pp.ParseException:
pass
@@ -390,8 +390,8 @@ class ParserAArch64(BaseParser):
if "comment" in operand["directive"]
else None,
)
if "condition" in operand:
return self.process_condition(operand["condition"])
if self.CONDITION_ID in operand:
return self.process_condition(operand[self.CONDITION_ID])
return operand
def process_register_operand(self, operand):
@@ -449,7 +449,7 @@ class ParserAArch64(BaseParser):
return new_reg
def process_condition(self, condition):
return ConditionOperand(ccode=condition.lower())
return ConditionOperand(ccode=condition.upper())
def resolve_range_list(self, operand):
"""
@@ -502,7 +502,7 @@ class ParserAArch64(BaseParser):
index = register_list.get("index", None)
new_dict = {dict_name: rlist, "index": index}
if len(new_dict[dict_name]) == 1:
return {self.REGISTER_ID: new_dict[dict_name][0]}
return {self.REGISTER_ID: new_dict}
return {self.REGISTER_ID: new_dict}
def process_immediate(self, immediate):
@@ -581,11 +581,11 @@ class ParserAArch64(BaseParser):
"""Normalize immediate to decimal based representation"""
if isinstance(imd, IdentifierOperand):
return imd
if imd.value != None and imd.type == "float":
if imd.value is not None and imd.type == "float":
return self.ieee_to_float(imd.value)
elif imd.value != None and imd.type == "double":
elif imd.value is not None and imd.type == "double":
return self.ieee_to_float(imd.value)
elif imd.value != None:
elif imd.value is not None:
if isinstance(imd.value, str):
# hex or bin, return decimal
return int(imd.value, 0)

View File

@@ -14,7 +14,6 @@ from osaca.parser.label import LabelOperand
from osaca.parser.register import RegisterOperand
from osaca.parser.identifier import IdentifierOperand
from osaca.parser.immediate import ImmediateOperand
from osaca.parser.operand import Operand
class ParserX86ATT(BaseParser):
@@ -223,7 +222,7 @@ class ParserX86ATT(BaseParser):
try:
result = self.process_operand(self.label.parseString(line, parseAll=True).asDict())
instruction_form.label = result.name
if result.comment != None:
if result.comment is not None:
instruction_form.comment = " ".join(result.comment)
except pp.ParseException:
pass
@@ -239,7 +238,7 @@ class ParserX86ATT(BaseParser):
parameter_id=result.parameters,
)
if result.comment != None:
if result.comment is not None:
instruction_form.comment = " ".join(result.comment)
except pp.ParseException:
pass
@@ -340,11 +339,11 @@ class ParserX86ATT(BaseParser):
offset = ImmediateOperand(value_id=offset)
elif offset is not None and "value" in offset:
offset = ImmediateOperand(value_id=int(offset["value"], 0))
if base != None:
if base is not None:
baseOp = RegisterOperand(
name=base["name"], prefix_id=base["prefix"] if "prefix" in base else None
)
if index != None:
if index is not None:
indexOp = RegisterOperand(
name=index["name"], prefix_id=index["prefix"] if "prefix" in index else None
)
@@ -386,7 +385,7 @@ class ParserX86ATT(BaseParser):
"""Normalize immediate to decimal based representation"""
if isinstance(imd, IdentifierOperand):
return imd
if imd.value != None:
if imd.value is not None:
if isinstance(imd.value, str):
# return decimal
return int(imd.value, 0)