osaca.parser package

Parser module for parsing the assembly code.

osaca.parser.attr_dict module

Attribute Dictionary to access dictionary entries as attributes.

class AttrDict(*args, **kwargs)[source]

Bases: dict

static convert_dict(dictionary)[source]

Convert given dictionary to AttrDict.

Parameters:dictionary (dict) – dict to be converted
Returns:AttrDict representation of dictionary
static get_dict(attrdict)[source]

Convert given AttrDict to a standard dictionary.

Parameters:attrdict (AttrDict) – AttrDict to be converted
Returns:dict representation of AttrDict

osaca.parser.base_parser module

Parser superclass of specific parsers.

class BaseParser[source]

Bases: object

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'
static detect_ISA(file_content)[source]

Detect the ISA of the assembly based on the used registers and return the ISA code.

parse_file(file_content, start_line=0)[source]

Parse assembly file. This includes not extracting of the marked kernel and the parsing of the instruction forms.

Parameters:
  • file_content (str) – assembly code
  • start_line (int) – offset, if first line in file_content is meant to be not 1
Returns:

list of instruction forms

parse_line(line, line_number=None)[source]
parse_instruction(instruction)[source]
parse_register(register_string)[source]
is_gpr(register)[source]
is_vector_register(register)[source]
get_reg_type(register)[source]
construct_parser()[source]
process_operand(operand)[source]
get_full_reg_name(register)[source]
normalize_imd(imd)[source]
is_reg_dependend_of(reg_a, reg_b)[source]

osaca.parser.parser_AArch64v81 module

osaca.parser.parser_x86att module

class ParserX86ATT[source]

Bases: osaca.parser.base_parser.BaseParser

construct_parser()[source]

Create parser for x86 AT&T ISA.

parse_register(register_string)[source]

Parse register string

parse_line(line, line_number=None)[source]

Parse line and return instruction form.

Parameters:
  • line (str) – line of assembly code
  • line_number (int, optional) – default None, identifier of instruction form
Returns:

dict – parsed asm line (comment, label, directive or instruction form)

parse_instruction(instruction)[source]

Parse instruction in asm line.

Parameters:instruction (str) – Assembly line string.
Returns:dict – parsed instruction form
process_operand(operand)[source]

Post-process operand

process_directive(directive)[source]
process_memory_address(memory_address)[source]

Post-process memory address operand

process_label(label)[source]

Post-process label asm line

process_immediate(immediate)[source]

Post-process immediate operand

get_full_reg_name(register)[source]

Return one register name string including all attributes

normalize_imd(imd)[source]

Normalize immediate to decimal based representation

is_flag_dependend_of(flag_a, flag_b)[source]

Check if flag_a is dependent on flag_b

is_reg_dependend_of(reg_a, reg_b)[source]

Check if reg_a is dependent on reg_b

is_basic_gpr(register)[source]

Check if register is a basic general purpose register (ebi, rax, …)

is_gpr(register)[source]

Check if register is a general purpose register

is_vector_register(register)[source]

Check if register is a vector register

get_reg_type(register)[source]

Get register type

Module contents

Collection of parsers supported by OSACA.

Only the parser below will be exported, so please add new parsers to __all__.

get_parser(isa)[source]
class AttrDict(*args, **kwargs)[source]

Bases: dict

static convert_dict(dictionary)[source]

Convert given dictionary to AttrDict.

Parameters:dictionary (dict) – dict to be converted
Returns:AttrDict representation of dictionary
static get_dict(attrdict)[source]

Convert given AttrDict to a standard dictionary.

Parameters:attrdict (AttrDict) – AttrDict to be converted
Returns:dict representation of AttrDict
class BaseParser[source]

Bases: object

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'
static detect_ISA(file_content)[source]

Detect the ISA of the assembly based on the used registers and return the ISA code.

parse_file(file_content, start_line=0)[source]

Parse assembly file. This includes not extracting of the marked kernel and the parsing of the instruction forms.

Parameters:
  • file_content (str) – assembly code
  • start_line (int) – offset, if first line in file_content is meant to be not 1
Returns:

list of instruction forms

parse_line(line, line_number=None)[source]
parse_instruction(instruction)[source]
parse_register(register_string)[source]
is_gpr(register)[source]
is_vector_register(register)[source]
get_reg_type(register)[source]
construct_parser()[source]
process_operand(operand)[source]
get_full_reg_name(register)[source]
normalize_imd(imd)[source]
is_reg_dependend_of(reg_a, reg_b)[source]
class ParserX86ATT[source]

Bases: osaca.parser.base_parser.BaseParser

construct_parser()[source]

Create parser for x86 AT&T ISA.

parse_register(register_string)[source]

Parse register string

parse_line(line, line_number=None)[source]

Parse line and return instruction form.

Parameters:
  • line (str) – line of assembly code
  • line_number (int, optional) – default None, identifier of instruction form
Returns:

dict – parsed asm line (comment, label, directive or instruction form)

parse_instruction(instruction)[source]

Parse instruction in asm line.

Parameters:instruction (str) – Assembly line string.
Returns:dict – parsed instruction form
process_operand(operand)[source]

Post-process operand

process_directive(directive)[source]
process_memory_address(memory_address)[source]

Post-process memory address operand

process_label(label)[source]

Post-process label asm line

process_immediate(immediate)[source]

Post-process immediate operand

get_full_reg_name(register)[source]

Return one register name string including all attributes

normalize_imd(imd)[source]

Normalize immediate to decimal based representation

is_flag_dependend_of(flag_a, flag_b)[source]

Check if flag_a is dependent on flag_b

is_reg_dependend_of(reg_a, reg_b)[source]

Check if reg_a is dependent on reg_b

is_basic_gpr(register)[source]

Check if register is a basic general purpose register (ebi, rax, …)

is_gpr(register)[source]

Check if register is a general purpose register

is_vector_register(register)[source]

Check if register is a vector register

get_reg_type(register)[source]

Get register type

class ParserAArch64[source]

Bases: osaca.parser.base_parser.BaseParser

construct_parser()[source]

Create parser for ARM AArch64 ISA.

parse_line(line, line_number=None)[source]

Parse line and return instruction form.

Parameters:
  • line (str) – line of assembly code
  • line_number (int, optional) – identifier of instruction form, defautls to None
Returns:

dict – parsed asm line (comment, label, directive or instruction form)

parse_instruction(instruction)[source]

Parse instruction in asm line.

Parameters:instruction (str) – Assembly line string.
Returns:dict – parsed instruction form
process_operand(operand)[source]

Post-process operand

process_memory_address(memory_address)[source]

Post-process memory address operand

process_sp_register(register)[source]

Post-process stack pointer register

resolve_range_list(operand)[source]

Resolve range or list register operand to list of registers. Returns None if neither list nor range

process_register_list(register_list)[source]

Post-process register lists (e.g., {r0,r3,r5}) and register ranges (e.g., {r0-r7})

process_immediate(immediate)[source]

Post-process immediate operand

process_label(label)[source]

Post-process label asm line

process_identifier(identifier)[source]

Post-process identifier operand

get_full_reg_name(register)[source]

Return one register name string including all attributes

normalize_imd(imd)[source]

Normalize immediate to decimal based representation

ieee_to_float(ieee_val)[source]

Convert IEEE representation to python float

parse_register(register_string)[source]
is_gpr(register)[source]

Check if register is a general purpose register

is_vector_register(register)[source]

Check if register is a vector register

is_flag_dependend_of(flag_a, flag_b)[source]

Check if flag_a is dependent on flag_b

is_reg_dependend_of(reg_a, reg_b)[source]

Check if reg_a is dependent on reg_b

get_reg_type(register)[source]

Get register type