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.
Definition at line 47 of file codegen.c.
◆ 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.
Definition at line 103 of file codegen.c.
◆ 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.
Definition at line 57 of file codegen.c.
◆ 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
Definition at line 115 of file codegen.c.
◆ 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.
Definition at line 289 of file codegen.c.
◆ 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.
Definition at line 313 of file codegen.c.
◆ 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.
Definition at line 319 of file codegen.c.
◆ 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.
Definition at line 325 of file codegen.c.
◆ 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.
Definition at line 331 of file codegen.c.
◆ 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.
Definition at line 337 of file codegen.c.
◆ 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.
Definition at line 343 of file codegen.c.
◆ 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.
Definition at line 301 of file codegen.c.
◆ 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.
Definition at line 307 of file codegen.c.
◆ 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.
Definition at line 295 of file codegen.c.
◆ 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.
Definition at line 77 of file codegen.c.
◆ 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.
Definition at line 139 of file codegen.c.
◆ genEBREAK()
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.
Definition at line 407 of file codegen.c.
◆ genECALL()
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.
Definition at line 401 of file codegen.c.
◆ genExit0Syscall()
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.
Definition at line 414 of file codegen.c.
◆ genJ()
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.
Definition at line 282 of file codegen.c.
◆ 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.
Definition at line 357 of file codegen.c.
◆ 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.
Definition at line 350 of file codegen.c.
◆ 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.
Definition at line 527 of file codegen.c.
◆ 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.
Definition at line 442 of file codegen.c.
◆ 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.
Definition at line 364 of file codegen.c.
◆ genLWGlobal()
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.
Definition at line 380 of file codegen.c.
◆ 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.
Definition at line 72 of file codegen.c.
◆ 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.
Definition at line 121 of file codegen.c.
◆ genNOP()
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
Definition at line 395 of file codegen.c.
◆ 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.
Definition at line 62 of file codegen.c.
◆ 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
Definition at line 127 of file codegen.c.
◆ 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.
Definition at line 434 of file codegen.c.
◆ 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.
Definition at line 427 of file codegen.c.
◆ 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.
Definition at line 420 of file codegen.c.
◆ 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.
Definition at line 82 of file codegen.c.
◆ 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.
Definition at line 145 of file codegen.c.
◆ 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.
Definition at line 170 of file codegen.c.
◆ 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.
Definition at line 221 of file codegen.c.
◆ 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.
Definition at line 190 of file codegen.c.
◆ 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
Definition at line 245 of file codegen.c.
◆ 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.
Definition at line 251 of file codegen.c.
◆ 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.
Definition at line 195 of file codegen.c.
◆ 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.
Definition at line 200 of file codegen.c.
◆ 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.
Definition at line 257 of file codegen.c.
◆ 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.
Definition at line 263 of file codegen.c.
◆ 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.
Definition at line 205 of file codegen.c.
◆ 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.
Definition at line 210 of file codegen.c.
◆ 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.
Definition at line 269 of file codegen.c.
◆ 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.
Definition at line 275 of file codegen.c.
◆ 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.
Definition at line 215 of file codegen.c.
◆ 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.
Definition at line 87 of file codegen.c.
◆ 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.
Definition at line 151 of file codegen.c.
◆ 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.
Definition at line 180 of file codegen.c.
◆ 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.
Definition at line 233 of file codegen.c.
◆ 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.
Definition at line 239 of file codegen.c.
◆ 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.
Definition at line 185 of file codegen.c.
◆ 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.
Definition at line 175 of file codegen.c.
◆ 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.
Definition at line 227 of file codegen.c.
◆ 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.
Definition at line 97 of file codegen.c.
◆ 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.
Definition at line 163 of file codegen.c.
◆ 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.
Definition at line 92 of file codegen.c.
◆ 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.
Definition at line 157 of file codegen.c.
◆ 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. |
Definition at line 547 of file codegen.c.
◆ 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. |
Definition at line 478 of file codegen.c.
◆ 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. |
Definition at line 538 of file codegen.c.
◆ 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. |
Definition at line 461 of file codegen.c.
◆ 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.
Definition at line 52 of file codegen.c.
◆ 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.
Definition at line 109 of file codegen.c.
◆ 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.
Definition at line 371 of file codegen.c.
◆ 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.
Definition at line 387 of file codegen.c.
◆ 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.
Definition at line 67 of file codegen.c.
◆ 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.
Definition at line 133 of file codegen.c.