microprobe.code.bbl.Bbl

class Bbl(size: int, instructions: List[Instruction] = [])[source]

Bases: object

Class to represent a basic block.

__init__(size: int, instructions: List[Instruction] = [])[source]
Parameters:

size

Methods

__init__(size[, instructions])

param size:

distance(instr1, instr2)

get_instruction_by_distance(instr, distance)

get_instruction_index(instr)

Returns the index of the given instruction within the basic block.

insert_instr(instrs[, before, after])

Inserts a list of instruction in the basic block.

remove_instructions_from(instr)

Removes the given instruction from the basic block.

replicate([displacement])

Replicates current basic block.

reset_instruction(instr, new_instr)

Resets the instruction within a basic block by another instruction.

set_address(address)

Set the basic block address.

set_displacement(displacement)

Set the displacement of the basic block.

Attributes

address

Basic block address (Address)

displacement

Displacement of the basic block (:int)

instrs

List of instructions in the basic block (list of Instruction)

size

Size of the basic block, number of instructions (:int)




property instrs

List of instructions in the basic block (list of Instruction)

property address

Basic block address (Address)

set_address(address: Address)[source]

Set the basic block address.

Parameters:

address (Address) – Address for the basic block

property displacement

Displacement of the basic block (:int)

set_displacement(displacement: int | None)[source]

Set the displacement of the basic block.

Parameters:

displacement (int) – Displacement for the basic block

property size

Size of the basic block, number of instructions (:int)

get_instruction_index(instr: Instruction)[source]

Returns the index of the given instruction within the basic block.

Returns the index of the given instruction within the basic block. If the instruction is not found, return a negative number.

Parameters:

instr (Instruction) – Instruction instance

reset_instruction(instr: Instruction, new_instr: Instruction)[source]

Resets the instruction within a basic block by another instruction.

Resets the instruction within a basic block by another instruction. If the instruction is not found, an exception is raised.

Parameters:
Raises:

microprobe.exceptions.MicroprobeCodeGenerationError – if the instruction is not found in the basic block

remove_instructions_from(instr: Instruction)[source]

Removes the given instruction from the basic block.

Removes the given instruction from the basic block. If the instruction is not found, the basic block is not changed.

Parameters:

instr (Instruction) – Instruction to remove

insert_instr(instrs: List[Instruction], before: Instruction | None = None, after: Instruction | None = None)[source]

Inserts a list of instruction in the basic block.

Inserts a list of instruction in the basic block. Before/After parameters specify the instructions before/after which the new instruction should be added.

Parameters:
  • instrs (list of Instruction) – Instruction to insert

  • before (list of Instruction) – Instructions will be inserted before this instruction (Default value = None)

  • after (list of Instruction) – Instructions will be inserted after this instruction (Default value = None)

replicate(displacement: int | None = 0)[source]

Replicates current basic block.

Replicates current basic block with the given extra displacement.

Parameters:

displacement (int) – Extra displacement (Default value = 0)

distance(instr1: Instruction, instr2: Instruction)[source]
get_instruction_by_distance(instr: Instruction, distance: int)[source]