ACSE 2.0.2
Advanced Compiler System for Education (basic documentation)
Loading...
Searching...
No Matches
Code Generation Functions

Functions for adding instructions to a program. More...

Register-Register Arithmetic Instructions

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)
 

Register-Constant Arithmetic Instructions

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)
 

Register-Register Comparison Instructions

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)
 

Register-Constant Comparison Instructions

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)
 

Jump and Branch Instructions

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)
 

Memory Load/Store Instructions

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)
 

Variable/array accesses

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)
 

System Calls

t_instruction * genExit0Syscall (t_program *program)
 
t_instruction * genReadIntSyscall (t_program *program, t_regID rd)
 
t_instruction * genPrintIntSyscall (t_program *program, t_regID rs1)
 
t_instruction * genPrintCharSyscall (t_program *program, t_regID rs1)
 

Other Instructions

t_instruction * genNOP (t_program *program)
 
t_instruction * genECALL (t_program *program)
 
t_instruction * genEBREAK (t_program *program)
 

Detailed Description

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.

Function Documentation

◆ genADD()

t_instruction * genADD ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register (first addend).
rs2Identifier of the second source register (second addend).
Returns
the instruction object added to the instruction list.

◆ genADDI()

t_instruction * genADDI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register (first addend).
immediateThe constant operand (second addend).
Returns
the instruction object added to the instruction list.

◆ genAND()

t_instruction * genAND ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genANDI()

t_instruction * genANDI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list

◆ genBEQ()

t_instruction * genBEQ ( t_program * program,
t_regID rs1,
t_regID rs2,
t_label * label )

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
programThe program where the instruction will be added.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genBGE()

t_instruction * genBGE ( t_program * program,
t_regID rs1,
t_regID rs2,
t_label * label )

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
programThe program where the instruction will be added.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genBGEU()

t_instruction * genBGEU ( t_program * program,
t_regID rs1,
t_regID rs2,
t_label * label )

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
programThe program where the instruction will be added.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genBGT()

t_instruction * genBGT ( t_program * program,
t_regID rs1,
t_regID rs2,
t_label * label )

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
programThe program where the instruction will be added.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genBGTU()

t_instruction * genBGTU ( t_program * program,
t_regID rs1,
t_regID rs2,
t_label * label )

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
programThe program where the instruction will be added.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genBLE()

t_instruction * genBLE ( t_program * program,
t_regID rs1,
t_regID rs2,
t_label * label )

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
programThe program where the instruction will be added.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genBLEU()

t_instruction * genBLEU ( t_program * program,
t_regID rs1,
t_regID rs2,
t_label * label )

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
programThe program where the instruction will be added.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genBLT()

t_instruction * genBLT ( t_program * program,
t_regID rs1,
t_regID rs2,
t_label * label )

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
programThe program where the instruction will be added.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genBLTU()

t_instruction * genBLTU ( t_program * program,
t_regID rs1,
t_regID rs2,
t_label * label )

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
programThe program where the instruction will be added.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genBNE()

t_instruction * genBNE ( t_program * program,
t_regID rs1,
t_regID rs2,
t_label * label )

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
programThe program where the instruction will be added.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genDIV()

t_instruction * genDIV ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register (dividend).
rs2Identifier of the second source register (divisor).
Returns
the instruction object added to the instruction list.

◆ genDIVI()

t_instruction * genDIVI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register (dividend).
immediateThe 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
programThe 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
programThe 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
programThe 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
programThe program where the instruction will be added.
labelThe label where to jump at runtime.
Returns
the instruction object added to the instruction list.

◆ genLA()

t_instruction * genLA ( t_program * program,
t_regID rd,
t_label * label )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
labelThe label whose address needs to be loaded.
Returns
the instruction object added to the instruction list.

◆ genLI()

t_instruction * genLI ( t_program * program,
t_regID rd,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
immediateThe constant to load.
Returns
the instruction object added to the instruction list.

◆ genLoadArrayElement()

t_regID genLoadArrayElement ( t_program * program,
t_symbol * array,
t_regID rIdx )

Generate instructions that load the content of an array element into a register.

Parameters
programThe program where the array belongs.
arrayThe symbol object that refers to the array.
rIdxThe 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()

t_regID genLoadVariable ( t_program * program,
t_symbol * var )

Generate instructions that load the content of a scalar variable into a register.

Parameters
programThe program where the variable belongs.
varThe 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()

t_instruction * genLW ( t_program * program,
t_regID rd,
int immediate,
t_regID rs1 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
immediateThe constant operand (address offset).
rs1Identifier 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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
labelThe label (points to a 32-bit word).
Returns
the instruction object added to the instruction list.

◆ genMUL()

t_instruction * genMUL ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register (first factor).
rs2Identifier of the second source register (second factor).
Returns
the instruction object added to the instruction list.

◆ genMULI()

t_instruction * genMULI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register (first factor).
immediateThe 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
programThe program where the instruction will be added
Returns
the instruction object added to the instruction list

◆ genOR()

t_instruction * genOR ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genORI()

t_instruction * genORI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list

◆ genPrintCharSyscall()

t_instruction * genPrintCharSyscall ( t_program * program,
t_regID rs1 )

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
programThe program where the instruction will be added.
rs1Identifier 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()

t_instruction * genPrintIntSyscall ( t_program * program,
t_regID rs1 )

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
programThe program where the instruction will be added.
rs1Identifier 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()

t_instruction * genReadIntSyscall ( t_program * program,
t_regID rd )

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
programThe program where the instruction will be added.
rdIdentifier 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()

t_instruction * genREM ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register (dividend).
rs2Identifier of the second source register (divisor).
Returns
the instruction object added to the instruction list.

◆ genREMI()

t_instruction * genREMI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register (dividend).
immediateThe constant operand (divisor).
Returns
the instruction object added to the instruction list.

◆ genSEQ()

t_instruction * genSEQ ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genSEQI()

t_instruction * genSEQI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list.

◆ genSGE()

t_instruction * genSGE ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genSGEI()

t_instruction * genSGEI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added
rdIdentifier of the destination register
rs1Identifier of the source register
immediateThe constant operand
Returns
the instruction object added to the instruction list

◆ genSGEIU()

t_instruction * genSGEIU ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list.

◆ genSGEU()

t_instruction * genSGEU ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genSGT()

t_instruction * genSGT ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genSGTI()

t_instruction * genSGTI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list.

◆ genSGTIU()

t_instruction * genSGTIU ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list.

◆ genSGTU()

t_instruction * genSGTU ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genSLE()

t_instruction * genSLE ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genSLEI()

t_instruction * genSLEI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list.

◆ genSLEIU()

t_instruction * genSLEIU ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list.

◆ genSLEU()

t_instruction * genSLEU ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genSLL()

t_instruction * genSLL ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register (value to shift).
rs2Identifier of the second source register (shift amount).
Returns
the instruction object added to the instruction list.

◆ genSLLI()

t_instruction * genSLLI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register (value to shift).
immediateThe constant operand (shift amount).
Returns
the instruction object added to the instruction list.

◆ genSLT()

t_instruction * genSLT ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genSLTI()

t_instruction * genSLTI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list.

◆ genSLTIU()

t_instruction * genSLTIU ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list.

◆ genSLTU()

t_instruction * genSLTU ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genSNE()

t_instruction * genSNE ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genSNEI()

t_instruction * genSNEI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list.

◆ genSRA()

t_instruction * genSRA ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register (value to shift).
rs2Identifier of the second source register (shift amount).
Returns
the instruction object added to the instruction list.

◆ genSRAI()

t_instruction * genSRAI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register (value to shift).
immediateThe constant operand (shift amount).
Returns
the instruction object added to the instruction list.

◆ genSRL()

t_instruction * genSRL ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register (value to shift).
rs2Identifier of the second source register (shift amount).
Returns
the instruction object added to the instruction list.

◆ genSRLI()

t_instruction * genSRLI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register (value to shift).
immediateThe constant operand (shift amount).
Returns
the instruction object added to the instruction list.

◆ genStoreConstantToArrayElement()

void genStoreConstantToArrayElement ( t_program * program,
t_symbol * array,
t_regID rIdx,
int val )

Generate instructions that store the content of a register into an array element.

Parameters
programThe program where the array belongs.
arrayThe symbol object that refers to the array.
rIdxThe identifier of the register that will contain the index into the array.
valThe value to be stored.

◆ genStoreConstantToVariable()

void genStoreConstantToVariable ( t_program * program,
t_symbol * var,
int val )

Generate instructions that store a constant into a variable.

Parameters
programThe program where the variable belongs.
varThe symbol object that refers to the variable.
valThe constant value which needs to be assigned.

◆ genStoreRegisterToArrayElement()

void genStoreRegisterToArrayElement ( t_program * program,
t_symbol * array,
t_regID rIdx,
t_regID rVal )

Generate instructions that store the content of a register into an array element.

Parameters
programThe program where the array belongs.
arrayThe symbol object that refers to the array.
rIdxThe identifier of the register that will contain the index into the array.
rValThe identifier of the register that will contain the value to be stored.

◆ genStoreRegisterToVariable()

void genStoreRegisterToVariable ( t_program * program,
t_symbol * var,
t_regID reg )

Generate instructions that store the content of a register into a variable.

Parameters
programThe program where the variable belongs.
varThe symbol object that refers to the variable.
regThe register whose value needs to be assigned.

◆ genSUB()

t_instruction * genSUB ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register (minuend).
rs2Identifier of the second source register (subtrahend).
Returns
the instruction object added to the instruction list.

◆ genSUBI()

t_instruction * genSUBI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register (minuend).
immediateThe constant operand (subtrahend).
Returns
the instruction object added to the instruction list.

◆ genSW()

t_instruction * genSW ( t_program * program,
t_regID rs2,
int immediate,
t_regID rs1 )

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
programThe program where the instruction will be added.
rs2Identifier of the second source register (value to store).
immediateThe constant operand (address offset).
rs1Identifier 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()

t_instruction * genSWGlobal ( t_program * program,
t_regID rs1,
t_label * label,
t_regID rtemp )

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
programThe program where the instruction will be added.
rs1Identifier of the source register (value to store).
labelThe label (points to a 32-bit word).
rtempIdentifier 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()

t_instruction * genXOR ( t_program * program,
t_regID rd,
t_regID rs1,
t_regID rs2 )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the first source register.
rs2Identifier of the second source register.
Returns
the instruction object added to the instruction list.

◆ genXORI()

t_instruction * genXORI ( t_program * program,
t_regID rd,
t_regID rs1,
int immediate )

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
programThe program where the instruction will be added.
rdIdentifier of the destination register.
rs1Identifier of the source register.
immediateThe constant operand.
Returns
the instruction object added to the instruction list.