Lib.Operands module
This file defines the base class Operand
and its subclasses for different operands: Condition,
DataLocation and Function.
The class DataLocation itself has subclasses:
Register, Offset for address in memory,
Immediate for constants and Temporary
for location not yet allocated.
This file also define shortcuts for registers in RISCV.
- class Lib.Operands.Condition(optype)[source]
Bases:
OperandCondition, i.e. comparison operand for a CondJump.
Example usage :
Condition(‘beq’) = branch if equal.
Condition(MiniCParser.LT) = branch if lower than.
…
The constructor’s argument shall be a string in the list all_ops, or a comparison operator in MiniCParser.LT, MiniCParser.GT, … (one of the keys in opdict).
A ‘negate’ method allows getting the negation of this condition.
- class Lib.Operands.DataLocation[source]
Bases:
OperandA Data Location is either a register, a temporary or a place in memory (offset).
- class Lib.Operands.Immediate(val)[source]
Bases:
DataLocationImmediate operand (integer).
- class Lib.Operands.Offset(basereg: Register, offset: int)[source]
Bases:
DataLocationOffset = address in memory computed with base + offset.
- class Lib.Operands.Register(number: int)[source]
Bases:
DataLocationA (physical) register.
- class Lib.Operands.Renamer(pool: TemporaryPool)[source]
Bases:
objectManage a renaming of temporaries.
- class Lib.Operands.Temporary(number: int, pool: TemporaryPool)[source]
Bases:
DataLocationTemporary, a location that has not been allocated yet. It will later be mapped to a physical register (Register) or to a memory location (Offset).
- get_alloced_loc() DataLocation[source]
Return the DataLocation allocated to this Temporary.
- class Lib.Operands.TemporaryPool[source]
Bases:
objectManage a pool of temporaries.
- get_alloced_loc(t: Temporary) DataLocation[source]
Get the actual DataLocation allocated for the temporary t.
- set_temp_allocation(allocation: Dict[Temporary, DataLocation]) None[source]
Give a mapping from temporaries to actual registers. The argument allocation must be a dict from Temporary to DataLocation other than Temporary (typically Register or Offset). Typing enforces that keys are Temporary and values are Datalocation. We check the values are indeed not Temporary.