asm_analyser package
Subpackages
- asm_analyser.architectures package
- Subpackages
- asm_analyser.architectures.arm package
- Submodules
- asm_analyser.architectures.arm.arm_util module
- asm_analyser.architectures.arm.auxiliary_functions module
- asm_analyser.architectures.arm.branch_pred module
- asm_analyser.architectures.arm.counter module
- asm_analyser.architectures.arm.instr_translator module
- asm_analyser.architectures.arm.parser module
- asm_analyser.architectures.arm.processor module
- asm_analyser.architectures.arm.translator module
- Module contents
- asm_analyser.architectures.arm package
- Module contents
- Subpackages
- asm_analyser.blocks package
Submodules
asm_analyser.branch_pred module
Provides the basis for a branch prediction simulation.
- class asm_analyser.branch_pred.BranchPredictor(c_code)[source]
Bases:
abc.ABCResponsible for branch prediction simulation.
- abstract insert_branch_pred(method_name: str) str[source]
Inserts the everything necessary for the desired branch prediction strategy.
- Parameters
c_code (str) – The C code containing placeholders for the branch predictions.
method_name (str) – Name of the branch prediction strategy that should be used.
- Returns
C code containing all necessary elements to simulate branch predictions.
- Return type
str
- abstract 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
- abstract 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.counter module
Provides the basis for instruction counting.
- class asm_analyser.counter.Counter[source]
Bases:
abc.ABCResponsible for counting the instructions.
- abstract 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
- abstract 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
- abstract 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]
- abstract 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.main module
asm_analyser.parser module
Provides the basis for a Parser.
- class asm_analyser.parser.Parser(filepath: str)[source]
Bases:
abc.ABCConverts the input into a suitable format.
Parser class, responsible for reading the assembler input file. Transforms the lines into code blocks.
- abstract 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.processor module
Provides the basis for processing code blocks further.
- class asm_analyser.processor.Processor[source]
Bases:
abc.ABCProcesses the instructions.
- abstract 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.
- abstract 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.testing module
asm_analyser.translator module
Provides the basis for the translation of an assembly file.
- class asm_analyser.translator.Translator(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:
abc.ABCTranslates all the assembly instructions to C.
asm_analyser.util module
Provides some utility functions.
- asm_analyser.util.cleanup(filepath: str) None[source]
Cleans the compiled files for the current program. That way we can assure new files are generated.
- Parameters
filepath (str) – Path of the input file without the file ending.
- asm_analyser.util.compile_asm(filepath: str, optimization: str) None[source]
Compiles the selected C file to assembler.
- Parameters
filepath (str) – Path of the input C file.
optimization (str) – Specifies the optimization level that should be used.
- asm_analyser.util.format_c(out_path: str) None[source]
Formats the given C file using astyle for better readability.
- Parameters
out_path (str) – Name of the file to be formatted.
- asm_analyser.util.parse_output(out_path: str, bp: bool) Tuple[List[int], List[int], str][source]
Parses and processes the output from the C-file.
Any important information that is used in other features (e.g. branch prediction) will be returned in this function.
- Parameters
out_path (str) – Path of the output C file.
bp (bool) – Determines whether the branch prediction is activated.
- Returns
list[int] – Number of executions of each basic block.
list[int] – Branch prediction success rate of each branch instruction.
str – Outputs that will be logged to the console.