ACSE 2.0.3
Advanced Compiler System for Education
Loading...
Searching...
No Matches
target_info.h
Go to the documentation of this file.
1
3
4#ifndef TARGET_INFO_H
5#define TARGET_INFO_H
6
7#include <stdbool.h>
8#include <stdint.h>
9#include "list.h"
10#include "program.h"
11
22
24typedef int32_t t_regInt;
25
27#define TARGET_NAME "RISC-V_RV32IM"
28
30#define TARGET_PTR_GRANULARITY 1
31
34#define TARGET_REG_ZERO_IS_CONST true
35
37#define NUM_GP_REGS 23
38
41#define NUM_SPILL_REGS 3
42
44enum {
78};
79
86enum {
87 // Arithmetic
88 OPC_ADD, // rd = rs1 + rs2
89 OPC_SUB, // rd = rs1 - rs2
90 OPC_AND, // rd = rs1 & rs2
91 OPC_OR, // rd = rs1 | rs2
92 OPC_XOR, // rd = rs1 ^ rs2
93 OPC_MUL, // rd = rs1 * rs2
94 OPC_DIV, // rd = rs1 / rs2
95 OPC_REM, // rd = rs1 % rs2
96 OPC_SLL, // rd = rs1 << rs2
97 OPC_SRL, // rd = rs1 >> rs2 (logical)
98 OPC_SRA, // rd = rs1 >> rs2 (arithmetic)
99
100 // Arithmetic with immediate
101 OPC_ADDI, // rd = rs1 + imm
102 OPC_SUBI, // rd = rs1 - imm (pseudo)
103 OPC_ANDI, // rd = rs1 & imm
104 OPC_ORI, // rd = rs1 | imm
105 OPC_XORI, // rd = rs1 ^ imm
106 OPC_MULI, // rd = rs1 * imm (pseudo)
107 OPC_DIVI, // rd = rs1 / imm (pseudo)
108 OPC_REMI, // rd = rs1 % imm (pseudo)
109 OPC_SLLI, // rd = rs1 << imm
110 OPC_SRLI, // rd = rs1 >> imm (logical)
111 OPC_SRAI, // rd = rs1 >> imm (arithmetic)
112
113 // Comparison
114 OPC_SEQ, // rd = rs1 == rs2 (pseudo)
115 OPC_SNE, // rd = rs1 != rs2 (pseudo)
116 OPC_SLT, // rd = rs1 < rs2 (signed)
117 OPC_SLTU, // rd = rs1 < rs2 (unsigned)
118 OPC_SGE, // rd = rs1 >= rs2 (signed) (pseudo)
119 OPC_SGEU, // rd = rs1 >= rs2 (unsigned) (pseudo)
120 OPC_SGT, // rd = rs1 > rs2 (signed) (pseudo)
121 OPC_SGTU, // rd = rs1 > rs2 (unsigned) (pseudo)
122 OPC_SLE, // rd = rs1 <= rs2 (signed) (pseudo)
123 OPC_SLEU, // rd = rs1 <= rs2 (unsigned) (pseudo)
124
125 // Comparison with immediate
126 OPC_SEQI, // rd = rs1 == imm (pseudo)
127 OPC_SNEI, // rd = rs1 != imm (pseudo)
128 OPC_SLTI, // rd = rs1 < imm (signed)
129 OPC_SLTIU, // rd = rs1 < imm (unsigned)
130 OPC_SGEI, // rd = rs1 >= imm (signed) (pseudo)
131 OPC_SGEIU, // rd = rs1 >= imm (unsigned) (pseudo)
132 OPC_SGTI, // rd = rs1 > imm (signed) (pseudo)
133 OPC_SGTIU, // rd = rs1 > imm (unsigned) (pseudo)
134 OPC_SLEI, // rd = rs1 <= imm (signed) (pseudo)
135 OPC_SLEIU, // rd = rs1 <= imm (unsigned) (pseudo)
136
137 // Jump/Branch
138 OPC_J, // goto addr;
139 OPC_BEQ, // if (rs1 == rs2) goto addr;
140 OPC_BNE, // if (rs1 == rs2) goto addr;
141 OPC_BLT, // if (rs1 < rs2) goto addr; (signed)
142 OPC_BLTU, // if (rs1 < rs2) goto addr; (unsigned)
143 OPC_BGE, // if (rs1 >= rs2) goto addr; (signed)
144 OPC_BGEU, // if (rs1 >= rs2) goto addr; (unsigned)
145 OPC_BGT, // if (rs1 > rs2) goto addr; (signed) (pseudo)
146 OPC_BGTU, // if (rs1 > rs2) goto addr; (unsigned) (pseudo)
147 OPC_BLE, // if (rs1 <= rs2) goto addr; (signed) (pseudo)
148 OPC_BLEU, // if (rs1 <= rs2) goto addr; (unsigned) (pseudo)
149
150 // Load/Store
151 OPC_LI, // rd = imm
152 OPC_LA, // rd = addr
153 OPC_LW, // rd = *(int *)(immediate + rs1)
154 OPC_SW, // *(int *)(immediate + rs1) = rs2
155 OPC_LW_G, // rd = *(int *)label (pseudo)
156 OPC_SW_G, // *(int *)label = rs2 (pseudo)
157
158 // Other
162
163 // Syscall opcodes
168};
169
170
175
180
185
190
191
198
203
208
213
217
218#endif
A node belonging a list.
Definition list.h:39
int t_regID
Type for register identifiers.
Definition program.h:28
int32_t t_regInt
Signed data type with the same size of a target register.
Definition target_info.h:24
t_listNode * getListOfMachineRegisters(void)
Definition target_info.c:68
t_regID getSpillMachineRegister(int i)
Definition target_info.c:48
t_listNode * getListOfCallerSaveMachineRegisters(void)
Definition target_info.c:77
bool isUnconditionalJump(t_instruction *instr)
Definition target_info.c:15
bool isJumpInstruction(t_instruction *instr)
Definition target_info.c:21
bool isExitInstruction(t_instruction *instr)
Definition target_info.c:9
bool isCallInstruction(t_instruction *instr)
Definition target_info.c:42
t_listNode * getListOfGenPurposeMachineRegisters(void)
Definition target_info.c:55
@ OPC_SGTU
@ OPC_SW
@ OPC_ECALL
@ OPC_SGTI
@ OPC_CALL_EXIT_0
@ OPC_SW_G
@ OPC_BGT
@ OPC_MULI
@ OPC_BGE
@ OPC_LI
@ OPC_DIV
Definition target_info.h:94
@ OPC_SLTU
@ OPC_SLT
@ OPC_SRL
Definition target_info.h:97
@ OPC_XORI
@ OPC_ADDI
@ OPC_SGT
@ OPC_LW_G
@ OPC_SEQI
@ OPC_OR
Definition target_info.h:91
@ OPC_SUB
Definition target_info.h:89
@ OPC_SGEIU
@ OPC_XOR
Definition target_info.h:92
@ OPC_SLTIU
@ OPC_CALL_PRINT_CHAR
@ OPC_BLT
@ OPC_SGTIU
@ OPC_CALL_READ_INT
@ OPC_EBREAK
@ OPC_SLTI
@ OPC_SNE
@ OPC_BLTU
@ OPC_SRLI
@ OPC_SRA
Definition target_info.h:98
@ OPC_SLL
Definition target_info.h:96
@ OPC_SLEU
@ OPC_BNE
@ OPC_ORI
@ OPC_REM
Definition target_info.h:95
@ OPC_SLEI
@ OPC_ANDI
@ OPC_LW
@ OPC_J
@ OPC_BLEU
@ OPC_NOP
@ OPC_BGTU
@ OPC_SEQ
@ OPC_ADD
Definition target_info.h:88
@ OPC_BEQ
@ OPC_SLEIU
@ OPC_SGEI
@ OPC_LA
@ OPC_CALL_PRINT_INT
@ OPC_SNEI
@ OPC_BLE
@ OPC_SUBI
@ OPC_DIVI
@ OPC_SRAI
@ OPC_MUL
Definition target_info.h:93
@ OPC_REMI
@ OPC_SLLI
@ OPC_AND
Definition target_info.h:90
@ OPC_SGEU
@ OPC_BGEU
@ OPC_SLE
@ OPC_SGE
@ REG_A5
Definition target_info.h:60
@ REG_A0
Definition target_info.h:55
@ REG_S11
Definition target_info.h:72
@ REG_A7
Definition target_info.h:62
@ REG_T5
Definition target_info.h:75
@ NUM_REGISTERS
Definition target_info.h:77
@ REG_ZERO
Definition target_info.h:45
@ REG_S5
Definition target_info.h:66
@ REG_T1
Definition target_info.h:51
@ REG_A6
Definition target_info.h:61
@ REG_A2
Definition target_info.h:57
@ REG_TP
Definition target_info.h:49
@ REG_S6
Definition target_info.h:67
@ REG_S10
Definition target_info.h:71
@ REG_SP
Definition target_info.h:47
@ REG_T3
Definition target_info.h:73
@ REG_S4
Definition target_info.h:65
@ REG_A4
Definition target_info.h:59
@ REG_T4
Definition target_info.h:74
@ REG_RA
Definition target_info.h:46
@ REG_S9
Definition target_info.h:70
@ REG_S3
Definition target_info.h:64
@ REG_S2
Definition target_info.h:63
@ REG_S1
Definition target_info.h:54
@ REG_T2
Definition target_info.h:52
@ REG_A1
Definition target_info.h:56
@ REG_T0
Definition target_info.h:50
@ REG_A3
Definition target_info.h:58
@ REG_GP
Definition target_info.h:48
@ REG_S8
Definition target_info.h:69
@ REG_S7
Definition target_info.h:68
@ REG_T6
Definition target_info.h:76
@ REG_S0
Definition target_info.h:53
A double-linked list.
Program object definition and management.