mirror of
https://github.com/RRZE-HPC/OSACA.git
synced 2025-12-16 09:00:05 +01:00
Added seperate operand class files
This commit is contained in:
42
osaca/parser/directive.py
Normal file
42
osaca/parser/directive.py
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from osaca.parser.operand import Operand
|
||||
|
||||
class DirectiveOperand(Operand):
|
||||
def __init__(self, NAME_ID = None, PARAMETER_ID = None, COMMENT_ID = None):
|
||||
super().__init__()
|
||||
self._NAME_ID = NAME_ID
|
||||
self._PARAMETER_ID = PARAMETER_ID
|
||||
self._COMMENT_ID = COMMENT_ID
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._NAME_ID
|
||||
|
||||
@property
|
||||
def parameters(self):
|
||||
return self._PARAMETER_ID
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
return self._COMMENT_ID
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if not self._COMMENT_ID:
|
||||
raise StopIteration
|
||||
return self._COMMENT_ID.pop(0)
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._NAME_ID = name
|
||||
|
||||
@parameters.setter
|
||||
def parameters(self, parameters):
|
||||
self._PARAMETER_ID = parameters
|
||||
|
||||
@comment.setter
|
||||
def comment(self, comment):
|
||||
self._COMMENT_ID = comment
|
||||
45
osaca/parser/immediate.py
Normal file
45
osaca/parser/immediate.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from osaca.parser.operand import Operand
|
||||
|
||||
class ImmediateOperand(Operand):
|
||||
def __init__(self, IDENTIFIER_ID = None, TYPE_ID = None, VALUE_ID = None, SHIFT_ID = None
|
||||
, ):
|
||||
super().__init__()
|
||||
self._IDENTIFIER_ID = IDENTIFIER_ID
|
||||
self._TYPE_ID = TYPE_ID
|
||||
self._VALUE_ID = VALUE_ID
|
||||
self._SHIFT_ID = SHIFT_ID
|
||||
|
||||
@property
|
||||
def identifier(self):
|
||||
return self._IDENTIFIER_ID
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
return self._TYPE_ID
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._VALUE_ID
|
||||
|
||||
@property
|
||||
def shift(self):
|
||||
return self._TYPE_ID
|
||||
|
||||
@identifier.setter
|
||||
def identifier(self, identifier):
|
||||
self._IDENTIFIER_ID = identifier
|
||||
|
||||
@type.setter
|
||||
def type(self, type):
|
||||
self._TYPE_ID = type
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self._VALUE_ID = value
|
||||
|
||||
@shift.setter
|
||||
def index(self, shift):
|
||||
self._SHIFT_ID = shift
|
||||
|
||||
111
osaca/parser/instruction_form copy.py
Normal file
111
osaca/parser/instruction_form copy.py
Normal file
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
class InstructionForm:
|
||||
# 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"
|
||||
|
||||
def __init__(self, INSTRUCTION_ID = None, OPERANDS_ID = [], DIRECTIVE_ID = None
|
||||
, COMMENT_ID = None, LABEL_ID = None, LINE = None, LINE_NUMBER = None
|
||||
, SEMANTIC_OPERANDS = None):
|
||||
self._INSTRUCTION_ID = INSTRUCTION_ID
|
||||
self._OPERANDS_ID = OPERANDS_ID
|
||||
self._DIRECTIVE_ID = DIRECTIVE_ID
|
||||
self._COMMENT_ID = COMMENT_ID
|
||||
self._LABEL_ID = LABEL_ID
|
||||
self._LINE = LINE
|
||||
self._LINE_NUMBER = LINE_NUMBER
|
||||
self._SEMANTIC_OPERANDS = SEMANTIC_OPERANDS
|
||||
|
||||
@property
|
||||
def semantic_operands(self):
|
||||
return self._SEMANTIC_OPERANDS
|
||||
|
||||
@property
|
||||
def instruction(self):
|
||||
return self._INSTRUCTION_ID
|
||||
|
||||
@property
|
||||
def label(self):
|
||||
return self._LABEL_ID
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
return self._COMMENT_ID
|
||||
|
||||
@property
|
||||
def directive(self):
|
||||
return self._DIRECTIVE_ID
|
||||
|
||||
@property
|
||||
def line_number(self):
|
||||
return self._LINE_NUMBER
|
||||
|
||||
@property
|
||||
def line(self):
|
||||
return self._LINE
|
||||
|
||||
@property
|
||||
def operands(self):
|
||||
return self._OPERANDS_ID
|
||||
|
||||
@semantic_operands.setter
|
||||
def semantic_operands(self, semantic_operands):
|
||||
self._SEMANTIC_OPERANDS = semantic_operands
|
||||
|
||||
@directive.setter
|
||||
def directive(self, directive):
|
||||
self._DIRECTIVE_ID = directive
|
||||
|
||||
@line_number.setter
|
||||
def line_number(self, line_number):
|
||||
self._LINE_NUMBER = line_number
|
||||
|
||||
@line.setter
|
||||
def line(self, line):
|
||||
self._LINE = line
|
||||
|
||||
@operands.setter
|
||||
def operands(self, operands):
|
||||
self._OPERANDS_ID = operands
|
||||
|
||||
@instruction.setter
|
||||
def instruction(self, instruction):
|
||||
self._INSTRUCTION_ID = instruction
|
||||
|
||||
@label.setter
|
||||
def label(self, label):
|
||||
self._LABEL_ID = label
|
||||
|
||||
@comment.setter
|
||||
def comment(self, comment):
|
||||
self._COMMENT_ID =comment
|
||||
|
||||
def __repr__(self):
|
||||
return f"InstructionForm(INSTRUCTION_ID={self._INSTRUCTION_ID}, OPERANDS_ID={self._OPERANDS_ID}, DIRECTIVE_ID={self._DIRECTIVE_ID}, COMMENT_ID={self._COMMENT_ID}, LABEL_ID={self._LABEL_ID}, LINE={self._LINE}, LINE_NUMBER={self._LINE_NUMBER}, SEMANTIC_OPERANDS={self._SEMANTIC_OPERANDS})"
|
||||
|
||||
def __str__(self):
|
||||
return f"Instruction: {self._INSTRUCTION_ID}\nOperands: {self._OPERANDS_ID}\nDirective: {self._DIRECTIVE_ID}\nComment: {self._COMMENT_ID}\nLabel: {self._LABEL_ID}\nLine: {self._LINE}\nLine Number: {self._LINE_NUMBER}\nSemantic Operands: {self._SEMANTIC_OPERANDS}"
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, InstructionForm):
|
||||
return (
|
||||
self._INSTRUCTION_ID == other._INSTRUCTION_ID and
|
||||
self._OPERANDS_ID == other._OPERANDS_ID and
|
||||
self._DIRECTIVE_ID == other._DIRECTIVE_ID and
|
||||
self._COMMENT_ID == other._COMMENT_ID and
|
||||
self._LABEL_ID == other._LABEL_ID and
|
||||
self._LINE == other._LINE and
|
||||
self._LINE_NUMBER == other._LINE_NUMBER and
|
||||
self._SEMANTIC_OPERANDS == other._SEMANTIC_OPERANDS
|
||||
)
|
||||
return False
|
||||
|
||||
111
osaca/parser/instruction_form.py
Normal file
111
osaca/parser/instruction_form.py
Normal file
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
class InstructionForm:
|
||||
# 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"
|
||||
|
||||
def __init__(self, INSTRUCTION_ID = None, OPERANDS_ID = [], DIRECTIVE_ID = None
|
||||
, COMMENT_ID = None, LABEL_ID = None, LINE = None, LINE_NUMBER = None
|
||||
, SEMANTIC_OPERANDS = None):
|
||||
self._INSTRUCTION_ID = INSTRUCTION_ID
|
||||
self._OPERANDS_ID = OPERANDS_ID
|
||||
self._DIRECTIVE_ID = DIRECTIVE_ID
|
||||
self._COMMENT_ID = COMMENT_ID
|
||||
self._LABEL_ID = LABEL_ID
|
||||
self._LINE = LINE
|
||||
self._LINE_NUMBER = LINE_NUMBER
|
||||
self._SEMANTIC_OPERANDS = SEMANTIC_OPERANDS
|
||||
|
||||
@property
|
||||
def semantic_operands(self):
|
||||
return self._SEMANTIC_OPERANDS
|
||||
|
||||
@property
|
||||
def instruction(self):
|
||||
return self._INSTRUCTION_ID
|
||||
|
||||
@property
|
||||
def label(self):
|
||||
return self._LABEL_ID
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
return self._COMMENT_ID
|
||||
|
||||
@property
|
||||
def directive(self):
|
||||
return self._DIRECTIVE_ID
|
||||
|
||||
@property
|
||||
def line_number(self):
|
||||
return self._LINE_NUMBER
|
||||
|
||||
@property
|
||||
def line(self):
|
||||
return self._LINE
|
||||
|
||||
@property
|
||||
def operands(self):
|
||||
return self._OPERANDS_ID
|
||||
|
||||
@semantic_operands.setter
|
||||
def semantic_operands(self, semantic_operands):
|
||||
self._SEMANTIC_OPERANDS = semantic_operands
|
||||
|
||||
@directive.setter
|
||||
def directive(self, directive):
|
||||
self._DIRECTIVE_ID = directive
|
||||
|
||||
@line_number.setter
|
||||
def line_number(self, line_number):
|
||||
self._LINE_NUMBER = line_number
|
||||
|
||||
@line.setter
|
||||
def line(self, line):
|
||||
self._LINE = line
|
||||
|
||||
@operands.setter
|
||||
def operands(self, operands):
|
||||
self._OPERANDS_ID = operands
|
||||
|
||||
@instruction.setter
|
||||
def instruction(self, instruction):
|
||||
self._INSTRUCTION_ID = instruction
|
||||
|
||||
@label.setter
|
||||
def label(self, label):
|
||||
self._LABEL_ID = label
|
||||
|
||||
@comment.setter
|
||||
def comment(self, comment):
|
||||
self._COMMENT_ID =comment
|
||||
|
||||
def __repr__(self):
|
||||
return f"InstructionForm(INSTRUCTION_ID={self._INSTRUCTION_ID}, OPERANDS_ID={self._OPERANDS_ID}, DIRECTIVE_ID={self._DIRECTIVE_ID}, COMMENT_ID={self._COMMENT_ID}, LABEL_ID={self._LABEL_ID}, LINE={self._LINE}, LINE_NUMBER={self._LINE_NUMBER}, SEMANTIC_OPERANDS={self._SEMANTIC_OPERANDS})"
|
||||
|
||||
def __str__(self):
|
||||
return f"Instruction: {self._INSTRUCTION_ID}\nOperands: {self._OPERANDS_ID}\nDirective: {self._DIRECTIVE_ID}\nComment: {self._COMMENT_ID}\nLabel: {self._LABEL_ID}\nLine: {self._LINE}\nLine Number: {self._LINE_NUMBER}\nSemantic Operands: {self._SEMANTIC_OPERANDS}"
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, InstructionForm):
|
||||
return (
|
||||
self._INSTRUCTION_ID == other._INSTRUCTION_ID and
|
||||
self._OPERANDS_ID == other._OPERANDS_ID and
|
||||
self._DIRECTIVE_ID == other._DIRECTIVE_ID and
|
||||
self._COMMENT_ID == other._COMMENT_ID and
|
||||
self._LABEL_ID == other._LABEL_ID and
|
||||
self._LINE == other._LINE and
|
||||
self._LINE_NUMBER == other._LINE_NUMBER and
|
||||
self._SEMANTIC_OPERANDS == other._SEMANTIC_OPERANDS
|
||||
)
|
||||
return False
|
||||
|
||||
34
osaca/parser/label.py
Normal file
34
osaca/parser/label.py
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from osaca.parser.operand import Operand
|
||||
|
||||
class LabelOperand(Operand):
|
||||
def __init__(self, NAME_ID = None, COMMENT_ID = None):
|
||||
super().__init__()
|
||||
self._NAME_ID = NAME_ID
|
||||
self._COMMENT_ID = COMMENT_ID
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._NAME_ID
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._NAME_ID = name
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
return self._COMMENT_ID
|
||||
|
||||
@comment.setter
|
||||
def comment(self, comment):
|
||||
self._COMMENT_ID = comment
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if not self._COMMENT_ID:
|
||||
raise StopIteration
|
||||
return self._COMMENT_ID.pop(0)
|
||||
|
||||
86
osaca/parser/memory.py
Normal file
86
osaca/parser/memory.py
Normal file
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from osaca.parser.operand import Operand
|
||||
|
||||
class MemoryOperand(Operand):
|
||||
def __init__(self, OFFSET_ID = None, BASE_ID = None, INDEX_ID = None
|
||||
, SCALE_ID = None, SEGMENT_EXT_ID = None, MASK = None, PRE_INDEXED = False
|
||||
, POST_INDEXED = False, IMMEDIATE_ID = None):
|
||||
super().__init__()
|
||||
self._OFFSET_ID = OFFSET_ID
|
||||
self._BASE_ID = BASE_ID
|
||||
self._INDEX_ID = INDEX_ID
|
||||
self._SCALE_ID = SCALE_ID
|
||||
self._SEGMENT_EXT_ID = SEGMENT_EXT_ID
|
||||
self._MASK = MASK
|
||||
self._PRE_INDEXED = PRE_INDEXED
|
||||
self._POST_INDEXED = POST_INDEXED
|
||||
self._IMMEDIATE_ID = IMMEDIATE_ID
|
||||
|
||||
@property
|
||||
def offset(self):
|
||||
return self._OFFSET_ID
|
||||
|
||||
@property
|
||||
def immediate(self):
|
||||
return self._IMMEDIATE_ID
|
||||
|
||||
@property
|
||||
def base(self):
|
||||
return self._BASE_ID
|
||||
|
||||
@property
|
||||
def index(self):
|
||||
return self._INDEX_ID
|
||||
|
||||
@property
|
||||
def scale(self):
|
||||
return self._SCALE_ID
|
||||
|
||||
@property
|
||||
def segment_ext_id(self):
|
||||
return self._SEGMENT_EXT_ID
|
||||
|
||||
@property
|
||||
def mask(self):
|
||||
return self._MASK
|
||||
|
||||
@property
|
||||
def pre_indexed(self):
|
||||
return self._PRE_INDEXED
|
||||
|
||||
@property
|
||||
def post_indexed(self):
|
||||
return self._POST_INDEXED
|
||||
|
||||
@segment_ext_id.setter
|
||||
def segment_ext_id(self, segment):
|
||||
self._SEGMENT_EXT_ID= segment
|
||||
|
||||
@offset.setter
|
||||
def offset(self, offset):
|
||||
self._OFFSET_ID = offset
|
||||
|
||||
@base.setter
|
||||
def base(self, base):
|
||||
self._BASE_ID = base
|
||||
|
||||
@index.setter
|
||||
def index(self, index):
|
||||
self._INDEX_ID = index
|
||||
|
||||
@scale.setter
|
||||
def scale(self, scale):
|
||||
self._SCALE_ID = scale
|
||||
|
||||
@mask.setter
|
||||
def mask(self, mask):
|
||||
self._MASK = mask
|
||||
|
||||
@pre_indexed.setter
|
||||
def pre_indexed(self, pre_indexed):
|
||||
self._PRE_INDEXED = pre_indexed
|
||||
|
||||
@post_indexed.setter
|
||||
def post_indexed(self, post_indexed):
|
||||
self._POST_INDEXED = post_indexed
|
||||
88
osaca/parser/operand.py
Normal file
88
osaca/parser/operand.py
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
class Operand:
|
||||
def __init__(self, MEMORY_ID = None, IMMEDIATE_ID = None, DIRECTIVE_ID = None, LABEL_ID = None
|
||||
, COMMENT_ID = None, REGISTER_ID = None, IDENTIFIER_ID = None, CONDITION_ID = None):
|
||||
self._MEMORY_ID = MEMORY_ID
|
||||
self._IMMEDIATE_ID = IMMEDIATE_ID
|
||||
self._DIRECTIVE_ID = DIRECTIVE_ID
|
||||
self._LABEL_ID = LABEL_ID
|
||||
self._COMMENT_ID = COMMENT_ID
|
||||
self._REGISTER_ID = REGISTER_ID
|
||||
self._IDENTIFIER_ID = IDENTIFIER_ID
|
||||
self._CONDITION_ID = CONDITION_ID
|
||||
|
||||
@property
|
||||
def memory(self):
|
||||
return self._MEMORY_ID
|
||||
|
||||
@property
|
||||
def condition(self):
|
||||
return self._CONDITION_ID
|
||||
|
||||
@property
|
||||
def immediate(self):
|
||||
return self._IMMEDIATE_ID
|
||||
|
||||
@property
|
||||
def directive(self):
|
||||
return self._DIRECTIVE_ID
|
||||
|
||||
@property
|
||||
def label(self):
|
||||
return self._LABEL_ID
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
return self._COMMENT_ID
|
||||
|
||||
@property
|
||||
def register(self):
|
||||
return self._REGISTER_ID
|
||||
|
||||
@property
|
||||
def identifier(self):
|
||||
return self._IDENTIFIER_ID
|
||||
|
||||
def copyFrom(self, operand_dict):
|
||||
#self._COMMENT_ID = operand_dict["comment"] if "comment" in operand_dict else None
|
||||
for key, value in operand_dict.items():
|
||||
setattr(self, key, value)
|
||||
|
||||
@memory.setter
|
||||
def memory(self, memory):
|
||||
self._MEMORY_ID = memory
|
||||
|
||||
@immediate.setter
|
||||
def immediate(self, immediate):
|
||||
self._IMMEDIATE_ID = immediate
|
||||
|
||||
@directive.setter
|
||||
def directive(self, directive):
|
||||
self._DIRECTIVE_ID = directive
|
||||
|
||||
@label.setter
|
||||
def label(self, label):
|
||||
self._LABEL_ID = label
|
||||
|
||||
@comment.setter
|
||||
def comment(self, comment):
|
||||
self._COMMENT_ID = comment
|
||||
|
||||
@register.setter
|
||||
def register(self, register):
|
||||
self._REGISTER_ID = register
|
||||
|
||||
@identifier.setter
|
||||
def identifier(self, identifier):
|
||||
self._IDENTIFIER_ID = identifier
|
||||
|
||||
@condition.setter
|
||||
def condition(self, condition):
|
||||
self._CONDITION_ID = condition
|
||||
|
||||
def __repr__(self):
|
||||
return f"Operand(MEMORY_ID={self._MEMORY_ID}, IMMEDIATE_ID={self._IMMEDIATE_ID}, DIRECTIVE_ID={self._DIRECTIVE_ID}, LABEL_ID={self._LABEL_ID}, COMMENT_ID={self._COMMENT_ID}), REGISTER_ID={self._REGISTER_ID}, IDENTIFIER_ID={self._IDENTIFIER_ID})"
|
||||
|
||||
def __str__(self):
|
||||
return f"Memory: {self._MEMORY_ID}\nImmediate: {self._IMMEDIATE_ID}\nDirective: {self._DIRECTIVE_ID}\nLabel: {self._LABEL_ID}\nComment: {self._COMMENT_ID}\nRegister: {self._REGISTER_ID}\nIdentifier: {self._IDENTIFIER_ID}"
|
||||
@@ -6,261 +6,11 @@ import re
|
||||
import pyparsing as pp
|
||||
|
||||
from osaca.parser import AttrDict, BaseParser
|
||||
|
||||
class InstructionForm:
|
||||
# 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"
|
||||
|
||||
def __init__(self, INSTRUCTION_ID = None, OPERANDS_ID = [], DIRECTIVE_ID = None
|
||||
, COMMENT_ID = None, LABEL_ID = None, LINE = None, LINE_NUMBER = None
|
||||
, SEMANTIC_OPERANDS = None):
|
||||
self._INSTRUCTION_ID = INSTRUCTION_ID
|
||||
self._OPERANDS_ID = OPERANDS_ID
|
||||
self._DIRECTIVE_ID = DIRECTIVE_ID
|
||||
self._COMMENT_ID = COMMENT_ID
|
||||
self._LABEL_ID = LABEL_ID
|
||||
self._LINE = LINE
|
||||
self._LINE_NUMBER = LINE_NUMBER
|
||||
self._SEMANTIC_OPERANDS = SEMANTIC_OPERANDS
|
||||
|
||||
@property
|
||||
def semantic_operands(self):
|
||||
return self._SEMANTIC_OPERANDS
|
||||
|
||||
@property
|
||||
def instruction(self):
|
||||
return self._INSTRUCTION_ID
|
||||
|
||||
@property
|
||||
def label(self):
|
||||
return self._LABEL_ID
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
return self._COMMENT_ID
|
||||
|
||||
@property
|
||||
def directive(self):
|
||||
return self._DIRECTIVE_ID
|
||||
|
||||
@property
|
||||
def line_number(self):
|
||||
return self._LINE_NUMBER
|
||||
|
||||
@property
|
||||
def line(self):
|
||||
return self._LINE
|
||||
|
||||
@property
|
||||
def operands(self):
|
||||
return self._OPERANDS_ID
|
||||
|
||||
@semantic_operands.setter
|
||||
def semantic_operands(self, semantic_operands):
|
||||
self._SEMANTIC_OPERANDS = semantic_operands
|
||||
|
||||
@directive.setter
|
||||
def directive(self, directive):
|
||||
self._DIRECTIVE_ID = directive
|
||||
|
||||
@line_number.setter
|
||||
def line_number(self, line_number):
|
||||
self._LINE_NUMBER = line_number
|
||||
|
||||
@line.setter
|
||||
def line(self, line):
|
||||
self._LINE = line
|
||||
|
||||
@operands.setter
|
||||
def operands(self, operands):
|
||||
self._OPERANDS_ID = operands
|
||||
|
||||
@instruction.setter
|
||||
def instruction(self, instruction):
|
||||
self._INSTRUCTION_ID = instruction
|
||||
|
||||
@label.setter
|
||||
def label(self, label):
|
||||
self._LABEL_ID = label
|
||||
|
||||
@comment.setter
|
||||
def comment(self, comment):
|
||||
self._COMMENT_ID =comment
|
||||
|
||||
class OperandForm:
|
||||
def __init__(self, MEMORY_ID = None, IMMEDIATE_ID = None, DIRECTIVE_ID = None, LABEL_ID = None
|
||||
, COMMENT_ID = None):
|
||||
self._MEMORY_ID = MEMORY_ID
|
||||
self._IMMEDIATE_ID = IMMEDIATE_ID
|
||||
self._DIRECTIVE_ID = DIRECTIVE_ID
|
||||
self._LABEL_ID = LABEL_ID
|
||||
self._COMMENT_ID = COMMENT_ID
|
||||
|
||||
@property
|
||||
def memory(self):
|
||||
return self._MEMORY_ID
|
||||
|
||||
@property
|
||||
def immediate(self):
|
||||
return self._IMMEDIATE_ID
|
||||
|
||||
@property
|
||||
def directive(self):
|
||||
return self._DIRECTIVE_ID
|
||||
|
||||
@property
|
||||
def label(self):
|
||||
return self._LABEL_ID
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
return self._COMMENT_ID
|
||||
|
||||
@memory.setter
|
||||
def memory(self, memory):
|
||||
self._MEMORY_ID = memory
|
||||
|
||||
@immediate.setter
|
||||
def immediate(self, immediate):
|
||||
self._IMMEDIATE_ID = immediate
|
||||
|
||||
@directive.setter
|
||||
def directive(self, directive):
|
||||
self._DIRECTIVE_ID = directive
|
||||
|
||||
@label.setter
|
||||
def label(self, label):
|
||||
self._LABEL_ID = label
|
||||
|
||||
@comment.setter
|
||||
def comment(self, comment):
|
||||
self._COMMENT_ID = comment
|
||||
|
||||
class DirectiveForm:
|
||||
def __init__(self, NAME_ID = None, PARAMETER_ID = None, COMMENT_ID = None):
|
||||
self._NAME_ID = NAME_ID
|
||||
self._PARAMETER_ID = PARAMETER_ID
|
||||
self._COMMENT_ID = COMMENT_ID
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._NAME_ID
|
||||
|
||||
@property
|
||||
def parameters(self):
|
||||
return self._PARAMETER_ID
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
return self._COMMENT_ID
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if not self._COMMENT_ID:
|
||||
raise StopIteration
|
||||
return self._COMMENT_ID.pop(0)
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._NAME_ID = name
|
||||
|
||||
@parameters.setter
|
||||
def parameters(self, parameters):
|
||||
self._PARAMETER_ID = parameters
|
||||
|
||||
@comment.setter
|
||||
def comment(self, comment):
|
||||
self._COMMENT_ID = comment
|
||||
|
||||
class MemoryForm:
|
||||
def __init__(self, OFFSET_ID = None, BASE_ID = None, INDEX_ID = None
|
||||
, SCALE_ID = None, SEGMENT_EXT_ID = None):
|
||||
self._OFFSET_ID = OFFSET_ID
|
||||
self._BASE_ID = BASE_ID
|
||||
self._INDEX_ID = INDEX_ID
|
||||
self._SCALE_ID = SCALE_ID
|
||||
self._SEGMENT_EXT_ID = SEGMENT_EXT_ID
|
||||
|
||||
@property
|
||||
def offset(self):
|
||||
return self._OFFSET_ID
|
||||
|
||||
@property
|
||||
def base(self):
|
||||
return self._BASE_ID
|
||||
|
||||
@property
|
||||
def index(self):
|
||||
return self._INDEX_ID
|
||||
|
||||
@property
|
||||
def scale(self):
|
||||
return self._SCALE_ID
|
||||
|
||||
@property
|
||||
def segment_ext_id(self):
|
||||
return self._SEGMENT_EXT_ID
|
||||
|
||||
@segment_ext_id.setter
|
||||
def segment_ext_id(self, segment):
|
||||
self._SEGMENT_EXT_ID= segment
|
||||
|
||||
@offset.setter
|
||||
def offset(self, offset):
|
||||
self._OFFSET_ID = offset
|
||||
|
||||
@base.setter
|
||||
def base(self, base):
|
||||
self._BASE_ID = base
|
||||
|
||||
@index.setter
|
||||
def index(self, index):
|
||||
self._INDEX_ID = index
|
||||
|
||||
@scale.setter
|
||||
def scale(self, scale):
|
||||
self._SCALE_ID = scale
|
||||
|
||||
class LabelForm:
|
||||
def __init__(self, NAME_ID = None, COMMENT_ID = None):
|
||||
self._NAME_ID = NAME_ID
|
||||
self._COMMENT_ID = COMMENT_ID
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._NAME_ID
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._NAME_ID = name
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
return self._COMMENT_ID
|
||||
|
||||
@comment.setter
|
||||
def comment(self, comment):
|
||||
self._COMMENT_ID = comment
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if not self._COMMENT_ID:
|
||||
raise StopIteration
|
||||
return self._COMMENT_ID.pop(0)
|
||||
|
||||
from osaca.parser.instruction_form import InstructionForm
|
||||
from osaca.parser.operand import Operand
|
||||
from osaca.parser.directive import DirectiveOperand
|
||||
from osaca.parser.memory import MemoryOperand
|
||||
from osaca.parser.label import LabelOperand
|
||||
|
||||
class ParserX86ATT(BaseParser):
|
||||
_instance = None
|
||||
@@ -481,7 +231,7 @@ class ParserX86ATT(BaseParser):
|
||||
result = self.process_operand(
|
||||
self.directive.parseString(line, parseAll=True).asDict()
|
||||
)
|
||||
instruction_form.directive = DirectiveForm(
|
||||
instruction_form.directive = DirectiveOperand(
|
||||
NAME_ID = result.directive.name,
|
||||
PARAMETER_ID = result.directive.parameters,
|
||||
)
|
||||
@@ -554,12 +304,12 @@ class ParserX86ATT(BaseParser):
|
||||
return operand
|
||||
|
||||
def process_directive(self, directive):
|
||||
directive_new = DirectiveForm(NAME_ID = directive["name"], PARAMETER_ID = [])
|
||||
directive_new = DirectiveOperand(NAME_ID = directive["name"], PARAMETER_ID = [])
|
||||
if "parameters" in directive:
|
||||
directive_new.parameters = directive["parameters"]
|
||||
if "comment" in directive:
|
||||
directive_new.comment = directive["comment"]
|
||||
return OperandForm(DIRECTIVE_ID = directive_new)
|
||||
return Operand(DIRECTIVE_ID = directive_new)
|
||||
|
||||
def process_memory_address(self, memory_address):
|
||||
"""Post-process memory address operand"""
|
||||
@@ -575,18 +325,18 @@ class ParserX86ATT(BaseParser):
|
||||
offset = {"value": offset}
|
||||
elif offset is not None and "value" in offset:
|
||||
offset["value"] = int(offset["value"], 0)
|
||||
new_dict = MemoryForm(OFFSET_ID = offset, BASE_ID = base, INDEX_ID = index, SCALE_ID = scale)
|
||||
new_dict = MemoryOperand(OFFSET_ID = offset, BASE_ID = base, INDEX_ID = index, SCALE_ID = scale)
|
||||
# Add segmentation extension if existing
|
||||
if self.SEGMENT_EXT_ID in memory_address:
|
||||
new_dict.segment_ext_id = memory_address[self.SEGMENT_EXT_ID]
|
||||
return OperandForm(MEMORY_ID = new_dict)
|
||||
return Operand(MEMORY_ID = new_dict)
|
||||
|
||||
def process_label(self, label):
|
||||
"""Post-process label asm line"""
|
||||
# remove duplicated 'name' level due to identifier
|
||||
label["name"] = label["name"][0]["name"]
|
||||
new_label = LabelForm(NAME_ID = label["name"], COMMENT_ID = label["comment"] if "comment" in label else None)
|
||||
return OperandForm(LABEL_ID = new_label)
|
||||
new_label = LabelOperand(NAME_ID = label["name"], COMMENT_ID = label["comment"] if "comment" in label else None)
|
||||
return Operand(LABEL_ID = new_label)
|
||||
|
||||
def process_immediate(self, immediate):
|
||||
"""Post-process immediate operand"""
|
||||
@@ -595,7 +345,7 @@ class ParserX86ATT(BaseParser):
|
||||
return immediate
|
||||
# otherwise just make sure the immediate is a decimal
|
||||
immediate["value"] = int(immediate["value"], 0)
|
||||
return OperandForm(IMMEDIATE_ID = immediate)
|
||||
return Operand(IMMEDIATE_ID = immediate)
|
||||
|
||||
def get_full_reg_name(self, register):
|
||||
"""Return one register name string including all attributes"""
|
||||
|
||||
@@ -8,7 +8,7 @@ import unittest
|
||||
|
||||
from pyparsing import ParseException
|
||||
|
||||
from osaca.parser import AttrDict, ParserAArch64
|
||||
from osaca.parser import AttrDict, ParserAArch64, InstructionForm
|
||||
|
||||
|
||||
class TestParserAArch64(unittest.TestCase):
|
||||
@@ -458,19 +458,13 @@ class TestParserAArch64(unittest.TestCase):
|
||||
)
|
||||
|
||||
def _get_label(self, parser, label):
|
||||
return AttrDict.convert_dict(
|
||||
parser.process_operand(parser.label.parseString(label, parseAll=True).asDict())
|
||||
).label
|
||||
return parser.process_operand(parser.label.parseString(label, parseAll=True).asDict()).label
|
||||
|
||||
def _get_directive(self, parser, directive):
|
||||
return AttrDict.convert_dict(
|
||||
parser.process_operand(parser.directive.parseString(directive, parseAll=True).asDict())
|
||||
).directive
|
||||
return parser.process_operand(parser.directive.parseString(directive, parseAll=True).asDict()).directive
|
||||
|
||||
def _get_condition(self, parser, condition):
|
||||
return AttrDict.convert_dict(
|
||||
parser.process_operand(parser.condition.parseString(condition, parseAll=True).asDict())
|
||||
).condition
|
||||
return parser.process_operand(parser.condition.parseString(condition, parseAll=True).asDict()).condition
|
||||
|
||||
@staticmethod
|
||||
def _find_file(name):
|
||||
|
||||
@@ -8,8 +8,7 @@ import unittest
|
||||
|
||||
from pyparsing import ParseException
|
||||
|
||||
from osaca.parser import AttrDict, ParserX86ATT
|
||||
from osaca.parser.parser_x86att import InstructionForm
|
||||
from osaca.parser import AttrDict, ParserX86ATT, InstructionForm
|
||||
|
||||
class TestParserX86ATT(unittest.TestCase):
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user