Functions for adding instructions to a program.
More...
|
t_instruction * | genADD (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSUB (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genAND (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genOR (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genXOR (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genMUL (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genDIV (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genREM (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSLL (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSRL (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSRA (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
|
t_instruction * | genADDI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSUBI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genANDI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genORI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genXORI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genMULI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genDIVI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genREMI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSLLI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSRLI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSRAI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
|
t_instruction * | genSEQ (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSNE (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSLT (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSLTU (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSGE (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSGEU (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSGT (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSGTU (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSLE (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
t_instruction * | genSLEU (t_program *program, t_regID rd, t_regID rs1, t_regID rs2) |
|
|
t_instruction * | genSEQI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSNEI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSLTI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSLTIU (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSGEI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSGEIU (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSGTI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSGTIU (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSLEI (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
t_instruction * | genSLEIU (t_program *program, t_regID rd, t_regID rs1, int immediate) |
|
|
t_instruction * | genJ (t_program *program, t_label *label) |
|
t_instruction * | genBEQ (t_program *program, t_regID rs1, t_regID rs2, t_label *label) |
|
t_instruction * | genBNE (t_program *program, t_regID rs1, t_regID rs2, t_label *label) |
|
t_instruction * | genBLT (t_program *program, t_regID rs1, t_regID rs2, t_label *label) |
|
t_instruction * | genBLTU (t_program *program, t_regID rs1, t_regID rs2, t_label *label) |
|
t_instruction * | genBGE (t_program *program, t_regID rs1, t_regID rs2, t_label *label) |
|
t_instruction * | genBGEU (t_program *program, t_regID rs1, t_regID rs2, t_label *label) |
|
t_instruction * | genBGT (t_program *program, t_regID rs1, t_regID rs2, t_label *label) |
|
t_instruction * | genBGTU (t_program *program, t_regID rs1, t_regID rs2, t_label *label) |
|
t_instruction * | genBLE (t_program *program, t_regID rs1, t_regID rs2, t_label *label) |
|
t_instruction * | genBLEU (t_program *program, t_regID rs1, t_regID rs2, t_label *label) |
|
|
t_instruction * | genLI (t_program *program, t_regID rd, int immediate) |
|
t_instruction * | genLA (t_program *program, t_regID rd, t_label *label) |
|
t_instruction * | genLW (t_program *program, t_regID rd, int immediate, t_regID rs1) |
|
t_instruction * | genSW (t_program *program, t_regID rs2, int immediate, t_regID rs1) |
|
t_instruction * | genLWGlobal (t_program *program, t_regID rd, t_label *label) |
|
t_instruction * | genSWGlobal (t_program *program, t_regID rs1, t_label *label, t_regID rtemp) |
|
|
t_regID | genLoadVariable (t_program *program, t_symbol *var) |
|
void | genStoreRegisterToVariable (t_program *program, t_symbol *var, t_regID reg) |
|
void | genStoreConstantToVariable (t_program *program, t_symbol *var, int val) |
|
t_regID | genLoadArrayElement (t_program *program, t_symbol *array, t_regID rIdx) |
|
void | genStoreRegisterToArrayElement (t_program *program, t_symbol *array, t_regID rIdx, t_regID rVal) |
|
void | genStoreConstantToArrayElement (t_program *program, t_symbol *array, t_regID rIdx, int val) |
|
Functions for adding instructions to a program.
In ACSE, the semantic actions in the parser directly translate the source code into intermediate assembly by appending new instructions inside the 'program' structure. The functions defined here are helpers that add a specific instruction code with given parameters to the end of the program.
◆ genADD()
Add a new ADD instruction at the end of the instruction list of the specified program. At runtime, an ADD instruction sums the values in the two source registers, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register (first addend). |
rs2 | Identifier of the second source register (second addend). |
- Returns
- the instruction object added to the instruction list.
◆ genADDI()
Add a new ADDI instruction at the end of the instruction list of the specified program. At runtime, an ADDI instruction sums the values in the source register with a constant, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register (first addend). |
immediate | The constant operand (second addend). |
- Returns
- the instruction object added to the instruction list.
◆ genAND()
Add a new AND instruction at the end of the instruction list of the specified program. At runtime, an AND instruction computes the bitwise AND (&) of the values in the source registers, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genANDI()
Add a new ANDI instruction at the end of the instruction list of the specified program. At runtime, an ANDI instruction computes the bitwise AND (&) of the value in the source register and a constant, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list
◆ genBEQ()
Add a new BEQ instruction at the end of the instruction list of the specified program. At runtime, a BEQ instruction branches to the given label if and only if the two source registers are equal.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genBGE()
Add a new BGE instruction at the end of the instruction list of the specified program. At runtime, a BGE instruction branches to the given label if and only if the value in the first source register is greater or equal than the value in the second source register (src1 >= src2). The source registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genBGEU()
Add a new BGEU instruction at the end of the instruction list of the specified program. At runtime, a BGEU instruction branches to the given label if and only if the value in the first source register is greater or equal than the value in the second source register (src1 >= src2). The source registers are assumed to contain unsigned integers.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genBGT()
Add a new BGT instruction at the end of the instruction list of the specified program. At runtime, a BGT instruction branches to the given label if and only if the value in the first source register is greater than the value in the second source register (src1 > src2). The source registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genBGTU()
Add a new BGTU instruction at the end of the instruction list of the specified program. At runtime, a BGTU instruction branches to the given label if and only if the value in the first source register is greater than the value in the second source register (src1 > src2). The source registers are assumed to contain unsigned integers.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genBLE()
Add a new BLE instruction at the end of the instruction list of the specified program. At runtime, a BLE instruction branches to the given label if and only if the value in the first source register is lesser or equal than the value in the second source register (src1 <= src2). The source registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genBLEU()
Add a new BLE instruction at the end of the instruction list of the specified program. At runtime, a BLE instruction branches to the given label if and only if the value in the first source register is lesser or equal than the value in the second source register (src1 <= src2). The source registers are assumed to contain unsigned integers.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genBLT()
Add a new BLT instruction at the end of the instruction list of the specified program. At runtime, a BLT instruction branches to the given label if and only if the value in the first source register is less than the value in the second source register (src1 < src2). The source registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genBLTU()
Add a new BLTU instruction at the end of the instruction list of the specified program. At runtime, a BLTU instruction branches to the given label if and only if the value in the first source register is less than the value in the second source register (src1 < src2). The source registers are assumed to contain unsigned integers.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genBNE()
Add a new BNE instruction at the end of the instruction list of the specified program. At runtime, a BNE instruction branches to the given label if and only if the two source registers are not equal.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genDIV()
Add a new DIV instruction at the end of the instruction list of the specified program. At runtime, a DIV instruction divides the value in the first source register with the value in the second source register, and places the result in the destination register. All the registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register (dividend). |
rs2 | Identifier of the second source register (divisor). |
- Returns
- the instruction object added to the instruction list.
◆ genDIVI()
Add a new DIVI instruction at the end of the instruction list of the specified program. At runtime, a DIVI instruction divides the value in the first source register with a signed integer constant, and places the result in the destination register. The source register is assumed to contain a signed integer.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register (dividend). |
immediate | The constant operand (divisor). |
- Returns
- the instruction object added to the instruction list.
◆ genEBREAK()
t_instruction * genEBREAK |
( |
t_program * | program | ) |
|
Add a new EBREAK instruction at the end of the instruction list of the specified program. At runtime, a EBREAK instruction temporarily stops program execution for debugging purposes.
- Parameters
-
program | The program where the instruction will be added |
- Returns
- the instruction object added to the instruction list
- Note
- This function is only used internally by the target-specific transformation pass, it is not useful outside of that context.
◆ genECALL()
t_instruction * genECALL |
( |
t_program * | program | ) |
|
Add a new ECALL instruction at the end of the instruction list of the specified program. At runtime, a ECALL instruction temporarily transfers program control to a supervisor or operating system.
- Parameters
-
program | The program where the instruction will be added |
- Returns
- the instruction object added to the instruction list
- Note
- This function is only used internally by the target-specific transformation pass, it is not useful outside of that context.
◆ genExit0Syscall()
t_instruction * genExit0Syscall |
( |
t_program * | program | ) |
|
Add a new Exit0 syscall instruction at the end of the instruction list of the specified program. At runtime, this instruction terminates the program with an exit code of zero.
- Parameters
-
program | The program where the instruction will be added. |
- Returns
- the instruction object added to the instruction list.
- Note
- During the target-specific transformation passes, ACSE replaces syscall instructions with a sequence of lower-level instructions that use ECALL to transfer control to the supervisor/operating system.
◆ genJ()
t_instruction * genJ |
( |
t_program * | program, |
|
|
t_label * | label ) |
Add a new J instruction at the end of the instruction list of the specified program. At runtime, a J instruction unconditionally transfers the control flow to the instruction identified by a given label (in brief, jumps or branches to the label).
- Parameters
-
program | The program where the instruction will be added. |
label | The label where to jump at runtime. |
- Returns
- the instruction object added to the instruction list.
◆ genLA()
Add a new LA instruction at the end of the instruction list of the specified program. At runtime, a LA instruction loads the address specified by a label into the destination register
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
label | The label whose address needs to be loaded. |
- Returns
- the instruction object added to the instruction list.
◆ genLI()
Add a new LI instruction at the end of the instruction list of the specified program. At runtime, a LI instruction loads a specified constant in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
immediate | The constant to load. |
- Returns
- the instruction object added to the instruction list.
◆ genLoadArrayElement()
Generate instructions that load the content of an array element into a register.
- Parameters
-
program | The program where the array belongs. |
array | The symbol object that refers to the array. |
rIdx | The identifier of the register that will contain the index into the array. |
- Returns
- The identifier of the register that (at runtime) will contain the value of the array element loaded from memory.
◆ genLoadVariable()
Generate instructions that load the content of a scalar variable into a register.
- Parameters
-
program | The program where the variable belongs. |
var | The symbol object that refers to the variable. |
- Returns
- The identifier of the register that (at runtime) will contain the value of the variable loaded from memory.
◆ genLW()
Add a new LW instruction at the end of the instruction list of the specified program. At runtime, a LW instruction loads a 32-bit word stored in memory at the address specified by the source register plus an offset given by a constant (thus the address is rs1 + immediate). The loaded value is put into the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
immediate | The constant operand (address offset). |
rs1 | Identifier of the source register (base address). |
- Returns
- the instruction object added to the instruction list.
◆ genLWGlobal()
t_instruction * genLWGlobal |
( |
t_program * | program, |
|
|
t_regID | rd, |
|
|
t_label * | label ) |
Add a new "global LW" instruction at the end of the instruction list of the specified program. At runtime, a "global LW" instruction loads a 32-bit word at the address specified by a label to the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
label | The label (points to a 32-bit word). |
- Returns
- the instruction object added to the instruction list.
◆ genMUL()
Add a new MUL instruction at the end of the instruction list of the specified program. At runtime, a MUL instruction multiplies the values in the source registers, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register (first factor). |
rs2 | Identifier of the second source register (second factor). |
- Returns
- the instruction object added to the instruction list.
◆ genMULI()
Add a new MULI instruction at the end of the instruction list of the specified program. At runtime, a MULI instruction multiplies the value in the source register with a constant, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register (first factor). |
immediate | The constant operand (second factor). |
- Returns
- the instruction object added to the instruction list.
◆ genNOP()
t_instruction * genNOP |
( |
t_program * | program | ) |
|
Add a new NOP instruction at the end of the instruction list of the specified program. At runtime, a NOP instruction doesn't do anything (apart from incrementing the program counter like any other instruction).
- Parameters
-
program | The program where the instruction will be added |
- Returns
- the instruction object added to the instruction list
◆ genOR()
Add a new OR instruction at the end of the instruction list of the specified program. At runtime, an OR instruction computes the bitwise OR (|) of the values in the source registers, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genORI()
Add a new ORI instruction at the end of the instruction list of the specified program. At runtime, an ORI instruction computes the bitwise OR (|) of the value in the source register and a constant, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list
◆ genPrintCharSyscall()
Add a new PrintChar syscall instruction at the end of the instruction list of the specified program. At runtime, this instruction writes a character whose ASCII encoding is stored in the source register to the standard output stream.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the source register (ASCII character to print). |
- Returns
- the instruction object added to the instruction list.
- Note
- During the target-specific transformation passes, ACSE replaces syscall instructions with a sequence of lower-level instructions that use ECALL to transfer control to the supervisor/operating system.
◆ genPrintIntSyscall()
Add a new PrintInt syscall instruction at the end of the instruction list of the specified program. At runtime, this instruction writes the integer currently stored in the source register to the standard output stream.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the source register (integer to print). |
- Returns
- the instruction object added to the instruction list.
- Note
- During the target-specific transformation passes, ACSE replaces syscall instructions with a sequence of lower-level instructions that use ECALL to transfer control to the supervisor/operating system.
◆ genReadIntSyscall()
Add a new ReadInt syscall instruction at the end of the instruction list of the specified program. At runtime, this instruction reads an integer from standard input, storing that integer in the given destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
- Returns
- the instruction object added to the instruction list.
- Note
- During the target-specific transformation passes, ACSE replaces syscall instructions with a sequence of lower-level instructions that use ECALL to transfer control to the supervisor/operating system.
◆ genREM()
Add a new REM instruction at the end of the instruction list of the specified program. At runtime, a REM instruction places the remainder of the division between the first and second source registers in the destination register. All the registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register (dividend). |
rs2 | Identifier of the second source register (divisor). |
- Returns
- the instruction object added to the instruction list.
◆ genREMI()
Add a new REMI instruction at the end of the instruction list of the specified program. At runtime, a REM instruction places the remainder of the division between the first source register and an immediate in the destination register. All the registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register (dividend). |
immediate | The constant operand (divisor). |
- Returns
- the instruction object added to the instruction list.
◆ genSEQ()
Add a new SEQ instruction at the end of the instruction list of the specified program. At runtime, a SEQ instruction sets the destination register to 1 if the values in the source registers are equal (src1 == src2). Otherwise, the destination register is set to zero.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genSEQI()
Add a new SEQI instruction at the end of the instruction list of the specified program. At runtime, an SEQI instruction sets the destination register to 1 if the value in the source register is equal to a constant (src1 == immediate). Otherwise, the destination register is set to zero.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list.
◆ genSGE()
Add a new SGE instruction at the end of the instruction list of the specified program. At runtime, a SGE instruction sets the destination register to 1 if the value in the first source register is greater or equal than the value in the second source register (src1 >= src2). Otherwise, the destination register is set to zero. The source registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genSGEI()
Add a new SGEI instruction at the end of the instruction list of the specified program. At runtime, an SGEI instruction sets the destination register to 1 if the value in the source register is greater or equal than a constant (src1 >= immediate). Otherwise, the destination register is set to zero. The source register and the constant are assumed to be signed.
- Parameters
-
program | The program where the instruction will be added |
rd | Identifier of the destination register |
rs1 | Identifier of the source register |
immediate | The constant operand |
- Returns
- the instruction object added to the instruction list
◆ genSGEIU()
Add a new SGEIU instruction at the end of the instruction list of the specified program. At runtime, an SGEIU instruction sets the destination register to 1 if the value in the source register is greater or equal than a constant (src1 >= immediate). Otherwise, the destination register is set to zero. The source register and the constant are assumed to be unsigned.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list.
◆ genSGEU()
Add a new SGEU instruction at the end of the instruction list of the specified program. At runtime, a SGEU instruction sets the destination register to 1 if the value in the first source register is greater or equal than the value in the second source register (src1 >= src2). Otherwise, the destination register is set to zero. The source registers are assumed to contain unsigned integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genSGT()
Add a new SGT instruction at the end of the instruction list of the specified program. At runtime, a SGT instruction sets the destination register to 1 if the value in the first source register is greater than the value in the second source register (src1 > src2). Otherwise, the destination register is set to zero. The source registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genSGTI()
Add a new SGTI instruction at the end of the instruction list of the specified program. At runtime, an SGTI instruction sets the destination register to 1 if the value in the source register is greater than a constant (src1 > immediate). Otherwise, the destination register is set to zero. The source register and the constant are assumed to be signed.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list.
◆ genSGTIU()
Add a new SGTIU instruction at the end of the instruction list of the specified program. At runtime, an SGTIU instruction sets the destination register to 1 if the value in the source register is greater than a constant (src1 >= immediate). Otherwise, the destination register is set to zero. The source register and the constant are assumed to be unsigned.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list.
◆ genSGTU()
Add a new SGTU instruction at the end of the instruction list of the specified program. At runtime, a SGTU instruction sets the destination register to 1 if the value in the first source register is greater than the value in the second source register (src1 > src2). Otherwise, the destination register is set to zero. The source registers are assumed to contain unsigned integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genSLE()
Add a new SLE instruction at the end of the instruction list of the specified program. At runtime, a SLE instruction sets the destination register to 1 if the value in the first source register is lesser or equal than the value in the second source register (src1 <= src2). Otherwise, the destination register is set to zero. The source registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genSLEI()
Add a new SLEI instruction at the end of the instruction list of the specified program. At runtime, an SLEI instruction sets the destination register to 1 if the value in the source register is lesser or equal than a constant (src1 <= immediate). Otherwise, the destination register is set to zero. The source register and the constant are assumed to be signed.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list.
◆ genSLEIU()
Add a new SLEIU instruction at the end of the instruction list of the specified program. At runtime, an SLEIU instruction sets the destination register to 1 if the value in the source register is lesser or equal than a constant (src1 <= immediate). Otherwise, the destination register is set to zero. The source register and the constant are assumed to be unsigned.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list.
◆ genSLEU()
Add a new SLEU instruction at the end of the instruction list of the specified program. At runtime, a SLEU instruction sets the destination register to 1 if the value in the first source register is lesser or equal than the value in the second source register (src1 <= src2). Otherwise, the destination register is set to zero. The source registers are assumed to contain unsigned integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genSLL()
Add a new SLL instruction at the end of the instruction list of the specified program. At runtime, a SLL instruction shifts the binary value in the first source register to the left by the number of places specified by the value of the second source register. The shift amount is modulo 32; in other words, only the 5 least significant bits of the second source register are considered.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register (value to shift). |
rs2 | Identifier of the second source register (shift amount). |
- Returns
- the instruction object added to the instruction list.
◆ genSLLI()
Add a new SLLI instruction at the end of the instruction list of the specified program. At runtime, a SLLI instruction shifts the binary value in the source register to the left by the number of places specified by a constant amount. The shift amount is modulo 32; in other words, only the 5 least significant bits of the constant are considered.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register (value to shift). |
immediate | The constant operand (shift amount). |
- Returns
- the instruction object added to the instruction list.
◆ genSLT()
Add a new SLT instruction at the end of the instruction list of the specified program. At runtime, a SLT instruction sets the destination register to 1 if the value in the first source register is less than the value in the second source register (src1 < src2). Otherwise, the destination register is set to zero. The source registers are assumed to contain signed integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genSLTI()
Add a new SLTI instruction at the end of the instruction list of the specified program. At runtime, an SLTI instruction sets the destination register to 1 if the value in the source register is less than a constant (src1 < immediate). Otherwise, the destination register is set to zero. The source register and the constant are assumed to be signed.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list.
◆ genSLTIU()
Add a new SLTIU instruction at the end of the instruction list of the specified program. At runtime, an SLTIU instruction sets the destination register to 1 if the value in the source register is less than a constant (src1 < immediate). Otherwise, the destination register is set to zero. The source register and the constant are assumed to be unsigned.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list.
◆ genSLTU()
Add a new SLTU instruction at the end of the instruction list of the specified program. At runtime, a SLTU instruction sets the destination register to 1 if the value in the first source register is less than the value in the second source register (src1 < src2). Otherwise, the destination register is set to zero. The source registers are assumed to contain unsigned integers.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genSNE()
Add a new SNE instruction at the end of the instruction list of the specified program. At runtime, a SNE instruction sets the destination register to 1 if the values in the source registers are different (src1 != src2). Otherwise, the destination register is set to zero.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genSNEI()
Add a new SNEI instruction at the end of the instruction list of the specified program. At runtime, an SNEI instruction sets the destination register to 1 if the value in the source register is different from a constant (src1 != immediate). Otherwise, the destination register is set to zero.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list.
◆ genSRA()
Add a new SRA instruction at the end of the instruction list of the specified program. At runtime, a SRA instruction shifts the binary value in the first source register to the right by the number of places specified by the value of the second source register. The shift amount is modulo 32; in other words, only the 5 least significant bits of the second source register are considered. Additionally, the first source register is assumed to contain a signed integer.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register (value to shift). |
rs2 | Identifier of the second source register (shift amount). |
- Returns
- the instruction object added to the instruction list.
◆ genSRAI()
Add a new SRAI instruction at the end of the instruction list of the specified program. At runtime, a SRAI instruction shifts the binary value in the source register to the right by the number of places specified by a constant amount. The shift amount is modulo 32; in other words, only the 5 least significant bits of the constant are considered. Additionally, the source register is assumed to contain a signed integer.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register (value to shift). |
immediate | The constant operand (shift amount). |
- Returns
- the instruction object added to the instruction list.
◆ genSRL()
Add a new SRL instruction at the end of the instruction list of the specified program. At runtime, a SRL instruction shifts the binary value in the first source register to the right by the number of places specified by the value of the second source register. The shift amount is modulo 32; in other words, only the 5 least significant bits of the second source register are considered. Additionally, the first source register is assumed to contain an unsigned integer.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register (value to shift). |
rs2 | Identifier of the second source register (shift amount). |
- Returns
- the instruction object added to the instruction list.
◆ genSRLI()
Add a new SRLI instruction at the end of the instruction list of the specified program. At runtime, a SRLI instruction shifts the binary value in the source register to the right by the number of places specified by a constant amount. The shift amount is modulo 32; in other words, only the 5 least significant bits of the constant are considered. Additionally, the source register is assumed to contain an unsigned integer.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register (value to shift). |
immediate | The constant operand (shift amount). |
- Returns
- the instruction object added to the instruction list.
◆ genStoreConstantToArrayElement()
Generate instructions that store the content of a register into an array element.
- Parameters
-
program | The program where the array belongs. |
array | The symbol object that refers to the array. |
rIdx | The identifier of the register that will contain the index into the array. |
val | The value to be stored. |
◆ genStoreConstantToVariable()
Generate instructions that store a constant into a variable.
- Parameters
-
program | The program where the variable belongs. |
var | The symbol object that refers to the variable. |
val | The constant value which needs to be assigned. |
◆ genStoreRegisterToArrayElement()
Generate instructions that store the content of a register into an array element.
- Parameters
-
program | The program where the array belongs. |
array | The symbol object that refers to the array. |
rIdx | The identifier of the register that will contain the index into the array. |
rVal | The identifier of the register that will contain the value to be stored. |
◆ genStoreRegisterToVariable()
Generate instructions that store the content of a register into a variable.
- Parameters
-
program | The program where the variable belongs. |
var | The symbol object that refers to the variable. |
reg | The register whose value needs to be assigned. |
◆ genSUB()
Add a new SUB instruction at the end of the instruction list of the specified program. At runtime, a SUB instruction subtracts the value in the second source register from the value in the first source register, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register (minuend). |
rs2 | Identifier of the second source register (subtrahend). |
- Returns
- the instruction object added to the instruction list.
◆ genSUBI()
Add a new SUBI instruction at the end of the instruction list of the specified program. At runtime, a SUBI instruction subtracts a constant from the value in the source register, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register (minuend). |
immediate | The constant operand (subtrahend). |
- Returns
- the instruction object added to the instruction list.
◆ genSW()
Add a new LW instruction at the end of the instruction list of the specified program. At runtime, a LW instruction stores the 32-bit word contained in the second source register to memory. The destination address is specified by the first source register, plus an offset given by a constant (thus the address is rs1 + immediate).
- Parameters
-
program | The program where the instruction will be added. |
rs2 | Identifier of the second source register (value to store). |
immediate | The constant operand (address offset). |
rs1 | Identifier of the first source register (base address). |
- Returns
- the instruction object added to the instruction list.
- Note
- The order of the registers in the function signature is inverted with respect to the actual encoding, just like in the assembly listing format as described by the RISC-V specification.
◆ genSWGlobal()
Add a new "global SW" instruction at the end of the instruction list of the specified program. At runtime, a "global SW" instruction stores the 32-bit word contained in the first source register to the address specified by a label.
- Parameters
-
program | The program where the instruction will be added. |
rs1 | Identifier of the source register (value to store). |
label | The label (points to a 32-bit word). |
rtemp | Identifier of an otherwise unused register whose value will be modified by the instruction during its operation. |
- Returns
- the instruction object added to the instruction list.
- Note
- At assembly time, the "global SW" instruction translates to a sequence of multiple instructions which use rtemp to store the address of the label. This is the reason why rtemp is needed.
◆ genXOR()
Add a new XOR instruction at the end of the instruction list of the specified program. At runtime, a XOR instruction computes the bitwise XOR (^) of the values in the source registers, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the first source register. |
rs2 | Identifier of the second source register. |
- Returns
- the instruction object added to the instruction list.
◆ genXORI()
Add a new XORI instruction at the end of the instruction list of the specified program. At runtime, a XORI instruction computes the bitwise XOR (^) of the value in the source register and a constant, and places the result in the destination register.
- Parameters
-
program | The program where the instruction will be added. |
rd | Identifier of the destination register. |
rs1 | Identifier of the source register. |
immediate | The constant operand. |
- Returns
- the instruction object added to the instruction list.