Lib.Allocator module
This file defines the base class Allocator
and the naïve implementation NaiveAllocator
.
- class Lib.Allocator.Allocator(fdata: FunctionData)[source]
Bases:
object
General base class for Naive, AllInMem and Smart Allocators. Replace all temporaries in the code with actual data locations.
Allocation is done in two steps:
First,
prepare()
is responsible for callingLib.Operands.TemporaryPool.set_temp_allocation()
with a mapping from temporaries to where they should actually be stored (in registers or in memory).Then,
replace()
is called for each instruction in order to replace the temporary operands with the previously assigned locations (and possibly add some instructions before or after). Concretely, it returns a list of instructions that should replace the original instruction. The actual iteration over all the instructions is handled transparently byLib.LinearCode.LinearCode.iter_statements()
.
- replace(old_instr: Instruction) List[Instruction] [source]
Transform an instruction with temporaries into a list of instructions.
- class Lib.Allocator.NaiveAllocator(fdata: FunctionData)[source]
Bases:
Allocator
Naive Allocator: try to assign a register to each temporary, fails if there are more temporaries than registers.
- replace(old_instr: Instruction) List[Instruction] [source]
Replace Temporary operands with the corresponding allocated Register.