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:
Operand
Condition, 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:
Operand
A Data Location is either a register, a temporary or a place in memory (offset).
- class Lib.Operands.Register(number: int)[source]
Bases:
DataLocation
A (physical) register.
- Lib.Operands.ZERO = zero
Zero register
- Lib.Operands.RA = ra
- Lib.Operands.SP = sp
- Lib.Operands.GP
Register not used for this course
- Lib.Operands.TP
Register not used for this course
- Lib.Operands.A = (a0, a1, a2, a3, a4, a5, a6, a7)
- Lib.Operands.S = (fp, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11)
- Lib.Operands.T = (t0, t1, t2, t3, t4, t5, t6)
- Lib.Operands.A0 = a0
- Lib.Operands.A1 = a1
- Lib.Operands.FP = fp
Frame Pointer = Saved register 0
- Lib.Operands.GP_REGS = (s4, s5, s6, s7, s8, s9, s10, s11, t0, t1, t2, t3, t4, t5, t6)
General purpose registers, usable for the allocator
- class Lib.Operands.Offset(basereg: Register, offset: int)[source]
Bases:
DataLocation
Offset = address in memory computed with base + offset.
- class Lib.Operands.Immediate(val)[source]
Bases:
DataLocation
Immediate operand (integer).
- class Lib.Operands.Temporary(number: int, pool: TemporaryPool)[source]
Bases:
DataLocation
Temporary, 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:
object
Manage 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.