-
Notifications
You must be signed in to change notification settings - Fork 0
/
mir.h
166 lines (138 loc) · 3 KB
/
mir.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* mir.h
* Ryan Mallon
* Medium-level Intermediate Representation
*
* Based on the MIR specification from Advanced Compiler Design and
* Implementation by Steven S. Muchnick
*
*/
#include <stdio.h>
#include "symtable.h"
#include "typechk.h"
#include "astparse.h"
#include "icg.h"
#ifndef _MIR_H_
#define _MIR_H_
/* MIR instruction opcodes */
enum {
MIR_NOP,
MIR_LABEL,
MIR_BEGIN,
MIR_END,
MIR_RECEIVE,
MIR_CALL,
MIR_RETURN,
MIR_IF,
MIR_IF_NOT,
MIR_JUMP,
MIR_MEMBER,
MIR_MEMBER_DEREF,
MIR_MOVE,
MIR_SMOVE,
MIR_ADDR,
MIR_STACK_ADDR,
MIR_HEAP_ADDR,
MIR_LOAD,
MIR_STORE,
MIR_STACK_LOAD,
MIR_HEAP_LOAD,
MIR_REG_LOAD,
MIR_STACK_STORE,
MIR_HEAP_STORE,
MIR_REG_STORE,
MIR_PUSH_ARG,
MIR_LOAD_STRING,
MIR_ADD,
MIR_SUB,
MIR_MUL,
MIR_DIV,
MIR_EQL,
MIR_NEQ,
MIR_LSS,
MIR_LEQ,
MIR_GTR,
MIR_GEQ,
MIR_MAX_OPCODES
};
/* MIR parameter types */
enum {
MIR_ARG_VAL,
MIR_ARG_REF
};
/* MIR operands */
enum {
MIR_OP_VAR,
MIR_OP_CONST,
MIR_OP_REG,
MIR_OP_SPILL_REG,
};
typedef struct {
int optype;
int indirect;
name_record_t *var;
type_info_t *type_info;
int val;
} mir_operand_t;
/* Function argument for call instruction */
typedef struct {
mir_operand_t *arg_val;
} mir_arg_t;
/* MIR instruction */
typedef struct {
char *label;
int opcode;
mir_operand_t *operand[3];
int num_args;
mir_operand_t **args;
} mir_instr_t;
/* MIR instruction list */
struct mcfg_node_s;
typedef struct mir_node_s {
mir_instr_t *instruction;
int num;
int src_line_num;
int in_links;
struct mir_node_s *jump;
/* For inlining */
struct mir_node_s *copy_node;
/* Used for translating MIR to LIR */
ic_list_t *ic_instr;
/* Pointer to cfg node this is associated with */
struct mcfg_node_s *cfg_node;
struct mir_node_s *prev;
struct mir_node_s *next;
} mir_node_t;
/* Func headers */
void mir_print(char *, char *);
void mir_print_instr(FILE *, int, mir_node_t *);
void mir_label(mir_node_t **, char *);
void mir_set_jump(mir_node_t *, mir_node_t *);
void mir_move_label(mir_node_t *, mir_node_t *);
void mir_add_arg(mir_node_t **, mir_operand_t *);
void mir_remove_node(mir_node_t *);
mir_node_t *mir_emit(int, mir_operand_t *, mir_operand_t *,
mir_operand_t *);
mir_node_t *mir_list_tail(void);
mir_node_t *mir_list_head(void);
mir_operand_t *mir_opr(expression_t *);
mir_operand_t *mir_opr_copy(mir_operand_t *);
mir_operand_t *mir_reg(int);
mir_operand_t *mir_spill_reg(int);
mir_operand_t *mir_var(name_record_t *);
mir_operand_t *mir_const(int);
mir_node_t *mir_add_instr(mir_node_t *, int, mir_operand_t *,
mir_operand_t *, mir_operand_t *);
// void mir_to_sym_lir(ig_graph_t *);
char *mir_opstr(mir_operand_t *, char *);
void mir_spill_may_aliases(void);
void mir_fold_constants(void);
void mir_munge_globals(void);
void mir_strip(void);
void mir_munge(void);
void mir_munge_pointers(void);
void mir_rhs_constants(void);
void mir_args_to_regs(int);
void mir_inline(void);
void mir_label_nodes(void);
#endif /* _MIR_H_ */