ACSE 2.0.3
Advanced Compiler System for Education
Loading...
Searching...
No Matches
target_info.c
Go to the documentation of this file.
1
3
4#include <assert.h>
5#include <stddef.h>
6#include "target_info.h"
7
8
10{
11 return instr->opcode == OPC_CALL_EXIT_0;
12}
13
14
16{
17 return instr->opcode == OPC_J;
18}
19
20
22{
23 switch (instr->opcode) {
24 case OPC_J:
25 case OPC_BEQ:
26 case OPC_BNE:
27 case OPC_BLT:
28 case OPC_BLTU:
29 case OPC_BGE:
30 case OPC_BGEU:
31 case OPC_BGT:
32 case OPC_BGTU:
33 case OPC_BLE:
34 case OPC_BLEU:
35 return true;
36 default:
37 return false;
38 }
39}
40
41
43{
44 return instr->opcode == OPC_ECALL;
45}
46
47
49{
50 assert(i < NUM_SPILL_REGS);
51 return (t_regID)i + REG_S9;
52}
53
54
56{
57 static const int regs[NUM_GP_REGS] = {REG_S0, REG_S1, REG_S2, REG_S3, REG_S4,
60 t_listNode *res = NULL;
61
62 for (int i = NUM_GP_REGS - 1; i >= 0; i--) {
63 res = listInsert(res, INT_TO_LIST_DATA(regs[i]), 0);
64 }
65 return res;
66}
67
69{
70 t_listNode *res = NULL;
71 for (int i = 1; i < NUM_REGISTERS; i++) {
72 res = listInsert(res, INT_TO_LIST_DATA(i), 0);
73 }
74 return res;
75}
76
78{
79 static const t_regID regs[] = {REG_T0, REG_T1, REG_T2, REG_T3, REG_T4, REG_T5,
82 t_listNode *res = NULL;
83
84 for (int i = 0; regs[i] != REG_INVALID; i++) {
85 res = listInsert(res, INT_TO_LIST_DATA(regs[i]), 0);
86 }
87 return res;
88}
t_listNode * listInsert(t_listNode *list, void *data, int pos)
Definition list.c:86
#define INT_TO_LIST_DATA(data)
Convert an integer from a list data pointer.
Definition list.h:33
A node belonging a list.
Definition list.h:39
int opcode
Instruction opcode.
Definition program.h:72
#define REG_INVALID
Constant used for invalid register identifiers.
Definition program.h:31
int t_regID
Type for register identifiers.
Definition program.h:28
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
#define NUM_GP_REGS
Number of general-purpose registers usable by the register allocator.
Definition target_info.h:37
#define NUM_SPILL_REGS
Definition target_info.h:41
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_ECALL
@ OPC_CALL_EXIT_0
@ OPC_BGT
@ OPC_BGE
@ OPC_BLT
@ OPC_BLTU
@ OPC_BNE
@ OPC_J
@ OPC_BLEU
@ OPC_BGTU
@ OPC_BEQ
@ OPC_BLE
@ OPC_BGEU
@ REG_A5
Definition target_info.h:60
@ REG_A0
Definition target_info.h:55
@ REG_A7
Definition target_info.h:62
@ REG_T5
Definition target_info.h:75
@ NUM_REGISTERS
Definition target_info.h:77
@ 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_S6
Definition target_info.h:67
@ 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_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_S8
Definition target_info.h:69
@ REG_S7
Definition target_info.h:68
@ REG_S0
Definition target_info.h:53
Properties of the target machine.