asm_analyser.architectures.arm package

Submodules

asm_analyser.architectures.arm.arm_util module

Provides some utility functions that are useful for the translation of ARM assembly to C.

asm_analyser.architectures.arm.arm_util.get_constant_defs(blocks: List[asm_analyser.blocks.code_block.CodeBlock], stack_size: int) str[source]

Fills the constants from “get_needed_consts”.

This is done by allocating memory with malloc in C and then saving the values to that memory. The pointer to that memory is stored in a global variable.

Parameters
  • blocks (list[CodeBlock]) – All the labeled code blocks with their instructions.

  • stack_size (int) – Size of the simulated stack in bytes

Returns

C code that defines the arm constants.

Return type

str

asm_analyser.architectures.arm.arm_util.get_function_decls(blocks: List[asm_analyser.blocks.code_block.CodeBlock]) str[source]

Creates the functions declarations in C for every arm function.

Returns

C code containing the function declarations.

Return type

str

asm_analyser.architectures.arm.arm_util.get_malloc_start(blocks: List[asm_analyser.blocks.code_block.CodeBlock], stack_size: int) str[source]

Fills the malloc_start method in the template.

Constants for the C-code are defined in this section and the necessary memory is allocated.

Parameters
  • blocks (list[CodeBlock]) – All the labeled code blocks with their instructions.

  • stack_size (int) – Size of the simulated stack in bytes

Returns

C-code containing the contents for the malloc_start function in the template.

Return type

str

asm_analyser.architectures.arm.arm_util.get_needed_consts(blocks: List[asm_analyser.blocks.code_block.CodeBlock]) str[source]

Creates the global variables needed for constants.

These constants variables are used to store pointers to memory containing the constants (e.g. array, string,…)

Parameters

blocks (list[CodeBlock]) – All the labeled code blocks with their instructions.

Returns

Variable declarations in C.

Return type

str

asm_analyser.architectures.arm.arm_util.get_needed_regs(blocks: List[asm_analyser.blocks.code_block.CodeBlock]) str[source]

Determines the global variables that need to be created as registers.

Parameters

blocks (list[CodeBlock]) – All the labeled code blocks with their instructions.

Returns

Variable declarations in C.

Return type

str

asm_analyser.architectures.arm.auxiliary_functions module

Provides the necessary auxiliary functions for the translation.

asm_analyser.architectures.arm.auxiliary_functions.get_auxiliary_functions(blocks: List[asm_analyser.blocks.code_block.CodeBlock]) str[source]

Determines the needed auxiliary functions for the translation.

Parameters

blocks (list[CodeBlock]) – The code blocks with all their instructions.

Returns

The C code containing all the necessary function definitions.

Return type

str

asm_analyser.architectures.arm.branch_pred module

Implements everything required (including different strategies) for branch prediction simulation with ARM assembly.

class asm_analyser.architectures.arm.branch_pred.ArmBranchPredictor(c_code)[source]

Bases: asm_analyser.branch_pred.BranchPredictor

Implements the BranchPredictor class for ARM assembly.

insert_branch_pred(method_name: str) str[source]

Calls the desired branch prediction method.

Parameters

method_name (str) – Name of the desired branch prediction method.

Returns

C-code containing the necessary instructions for the branch prediction simulation.

Return type

str

static is_branch_instr(opcode: str, *args) bool[source]

Checks whether the given instruction is a branch instruction.

Parameters
  • opcode (str) – Name of the instruction

  • args (tuple(str)) – Operands for the instruction

Returns

Determines whether the instructions is a branch instruction.

Return type

bool

one_bit() str[source]

Branch prediction using one bit (saturating counter).

Returns

C code containing all necessary elements for this branch predictor.

Return type

str

two_bit1() str[source]

Branch prediction using two bits (saturating counter).

Returns

C code containing all necessary elements for this branch predictor.

Return type

str

two_bit2() str[source]

Another Branch prediction using two bits (bimodal predictor).

Returns

C code containing all necessary elements for this branch predictor.

Return type

str

static write_rates(file_path: str, blocks: List[asm_analyser.blocks.code_block.CodeBlock], branch_rates: List[float], branch_map: Dict[int, int]) None[source]

Writes the number of executions next to each assembly instruction.

Parameters
  • file_path (str) – File path of the assembly file.

  • blocks (list[BasicBlock]) – The basic blocks with all their instructions.

  • branch_rates (list[float]) – Branch prediction success rate for each branch instruction.

  • branch_map (dict[int, int]) – Maps the instruction index to the branch index.

asm_analyser.architectures.arm.counter module

Implements the required methods for instruction counting using ARM assembly.

class asm_analyser.architectures.arm.counter.ArmCounter[source]

Bases: asm_analyser.counter.Counter

Implements the Counter class for ARM assembly.

static get_counter_defs(blocks: List[asm_analyser.blocks.basic_block.BasicBlock]) str[source]

Returns the C code to define the necessary variables for counting.

Parameters

blocks (list[BasicBlock]) – The basic blocks with all their instructions.

Returns

The C code containing the definitions for all the counter variables.

Return type

str

static get_counter_init(blocks: List[asm_analyser.blocks.basic_block.BasicBlock]) str[source]

Returns the C code to initalize the counter variables properly.

Parameters

blocks (list[BasicBlock]) – The basic blocks with all their instructions.

Returns

The C code containing the variable initializations.

Return type

str

static insert_counters(code_blocks: List[asm_analyser.blocks.code_block.CodeBlock], basic_blocks: List[asm_analyser.blocks.basic_block.BasicBlock]) List[asm_analyser.blocks.code_block.CodeBlock][source]

Inserts the counter variables.

Inserts the counter variables by adding instructions to the codeblocks which will be later translated to C.

Parameters
  • code_blocks (list[CodeBlock]) – The code blocks with all their instructions.

  • basic_blocks (list[BasicBlock]) – The basic blocks with all their instructions.

Returns

The code blocks which now contain the instructions for counting.

Return type

list[CodeBlock]

static write_instr_counts(file_path: str, blocks: List[asm_analyser.blocks.basic_block.BasicBlock], block_counts: List[int]) None[source]

Writes the number of executions next to each assembly instruction.

Parameters
  • file_path (str) – File path of the assembly file.

  • blocks (list[BasicBlock]) – The basic blocks with all their instructions.

  • block_counts (list[int]) – Number of times each basic block was executed.

asm_analyser.architectures.arm.instr_translator module

Responsible for translating the ARM instructions.

asm_analyser.architectures.arm.instr_translator.translate(code_blocks: List[asm_analyser.blocks.code_block.CodeBlock], opcode: str, *args) str[source]

Translates an arm instruction to C using a dictionary.

Parameters
  • code_blocks (list[CodeBlock]) – The code blocks containing all the instructions

  • opcode (str) – Name of the instruction

  • args (tuple(str)) – Operands for the instruction

Returns

The translated C code

Return type

str

asm_analyser.architectures.arm.parser module

Implements methods for parsing ARM assembly.

class asm_analyser.architectures.arm.parser.ArmParser(filepath: str)[source]

Bases: asm_analyser.parser.Parser

Implements the Parser class for ARM assembly.

create_blocks() List[asm_analyser.blocks.code_block.CodeBlock][source]

Splits the instructions into a list of code blocks.

Returns

List of code blocks with a name and a set of instructions for each block.

Return type

list[CodeBlock]

asm_analyser.architectures.arm.processor module

Provides methods for further processing of parsed ARM assembly.

class asm_analyser.architectures.arm.processor.ArmProcessor[source]

Bases: asm_analyser.processor.Processor

Implements the Processor Class for ARM assembly.

static create_ir(blocks: List[asm_analyser.blocks.code_block.CodeBlock]) List[asm_analyser.blocks.code_block.CodeBlock][source]

Creates a the indermediate representation of the instructions.

Parameters

blocks (list[CodeBlock]) – The code blocks with all their instructions.

Returns

List of code blocks with the instrucitons.

Return type

list[CodeBlock]

static get_basic_blocks(blocks: List[asm_analyser.blocks.code_block.CodeBlock]) List[asm_analyser.blocks.basic_block.BasicBlock][source]

Divides the code blocks into basic blocks by looking at branching.

Parameters

blocks (list[CodeBlock]) – The code blocks with all their instructions.

Returns

List of basic blocks for all the code blocks.

Return type

list[BasicBlock]

asm_analyser.architectures.arm.translator module

Provides methods for translating an ARM assembly file.

class asm_analyser.architectures.arm.translator.ArmTranslator(code_blocks: List[asm_analyser.blocks.code_block.CodeBlock], basic_blocks: List[asm_analyser.blocks.basic_block.BasicBlock], counter: asm_analyser.counter.Counter, stack_size: int)[source]

Bases: asm_analyser.translator.Translator

Implements the Translator class for ARM assembly.

translate() str[source]

Main translation, translates the whole asm file.

Returns

The complete translated C file.

Return type

str

Module contents