annotate mc-code-mips.c @ 181:4beb7f079055

new file
author kono
date Sun, 30 Nov 2003 18:38:43 +0900
parents 3b33c7daae95
children f53d70110377
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1 /* Micro-C Code Generatation Part for MIPS (PS2Linux) */
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2 /* $Id$ */
fea1b499d47b fix register var save
kono
parents:
diff changeset
3
fea1b499d47b fix register var save
kono
parents:
diff changeset
4 #define EXTERN extern
fea1b499d47b fix register var save
kono
parents:
diff changeset
5 #include "mc.h"
fea1b499d47b fix register var save
kono
parents:
diff changeset
6 #include "mc-code.h"
fea1b499d47b fix register var save
kono
parents:
diff changeset
7 #include "mc-codegen.h"
fea1b499d47b fix register var save
kono
parents:
diff changeset
8
173
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
9 char *l_include_path[] = {
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
10 "/usr/include/",
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
11 0
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
12 };
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
13
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
14 #define TEXT_EMIT_MODE 0
fea1b499d47b fix register var save
kono
parents:
diff changeset
15 #define DATA_EMIT_MODE 1
fea1b499d47b fix register var save
kono
parents:
diff changeset
16 #define RODATA_EMIT_MODE 2
fea1b499d47b fix register var save
kono
parents:
diff changeset
17
fea1b499d47b fix register var save
kono
parents:
diff changeset
18 static void data_mode(char *name);
163
fc8514c9d685 *** empty log message ***
kono
parents: 156
diff changeset
19 static void ld_indexx(int byte, int n, int xreg,int sign);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
20 static void local_table(void);
fea1b499d47b fix register var save
kono
parents:
diff changeset
21 static void shift(char *op, int reg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
22 static int struct_push(int e4,int t,int arg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
23
fea1b499d47b fix register var save
kono
parents:
diff changeset
24 static int output_mode = TEXT_EMIT_MODE;
fea1b499d47b fix register var save
kono
parents:
diff changeset
25 static int data_alignment = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
26
fea1b499d47b fix register var save
kono
parents:
diff changeset
27 static int code_disp_label;
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
28 static int disp_label;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
29 static int r1_offset_label;
fea1b499d47b fix register var save
kono
parents:
diff changeset
30 static int lvar_offset_label;
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
31 static int cprestore_label;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
32
fea1b499d47b fix register var save
kono
parents:
diff changeset
33 static int reg_save;
fea1b499d47b fix register var save
kono
parents:
diff changeset
34 static int freg_save;
fea1b499d47b fix register var save
kono
parents:
diff changeset
35
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
36 static int freg,ireg,dreg;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
37
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
38 /* mips requires two registers for compare */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
39 static int cmpreg = -1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
40
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
41 int size_of_int = 4;
fea1b499d47b fix register var save
kono
parents:
diff changeset
42 int size_of_float = 4;
fea1b499d47b fix register var save
kono
parents:
diff changeset
43 int size_of_double = 8;
fea1b499d47b fix register var save
kono
parents:
diff changeset
44 int size_of_longlong = 8;
fea1b499d47b fix register var save
kono
parents:
diff changeset
45 int endian = 1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
46
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
47 int reg_sp; /* REGister Stack-Pointer */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
48 int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
49
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
50 /* floating point registers */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
51
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
52 int freg_sp; /* floating point REGister Stack-Pointer */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
53 int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
54
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
55 /* double floating point registers */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
56
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
57 int dreg_sp; /* floating point REGister Stack-Pointer */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
58 int dreg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
59
fea1b499d47b fix register var save
kono
parents:
diff changeset
60 #define REG_fp 1
fea1b499d47b fix register var save
kono
parents:
diff changeset
61 #define REG_sp 30
fea1b499d47b fix register var save
kono
parents:
diff changeset
62 #define REG_VAR_BASE 29
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
63 #define REG_VAR_MIN 18
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
64 #define MIN_TMP_REG 4
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
65 #define MAX_TMP_REG 11
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
66
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
67 #define DREG_VAR_BASE 29
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
68 #define DREG_VAR_MIN 18
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
69 #define MIN_TMP_DREG 4
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
70 #define MAX_TMP_DREG 17
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
71
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
72 #define PTRC_REG 3
fea1b499d47b fix register var save
kono
parents:
diff changeset
73
fea1b499d47b fix register var save
kono
parents:
diff changeset
74 #define FREG_VAR_BASE 31
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
75 #define FREG_VAR_MIN 20
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
76 #define MIN_TMP_FREG 1
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
77 #define MAX_TMP_FREG 14
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
78
fea1b499d47b fix register var save
kono
parents:
diff changeset
79 #define RET_REGISTER 3
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
80 #define RET_FREGISTER (1+FREG_OFFSET)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
81 #define RET_DREGISTER (1+DREG_OFFSET)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
82
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
83 int MAX_REGISTER=30; /* PowerPCのレジスタを10個まで使う*/
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
84 int MAX_FREGISTER=31;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
85 int MAX_DREGISTER=16;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
86 #define REAL_MAX_REGISTER 32 /* PowerPCのレジスタが32ということ*/
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
87 #define REAL_MAX_FREGISTER 32 /* PowerPCのFレジスタが32ということ*/
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
88 #define REAL_MAX_DREGISTER 31 /* PowerPCのDレジスタ番号が31ということ*/
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
89
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
90 #define FREG_OFFSET REAL_MAX_REGISTER
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
91 #define DREG_OFFSET (REAL_MAX_REGISTER+REAL_MAX_FREGISTER )
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
92
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
93 int MAX_INPUT_REGISTER_VAR = 7-MIN_TMP_REG;
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
94 int MAX_CODE_INPUT_REGISTER_VAR = 7-MIN_TMP_REG;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
95 int MAX_INPUT_DREGISTER_VAR = 14-MIN_TMP_FREG;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
96 int MAX_INPUT_FREGISTER_VAR = 14-MIN_TMP_FREG;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
97 int MAX_CODE_INPUT_DREGISTER_VAR = 14-MIN_TMP_FREG;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
98 int MAX_CODE_INPUT_FREGISTER_VAR = 14-MIN_TMP_FREG;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
99
fea1b499d47b fix register var save
kono
parents:
diff changeset
100 #define CREG_REGISTER MAX_TMP_REG
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
101 #define FREG_FREGISTER (MAX_TMP_FREG+FREG_OFFSET)
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
102 #define DREG_DREGISTER (2+DREG_OFFSET)
145
fb61020a9b48 fix macro
kono
parents: 143
diff changeset
103
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
104 int powerpc_regs[REAL_MAX_REGISTER+REAL_MAX_FREGISTER+REAL_MAX_DREGISTER];
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
105 int powerpc_regv[REAL_MAX_REGISTER+REAL_MAX_FREGISTER+REAL_MAX_DREGISTER];
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
106
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
107 int dreg_pair0[REAL_MAX_DREGISTER] = {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
108 0,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
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
109 };
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
110 int dreg_pair1[REAL_MAX_DREGISTER] = {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
111 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
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
112 };
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
113
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
114 int *regv = powerpc_regv;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
115 int *regs = powerpc_regs;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
116
fea1b499d47b fix register var save
kono
parents:
diff changeset
117 static int max_reg_var, max_freg_var;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
118 static int cond_reg=-1,cond_freg=-1,cond_dreg=-1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
119
fea1b499d47b fix register var save
kono
parents:
diff changeset
120 static char *reg_name[] = {
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
121 "$0","$1","$2","$3","$4","$5","$6","$7","$8","$9",
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
122 "$10","$11","$12","$13","$14","$15","$16","$17","$18","$19",
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
123 "$20","$21","$22","$23","$24","$25","$26","$27","$28","$29",
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
124 "$30","$31",
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
125 "$f0","$f1","$f2","$f3","$f4","$f5","$f6","$f7","$f8","$f9",
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
126 "$f10","$f11","$f12","$f13","$f14","$f15","$f16","$f17","$f18","$f19",
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
127 "$f20","$f21","$f22","$f23","$f24","$f25","$f26","$f27","$f28","$f29",
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
128 "$f30","$f31"
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
129 };
fea1b499d47b fix register var save
kono
parents:
diff changeset
130
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
131
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
132 #define register_name(i) reg_name0(i)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
133 #define fregister_name(i) reg_name0(i)
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
134 #define dregister_name0(i) reg_name1(i,dreg_pair0)
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
135 #define dregister_name1(i) reg_name1(i,dreg_pair1)
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
136
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
137 static char *
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
138 reg_name0(int i)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
139 {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
140 if (i<=REAL_MAX_REGISTER+REAL_MAX_FREGISTER)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
141 return reg_name[i];
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
142 else {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
143 error(-1);
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
144 return reg_name[0];
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
145 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
146 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
147
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
148 static char *
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
149 reg_name1(int i,int *d)
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
150 {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
151 if (i<=REAL_MAX_REGISTER+REAL_MAX_FREGISTER) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
152 error(-1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
153 return reg_name[0];
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
154 } else
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
155 return reg_name[d[i-DREG_OFFSET]];
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
156 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
157
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
158
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
159 #define is_int_reg(i) (0<=i&&i<REAL_MAX_REGISTER)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
160 #define is_float_reg(i) (REAL_MAX_REGISTER<=i&&i<REAL_MAX_FREGISTER+REAL_MAX_REGISTER)
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
161 #define is_double_reg(i) (REAL_MAX_REGISTER+REAL_MAX_FREGISTER<=i&&i<REAL_MAX_FREGISTER+REAL_MAX_REGISTER+REAL_MAX_DREGISTER)
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
162
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
163
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
164 int use_int(int i) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
165 if (!is_int_reg(i)) i = ireg;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
166 if (!regs[i]) regs[i]=1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
167 return i;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
168 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
169
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
170 int use_float(int i) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
171 if (!is_float_reg(i)) i = freg;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
172 if (!regs[i]) regs[i]=1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
173 return i;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
174 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
175
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
176 int use_double(int i) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
177 if (!is_double_reg(i)) i = dreg;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
178 if (!regs[i]) regs[i]=1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
179 return i;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
180 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
181
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
182 static int code_d1(double d);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
183 static int code_d2(double d);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
184
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
185 static void code_save_stacks();
fea1b499d47b fix register var save
kono
parents:
diff changeset
186 static void code_save_input_registers();
fea1b499d47b fix register var save
kono
parents:
diff changeset
187 static void set_creg(int,int);
fea1b499d47b fix register var save
kono
parents:
diff changeset
188 static void set_freg(int,int);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
189 static void set_dreg(int,int);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
190
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
191 static int mask_label;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
192 static int mask1_label;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
193 static int fmask_label;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
194 static int fmask1_label;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
195
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
196 static FILE *asi;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
197
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
198 static int max_func_args;
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
199 static int max_func_iargs;
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
200 static int my_func_args;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
201 #define ARG_LVAR_OFFSET 0x10000000
fea1b499d47b fix register var save
kono
parents:
diff changeset
202
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
203 #define DOT_SIZE 1
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
204
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
205 /*
fea1b499d47b fix register var save
kono
parents:
diff changeset
206
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
207 Reorder is automatically done in assembler.
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
208 delayed slot done within .set noreorder.
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
209
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
210 r0 return value etc.
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
211 $2,$3 return value. (dpcmp return value on $2)
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
212 $0 special register
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
213 $4-$7 input register
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
214 r22-r29 saved register variable (input register for code segement)
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
215 $31 stack pointer
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
216 $fp frame pointer
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
217
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
218 $f0 return value etc.
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
219 $f14,$f12 input register
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
220 $f20-$f31 saved register variable
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
221
fea1b499d47b fix register var save
kono
parents:
diff changeset
222 function call stack frame
fea1b499d47b fix register var save
kono
parents:
diff changeset
223 <------r1_offset------------------------------>
fea1b499d47b fix register var save
kono
parents:
diff changeset
224 <------------lvar_offset------->
fea1b499d47b fix register var save
kono
parents:
diff changeset
225 r+ +------------+---+---------------+----------+--------------+----+ -
fea1b499d47b fix register var save
kono
parents:
diff changeset
226 callee arg xx register save local caller arg xx
fea1b499d47b fix register var save
kono
parents:
diff changeset
227 reg_save disp max_func_args*size_of_int
fea1b499d47b fix register var save
kono
parents:
diff changeset
228 lvar>0 lvar<0 lvar>0x1000 0000
fea1b499d47b fix register var save
kono
parents:
diff changeset
229
fea1b499d47b fix register var save
kono
parents:
diff changeset
230 code segment stack frame
fea1b499d47b fix register var save
kono
parents:
diff changeset
231
fea1b499d47b fix register var save
kono
parents:
diff changeset
232 * gotoを呼び出した関数のr1 ! r1(goto前のr1)
fea1b499d47b fix register var save
kono
parents:
diff changeset
233 # * r30 <---r1_offset---------> r1
fea1b499d47b fix register var save
kono
parents:
diff changeset
234 r+ +----------+--+----------+----------------+-----------+----------+----+
fea1b499d47b fix register var save
kono
parents:
diff changeset
235 cousin arg xx reg save !callee arg !code local caller arg xx
fea1b499d47b fix register var save
kono
parents:
diff changeset
236 r20-r29 lvar>0 lvar<0 lvar>0x1000 000
fea1b499d47b fix register var save
kono
parents:
diff changeset
237 f20-f31 <-my_func_args--><--disp-----><-max_func_arg->
fea1b499d47b fix register var save
kono
parents:
diff changeset
238 *size_of_int *size_of_int
fea1b499d47b fix register var save
kono
parents:
diff changeset
239
fea1b499d47b fix register var save
kono
parents:
diff changeset
240 */
fea1b499d47b fix register var save
kono
parents:
diff changeset
241 int arg_offset = 24; int arg_offset1 = 24; int disp_offset = -12;
fea1b499d47b fix register var save
kono
parents:
diff changeset
242 #define func_disp_offset 60
fea1b499d47b fix register var save
kono
parents:
diff changeset
243 #define r1_offset func_disp_offset+12
fea1b499d47b fix register var save
kono
parents:
diff changeset
244 int code_disp_offset = 0; int jump_offset = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
245 #define CODE_LVAR l+code_disp_offset
fea1b499d47b fix register var save
kono
parents:
diff changeset
246 #define CODE_CALLER_ARG (l-ARG_LVAR_OFFSET)+arg_offset1
fea1b499d47b fix register var save
kono
parents:
diff changeset
247 #define FUNC_LVAR l+disp_offset
fea1b499d47b fix register var save
kono
parents:
diff changeset
248 #define CALLER_ARG (l-ARG_LVAR_OFFSET)+arg_offset1
fea1b499d47b fix register var save
kono
parents:
diff changeset
249 #define CALLEE_ARG l+arg_offset
fea1b499d47b fix register var save
kono
parents:
diff changeset
250
fea1b499d47b fix register var save
kono
parents:
diff changeset
251 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
252 code_offset_set()
fea1b499d47b fix register var save
kono
parents:
diff changeset
253 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
254 #if 0
fea1b499d47b fix register var save
kono
parents:
diff changeset
255 int l;
fea1b499d47b fix register var save
kono
parents:
diff changeset
256 #endif
fea1b499d47b fix register var save
kono
parents:
diff changeset
257 int lvar_offsetv = -disp+max_func_args*size_of_int+func_disp_offset;
fea1b499d47b fix register var save
kono
parents:
diff changeset
258 int r1_offsetv = -disp+max_func_args*size_of_int-reg_save+r1_offset;
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
259 printf("L_%d = %d\n",lvar_offset_label,lvar_offsetv);
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
260 printf("L_%d = %d\n",r1_offset_label,r1_offsetv);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
261 #if 0
fea1b499d47b fix register var save
kono
parents:
diff changeset
262 printf("# function %s\n",fnptr->nm);
fea1b499d47b fix register var save
kono
parents:
diff changeset
263 l = ARG_LVAR_OFFSET;
fea1b499d47b fix register var save
kono
parents:
diff changeset
264 printf("# offset call0\t%d\n",CALLER_ARG);
fea1b499d47b fix register var save
kono
parents:
diff changeset
265 l = ARG_LVAR_OFFSET+max_func_args*size_of_int;
fea1b499d47b fix register var save
kono
parents:
diff changeset
266 printf("# offset calln\t%d %d\n",CALLER_ARG,max_func_args*size_of_int);
fea1b499d47b fix register var save
kono
parents:
diff changeset
267 l = disp;
fea1b499d47b fix register var save
kono
parents:
diff changeset
268 printf("# offset lvarn\t%d %d\n",FUNC_LVAR+lvar_offsetv,disp);
fea1b499d47b fix register var save
kono
parents:
diff changeset
269 l = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
270 printf("# offset lvar0\t%d\n",FUNC_LVAR+lvar_offsetv);
fea1b499d47b fix register var save
kono
parents:
diff changeset
271 l = -reg_save;
fea1b499d47b fix register var save
kono
parents:
diff changeset
272 printf("# offset regs\t%d\n",FUNC_LVAR+lvar_offsetv);
fea1b499d47b fix register var save
kono
parents:
diff changeset
273 printf("# offset r1off\t%d\n",r1_offsetv);
fea1b499d47b fix register var save
kono
parents:
diff changeset
274 l = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
275 printf("# offset carg0\t%d\n",CALLEE_ARG+r1_offsetv);
fea1b499d47b fix register var save
kono
parents:
diff changeset
276 l = my_func_args;
fea1b499d47b fix register var save
kono
parents:
diff changeset
277 printf("# offset cargn\t%d %d\n",CALLEE_ARG+r1_offsetv,my_func_args);
fea1b499d47b fix register var save
kono
parents:
diff changeset
278 #endif
fea1b499d47b fix register var save
kono
parents:
diff changeset
279 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
280
fea1b499d47b fix register var save
kono
parents:
diff changeset
281 static void
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
282 lvar(int l)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
283 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
284 if (fnptr->sc==CODE) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
285 if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
286 printf("%d($fp)\n",CODE_CALLER_ARG);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
287 } else
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
288 printf("%d($fp)\n",CODE_LVAR);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
289 } else if (l<0) { /* local variable */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
290 printf("%d+L_%d($fp)\n",FUNC_LVAR,lvar_offset_label);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
291 } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
292 printf("%d($fp)\n",CALLER_ARG);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
293 } else { /* callee's arguments */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
294 printf("%d+L_%d($fp)\n",CALLEE_ARG,r1_offset_label);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
295 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
296 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
297
fea1b499d47b fix register var save
kono
parents:
diff changeset
298 static void
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
299 lvar_address(int l,int creg)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
300 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
301 if (fnptr->sc==CODE) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
302 if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
303 printf("\taddu\t%s,$fp,%d\n",register_name(creg),CODE_CALLER_ARG);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
304 } else
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
305 printf("\taddu\t%s,$fp,%d\n",register_name(creg),CODE_LVAR);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
306 } else if (l<0) { /* local variable */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
307 printf("\taddu\t%s,$fp,%d+L_%d\n",register_name(creg),FUNC_LVAR,lvar_offset_label);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
308 } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
309 printf("\taddu\t%s,$fp,%d\n",register_name(creg),CALLER_ARG);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
310 } else { /* callee's arguments */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
311 printf("\taddu\t%s,$fp,%d+L_%d\n",register_name(creg),CALLEE_ARG,r1_offset_label);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
312 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
313 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
314
fea1b499d47b fix register var save
kono
parents:
diff changeset
315 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
316 code_lvar(int e2,int creg) {
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
317 lvar_address(e2,creg);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
318 regv[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
319 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
320
fea1b499d47b fix register var save
kono
parents:
diff changeset
321 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
322 code_init(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
323 {
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
324 /* this is called once program call */
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
325 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
326
fea1b499d47b fix register var save
kono
parents:
diff changeset
327 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
328 gexpr_code_init(void){
fea1b499d47b fix register var save
kono
parents:
diff changeset
329 regv[creg]=0;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
330 regv[freg]=0;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
331 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
332
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
333 void
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
334 code_gexpr(int e){
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
335 if (is_int_reg(creg) && creg!=ireg) error(-1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
336 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
337
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
338
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
339 void
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
340 code_arg_register(NMTBL *fnptr)
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
341 {
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
342 int args = fnptr->dsp;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
343 NMTBL *n;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
344 int reg_var = 0;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
345 int freg_var = 0;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
346 int type;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
347 int reg;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
348 int is_code0 = is_code(fnptr);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
349
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
350 while (args) {
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
351 /* process in reverse order */
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
352 n = (NMTBL*)caddr(args);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
353 type = n->ty;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
354 if (scalar(type)) {
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
355 if ((reg = get_input_register_var(reg_var,n,is_code0))) {
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
356 n->sc = REGISTER;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
357 n->dsp = cadr(reg);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
358 regv[n->dsp]= 1;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
359 regs[n->dsp]= INPUT_REG;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
360 reg_var++;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
361 cadddr(args)=size_of_int; /* why we need this? */
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
362 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
363 } else if (type==FLOAT) {
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
364 if ((reg = get_input_dregister_var(freg_var,n,is_code0,0))) {
141
kono
parents: 139
diff changeset
365 n->sc = FREGISTER;
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
366 n->dsp = cadr(reg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
367 regv[n->dsp]= 1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
368 regs[n->dsp]= INPUT_REG;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
369 freg_var++;
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
370 cadddr(args)=size(type); /* why we need this? */
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
371 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
372 } else if (type==DOUBLE) {
141
kono
parents: 139
diff changeset
373 if ((reg = get_input_dregister_var(reg_var,n,is_code0,1))) {
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
374 n->sc = DREGISTER;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
375 n->dsp = cadr(reg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
376 regv[n->dsp]= 1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
377 regs[n->dsp]= INPUT_REG;
141
kono
parents: 139
diff changeset
378 reg_var+=2;
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
379 cadddr(args)=size(type); /* why we need this? */
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
380 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
381 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
382 args = cadr(args);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
383 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
384 if (is_function(fnptr))
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
385 code_save_input_registers();
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
386 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
387
fea1b499d47b fix register var save
kono
parents:
diff changeset
388 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
389 get_register(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
390 { /* 使われていないレジスタを調べる */
fea1b499d47b fix register var save
kono
parents:
diff changeset
391 int i,reg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
392 for(i=MAX_TMP_REG;i>MIN_TMP_REG;i--) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
393 if (regs[i]) continue; /* 使われている */
fea1b499d47b fix register var save
kono
parents:
diff changeset
394 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */
fea1b499d47b fix register var save
kono
parents:
diff changeset
395 return i; /* その場所を表す番号を返す */
fea1b499d47b fix register var save
kono
parents:
diff changeset
396 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
397 /* search register stack */
fea1b499d47b fix register var save
kono
parents:
diff changeset
398 for(i=0;i<reg_sp;i++) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
399 if ((reg=reg_stack[i])>=0) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
400 code_assign_lvar(
fea1b499d47b fix register var save
kono
parents:
diff changeset
401 (reg_stack[i]=new_lvar(size_of_int)),reg,0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
402 reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET;
fea1b499d47b fix register var save
kono
parents:
diff changeset
403 return reg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
404 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
405 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
406 /* search dregister stack */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
407 for(i=0;i<dreg_sp;i++) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
408 if ((reg=dreg_stack[i])>=0) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
409 code_dassign_lvar(
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
410 (dreg_stack[i]=new_lvar(size_of_double)),reg,1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
411 dreg_stack[i]= dreg_stack[i]-REG_LVAR_OFFSET;
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
412 free_register(reg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
413 return get_register(); /* 今度は必ずある */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
414 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
415 }
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
416 for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) {
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
417 reg =REG_VAR_BASE-i;
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
418 if (! regs[reg]) { /* 使われていないなら */
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
419 regs[reg]=USING_REG; /* そのレジスタを使うことを宣言し */
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
420 regv[reg]=0;
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
421 if (i>max_reg_var) max_reg_var=i;
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
422 return reg;
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
423 }
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
424 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
425 /* 空いている場所がないなら、エラー (いったい誰が使ってるの?) */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
426 error(HPERR); return creg;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
427 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
428
fea1b499d47b fix register var save
kono
parents:
diff changeset
429 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
430 pop_register(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
431 { /* レジスタから値を取り出す */
fea1b499d47b fix register var save
kono
parents:
diff changeset
432 return reg_stack[--reg_sp];
fea1b499d47b fix register var save
kono
parents:
diff changeset
433 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
434
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
435 static int
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
436 get_dregister1() {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
437 int i;
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
438 for(i=MAX_TMP_DREG+DREG_OFFSET;i>MIN_TMP_DREG+DREG_OFFSET;i--) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
439 if (regs[i]) continue; /* 使われている */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
440 if (regs[dreg_pair0[i-DREG_OFFSET]]) continue;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
441 if (regs[dreg_pair1[i-DREG_OFFSET]]) continue;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
442 regs[dreg_pair0[i-DREG_OFFSET]]=USING_REG;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
443 regs[dreg_pair1[i-DREG_OFFSET]]=USING_REG;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
444 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
445 return i; /* その場所を表す番号を返す */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
446 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
447 return -1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
448 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
449
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
450 static int
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
451 get_dregister0()
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
452 {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
453 int reg,i;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
454 /* とりあえず、空き int register pair を探す */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
455 if ((i=get_dregister1())!=-1) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
456 return i;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
457 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
458 /* search dregister stack */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
459 for(i=0;i<dreg_sp;i++) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
460 if ((reg=dreg_stack[i])>=0) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
461 code_dassign_lvar(
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
462 (dreg_stack[i]=new_lvar(size_of_double)),reg,1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
463 dreg_stack[i]= dreg_stack[i]-REG_LVAR_OFFSET;
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
464 return reg;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
465 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
466 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
467 /* clear integer register stack */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
468 for(i=0;i<reg_sp;i++) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
469 if ((reg=reg_stack[i])>=0) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
470 code_assign_lvar(
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
471 (reg_stack[i]=new_lvar(size_of_int)),reg,0);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
472 reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
473 free_register(reg);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
474 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
475 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
476 if ((i=get_dregister1())!=-1) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
477 return i;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
478 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
479
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
480 error(REG_ERR); return dreg;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
481 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
482
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
483 static int
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
484 get_fregister0()
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
485 { /* 使われていないレジスタを調べる */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
486 int i,reg;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
487 for(i=MAX_TMP_FREG+FREG_OFFSET;i>MIN_TMP_FREG+FREG_OFFSET;i--) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
488 if (regs[i]) continue; /* 使われている */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
489 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
490 return i; /* その場所を表す番号を返す */
fea1b499d47b fix register var save
kono
parents:
diff changeset
491 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
492 /* search register stack */
fea1b499d47b fix register var save
kono
parents:
diff changeset
493 for(i=0;i<freg_sp;i++) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
494 if ((reg=freg_stack[i])>=0) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
495 code_dassign_lvar(
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
496 (freg_stack[i]=new_lvar(size_of_float)),reg,0);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
497 freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET;
fea1b499d47b fix register var save
kono
parents:
diff changeset
498 return reg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
499 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
500 }
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
501 for(i=0;i<FREG_VAR_BASE-REG_VAR_MIN;i++) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
502 reg =FREG_VAR_BASE-i+FREG_OFFSET;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
503 if (! regs[reg]) { /* 使われていないなら */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
504 regs[reg]=USING_REG; /* そのレジスタを使うことを宣言し */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
505 regv[reg]=0;
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
506 if (i>max_freg_var) max_freg_var=i;
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
507 return reg;
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
508 }
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
509 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
510 /* 空いている場所がないなら、エラー (いったい誰が使ってるの?) */
fea1b499d47b fix register var save
kono
parents:
diff changeset
511 error(REG_ERR); return freg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
512 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
513
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
514 int
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
515 get_dregister(int d)
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
516 {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
517 if (d) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
518 return get_dregister0();
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
519 } else {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
520 return get_fregister0();
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
521 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
522 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
523
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
524 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
525 pop_fregister(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
526 { /* レジスタから値を取り出す */
fea1b499d47b fix register var save
kono
parents:
diff changeset
527 return freg_stack[--freg_sp];
fea1b499d47b fix register var save
kono
parents:
diff changeset
528 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
529
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
530 int
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
531 pop_dregister(void)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
532 { /* レジスタから値を取り出す */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
533 return dreg_stack[--dreg_sp];
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
534 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
535
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
536 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
537 emit_pop_free(int xreg)
fea1b499d47b fix register var save
kono
parents:
diff changeset
538 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
539 if (xreg>=0)
fea1b499d47b fix register var save
kono
parents:
diff changeset
540 free_register(xreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
541 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
542
fea1b499d47b fix register var save
kono
parents:
diff changeset
543 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
544 free_register(int i) { /* いらなくなったレジスタを開放 */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
545 int i0,i1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
546 if (i<0||MAX_FREGISTER+FREG_OFFSET+REAL_MAX_DREGISTER<i) error(-1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
547 if (is_double_reg(i)) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
548 i0 = dreg_pair0[i-DREG_OFFSET];
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
549 regv[i0]=regs[i0]=0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
550 i1 = dreg_pair1[i-DREG_OFFSET];
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
551 regv[i1]=regs[i1]=0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
552 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
553 regv[i]=regs[i]=0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
554 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
555
fea1b499d47b fix register var save
kono
parents:
diff changeset
556 int
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
557 get_input_dregister_var(int i,NMTBL *n,int is_code,int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
558 {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
559 if (d) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
560 if (is_code) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
561 if(!(i<DREG_VAR_BASE-DREG_VAR_MIN)) return 0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
562 i = DREG_VAR_BASE-i+DREG_OFFSET;
141
kono
parents: 139
diff changeset
563 } else {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
564 if (i<0||i>=MAX_INPUT_DREGISTER_VAR) return 0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
565 i = i+MIN_TMP_DREG+DREG_OFFSET;
141
kono
parents: 139
diff changeset
566 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
567 return list3(DREGISTER,i,(int)n);
141
kono
parents: 139
diff changeset
568 } else {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
569 if (is_code) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
570 if(!(i<FREG_VAR_BASE-FREG_VAR_MIN)) return 0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
571 i = FREG_VAR_BASE-i+FREG_OFFSET;
141
kono
parents: 139
diff changeset
572 } else {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
573 if (i<0||i>=MAX_INPUT_FREGISTER_VAR) return 0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
574 i = i+MIN_TMP_FREG+FREG_OFFSET;
141
kono
parents: 139
diff changeset
575 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
576 return list3(FREGISTER,i,(int)n);
141
kono
parents: 139
diff changeset
577 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
578 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
579
fea1b499d47b fix register var save
kono
parents:
diff changeset
580 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
581 get_input_register_var(int i,NMTBL *n,int is_code)
fea1b499d47b fix register var save
kono
parents:
diff changeset
582 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
583 if (is_code) {
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
584 if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
585 i = REG_VAR_BASE-i;
fea1b499d47b fix register var save
kono
parents:
diff changeset
586 } else {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
587 if (i<0||i>=MAX_INPUT_REGISTER_VAR) return 0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
588 i = i+MIN_TMP_REG;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
589 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
590 return list3(REGISTER,i,(int)n);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
591 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
592
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
593 /* double register case? */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
594
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
595 int
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
596 get_input_register_var_1(int i,NMTBL *n,int is_code)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
597 {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
598 if (is_code) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
599 if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
600 i = REG_VAR_BASE-i;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
601 } else {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
602 if (i<0||i>=MAX_INPUT_REGISTER_VAR+1) return 0;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
603 i = i+MIN_TMP_REG;
fea1b499d47b fix register var save
kono
parents:
diff changeset
604 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
605 return list3(REGISTER,i,(int)n);
fea1b499d47b fix register var save
kono
parents:
diff changeset
606 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
607
fea1b499d47b fix register var save
kono
parents:
diff changeset
608 int
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
609 free_register_count(int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
610 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
611 int i,count,fcount;
fea1b499d47b fix register var save
kono
parents:
diff changeset
612 fcount = count = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
613 for(i=0;i<MAX_REGISTER;i++) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
614 if (! regs[i] && ! regv[i]) count++;
fea1b499d47b fix register var save
kono
parents:
diff changeset
615 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
616 for(i=0;i<MAX_FREGISTER;i++) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
617 if (! regs[i+FREG_OFFSET] && ! regv[i+FREG_OFFSET]) fcount++;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
618 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
619 printf("# free reg %d freg %d\n",count,fcount);
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
620 return d?fcount:count;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
621 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
622
fea1b499d47b fix register var save
kono
parents:
diff changeset
623 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
624 register_full(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
625 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
626 int i;
fea1b499d47b fix register var save
kono
parents:
diff changeset
627 for(i=0;i<MAX_REGISTER;i++) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
628 if (! regs[i]) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
629 return 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
630 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
631 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
632 return 1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
633 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
634
fea1b499d47b fix register var save
kono
parents:
diff changeset
635 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
636 free_all_register(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
637 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
638 int i;
fea1b499d47b fix register var save
kono
parents:
diff changeset
639 for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; regv[i]=0; }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
640 for(i=0;i<MAX_FREGISTER;i++) { regs[i+FREG_OFFSET]=0; regv[i+FREG_OFFSET]=0; }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
641 for(i=0;i<MAX_DREGISTER;i++) { regs[i+DREG_OFFSET]=0; regv[i+DREG_OFFSET]=0; }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
642 creg = get_register();
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
643 freg = get_dregister(0);
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
644 dreg = DREG_DREGISTER;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
645 set_creg(CREG_REGISTER,0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
646 set_freg(FREG_FREGISTER,0);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
647 set_dreg(DREG_DREGISTER,0);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
648 return;
fea1b499d47b fix register var save
kono
parents:
diff changeset
649 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
650
fea1b499d47b fix register var save
kono
parents:
diff changeset
651 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
652 register_usage(char *s)
fea1b499d47b fix register var save
kono
parents:
diff changeset
653 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
654 #if 0
fea1b499d47b fix register var save
kono
parents:
diff changeset
655 int i;
fea1b499d47b fix register var save
kono
parents:
diff changeset
656 #endif
fea1b499d47b fix register var save
kono
parents:
diff changeset
657 if (chk) return;
fea1b499d47b fix register var save
kono
parents:
diff changeset
658 if (!lsrc) return;
fea1b499d47b fix register var save
kono
parents:
diff changeset
659 printf("# %d: %s:",lineno,s);
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
660 printf(" creg=%s ireg=%s freg=%s dreg=%s",
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
661 is_int_reg(creg)?register_name(creg):
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
662 is_float_reg(creg)?fregister_name(creg):
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
663 is_double_reg(creg)?dregister_name0(creg):"bad",
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
664 register_name(ireg),fregister_name(freg),dregister_name0(dreg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
665 #if 0
fea1b499d47b fix register var save
kono
parents:
diff changeset
666 printf("\n# regs:");
fea1b499d47b fix register var save
kono
parents:
diff changeset
667 for(i=0;i<MAX_REGISTER;i++) { printf("%d",regv[i]); }
fea1b499d47b fix register var save
kono
parents:
diff changeset
668 printf(":");
fea1b499d47b fix register var save
kono
parents:
diff changeset
669 for(i=0;i<MAX_REGISTER;i++) { printf("%d",regs[i]); }
fea1b499d47b fix register var save
kono
parents:
diff changeset
670 printf("\n# freg:");
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
671 for(i=0;i<MAX_FREGISTER;i++) { printf("%d",regs[i+FREG_OFFSET]); }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
672 for(i=reg_sp;i>=0;i--) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
673 if(reg_stack[i]>=0)
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
674 printf(" %s",register_name(reg_stack[i]));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
675 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
676 #endif
fea1b499d47b fix register var save
kono
parents:
diff changeset
677 printf("\n");
fea1b499d47b fix register var save
kono
parents:
diff changeset
678 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
679
fea1b499d47b fix register var save
kono
parents:
diff changeset
680 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
681 gexpr_init(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
682 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
683 while(reg_sp > 0) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
684 free_register(reg_stack[--reg_sp]);
fea1b499d47b fix register var save
kono
parents:
diff changeset
685 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
686 while(freg_sp > 0) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
687 free_register(freg_stack[--freg_sp]);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
688 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
689 while(dreg_sp > 0) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
690 free_register(dreg_stack[--dreg_sp]);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
691 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
692 if (cond_freg!=-1) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
693 if(car(cond_freg)==FREGISTER) free_register(cadr(cond_freg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
694 cond_freg=-1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
695 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
696 if (cond_dreg!=-1) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
697 if(car(cond_dreg)==DREGISTER) free_register(cadr(cond_dreg));
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
698 cond_dreg=-1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
699 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
700 if (cond_reg!=-1) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
701 if(car(cond_reg)==REGISTER) free_register(cadr(cond_reg));
fea1b499d47b fix register var save
kono
parents:
diff changeset
702 cond_reg=-1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
703 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
704 cmpreg = -1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
705 text_mode();
fea1b499d47b fix register var save
kono
parents:
diff changeset
706 gexpr_code_init();
fea1b499d47b fix register var save
kono
parents:
diff changeset
707 register_usage("gexpr_init");
fea1b499d47b fix register var save
kono
parents:
diff changeset
708 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
709
fea1b499d47b fix register var save
kono
parents:
diff changeset
710
fea1b499d47b fix register var save
kono
parents:
diff changeset
711 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
712 emit_init(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
713 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
714 free_all_register();
fea1b499d47b fix register var save
kono
parents:
diff changeset
715 max_reg_var=-1; max_freg_var=-1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
716 reg_sp = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
717 freg_sp = 0;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
718 dreg_sp = 0;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
719 text_mode();
fea1b499d47b fix register var save
kono
parents:
diff changeset
720 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
721
fea1b499d47b fix register var save
kono
parents:
diff changeset
722 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
723 register_var(int r) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
724 return r;
fea1b499d47b fix register var save
kono
parents:
diff changeset
725 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
726
fea1b499d47b fix register var save
kono
parents:
diff changeset
727
fea1b499d47b fix register var save
kono
parents:
diff changeset
728 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
729 get_register_var(NMTBL *n)
fea1b499d47b fix register var save
kono
parents:
diff changeset
730 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
731 int i;
fea1b499d47b fix register var save
kono
parents:
diff changeset
732 for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
733 if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
734 /* そのレジスタを使うことを宣言し */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
735 regs[REG_VAR_BASE-i]=USING_REG;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
736 regv[REG_VAR_BASE-i]=0;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
737 if (i>max_reg_var) max_reg_var=i;
fea1b499d47b fix register var save
kono
parents:
diff changeset
738 /* その場所を表す番号を返す */
fea1b499d47b fix register var save
kono
parents:
diff changeset
739 return list3(REGISTER,REG_VAR_BASE-i,(int)n);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
740 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
741 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
742 return list2(LVAR,new_lvar(size_of_int));
fea1b499d47b fix register var save
kono
parents:
diff changeset
743 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
744
fea1b499d47b fix register var save
kono
parents:
diff changeset
745 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
746 fregister_var(int r) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
747 return r;
fea1b499d47b fix register var save
kono
parents:
diff changeset
748 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
749
fea1b499d47b fix register var save
kono
parents:
diff changeset
750 int
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
751 get_dregister_var(NMTBL *n,int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
752 {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
753 int i,j;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
754 if (d) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
755 for(i=0;i<DREG_VAR_BASE-DREG_VAR_MIN;i++) {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
756 if (! regs[j=(DREG_VAR_BASE-i+DREG_OFFSET)]) { /* 使われていないなら */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
757 if (regs[dreg_pair0[j]] || regs[dreg_pair1[j]]) continue;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
758 regs[DREG_VAR_BASE-i+DREG_OFFSET]=USING_REG; /*そのレジスタを使うことを宣言し*/
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
759 regv[DREG_VAR_BASE-i+DREG_OFFSET]=0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
760 regs[dreg_pair0[j]] = regs[dreg_pair1[j]] = USING_REG;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
761 regv[dreg_pair0[j]] = regv[dreg_pair1[j]] = 0;
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
762 if (dreg_pair1[j]>max_reg_var) max_reg_var=dreg_pair1[j];
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
763 /* その場所を表す番号を返す */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
764 return list3(DREGISTER,DREG_VAR_BASE-i+DREG_OFFSET,(int)n);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
765 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
766 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
767 return list2(LVAR,new_lvar(size_of_double));
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
768 } else {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
769 for(i=0;i<FREG_VAR_BASE-FREG_VAR_MIN;i++) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
770 if (! regs[FREG_VAR_BASE-i+FREG_OFFSET]) { /* 使われていないなら */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
771 regs[FREG_VAR_BASE-i+FREG_OFFSET]=USING_REG; /*そのレジスタを使うことを宣言し*/
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
772 regv[FREG_VAR_BASE-i+FREG_OFFSET]=0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
773 if (i>max_freg_var) max_freg_var=i;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
774 /* その場所を表す番号を返す */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
775 return list3(FREGISTER,FREG_VAR_BASE-i+FREG_OFFSET,(int)n);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
776 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
777 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
778 return list2(LVAR,new_lvar(size_of_float));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
779 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
780 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
781
fea1b499d47b fix register var save
kono
parents:
diff changeset
782 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
783 emit_push()
fea1b499d47b fix register var save
kono
parents:
diff changeset
784 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
785 int new_reg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
786 if (reg_sp>MAX_MAX) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
787 new_reg = get_register();
fea1b499d47b fix register var save
kono
parents:
diff changeset
788 reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
789 ireg = creg = new_reg;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
790 regv[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
791 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
792
fea1b499d47b fix register var save
kono
parents:
diff changeset
793 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
794 emit_pop(int type)
fea1b499d47b fix register var save
kono
parents:
diff changeset
795 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
796 int xreg,reg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
797 xreg=pop_register();
fea1b499d47b fix register var save
kono
parents:
diff changeset
798 if (xreg<= -REG_LVAR_OFFSET) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
799 reg = get_register();
fea1b499d47b fix register var save
kono
parents:
diff changeset
800 code_rlvar(REG_LVAR_OFFSET+xreg,reg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
801 free_lvar(REG_LVAR_OFFSET+xreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
802 xreg = reg;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
803 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
804 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
805 return xreg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
806 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
807
fea1b499d47b fix register var save
kono
parents:
diff changeset
808 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
809 code_label(int labelno)
fea1b499d47b fix register var save
kono
parents:
diff changeset
810 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
811 printf("L_%d:\n",labelno);
fea1b499d47b fix register var save
kono
parents:
diff changeset
812 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
813
fea1b499d47b fix register var save
kono
parents:
diff changeset
814 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
815 code_gvar(int e1,int creg) {
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
816 printf("\tla %s,%s\n",register_name(creg),((NMTBL*)cadr(e1))->nm);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
817 regv[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
818 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
819
fea1b499d47b fix register var save
kono
parents:
diff changeset
820 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
821 code_rgvar(int e1,int creg) {
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
822 printf("\tlw %s,%s\n",register_name(creg),((NMTBL*)cadr(e1))->nm);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
823 regv[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
824 }
167
0197ca125567 mips short
kono
parents: 164
diff changeset
825 char *cload(int sign,int sz) { return sz==1?(sign?"lbu":"lb"):(sz==size_of_short?(sign?"lhu":"lh"):"lw");}
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
826 char *cstore(int sz) { return sz==1?"sb":(sz==size_of_short)?"sh":"sw";}
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
827 void
167
0197ca125567 mips short
kono
parents: 164
diff changeset
828 code_crgvar(int e1,int creg,int sign,int sz){
0197ca125567 mips short
kono
parents: 164
diff changeset
829 printf("\t%s %s,%s\n",cload(sign,sz),register_name(creg),((NMTBL*)cadr(e1))->nm);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
830 regv[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
831 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
832
fea1b499d47b fix register var save
kono
parents:
diff changeset
833
fea1b499d47b fix register var save
kono
parents:
diff changeset
834 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
835 code_register(int e2,int creg) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
836 if (creg!=e2)
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
837 printf("\tmove %s,%s\n",register_name(creg),register_name(e2));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
838 regv[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
839 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
840
fea1b499d47b fix register var save
kono
parents:
diff changeset
841
fea1b499d47b fix register var save
kono
parents:
diff changeset
842 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
843 code_rlvar(int e2,int reg) {
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
844 printf("\tlw %s,",register_name(reg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
845 lvar(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
846 regv[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
847 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
848
fea1b499d47b fix register var save
kono
parents:
diff changeset
849
fea1b499d47b fix register var save
kono
parents:
diff changeset
850 void
167
0197ca125567 mips short
kono
parents: 164
diff changeset
851 code_crlvar(int e2,int reg,int sign,int sz) {
0197ca125567 mips short
kono
parents: 164
diff changeset
852 printf("\t%s %s,",cload(sign,sz),register_name(reg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
853 lvar(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
854 regv[reg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
855 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
856
fea1b499d47b fix register var save
kono
parents:
diff changeset
857
fea1b499d47b fix register var save
kono
parents:
diff changeset
858 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
859 code_fname(NMTBL *n,int creg) {
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
860 printf("\tla %s,%s\n",register_name(creg),n->nm);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
861 regv[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
862 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
863
fea1b499d47b fix register var save
kono
parents:
diff changeset
864
fea1b499d47b fix register var save
kono
parents:
diff changeset
865 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
866 code_const(int e2,int creg) {
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
867 printf("\tli %s,%d\n",register_name(creg),e2);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
868 regv[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
869 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
870
fea1b499d47b fix register var save
kono
parents:
diff changeset
871
fea1b499d47b fix register var save
kono
parents:
diff changeset
872 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
873 code_neg(int creg) {
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
874 printf("\tsubu %s,$0,%s\n", register_name(creg), register_name(creg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
875 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
876
fea1b499d47b fix register var save
kono
parents:
diff changeset
877
fea1b499d47b fix register var save
kono
parents:
diff changeset
878 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
879 code_not(int creg) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
880 printf("\tnor %s,%s,%s\n",
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
881 register_name(creg), register_name(creg),register_name(creg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
882 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
883
fea1b499d47b fix register var save
kono
parents:
diff changeset
884
fea1b499d47b fix register var save
kono
parents:
diff changeset
885 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
886 code_lnot(int creg) {
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
887 /* if non zero 1 else 0 */
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
888 int dreg = get_register();
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
889 printf("\txori %s,%s,0x0\n",
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
890 register_name(dreg),register_name(creg));
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
891 printf("\tsltu %s,%s,1\n",
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
892 register_name(creg),register_name(dreg));
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
893 free_register(dreg);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
894 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
895
fea1b499d47b fix register var save
kono
parents:
diff changeset
896 void
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
897 code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
898 char *xrn,*drn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
899 int i,dreg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
900 if (car(e2)==REGISTER) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
901 printf("\taddu %s,%s,%d\n",
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
902 register_name(cadr(e2)),register_name(cadr(e2)), dir);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
903 if (cadr(reg)!=e2)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
904 printf("\tmove %s,%s\n",register_name(cadr(reg)),register_name(e2));
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
905 regv[reg]=1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
906 return;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
907 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
908 g_expr(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
909 xrn = register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
910 dreg=get_register(); if (!dreg) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
911 drn = register_name(dreg);
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
912 printf("\t%s %s,0(%s)\n",cload(sign,sz),drn,xrn);
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
913 printf("\taddu %s,%s,%d\n",drn,drn,dir);
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
914 printf("\t%s %s,0(%s)\n",cstore(sz),drn,xrn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
915 i=creg;creg=dreg;dreg=i;
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
916 regv[creg]=1; ireg=creg;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
917 free_register(dreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
918 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
919
fea1b499d47b fix register var save
kono
parents:
diff changeset
920
fea1b499d47b fix register var save
kono
parents:
diff changeset
921 void
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
922 code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
923 char *xrn,*crn,*nrn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
924 int dreg,nreg,i;
fea1b499d47b fix register var save
kono
parents:
diff changeset
925 if (car(e2)==REGISTER) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
926 printf("\tmove %s,%s\n",register_name(reg),register_name(cadr(e2)));
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
927 printf("\taddu %s,%s,%d\n",
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
928 register_name(cadr(e2)),register_name(cadr(e2)),dir);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
929 regv[reg]=1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
930 return;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
931 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
932 g_expr(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
933 crn = register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
934 dreg=get_register(); if (!dreg) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
935 xrn = register_name(dreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
936 nreg=get_register(); if (!nreg) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
937 nrn = register_name(nreg);
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
938 printf("\t%s %s,0(%s)\n",cload(sign,sz),xrn,crn);
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
939 printf("\taddu %s,%s,%d\n",nrn,xrn,dir);
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
940 printf("\t%s %s,0(%s)\n",cstore(sz),nrn,crn);
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
941 i=creg;creg=dreg;dreg=i;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
942 free_register(nreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
943 free_register(dreg);
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
944 regv[creg]=1; ireg=creg;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
945 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
946
fea1b499d47b fix register var save
kono
parents:
diff changeset
947
fea1b499d47b fix register var save
kono
parents:
diff changeset
948
fea1b499d47b fix register var save
kono
parents:
diff changeset
949 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
950 code_return(int creg) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
951 char *crn = register_name(creg);
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
952 printf("\tla %s,L_%d\n",crn,retcont);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
953 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
954
fea1b499d47b fix register var save
kono
parents:
diff changeset
955 #define R1SAVE 1
fea1b499d47b fix register var save
kono
parents:
diff changeset
956
fea1b499d47b fix register var save
kono
parents:
diff changeset
957 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
958 code_environment(int creg) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
959 /* save frame pointer */
fea1b499d47b fix register var save
kono
parents:
diff changeset
960 #if R1SAVE
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
961 printf("\tlw %s,0($fp)\n",register_name(creg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
962 #else
fea1b499d47b fix register var save
kono
parents:
diff changeset
963 int l = 0;
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
964 printf("\taddu %s,",register_name(creg));
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
965 printf("$fp,%d+L_%d\n",FUNC_LVAR,lvar_offset_label);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
966 #endif
fea1b499d47b fix register var save
kono
parents:
diff changeset
967 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
968
fea1b499d47b fix register var save
kono
parents:
diff changeset
969 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
970 code_bool(int e1) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
971 char *xrn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
972 int e2,e3;
fea1b499d47b fix register var save
kono
parents:
diff changeset
973 b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
974 creg = use_int(creg);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
975 xrn = register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
976 printf("\tli %s,0\n",xrn);
fea1b499d47b fix register var save
kono
parents:
diff changeset
977 jmp(e3=fwdlabel());
fea1b499d47b fix register var save
kono
parents:
diff changeset
978 fwddef(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
979 printf("\tli %s,1\n",xrn);
fea1b499d47b fix register var save
kono
parents:
diff changeset
980 fwddef(e3);
fea1b499d47b fix register var save
kono
parents:
diff changeset
981 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
982
fea1b499d47b fix register var save
kono
parents:
diff changeset
983 char *
fea1b499d47b fix register var save
kono
parents:
diff changeset
984 code_gt(int cond) {
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
985 return (cond?"\tslt %s,%s,%s\n\tbeq %s,$0,L_%d\n":
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
986 "\tslt %s,%s,%s\n\tbne %s,$0,L_%d\n");
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
987 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
988
fea1b499d47b fix register var save
kono
parents:
diff changeset
989 char *
fea1b499d47b fix register var save
kono
parents:
diff changeset
990 code_ugt(int cond) {
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
991 return (cond?"\tsltu %s,%s,%s\n\tbeq %s,$0,L_%d\n":
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
992 "\tsltu %s,%s,%s\n\tbne %s,$0,L_%d\n");
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
993 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
994
fea1b499d47b fix register var save
kono
parents:
diff changeset
995 char *
fea1b499d47b fix register var save
kono
parents:
diff changeset
996 code_ge(int cond) {
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
997 return (cond?"\tslt %s,%s,%s\n\txori %s,%s,0x1\n\tbeq %s,$0,L_%d\n":
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
998 "\tslt %s,%s,%s\n\txori %s,%s,0x1\n\tbne %s,$0,L_%d\n");
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
999 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1000
fea1b499d47b fix register var save
kono
parents:
diff changeset
1001 char *
fea1b499d47b fix register var save
kono
parents:
diff changeset
1002 code_uge(int cond) {
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1003 return (cond?"\tsltu %s,%s,%s\n\txori %s,%s,0x1\n\tbeq %s,$0,L_%d\n":
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1004 "\tsltu %s,%s,%s\n\txori %s,%s,0x1\n\tbne %s,$0,L_%d\n");
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1005 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1006
fea1b499d47b fix register var save
kono
parents:
diff changeset
1007 char *
fea1b499d47b fix register var save
kono
parents:
diff changeset
1008 code_eq(int cond) {
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1009 return (cond?"\tbeq %s,%s,L_%d\n":"\tbne %s,%s,L_%d\n");
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1010 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1011
fea1b499d47b fix register var save
kono
parents:
diff changeset
1012 void
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1013 code_cmp_crgvar(int e1,int sz) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1014 if (cmpreg==-1) cmpreg = get_register();
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1015 code_crgvar(cadr(e1),cmpreg,1,sz);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1016 regv[cmpreg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1017 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1018
fea1b499d47b fix register var save
kono
parents:
diff changeset
1019
fea1b499d47b fix register var save
kono
parents:
diff changeset
1020 void
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1021 code_cmp_crlvar(int e2,int sz) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1022 if (cmpreg==-1) cmpreg = get_register();
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1023 code_crlvar(e2,cmpreg,1,sz);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1024 regv[cmpreg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1025 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1026
fea1b499d47b fix register var save
kono
parents:
diff changeset
1027
fea1b499d47b fix register var save
kono
parents:
diff changeset
1028 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1029 code_cmp_rgvar(int e1) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1030 if (cmpreg==-1) cmpreg = get_register();
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1031 code_rgvar(e1,cmpreg);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1032 regv[cmpreg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1033 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1034
fea1b499d47b fix register var save
kono
parents:
diff changeset
1035
fea1b499d47b fix register var save
kono
parents:
diff changeset
1036 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1037 code_cmp_rlvar(int e2) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1038 if (cmpreg==-1) cmpreg = get_register();
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1039 code_rlvar(e2,cmpreg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1040 regv[cmpreg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1041 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1042
fea1b499d47b fix register var save
kono
parents:
diff changeset
1043
fea1b499d47b fix register var save
kono
parents:
diff changeset
1044 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1045 code_cmp_register(int e2) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1046 cmpreg = e2;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1047 /* prevent cmpreg freeing */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1048 regv[cmpreg]=2;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1049 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1050
fea1b499d47b fix register var save
kono
parents:
diff changeset
1051
fea1b499d47b fix register var save
kono
parents:
diff changeset
1052 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1053 ascii(char *s)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1054 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1055 printf("\t.ascii \"");
fea1b499d47b fix register var save
kono
parents:
diff changeset
1056 while(*s) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1057 if (*s=='\n')
fea1b499d47b fix register var save
kono
parents:
diff changeset
1058 printf("%cn",92);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1059 else if (*s<' ')
fea1b499d47b fix register var save
kono
parents:
diff changeset
1060 printf("%c%03o",92,*s);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1061 else if (*s=='\\')
fea1b499d47b fix register var save
kono
parents:
diff changeset
1062 printf("\\\\");
fea1b499d47b fix register var save
kono
parents:
diff changeset
1063 else if (*s==34)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1064 printf("%c%c",92,34);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1065 else
fea1b499d47b fix register var save
kono
parents:
diff changeset
1066 printf("%c",*s);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1067 s++;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1068 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1069 printf("\\0%c\n\t.align 2\n",34);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1070 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1071
fea1b499d47b fix register var save
kono
parents:
diff changeset
1072 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1073 code_string(int e1,int creg)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1074 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1075 char *s,*crn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1076 int lb;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1077 crn=register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1078
fea1b499d47b fix register var save
kono
parents:
diff changeset
1079 s=(char *)cadr(e1);
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1080 printf("\t.rdata\n\t.align 2\n");
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1081 lb=fwdlabel();
fea1b499d47b fix register var save
kono
parents:
diff changeset
1082 printf("L_%d:\n",lb);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1083 ascii(s);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1084 if (output_mode==TEXT_EMIT_MODE) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1085 printf(".text\n");
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1086 } else {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1087 text_mode();
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1088 }
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1089 printf("\tla %s,L_%d\n",crn,lb);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1090 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1091
fea1b499d47b fix register var save
kono
parents:
diff changeset
1092 #define MAX_COPY_LEN 20
fea1b499d47b fix register var save
kono
parents:
diff changeset
1093
fea1b499d47b fix register var save
kono
parents:
diff changeset
1094 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1095 emit_copy(int from,int to,int length,int offset,int value,int det)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1096 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1097 char *frn = register_name(from);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1098 char *trn = register_name(to);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1099 char *drn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1100 int fix = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1101 char *memmove = "memmove";
fea1b499d47b fix register var save
kono
parents:
diff changeset
1102 int dreg = get_register(); if (!dreg) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1103 drn = register_name(dreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1104
fea1b499d47b fix register var save
kono
parents:
diff changeset
1105 /* length <0 means upward direction copy */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1106 switch (length) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1107 case 0: break;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1108 case 1: case -1:
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1109 printf("\tlb %s,%d(%s)\n",drn,offset,frn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1110 printf("\tsb %s,%d(%s)\n",drn,offset,trn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1111 break;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1112 case 2: case -2:
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1113 printf("\tlh %s,%d(%s)\n",drn,offset,frn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1114 printf("\tsh %s,%d(%s)\n",drn,offset,trn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1115 break;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1116 case 4: case -4:
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1117 printf("\tlw %s,%d(%s)\n",drn,offset,frn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1118 printf("\tsw %s,%d(%s)\n",drn,offset,trn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1119 break;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1120 default:
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1121 if (-MAX_COPY_LEN<length && length <0) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1122 for(;length<=4;length+=4,offset-=4)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1123 emit_copy(from,to,4,offset,0,det);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1124 for(;length<=2;length+=2,offset-=2)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1125 emit_copy(from,to,2,offset,0,det);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1126 if(length>0)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1127 emit_copy(from,to,length,offset,0,det);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1128 break;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1129 } else if (length <=MAX_COPY_LEN) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1130 for(;length>=4;length-=4,offset+=4)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1131 emit_copy(from,to,4,offset,0,det);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1132 for(;length>=2;length-=2,offset+=2)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1133 emit_copy(from,to,2,offset,0,det);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1134 if(length>0)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1135 emit_copy(from,to,length,offset,0,det);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1136 break;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1137 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1138 code_save_stacks();
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1139 printf("\tli $6,%d\n",length);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1140 printf("\tmr $5,%s\n",frn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1141 printf("\tmr $4,%s\n",trn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1142 /* overrap must be allowed */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1143 printf("\tbl L_%s$stub\n",memmove);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1144 fix=0;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1145 set_creg(RET_REGISTER,0);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1146 if (creg!=to) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1147 free_register(to); to = creg;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1148 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1149 break;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1150 }
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1151 if (value) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1152 /* creg must point top of the destination data */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1153 /* this code is necessary for the value of assignment or function call */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1154 /* otherwise we don't need this */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1155 if (fix) printf("\taddi %s,%s,%d\n",trn,trn,fix);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1156 if(creg!=to) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1157 free_register(creg); creg=to;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1158 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1159 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1160 free_register(dreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1161 regv[from]=regv[to]=regv[dreg]=0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1162 regv[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1163 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1164
fea1b499d47b fix register var save
kono
parents:
diff changeset
1165 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
1166 struct_push(int e4,int t,int arg)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1167 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1168 int length,count;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1169 int dreg,sreg; char *drn,*crn,*srn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1170 g_expr(e4);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1171 length=size(t);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1172 if(length%size_of_int) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1173 length += size_of_int - (length%size_of_int);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1174 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1175 dreg = get_register(); if (!dreg) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1176 drn = register_name(dreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1177 crn = register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1178 if (length<MAX_COPY_LEN) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1179 sreg = get_register(); if (!sreg) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1180 srn = register_name(sreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1181 code_lvar(cadr(arg),sreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1182 for(count=0;length<MAX_COPY_LEN;count++,length-=size_of_int) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1183 if (length==0) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1184 free_register(sreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1185 free_register(dreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1186 return count;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1187 } else {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1188 printf("\tlw %s,%d(%s)\n",drn,length-size_of_int,crn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1189 printf("\tsw %s,%d(%s)\n",drn,length-size_of_int,srn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1190 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1191 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1192 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1193 code_lvar(cadr(arg),dreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1194 /* downward direction copy */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1195 emit_copy(creg,dreg,length,0,0,1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1196 if (dreg) free_register(dreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1197 return length/size_of_int;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1198 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1199
fea1b499d47b fix register var save
kono
parents:
diff changeset
1200 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1201 set_creg(int reg,int mode)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1202 {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1203 if (!is_int_reg(reg)) error(-1);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1204 if (reg!=creg) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1205 if (reg!=ireg && mode)
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
1206 printf("\tmove %s,%s\n",register_name(reg),register_name(ireg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1207 free_register(creg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1208 creg = ireg = reg;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1209 regs[creg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1210 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1211 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1212
fea1b499d47b fix register var save
kono
parents:
diff changeset
1213 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1214 set_freg(int reg,int mode)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1215 {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1216 if (!is_float_reg(reg)) error(-1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1217 if (reg!=creg) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1218 if (reg!=freg && mode) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1219 printf("\tfmove %s,%s\n",fregister_name(reg),fregister_name(freg));
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1220 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1221 free_register(creg);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1222 creg = freg = reg;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1223 regs[freg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1224 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1225 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1226
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1227 static void
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1228 move_dreg(int reg,int dreg)
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1229 {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1230 if (reg!=dreg) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1231 printf("\tmove %s,%s\n",dregister_name0(reg),
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1232 dregister_name0(dreg));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1233 printf("\tmove %s,%s\n",dregister_name1(reg),
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1234 dregister_name1(dreg));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1235 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1236 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1237
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1238 void
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1239 set_dreg(int reg,int mode)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1240 {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1241 if (!is_double_reg(reg)) error(-1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1242 if (reg!=creg) {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1243 if (mode) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1244 move_dreg(reg,dreg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1245 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1246 free_register(creg);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1247 creg = dreg = reg;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1248 regs[dreg]=1;
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1249 regs[dreg_pair0[dreg-DREG_OFFSET]]=1;
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1250 regs[dreg_pair1[dreg-DREG_OFFSET]]=1;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1251 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1252 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1253
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1254
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1255 void
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1256 use_var(int arg)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1257 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1258 if (car(arg)==REGISTER)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1259 regs[cadr(arg)]=USING_REG;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1260 else if (car(arg)==FREGISTER)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1261 regs[cadr(arg)]=USING_REG;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1262 else if (car(arg)==DREGISTER)
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1263 regs[cadr(arg)]=USING_REG;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1264 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1265
fea1b499d47b fix register var save
kono
parents:
diff changeset
1266 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1267 code_save_input_registers()
fea1b499d47b fix register var save
kono
parents:
diff changeset
1268 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1269 int args;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1270 NMTBL *n;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1271 int reg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1272 int tag;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1273 int lvar;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1274 int t;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1275 /* fnptr->dsp=list4(type,fnptr->dsp,(int)n,0); */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1276 int reg_offset = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1277 int offset = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1278
fea1b499d47b fix register var save
kono
parents:
diff changeset
1279 for(args = fnptr->dsp;args;args = cadr(args)) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1280 n = (NMTBL *)caddr(args);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1281 tag = n->sc;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1282 reg = n->dsp;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1283 if (!n||n==&null_nptr) error(REG_ERR);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1284 if (tag==REGISTER) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1285 /* regs[reg]==INPUT_REG case should be considered */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1286 n->dsp = offset;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1287 offset+=size_of_int;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1288 t = INT;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1289 reg += reg_offset; /* for duplicated floating point argument */
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1290 } else if (tag==FREGISTER) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1291 /* fregs[reg]==INPUT_REG case should be considered */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1292 n->dsp = offset;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1293 t = n->ty;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1294 if(t==FLOAT) { offset+=size_of_float; reg_offset+=1; }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1295 else if(t==DOUBLE) { offset+=size_of_double; reg_offset+=2; }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1296 else error(-1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1297 } else if (tag==DREGISTER) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1298 /* fregs[reg]==INPUT_REG case should be considered */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1299 n->dsp = offset;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1300 t = n->ty;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1301 if(t==FLOAT) { offset+=size_of_float; reg_offset+=1; }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1302 else if(t==DOUBLE) { offset+=size_of_double; reg_offset+=2; }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1303 else error(-1);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1304 } else {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1305 offset += size(n->ty);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1306 continue;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1307 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1308 n->sc = LVAR;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1309 lvar = list2(LVAR,n->dsp);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1310 g_expr_u(assign_expr0(list2(LVAR,n->dsp),list3(tag,reg,(int)n),n->ty,t));
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1311 if (tag==REGISTER||tag==DREGISTER||tag==FREGISTER) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1312 free_register(reg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1313 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1314 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1315 my_func_args = offset;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1316 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1317
fea1b499d47b fix register var save
kono
parents:
diff changeset
1318 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
1319 simple_args(int e3)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1320 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1321 return
fea1b499d47b fix register var save
kono
parents:
diff changeset
1322 !contains_in_list(e3,FUNCTION) &&
fea1b499d47b fix register var save
kono
parents:
diff changeset
1323 !contains_in_list(e3,CONV) &&
fea1b499d47b fix register var save
kono
parents:
diff changeset
1324 !contains_in_list(e3,RSTRUCT) &&
164
1c2a9232ea93 mc.h generation
kono
parents: 163
diff changeset
1325 !contains_in_list(e3,STASS)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1326 ;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1327 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1328
fea1b499d47b fix register var save
kono
parents:
diff changeset
1329 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
1330 caller_arg_offset_v(int arg)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1331 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1332 return ARG_LVAR_OFFSET+arg*size_of_int;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1333 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1334
fea1b499d47b fix register var save
kono
parents:
diff changeset
1335 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
1336 function(int e1)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1337 {
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
1338 int e2,e3,e4,nargs,t;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1339 int arg,reg_arg,freg_arg,arg_assign;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1340 int dots;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1341 int reg_arg_list=0,ret_type,special_lvar;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1342 NMTBL *fn = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1343 int jmp = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1344 char *jrn;
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1345 int iargs=0;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1346
fea1b499d47b fix register var save
kono
parents:
diff changeset
1347 special_lvar = -1;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1348 ret_type = cadr(cadddr(e1));
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1349 if (ret_type==CHAR) ret_type=INT;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1350
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1351 /* check argments type is DOTS? */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1352 t = caddr(cadddr(e1));
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1353 if (t==0 || t==DOTS) dots = 1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1354 else {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1355 dots = 0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1356 for(t = caddr(cadddr(e1));t;t = cadr(t)) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1357 if (car(t)==DOTS) dots = 1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1358 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1359 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1360
fea1b499d47b fix register var save
kono
parents:
diff changeset
1361 e2 = cadr(e1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1362 if (car(e2) == FNAME) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1363 fn=(NMTBL *)cadr(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1364 } else {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1365 jmp = get_register_var(0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1366 if (car(jmp)!=REGISTER) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1367 reg_arg_list = list2(jmp,reg_arg_list);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1368 g_expr(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1369 code_register(creg,cadr(jmp));
fea1b499d47b fix register var save
kono
parents:
diff changeset
1370 /* g_expr(assign_expr0(jmp,e2,INT,INT)); functions are lvalue */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1371 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1372
fea1b499d47b fix register var save
kono
parents:
diff changeset
1373 /* now all input register vars are free */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1374 code_save_stacks();
fea1b499d47b fix register var save
kono
parents:
diff changeset
1375 set_creg(CREG_REGISTER,0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1376 set_freg(FREG_FREGISTER,0);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1377 set_dreg(DREG_DREGISTER,0);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1378
fea1b499d47b fix register var save
kono
parents:
diff changeset
1379 nargs = reg_arg = freg_arg = arg_assign = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1380 for (e3 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1381 t=caddr(e3);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1382 e4 = car(e3);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1383 if(scalar(t)) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1384 if (reg_arg>=MAX_INPUT_REGISTER_VAR) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1385 arg = list2(LVAR,caller_arg_offset_v(nargs));
fea1b499d47b fix register var save
kono
parents:
diff changeset
1386 } else if (!simple_args(e3) && cadr(e3)) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1387 arg = get_register_var(0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1388 arg_assign = list2(
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1389 assign_expr0(get_input_register_var(reg_arg,0,0),
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1390 arg,t,t),
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1391 arg_assign);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1392 } else {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1393 arg = get_input_register_var(reg_arg,0,0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1394 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1395 use_var(arg); /* protect from input register free */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1396 reg_arg_list = list2(arg,reg_arg_list);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1397 g_expr_u(assign_expr0(arg,e4,t,t));
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1398 nargs ++ ; reg_arg++; iargs += size_of_int;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1399 continue;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1400 } else if (t==DOUBLE||t==FLOAT) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1401 if (freg_arg>=MAX_INPUT_DREGISTER_VAR) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1402 arg = list2(LVAR,caller_arg_offset_v(nargs));
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1403 } else if (!simple_args(e3) && cadr(e3)) {
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1404 arg = get_dregister_var(0,1);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1405 arg_assign = list2(
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1406 assign_expr0(get_input_dregister_var(freg_arg,0,0,1),
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1407 arg,t,t),
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1408 arg_assign);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1409 } else {
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1410 arg = get_input_dregister_var(freg_arg,0,0,1);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1411 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1412 use_var(arg); /* protect from input register free */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1413 reg_arg_list = list2(arg,reg_arg_list);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1414 g_expr_u(assign_expr0(arg,e4,t,t)); /* XXX */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1415 freg_arg++;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1416 nargs += size(t)/size_of_int;
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1417 if (t==DOUBLE) iargs += size(t);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1418 continue;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1419 } else if (car(t)==STRUCT||car(t)==UNION) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1420 arg = list2(LVAR,caller_arg_offset_v(nargs));
fea1b499d47b fix register var save
kono
parents:
diff changeset
1421 nargs += struct_push(e4,t,arg);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1422 iargs += ((size(t)+3)/size_of_int)*size_of_int;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1423 continue;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1424 } else {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1425 error(TYERR);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1426 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1427 ++nargs;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1428 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1429 if (max_func_args<nargs) max_func_args=nargs;
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1430 if (max_func_iargs<iargs) max_func_iargs=iargs;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1431 for(;arg_assign;arg_assign=cadr(arg_assign)) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1432 g_expr_u(car(arg_assign));
fea1b499d47b fix register var save
kono
parents:
diff changeset
1433 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1434 if (car(e2) == FNAME) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1435 printf("\tbl\tL_%s$stub\n",fn->nm);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1436 } else {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1437 jrn = register_name(cadr(jmp));
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1438 printf("\tj %s\n",jrn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1439 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1440 for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1441 arg = car(reg_arg_list);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1442 if (car(arg)==REGISTER||car(arg)==DREGISTER||car(arg)==FREGISTER)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1443 free_register(cadr(arg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1444 else if (car(arg)==LVAR&&cadr(arg)<0) free_lvar(cadr(arg));
fea1b499d47b fix register var save
kono
parents:
diff changeset
1445 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1446 if (ret_type==DOUBLE) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1447 set_dreg(RET_DREGISTER,0);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1448 regv[dreg]=1; regv[creg]=0;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1449 } else if (ret_type==FLOAT) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1450 set_freg(RET_FREGISTER,0);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1451 regv[freg]=1; regv[creg]=0;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1452 } else if (ret_type==VOID) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1453 regv[freg]=0; regv[creg]=0;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1454 } else {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1455 set_creg(RET_REGISTER,0);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1456 regv[freg]=0; regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1457 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1458 return ret_type;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1459 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1460
fea1b499d47b fix register var save
kono
parents:
diff changeset
1461 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1462 code_frame_pointer(int e3) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1463 #if R1SAVE
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1464 printf("\tmove $fp,%s\n",register_name(e3));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1465 #else
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1466 printf("\tmove $fp,%s\n",register_name(e3));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1467 #endif
fea1b499d47b fix register var save
kono
parents:
diff changeset
1468 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1469
fea1b499d47b fix register var save
kono
parents:
diff changeset
1470
fea1b499d47b fix register var save
kono
parents:
diff changeset
1471 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1472 code_fix_frame_pointer(int disp_offset) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1473 int l = 0;
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1474 printf("\tla $fp,");
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1475 printf("%d+L_%d($sp)\n",FUNC_LVAR,lvar_offset_label);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1476 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1477
fea1b499d47b fix register var save
kono
parents:
diff changeset
1478 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1479 code_jmp(char *s) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1480 max_reg_var = REG_VAR_BASE-REG_VAR_MIN;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1481 max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN;
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1482 printf("\tj L_%s\n",s);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1483 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1484
fea1b499d47b fix register var save
kono
parents:
diff changeset
1485
fea1b499d47b fix register var save
kono
parents:
diff changeset
1486 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1487 code_indirect_jmp(int e2) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1488 max_reg_var = REG_VAR_BASE-REG_VAR_MIN;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1489 max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN;
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1490 printf("\tj %s\n",register_name(e2));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1491 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1492
fea1b499d47b fix register var save
kono
parents:
diff changeset
1493 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
1494 rindirect(int e1) /* *(p +5 ) */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1495 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1496 char *crn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1497 int e2,e3,e4,offset;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1498
fea1b499d47b fix register var save
kono
parents:
diff changeset
1499 offset=0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1500 e3 = cadr(e2 = cadr(e1));
fea1b499d47b fix register var save
kono
parents:
diff changeset
1501 if (car(e2)==ADD) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1502 e4=caddr(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1503 if (car(e4)==CONST) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1504 offset=cadr(e4);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1505 e2=e3;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1506 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1507 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1508 g_expr(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1509 crn=register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1510 switch (car(e1)) {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1511 case FRINDIRECT:
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1512 printf("\tl.s %s,%d(%s)\n", fregister_name(freg),offset,crn);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1513 regv[creg]=0; regv[freg]=1;
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1514 creg = freg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1515 return FLOAT;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1516 case DRINDIRECT:
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1517 printf("\tlw %s,%d(%s)\n",
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1518 dregister_name0(dreg),offset,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1519 printf("\tlw %s,%d(%s)\n",
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1520 dregister_name1(dreg),offset+size_of_int,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1521 regv[creg]=0; regv[dreg]=1;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1522 creg = dreg;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1523 return DOUBLE;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1524 case CRINDIRECT:
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1525 printf("\tlb %s,%d(%s)\n",crn,offset,crn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1526 return CHAR;
163
fc8514c9d685 *** empty log message ***
kono
parents: 156
diff changeset
1527 case CURINDIRECT:
fc8514c9d685 *** empty log message ***
kono
parents: 156
diff changeset
1528 printf("\tlbu %s,%d(%s)\n",crn,offset,crn);
fc8514c9d685 *** empty log message ***
kono
parents: 156
diff changeset
1529 return UCHAR;
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1530 case SRINDIRECT:
0197ca125567 mips short
kono
parents: 164
diff changeset
1531 printf("\tlh %s,%d(%s)\n",crn,offset,crn);
0197ca125567 mips short
kono
parents: 164
diff changeset
1532 return SHORT;
0197ca125567 mips short
kono
parents: 164
diff changeset
1533 case SURINDIRECT:
0197ca125567 mips short
kono
parents: 164
diff changeset
1534 printf("\tlhu %s,%d(%s)\n",crn,offset,crn);
0197ca125567 mips short
kono
parents: 164
diff changeset
1535 return USHORT;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1536 case RINDIRECT:
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1537 printf("\tlw %s,%d(%s)\n",crn,offset,crn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1538 return INT;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1539 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1540 error(-1); return INT;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1541 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1542
fea1b499d47b fix register var save
kono
parents:
diff changeset
1543 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1544 code_assign_gvar(int e2,int creg,int byte) {
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
1545 char *crn,*name;
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
1546
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
1547 name = ((NMTBL*)cadr(e2))->nm;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1548 crn=register_name(creg);
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1549 if (byte==1) {
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
1550 printf("\tsb %s,%s\n",crn,name);
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1551 } if (byte==size_of_short) {
0197ca125567 mips short
kono
parents: 164
diff changeset
1552 printf("\tsh %s,%s\n",crn,name);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1553 } else {
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
1554 printf("\tsw %s,%s\n",crn,name);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1555 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1556 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1557
fea1b499d47b fix register var save
kono
parents:
diff changeset
1558 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1559 code_assign_lvar(int e2,int creg,int byte) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1560 char *crn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1561 crn=register_name(creg);
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1562 if (byte==1) {
0197ca125567 mips short
kono
parents: 164
diff changeset
1563 printf("\tsb %s,",crn);
0197ca125567 mips short
kono
parents: 164
diff changeset
1564 } else if (byte==size_of_short) {
0197ca125567 mips short
kono
parents: 164
diff changeset
1565 printf("\tsh %s,",crn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1566 } else {
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1567 printf("\tsw %s,",crn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1568 }
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1569 lvar(e2);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1570 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1571
fea1b499d47b fix register var save
kono
parents:
diff changeset
1572 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1573 code_assign_register(int e2,int byte,int creg) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1574 if (e2!=creg)
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1575 printf("\tmove %s,%s\n",register_name(e2),register_name(creg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1576 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1577
fea1b499d47b fix register var save
kono
parents:
diff changeset
1578 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1579 code_assign(int e2,int byte,int creg) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1580 char *drn=register_name(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1581 char *crn=register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1582
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1583 if (byte==1) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1584 printf("\tsb %s,0(%s)\n",crn,drn);
167
0197ca125567 mips short
kono
parents: 164
diff changeset
1585 } else if (byte==size_of_short) {
0197ca125567 mips short
kono
parents: 164
diff changeset
1586 printf("\tsh %s,0(%s)\n",crn,drn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1587 } else {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1588 printf("\tsw %s,0(%s)\n",crn,drn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1589 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1590 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1591 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1592
fea1b499d47b fix register var save
kono
parents:
diff changeset
1593
fea1b499d47b fix register var save
kono
parents:
diff changeset
1594 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1595 code_register_assop(int e2,int op,int byte) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1596 int reg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1597 int xreg = creg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1598 creg = reg = e2;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1599 tosop(op,xreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1600 creg = xreg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1601 if (creg!=reg)
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1602 printf("\tmove %s,%s\n",register_name(creg),register_name(reg));
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1603 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1604 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1605
fea1b499d47b fix register var save
kono
parents:
diff changeset
1606
fea1b499d47b fix register var save
kono
parents:
diff changeset
1607 void
163
fc8514c9d685 *** empty log message ***
kono
parents: 156
diff changeset
1608 code_assop(int op,int byte,int sign) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1609 char *xrn,*crn,*drn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1610 int xreg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1611 int edx = get_register(); if(!edx) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1612 xrn = register_name(xreg = emit_pop(0)); /* pop e3 value */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1613 regv[xreg]=regs[xreg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1614 printf("# assop\n\tmr %s,%s\n",register_name(edx),register_name(creg));
fea1b499d47b fix register var save
kono
parents:
diff changeset
1615 regv[edx]=1;
163
fc8514c9d685 *** empty log message ***
kono
parents: 156
diff changeset
1616 ld_indexx(byte,0,edx,sign);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1617 tosop(op,xreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1618 crn = register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1619 drn = register_name(edx);
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
1620 printf("\t%s %s,0(%s)\n",cstore(byte),crn,drn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1621 free_register(edx);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1622 emit_pop_free(xreg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1623 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1624 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1625
fea1b499d47b fix register var save
kono
parents:
diff changeset
1626
fea1b499d47b fix register var save
kono
parents:
diff changeset
1627 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1628 tosop(int op,int oreg)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1629 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1630 int dx;
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1631 char *orn,*crn;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1632
fea1b499d47b fix register var save
kono
parents:
diff changeset
1633 if(oreg==-1) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1634 error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1635 } else if (oreg<= -REG_LVAR_OFFSET) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1636 dx = get_register(); if (dx<0) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1637 code_rlvar(oreg+REG_LVAR_OFFSET,dx);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1638 oreg = dx;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1639 regv[oreg]=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1640 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1641
fea1b499d47b fix register var save
kono
parents:
diff changeset
1642 switch(op) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1643 case LSHIFT:
fea1b499d47b fix register var save
kono
parents:
diff changeset
1644 case ULSHIFT:
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1645 shift("sll",oreg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1646 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1647 return;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1648 case RSHIFT:
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1649 shift("srl",oreg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1650 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1651 return;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1652 case URSHIFT:
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1653 shift("sra",oreg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1654 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1655 return;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1656 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1657 orn = register_name(oreg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1658 crn = register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1659 switch(op) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1660 case ADD:
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1661 printf("\taddu %s,%s,%s\n",crn,crn,orn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1662 break;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1663 case SUB:
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1664 printf("\tsubu %s,%s,%s\n",crn,crn,orn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1665 break;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1666 case CMP:
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1667 printf("\tslt %s,%s\n",crn,orn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1668 break;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1669 case BAND:
fea1b499d47b fix register var save
kono
parents:
diff changeset
1670 printf("\tand %s,%s,%s\n",crn,crn,orn);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1671 break;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1672 case EOR:
fea1b499d47b fix register var save
kono
parents:
diff changeset
1673 printf("\txor %s,%s,%s\n",crn,crn,orn);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1674 break;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1675 case BOR:
fea1b499d47b fix register var save
kono
parents:
diff changeset
1676 printf("\tor %s,%s,%s\n",crn,crn,orn);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1677 break;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1678 case MUL:
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1679 printf("\tmult %s,%s,%s\n",crn,crn,orn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1680 break;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1681 case UMUL:
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1682 printf("\tmultu %s,%s,%s\n",crn,crn,orn);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1683 break;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1684 case DIV:
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1685 printf("\tdivw %s,%s,%s\n",crn,crn,orn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1686 break;
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
1687 case UDIV: case MOD: case UMOD:
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1688 printf("\t%s $0,%s,%s\n",(op==UDIV||op==UMOD)?"divu":"div",crn,orn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1689 printf("\t%s %s\n",(op==MOD||op==UMOD)?"mflo":"mfhi",crn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1690 printf("\t.set noreorder\n");
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1691 printf("\tbeql %s,$0,1f\n",orn);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1692 printf("\tbreak 7\n");
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1693 printf("1:\n");
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1694 printf("\t.set reorder\n");
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1695 break;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1696 default:
fea1b499d47b fix register var save
kono
parents:
diff changeset
1697 error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1698 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1699 if(oreg!=creg) free_register(oreg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1700 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1701 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1702
fea1b499d47b fix register var save
kono
parents:
diff changeset
1703
fea1b499d47b fix register var save
kono
parents:
diff changeset
1704 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1705 shift(char *op, int reg)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1706 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1707 char *crn = register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1708 char *rrn = register_name(reg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1709 printf("\t%s %s,%s,%s\n",op,crn,rrn,crn);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1710 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1711
fea1b499d47b fix register var save
kono
parents:
diff changeset
1712 void
163
fc8514c9d685 *** empty log message ***
kono
parents: 156
diff changeset
1713 ld_indexx(int byte, int n, int xreg,int sign)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1714 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1715 char *crn = register_name(creg);
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
1716 printf("\t%s %s,%d(%s)\n",cload(sign,byte),crn,n,
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
1717 register_name(xreg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1718 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1719
fea1b499d47b fix register var save
kono
parents:
diff changeset
1720 int
fea1b499d47b fix register var save
kono
parents:
diff changeset
1721 code_csvalue()
fea1b499d47b fix register var save
kono
parents:
diff changeset
1722 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1723 return creg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1724 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1725
fea1b499d47b fix register var save
kono
parents:
diff changeset
1726 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1727 code_cmpdimm(int e, int csreg)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1728 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1729 /* used in dosiwtch() */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1730 if(chk) return;
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
1731 creg = use_int(creg);
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1732 printf("\tli %s,%d\n",register_name(creg),e);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1733 cmpreg = csreg;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1734 regv[cmpreg]=2; /* prevent from freeing */
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1735 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1736
fea1b499d47b fix register var save
kono
parents:
diff changeset
1737 void
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
1738 code_opening(char *s)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1739 {
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1740 /* this is called once per month */
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1741 char *p=cheapp;
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1742
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
1743 printf("\t.file \"%s\"\n",s);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1744 /* printf("\t.version\t\"01.01\"\n"); */
fea1b499d47b fix register var save
kono
parents:
diff changeset
1745 /* printf("gcc2_compiled.:\n"); */
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1746 printf("\t.abicalls\n");
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1747 printf("\t.text\n");
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1748
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1749 if (asi) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1750 fclose(asi);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1751 asi = 0;
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1752 }
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1753 while ((*cheapp++ = *s++)) {
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1754 if (*s=='.') {
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1755 *cheapp++=*s++; *cheapp++='i';
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1756 *cheapp++=0;
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1757 break;
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1758 }
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1759 }
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1760 asi = fopen(p,"w");
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
1761 printf(".include \"%s\"\n",p);
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1762 if (!asi) error(-1);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1763 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1764
fea1b499d47b fix register var save
kono
parents:
diff changeset
1765 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1766 rexpr(int e1, int l1, char *s,int t)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1767 {
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1768 char *crn,*drn;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1769 if (cmpreg>=0) { free_register(cmpreg); cmpreg = -1; }
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1770
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1771 g_expr(cadr(e1));
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1772 emit_push();
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1773 g_expr(caddr(e1));
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
1774 cmpreg = emit_pop(0);
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1775 crn = register_name(creg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1776 drn = register_name(cmpreg);
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1777
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1778 if (s[1] == 's') {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1779 if (s[16]=='x') {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1780 /* slt $2,$2,$3; xroi $2,$2,0x1; beq $2,$0,L1 */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1781 printf(s,crn,drn,drn,crn,crn,crn,l1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1782 } else {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1783 /* slt $2,$2,$3; beq $2,$0,L1 */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1784 printf(s,crn,drn,drn,crn,l1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1785 }
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1786 } else {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1787 /* beq $2,$3,L1 */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1788 printf(s,crn,drn,l1);
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1789 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1790 free_register(cmpreg) ; cmpreg = -1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1791 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1792
fea1b499d47b fix register var save
kono
parents:
diff changeset
1793 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1794 jcond(int l, char cond)
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1795 {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1796 if (chk) return;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1797 if (cmpreg==-1) error(-1);
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
1798 printf("\tb%s %s,%s,L_%d\n",
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
1799 cond?"ne":"eq",
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
1800 register_name(creg),register_name(cmpreg),
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
1801 l);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1802 if (regv[cmpreg]==1) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1803 free_register(cmpreg); cmpreg = -1;
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1804 }
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1805 regv[creg]=0;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1806 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1807
fea1b499d47b fix register var save
kono
parents:
diff changeset
1808 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1809 jmp(int l)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1810 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1811 control=0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1812 if (chk) return;
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1813 printf("\tj\tL_%d\n",l);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1814 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1815
fea1b499d47b fix register var save
kono
parents:
diff changeset
1816 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1817 gen_comment(char *s)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1818 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1819 if (chk) return;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1820 printf("## %s",s);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1821 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1822
fea1b499d47b fix register var save
kono
parents:
diff changeset
1823 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1824 code_enter(char *name)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1825 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1826 if (output_mode!=TEXT_EMIT_MODE)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1827 text_mode();
fea1b499d47b fix register var save
kono
parents:
diff changeset
1828 else
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1829 printf("\t.align 3\n");
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1830 /* if (stmode!=STATIC)
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1831 printf(".globl _%s\n",name); */
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1832 printf(".ent %s\n",name);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1833 printf("_%s:\n",name);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1834 code_disp_label=fwdlabel();
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1835
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1836 printf("\t.set noreorder\n");
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1837 printf("\t.cpload $25\n");
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1838 printf("\t.set reorder\n");
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1839 printf("\tsubu $sp,$sp,L_%d\n",code_disp_label);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1840 printf("\t.cprestore L_%d\n",cprestore_label);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1841
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1842 max_func_args = 0;
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1843 max_func_iargs = 0;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1844 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1845
fea1b499d47b fix register var save
kono
parents:
diff changeset
1846
fea1b499d47b fix register var save
kono
parents:
diff changeset
1847 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1848 code_enter1(int args)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1849 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1850 set_creg(CREG_REGISTER,0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1851 set_freg(FREG_FREGISTER,0);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1852 set_dreg(DREG_DREGISTER,0);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1853 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1854
fea1b499d47b fix register var save
kono
parents:
diff changeset
1855 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1856 code_leave(char *name)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1857 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1858 int r1_offsetv;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1859 disp&= -size_of_int;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1860 r1_offsetv = -disp+max_func_args*size_of_int+code_disp_offset;
fea1b499d47b fix register var save
kono
parents:
diff changeset
1861
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1862 fprintf(asi,"L_%d=%d\n",code_disp_label,-r1_offsetv);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1863
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1864 local_table();
fea1b499d47b fix register var save
kono
parents:
diff changeset
1865 free_all_register();
fea1b499d47b fix register var save
kono
parents:
diff changeset
1866 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1867
fea1b499d47b fix register var save
kono
parents:
diff changeset
1868 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1869 enter(char *name)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1870 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1871 if (output_mode!=TEXT_EMIT_MODE)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1872 text_mode();
fea1b499d47b fix register var save
kono
parents:
diff changeset
1873 else
fea1b499d47b fix register var save
kono
parents:
diff changeset
1874 printf("\t.align 2\n");
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1875 /* if (stmode!=STATIC)
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1876 printf(".globl _%s\n",name); */
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1877 printf(".ent %s\n",name);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1878 printf("_%s:\n",name);
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1879
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1880 r1_offset_label = fwdlabel();
fea1b499d47b fix register var save
kono
parents:
diff changeset
1881 lvar_offset_label = fwdlabel();
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1882 disp_label = fwdlabel();
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1883 mask_label = fwdlabel();
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1884 mask1_label = fwdlabel();
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1885 fmask_label = fwdlabel();
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1886 fmask1_label = fwdlabel();
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1887 cprestore_label = fwdlabel();
132
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1888
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1889 printf("\t.frame $fp,L_%d,$31\n",r1_offset_label);
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1890 printf("\t.mask L_%d,L_%d\n",mask_label,mask1_label);
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1891 printf("\t.fmask L_%d,L_%d\n",fmask_label,fmask1_label);
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1892
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1893 printf("\t.set noreorder\n");
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1894 printf("\t.cpload $25\n");
07eb1249f07a *** empty log message ***
kono
parents: 131
diff changeset
1895 printf("\t.set reorder\n");
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1896 printf("\tsubu $sp,$sp,L_%d\n",disp_label);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1897 printf("\t.cprestore L_%d\n",cprestore_label);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1898 max_func_args = 0;
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1899 max_func_iargs = 0;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1900
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1901 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1902
fea1b499d47b fix register var save
kono
parents:
diff changeset
1903 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1904 enter1()
fea1b499d47b fix register var save
kono
parents:
diff changeset
1905 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1906 set_creg(CREG_REGISTER,0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1907 set_freg(FREG_FREGISTER,0);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
1908 set_dreg(DREG_DREGISTER,0);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1909 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1910
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1911 static unsigned int
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1912 code_mask_label()
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1913 {
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1914 int i;
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1915 unsigned int mask=0;
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1916 for(i=0;i<32;i++) {
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1917 if (i==28||i==31||(REG_VAR_MIN<=i&&i<=REG_VAR_MIN+max_reg_var)) {
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1918 mask |= (1<<i);
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1919 }
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1920 }
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1921 return mask;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1922 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1923
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1924 static unsigned int
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1925 code_fmask_label()
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1926 {
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1927 int i;
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1928 unsigned int mask=0;
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1929 for(i=0;i<32;i++) {
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1930 if (FREG_VAR_MIN<=i&&i<=FREG_VAR_MIN+max_freg_var) {
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1931 mask |= (1<<i);
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1932 }
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1933 }
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1934 return mask;
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1935 }
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1936
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1937
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1938 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
1939 leave(int control, char *name)
fea1b499d47b fix register var save
kono
parents:
diff changeset
1940 {
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
1941 int retcont1=0,sz;
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1942 int r1_offsetv;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1943
fea1b499d47b fix register var save
kono
parents:
diff changeset
1944 if (max_freg_var>=0 && max_freg_var<=3) max_freg_var=3;
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1945 reg_save =
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1946 (REAL_MAX_REGISTER-(REG_VAR_BASE-max_reg_var))*size_of_int;
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1947 freg_save =
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1948 (REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*size_of_float;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1949
fea1b499d47b fix register var save
kono
parents:
diff changeset
1950 if (control) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1951 code_set_return_register(1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1952 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1953 if (retcont) {
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1954 /* return from CbC segement */
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1955 if (control) jmp(retlabel);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1956 retcont1 = fwdlabel();
fea1b499d47b fix register var save
kono
parents:
diff changeset
1957 fwddef(retcont);
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1958 if (cadr(fnptr->ty)==FLOAT) {
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1959 if (freg!=RET_FREGISTER)
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1960 printf("\tmov.s %s,%s\n",register_name(RET_FREGISTER),
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1961 register_name(freg));
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1962 } else if (cadr(fnptr->ty)==DOUBLE) {
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1963 move_dreg(RET_DREGISTER,dreg);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1964 } else if (cadr(fnptr->ty)>0&&(
fea1b499d47b fix register var save
kono
parents:
diff changeset
1965 car(cadr(fnptr->ty))==STRUCT ||
fea1b499d47b fix register var save
kono
parents:
diff changeset
1966 car(cadr(fnptr->ty))==UNION)) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1967 sz = size(cadr(fnptr->ty));
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1968 printf("\tli $4,%d\n",sz);
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1969 printf("\tsubl $5,$4,$fp\n");
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1970 printf("\tlw $3,(%d)($fp)\n",(my_func_args-1)*size_of_int);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1971 emit_copy(6,3,sz,0,1,1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1972 } else if (cadr(fnptr->ty)!=VOID) {
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1973 if (creg!=RET_REGISTER)
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1974 printf("\tmove $3,%s\n",register_name(creg));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1975 }
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1976 printf("\tj L_%d\n",retcont1);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1977 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1978 fwddef(retlabel);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1979 if (retcont) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1980 fwddef(retcont1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
1981 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
1982 if (max_freg_var>=0) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1983 } else {
fea1b499d47b fix register var save
kono
parents:
diff changeset
1984 }
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1985 fprintf(asi,"L_%d=%d\n",r1_offset_label,0);
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1986 fprintf(asi,"L_%d=%d\n",lvar_offset_label,0);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1987 fprintf(asi,"L_%d=0x%x\n",mask_label,code_mask_label());
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1988 fprintf(asi,"L_%d=%d\n",mask1_label,0);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1989 fprintf(asi,"L_%d=0x%x\n",fmask_label ,code_fmask_label());
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1990 fprintf(asi,"L_%d=%d\n",fmask1_label,0);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
1991 fprintf(asi,"L_%d=%d\n",cprestore_label ,max_func_iargs);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
1992
fea1b499d47b fix register var save
kono
parents:
diff changeset
1993 disp &= -size_of_int;
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1994 r1_offsetv = 0;
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1995
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1996 printf("\tmove $sp,$fp\n");
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1997 printf("\tlw $31,%d($sp)\n",-disp);
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1998 printf("\tlw $fp,%d($sp)\n",-disp-4);
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
1999 printf("\taddu $sp,$sp,%d\n",r1_offsetv);
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
2000 printf("\tj $31\n");
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
2001 printf("\t.end print\n");
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
2002
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
2003 fprintf(asi,"L_%d=%d\n",disp_label,-r1_offsetv);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2004
fea1b499d47b fix register var save
kono
parents:
diff changeset
2005 code_offset_set();
fea1b499d47b fix register var save
kono
parents:
diff changeset
2006 local_table();
fea1b499d47b fix register var save
kono
parents:
diff changeset
2007 labelno++;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2008 free_all_register();
fea1b499d47b fix register var save
kono
parents:
diff changeset
2009 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2010
fea1b499d47b fix register var save
kono
parents:
diff changeset
2011
fea1b499d47b fix register var save
kono
parents:
diff changeset
2012 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2013 code_set_return_register(int mode) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2014 if (cadr(fnptr->ty)==DOUBLE) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2015 set_dreg(RET_DREGISTER,mode);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2016 } else if (cadr(fnptr->ty)==FLOAT) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2017 set_freg(RET_FREGISTER,mode);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2018 } else if (cadr(fnptr->ty)==VOID) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2019 } else {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2020 set_creg(RET_REGISTER,mode);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2021 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2022 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2023
fea1b499d47b fix register var save
kono
parents:
diff changeset
2024 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2025 code_set_fixed_creg(int mode,int type) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2026 if (type==FLOAT) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2027 if (cond_freg== -1) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2028 cond_freg = get_dregister_var(0,0);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2029 if(car(cond_freg)!=FREGISTER) error(-1);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2030 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2031 set_freg(cadr(cond_freg),mode);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2032 } else if (type==DOUBLE) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2033 if (cond_dreg== -1) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2034 cond_dreg = get_dregister_var(0,1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2035 if(car(cond_dreg)!=DREGISTER) error(-1);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2036 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2037 set_dreg(cadr(cond_dreg),mode);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2038 } else {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2039 if (cond_reg== -1) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2040 cond_reg = get_register_var(0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2041 if(car(cond_reg)!=REGISTER) error(-1);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2042 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2043 set_creg(cadr(cond_reg),mode);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2044 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2045 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2046
fea1b499d47b fix register var save
kono
parents:
diff changeset
2047 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2048 gen_gdecl(char *n, int gpc)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2049 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2050 if (stmode!=STATIC)
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2051 printf("\t.globl _%s\n",n);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2052 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2053
fea1b499d47b fix register var save
kono
parents:
diff changeset
2054 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2055 align(int t)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2056 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2057 if (t!=CHAR) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2058 if (data_alignment & 1)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2059 printf("\t.align 2\n");
fea1b499d47b fix register var save
kono
parents:
diff changeset
2060 data_alignment = 0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2061 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2062 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2063
fea1b499d47b fix register var save
kono
parents:
diff changeset
2064 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2065 emit_data(int e, int t, NMTBL *n)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2066 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2067 int l;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2068 double d;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2069 float f;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2070 char *name;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2071 name = n->nm;
156
da529eab5618 static initialization
kono
parents: 153
diff changeset
2072 if(mode!=GDECL&&mode!=STADECL) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2073 error(-1); return;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2074 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2075 if (chk) return;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2076 if (n->dsp != -1) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2077 n->dsp = -1; /* initiallized flag */
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2078 /* printf(".globl\t_%s\n",name); */
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2079 data_mode(name);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2080 align(t);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2081 printf("_%s:\n",name);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2082 } else {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2083 data_mode(0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2084 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2085 if(car(e)==CONST) {
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
2086 if (t==CHAR||t==UCHAR) {
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2087 printf("\t.byte %d\n",cadr(e));
fea1b499d47b fix register var save
kono
parents:
diff changeset
2088 if (data_alignment>0)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2089 data_alignment++;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2090 gpc += 1;
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
2091 } else if (t==SHORT||t==USHORT) {
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
2092 printf("\t.short %d\n",cadr(e));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2093 if (data_alignment>0) data_alignment++;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2094 gpc += 2;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2095 } else {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2096 printf("\t.word %d\n",cadr(e));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2097 gpc += size_of_int;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2098 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2099 } else if(t==DOUBLE) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2100 d = dcadr(e);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2101 printf("\t.word\t0x%x\n\t.word\t0x%x\n",code_d1(d),code_d2(d));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2102 } else if(t==FLOAT) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2103 f = dcadr(e);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2104 printf("\t.word\t0x%x\n",*(int *)&f);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2105 } else if(t!=CHAR) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2106 gpc += size_of_int;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2107 if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2108 printf("\t.word _%s\n",((NMTBL *)cadr(cadr(e)))->nm);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2109 } else if(car(e)==FNAME) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2110 printf("\t.word _%s\n",((NMTBL *)cadr(e))->nm);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2111 } else if(car(e)==GVAR) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2112 printf("\t.word _%s\n",((NMTBL *)cadr(e))->nm);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2113 } else if(car(e)==STRING) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2114 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2115 l = fwdlabel();
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2116 printf("\t.word L_%d\n",l);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2117 printf(".rdata\n\t.align 2\n");
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2118 printf("L_%d:\n",l);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2119 output_mode = RODATA_EMIT_MODE;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2120 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2121 ascii((char *)cadr(e));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2122 } else error(TYERR);
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
2123 } else error(TYERR);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2124 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2125
fea1b499d47b fix register var save
kono
parents:
diff changeset
2126 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2127 emit_data_closing(NMTBL *n)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2128 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2129 #ifdef DOT_SIZE
fea1b499d47b fix register var save
kono
parents:
diff changeset
2130 int lb;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2131 #endif
fea1b499d47b fix register var save
kono
parents:
diff changeset
2132 if (chk) return;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2133 if (mode==GDECL) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2134 data_mode(0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2135 #ifdef DOT_SIZE
fea1b499d47b fix register var save
kono
parents:
diff changeset
2136 lb=fwdlabel();
fea1b499d47b fix register var save
kono
parents:
diff changeset
2137 printf("L_%d:\n",lb);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2138 printf("\t.size\t%s,L_%d-%s\n",n->nm,lb,n->nm);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2139 #endif
fea1b499d47b fix register var save
kono
parents:
diff changeset
2140 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2141 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2142
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2143 void
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2144 global_table(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2145 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2146 NMTBL *n;
131
09379ec2a74b *** empty log message ***
kono
parents: 130
diff changeset
2147 int init;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2148 init=0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2149 for(n=ntable;n < &ntable[GSYMS];n++) {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2150 if ((n->sc == GVAR) && n->dsp != -1) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2151 /* n->dsp = -1 means initialized global */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2152 if (init==0) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2153 data_mode(0);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2154 init=1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2155 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2156 printf(".comm _%s,%d\n",n->nm,size(n->ty));
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2157 } else if ((n->sc==STATIC) && n->dsp != -1) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2158 /* n->dsp = -1 means initialized global */
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2159 if (init==0) {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2160 data_mode(0);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2161 init=1;
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2162 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2163 printf(".lcomm _%s,%d\n",n->nm,size(n->ty));
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2164 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2165 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2166 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2167
fea1b499d47b fix register var save
kono
parents:
diff changeset
2168 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2169 local_table(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2170 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2171 NMTBL *n;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2172 int init;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2173 init=0;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2174 /* static local variables */
fea1b499d47b fix register var save
kono
parents:
diff changeset
2175 for(n=ntable+GSYMS;n < &ntable[GSYMS+LSYMS];n++) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2176 if (n->sc == GVAR) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2177 if (init==0) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2178 data_mode(0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2179 init=1;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2180 }
156
da529eab5618 static initialization
kono
parents: 153
diff changeset
2181 if (n->dsp!=-1) /* n->dsp = -1 means initialized global */
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2182 printf(".lcomm _%s,%d\n",n->nm,size(n->ty));
fea1b499d47b fix register var save
kono
parents:
diff changeset
2183 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2184 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2185 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2186
fea1b499d47b fix register var save
kono
parents:
diff changeset
2187 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2188 text_mode(void)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2189 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2190 if (output_mode!=TEXT_EMIT_MODE) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2191 printf(".text\n");
fea1b499d47b fix register var save
kono
parents:
diff changeset
2192 printf("\t.align 2\n");
fea1b499d47b fix register var save
kono
parents:
diff changeset
2193 output_mode = TEXT_EMIT_MODE;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2194 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2195 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2196
fea1b499d47b fix register var save
kono
parents:
diff changeset
2197 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2198 data_mode(char *name)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2199 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2200 if (output_mode!=DATA_EMIT_MODE) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2201 printf(".data\n");
fea1b499d47b fix register var save
kono
parents:
diff changeset
2202 output_mode = DATA_EMIT_MODE;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2203 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2204 if (name)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2205 printf("\t.type\t%s,@object\n",name);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2206 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2207
fea1b499d47b fix register var save
kono
parents:
diff changeset
2208 char *
fea1b499d47b fix register var save
kono
parents:
diff changeset
2209 fstore(int d)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2210 {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2211 return (d?"stfd":"stfs");
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2212 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2213
fea1b499d47b fix register var save
kono
parents:
diff changeset
2214 char *
fea1b499d47b fix register var save
kono
parents:
diff changeset
2215 fload(int d)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2216 {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2217 return d?"lfd":"lfs";
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2218 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2219
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2220 static
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2221 void code_dpfunc(char *f)
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2222 {
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2223 if (max_func_iargs<16) max_func_iargs=16;
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2224 printf("\tjal %s\n",f);
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2225 }
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2226
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2227 void
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2228 code_cmp_dregister(int e2,int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2229 {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2230 char *frn,*grn;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2231 int greg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2232
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2233 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2234 printf("\tli.d $6,%g\n",0.0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2235 code_save_stacks();
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2236 move_dreg(4+DREG_OFFSET,freg);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2237 code_dpfunc("dpcmp");
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2238 if (max_func_iargs<16) max_func_iargs=16;
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2239 set_dreg(RET_DREGISTER,0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2240 return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2241 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2242 grn = register_name(greg = get_dregister(d));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2243 frn = register_name(e2);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2244 printf("\tli.s %s,%g\n",grn,0.0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2245 printf("\tc.eq.s %s,%s\n",grn,frn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2246 free_register(greg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2247 return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2248 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2249 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2250
fea1b499d47b fix register var save
kono
parents:
diff changeset
2251 void
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2252 code_dregister(int e2,int freg,int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2253 {
141
kono
parents: 139
diff changeset
2254 if (freg!=e2) {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2255 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2256 if (!is_double_reg(e2)) error(-1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2257 move_dreg(freg,e2);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2258 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2259 if (!is_float_reg(e2)) error(-1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2260 printf("\tfmr %s,%s\n",fregister_name(freg),fregister_name(e2));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2261 }
141
kono
parents: 139
diff changeset
2262 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2263 regv[freg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2264 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2265
fea1b499d47b fix register var save
kono
parents:
diff changeset
2266 void code_dassign_gvar(int e2,int freg,int d)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2267 {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2268 NMTBL *n = (NMTBL*)cadr(e2);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2269 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2270 if (!is_double_reg(freg)) error(-1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2271 printf("\tsw %s,0(%s)\n",dregister_name0(freg),n->nm);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2272 printf("\tsw %s,0(%s)\n",dregister_name1(freg),n->nm);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2273 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2274 printf("\ts.s %s,0(%s)\n",fregister_name(freg),n->nm);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2275 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2276 regv[freg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2277 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2278
fea1b499d47b fix register var save
kono
parents:
diff changeset
2279 void code_dassign_lvar(int e2,int freg,int d)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2280 {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2281 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2282 if (!is_double_reg(freg)) error(-1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2283 printf("\tsw %s,",dregister_name0(freg));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2284 lvar(e2);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2285 printf("\tsw %s,",dregister_name1(freg));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2286 e2 += size_of_double/2;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2287 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2288 printf("\ts.s %s,",fregister_name(freg));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2289 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2290 lvar(e2);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2291 regv[freg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2292 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2293
fea1b499d47b fix register var save
kono
parents:
diff changeset
2294 void code_dassign(int e2,int freg,int d)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2295 {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2296 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2297 if (!is_double_reg(freg)) error(-1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2298 printf("\tsw %s,0(%s)\n",dregister_name0(freg),register_name(e2));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2299 printf("\tsw %s,4(%s)\n",dregister_name1(freg),register_name(e2));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2300 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2301 printf("\ts.s %s,0(%s)\n",fregister_name(freg),register_name(e2));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2302 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2303 regv[freg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2304 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2305
fea1b499d47b fix register var save
kono
parents:
diff changeset
2306 void
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2307 code_dassign_dregister(int e2,int d,int freg) {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2308 /* これってさ、code_dregister と同じ? */
141
kono
parents: 139
diff changeset
2309 if (e2!=freg) {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2310 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2311 if (!is_double_reg(freg)) error(-1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2312 move_dreg(freg,e2);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2313 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2314 printf("\tmov.s %s,%s\n",fregister_name(e2),fregister_name(freg));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2315 }
141
kono
parents: 139
diff changeset
2316 }
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2317
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2318 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2319
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2320 static double d0 = 1.0;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2321
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2322 int
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2323 code_d1(double d)
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2324 {
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2325 int *i = (int *)&d0; int *j = (int *)&d;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2326 return (i[1] == 0x3ff00000)?j[0]:j[1];
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2327 }
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2328
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2329 int
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2330 code_d2(double d)
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2331 {
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2332 int *i = (int *)&d0; int *j = (int *)&d;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2333 return (i[1] == 0x3ff00000)?j[1]:j[0];
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2334 }
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2335
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2336 int
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2337 code_f(double d)
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2338 {
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2339 float f = d;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2340 int *j = (int *)&f;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2341 return *j;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2342 }
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2343
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2344 void
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2345 code_dconst(int e2,int freg,int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2346 {
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2347 double value = dcadr(e2);
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2348 char *frn;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2349 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2350 printf("\tli.d %s,%g\n",dregister_name0(freg),value);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2351 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2352 frn = fregister_name(freg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2353 printf("\tli.s %s,%g\n",frn,value);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2354 }
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2355 regv[freg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2356 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2357
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2358
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2359 void code_dneg(int freg,int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2360 {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2361 char *frn;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2362 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2363 code_save_stacks();
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2364 move_dreg(4+DREG_OFFSET,freg);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2365 code_dpfunc("dpneg");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2366 set_dreg(RET_DREGISTER,0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2367 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2368 frn = fregister_name(freg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2369 printf("\tfneg %s,%s\n",frn,frn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2370 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2371 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2372
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2373 void code_d2i(int freg0)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2374 {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2375 code_save_stacks();
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2376 set_dreg(RET_DREGISTER,1);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2377 code_dpfunc("dptoli");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2378 set_creg(RET_REGISTER,0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2379 regv[freg]=0;
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2380 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2381 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2382
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2383 void code_i2d(int creg0)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2384 {
141
kono
parents: 139
diff changeset
2385 code_save_stacks();
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2386 set_creg(RET_REGISTER,1);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2387 code_dpfunc("litodp");
150
f8271009a314 MIPS continue
kono
parents: 149
diff changeset
2388 set_dreg(RET_DREGISTER,0);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2389 regv[freg]=1;
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2390 regv[creg]=0;
141
kono
parents: 139
diff changeset
2391 }
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2392
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2393 void code_d2u(int freg0)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2394 {
141
kono
parents: 139
diff changeset
2395 code_save_stacks();
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2396 set_dreg(RET_DREGISTER,1);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2397 code_dpfunc("dptoul");
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2398 set_creg(RET_REGISTER,0);
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2399 regv[freg]=1;
141
kono
parents: 139
diff changeset
2400 }
kono
parents: 139
diff changeset
2401
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2402 void code_u2d(int creg0)
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2403 {
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2404 code_save_stacks();
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2405 set_creg(RET_REGISTER,1);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2406 code_dpfunc("ultodp");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2407 set_dreg(RET_DREGISTER,0);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2408 regv[freg]=1;
141
kono
parents: 139
diff changeset
2409 }
kono
parents: 139
diff changeset
2410
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2411 void code_d2f(int freg) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2412 code_save_stacks();
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2413 set_dreg(RET_DREGISTER,1);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2414 code_dpfunc("dptofp");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2415 set_freg(RET_FREGISTER,0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2416 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2417
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2418 void code_f2d(int freg) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2419 code_save_stacks();
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2420 set_freg(RET_FREGISTER,1);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2421 code_dpfunc("fptodp");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2422 set_dreg(RET_DREGISTER,0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2423 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2424
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2425 void code_f2i(int freg) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2426 printf("\ttrunc.w.s %s,%s,%s\n",register_name(freg),
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2427 register_name(freg),register_name(ireg));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2428 creg = ireg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2429 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2430
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2431 void code_f2u(int freg) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2432 printf("\ttrunc.w.s %s,%s,%s\n",register_name(freg),
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2433 register_name(freg),register_name(ireg));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2434 creg = ireg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2435 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2436
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2437 void code_i2f(int creg0) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2438 printf("\tcvt.s.w %s,%s\n",register_name(freg),register_name(freg));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2439 creg = freg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2440 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2441
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2442 void code_u2f(int creg0) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2443 printf("\tcvt.s.w %s,%s\n",register_name(freg),register_name(freg));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2444 creg = freg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2445 }
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2446
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2447 void code_drgvar(int e2,int d,int freg)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2448 {
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2449 char *name = ((NMTBL*)cadr(e2))->nm;
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2450 if (d) {
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2451 printf("\tlw %s,%s\n",dregister_name0(freg),name);
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2452 printf("\tlw %s,%s\n",dregister_name1(freg),name);
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2453 } else {
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2454 printf("\tl.s %s,%s\n",fregister_name(freg),name);
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2455 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2456 regv[freg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2457 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2458
fea1b499d47b fix register var save
kono
parents:
diff changeset
2459
fea1b499d47b fix register var save
kono
parents:
diff changeset
2460 void code_drlvar(int e2,int d,int freg)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2461 {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2462 if (d) {
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
2463 printf("\tlw %s,",dregister_name0(freg)); lvar(e2);
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
2464 printf("\tlw %s,",dregister_name1(freg)); lvar(e2+size_of_double/2);
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2465 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2466 printf("\tl.s %s,",fregister_name(freg)); lvar(e2);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2467 }
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2468 regv[freg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2469 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2470
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2471 void code_cmp_drgvar(int e2,int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2472 {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2473 char *frn;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2474 int g;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2475 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2476 code_save_stacks();
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2477 set_dreg(RET_DREGISTER,1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2478 code_drgvar(e2,d,RET_DREGISTER+2);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2479 code_dpfunc("dcmp");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2480 regv[dreg]=0;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2481 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2482 frn=fregister_name(freg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2483 g=get_dregister(d);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2484 code_drgvar(e2,d,g);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2485 printf("\tfc.eq.s %s,%s\n",frn,fregister_name(g));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2486 free_register(g);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2487 regv[freg]=0;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2488 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2489 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2490
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2491 void code_cmp_drlvar(int e2,int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2492 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2493 char *frn=fregister_name(freg);
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2494 int g;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2495 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2496 code_save_stacks();
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2497 set_dreg(RET_DREGISTER,1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2498 code_drgvar(e2,d,RET_DREGISTER+2);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2499 code_dpfunc("dcmp");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2500 regv[dreg]=0;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2501 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2502 g=get_dregister(d);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2503 code_drlvar(e2,d,g);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2504 printf("\tc.eq.s %s,%s\n",frn,fregister_name(g));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2505 free_register(g);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2506 regv[freg]=0;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2507 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2508 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2509
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2510 static void
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2511 dtosop0(char *opn,int e1,int d,int cmp)
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2512 {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2513 char *frn;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2514 char *grn;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2515 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2516 code_save_stacks();
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2517 set_dreg(RET_DREGISTER,1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2518 move_dreg(RET_DREGISTER+2,e1);
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2519 code_dpfunc(opn);
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2520 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2521 frn=fregister_name(freg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2522 grn=fregister_name(e1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2523 if (cmp) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2524 printf("\t%s %s,%s\n",opn,frn,grn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2525 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2526 printf("\t%s %s,%s,%s\n",opn,frn,frn,grn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2527 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2528 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2529 free_register(e1);
141
kono
parents: 139
diff changeset
2530 }
kono
parents: 139
diff changeset
2531
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2532
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2533 void dtosop(int op,int e1)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2534 {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2535 regv[freg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2536 switch(op) {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2537 case FADD: dtosop0("fadd",e1,0,0); return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2538 case DADD: dtosop0("dpadd",e1,1,0); return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2539 case FSUB: dtosop0("fadd",e1,0,0); return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2540 case DSUB: dtosop0("dpsub",e1,1,0); return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2541 case FDIV: dtosop0("fadd",e1,0,0); return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2542 case DDIV: dtosop0("dpdiv",e1,1,0); return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2543 case FMUL: dtosop0("fadd",e1,0,0); return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2544 case DMUL: dtosop0("dpmul",e1,1,0); return;
141
kono
parents: 139
diff changeset
2545 case DCMPGE:
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2546 case DCMP: dtosop0("dpcmp",e1,1,1); return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2547 case FCMPGE: dtosop0("c.le.s",e1,0,1); return;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2548 case FCMP: dtosop0("c.eq.s",e1,0,1); return;
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
2549 default:
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2550 error(-1); return;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2551 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2552 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2553
fea1b499d47b fix register var save
kono
parents:
diff changeset
2554 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2555 code_dassop(int op,int d) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2556 /* we have lvalue in creg, applied floating value is in freg */
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2557 char *frn;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2558 int xreg;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2559 char *crn=register_name(creg);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2560
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2561 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2562 xreg=emit_dpop(d);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2563 printf("\tlw %s,0(%s)\n",dregister_name0(freg),crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2564 printf("\tlw %s,%d(%s)\n",dregister_name1(freg),size_of_int,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2565 dtosop(op,xreg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2566 printf("\tsw %s,0(%s)\n",dregister_name0(freg),crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2567 printf("\tsw %s,%d(%s)\n",dregister_name1(freg),size_of_int,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2568 emit_dpop_free(xreg,d);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2569 creg = dreg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2570 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2571 xreg=emit_dpop(d);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2572 frn=fregister_name(freg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2573 crn=register_name(creg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2574
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2575 printf("\tl.s %s,0(%s)\n",frn,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2576 dtosop(op,xreg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2577 printf("\ts.s %s,0(%s)\n",frn,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2578 emit_dpop_free(xreg,d);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2579 creg = freg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2580 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2581 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2582 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2583
fea1b499d47b fix register var save
kono
parents:
diff changeset
2584
fea1b499d47b fix register var save
kono
parents:
diff changeset
2585 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2586 code_dpreinc(int e1,int e2,int d,int reg) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2587 char *frn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2588 char *crn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2589 int g;
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2590 char *grn;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2591
fea1b499d47b fix register var save
kono
parents:
diff changeset
2592 g_expr(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2593
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2594 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2595 crn=register_name(creg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2596 frn=fregister_name(freg);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2597
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2598 code_save_stacks();
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2599 set_dreg(RET_DREGISTER,0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2600 printf("\tlw $4,0(%s)\n",crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2601 printf("\tlw $5,%d(%s)\n",size_of_int,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2602 printf("\tli.d $6,1.0\n");
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2603 if (caddr(e1)>0)
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2604 code_dpfunc("dpadd");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2605 else
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2606 code_dpfunc("dpsub");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2607 printf("\tsw $2,0(%s)\n",crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2608 printf("\tsw $3,%d(%s)\n",size_of_int,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2609 creg = dreg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2610 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2611 crn=register_name(creg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2612 frn=fregister_name(freg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2613 grn=fregister_name(g=get_dregister(d));
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2614
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2615 printf("\tl.s %s,0(%s)\n",frn,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2616 printf("\tli.s %s,1.0\n",grn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2617 if (caddr(e1)>0)
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2618 printf("\tfadd %s,%s,%s\n",frn,frn,grn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2619 else
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2620 printf("\tfsub %s,%s,%s\n",frn,frn,grn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2621 printf("\ts.s %s,0(%s)\n",frn,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2622 free_register(g);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2623 creg = freg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2624 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2625 regv[creg]=1;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2626 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2627
fea1b499d47b fix register var save
kono
parents:
diff changeset
2628 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2629 code_dpostinc(int e1,int e2,int d,int reg) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2630 char *frn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2631 char *crn;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2632 int g;
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2633 char *grn;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2634
fea1b499d47b fix register var save
kono
parents:
diff changeset
2635 g_expr(e2);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2636
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2637 if (d) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2638 crn=register_name(creg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2639 g = get_dregister(d);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2640 set_dreg(RET_DREGISTER,0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2641 printf("\tlw $4,0(%s)\n",crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2642 printf("\tlw $5,%d(%s)\n",size_of_int,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2643 move_dreg(g,4+DREG_OFFSET);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2644 printf("\tli.d $6,1.0\n");
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2645 if (caddr(e1)>0)
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2646 code_dpfunc("dpadd");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2647 else
153
33b39002ac58 MIPS continue
kono
parents: 152
diff changeset
2648 code_dpfunc("dpsub");
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2649 set_dreg(RET_DREGISTER,0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2650 printf("\tsw $2,0(%s)\n",crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2651 printf("\tsw $3,%d(%s)\n",size_of_int,crn);
152
17c6598617f8 *** empty log message ***
kono
parents: 151
diff changeset
2652 free_register(dreg);
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2653 set_dreg(g,0);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2654 creg = g;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2655 } else {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2656 crn=register_name(creg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2657 frn=fregister_name(freg);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2658 grn=fregister_name(g=get_dregister(d));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2659
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2660 printf("\tl.s %s,0(%s)\n",frn,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2661 printf("\tli.s %s,1.0\n",grn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2662 if (caddr(e1)>0)
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2663 printf("\tfadd %s,%s,%s\n",frn,frn,grn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2664 else
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2665 printf("\tfsub %s,%s,%s\n",frn,frn,grn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2666 printf("\ts.s %s,0(%s)\n",grn,crn);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2667 free_register(g);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2668 creg = freg;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2669 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2670 regv[creg]=1;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2671
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2672 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2673
fea1b499d47b fix register var save
kono
parents:
diff changeset
2674 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2675 drexpr(int e1, int e2,int l1, int op)
fea1b499d47b fix register var save
kono
parents:
diff changeset
2676 {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2677 g_expr(list3(((op==FOP+EQ||op==FOP+NEQ)?DCMP:FCMPGE),e1,e2));
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2678 switch(op) {
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2679 case DOP+GE:
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2680 printf("\tbgez\tL_%d\n",l1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2681 break;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2682 case DOP+GT:
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2683 printf("\tbltz\tL_%d\n",l1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2684 break;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2685 case DOP+EQ:
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2686 printf("\tbeq\tL_%d\n",l1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2687 break;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2688 case DOP+NEQ:
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2689 printf("\tbne\tL_%d\n",l1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2690 break;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2691 case FOP+GE:
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2692 printf("\tbc1tl\tL_%d\n",l1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2693 break;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2694 case FOP+GT:
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2695 printf("\tbc1tl\tL_%d\n",l1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2696 break;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2697 case FOP+EQ:
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2698 printf("\tbc1f\tL_%d\n",l1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2699 break;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2700 case FOP+NEQ:
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2701 printf("\tbc1f\tL_%d\n",l1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2702 break;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2703 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2704 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2705
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2706 int emit_dpop(int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2707 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2708 int xreg,reg;
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2709 if (d)
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2710 xreg=pop_dregister();
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2711 else
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2712 xreg=pop_fregister();
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2713 if (xreg<= -REG_LVAR_OFFSET) {
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2714 reg = get_dregister(d);
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2715 code_drlvar(REG_LVAR_OFFSET+xreg,d,reg);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2716 free_lvar(REG_LVAR_OFFSET+xreg);
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2717 regv[reg]=1; xreg=reg;
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2718 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2719 return xreg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2720 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2721
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2722 void emit_dpop_free(int e1,int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2723 {
148
e0eba2993c37 MIPS version (incomplete)
kono
parents: 145
diff changeset
2724 free_register(e1);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2725 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2726
133
7d436c08e949 separate float / double flow
kono
parents: 132
diff changeset
2727 void emit_dpush(int d)
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2728 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2729 int new_reg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2730 if (freg_sp>MAX_MAX) error(-1);
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2731 new_reg = get_dregister(d);
151
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2732 if (d) {
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2733 dreg_stack[dreg_sp++] = dreg; /* push するかわりにレジスタを使う */
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2734 creg = dreg = new_reg;
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2735 regv[dreg]=1;
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2736 } else {
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2737 freg_stack[freg_sp++] = freg; /* push するかわりにレジスタを使う */
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2738 creg = freg = new_reg;
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2739 regv[freg]=1;
81032a1b8a5d MIPS continue
kono
parents: 150
diff changeset
2740 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2741 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2742
fea1b499d47b fix register var save
kono
parents:
diff changeset
2743 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2744 code_save_stacks()
fea1b499d47b fix register var save
kono
parents:
diff changeset
2745 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2746 int i,reg;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2747 for(i=0;i<reg_sp;i++) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2748 if ((reg=reg_stack[i])>=0) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2749 code_assign_lvar(
fea1b499d47b fix register var save
kono
parents:
diff changeset
2750 (reg_stack[i]=new_lvar(size_of_int)),reg,0);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2751 reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2752 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2753 }
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2754 for(i=0;i<dreg_sp;i++) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2755 if ((reg=dreg_stack[i])>=0) {
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2756 code_dassign_lvar(
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2757 (dreg_stack[i]=new_lvar(size_of_double)),reg,1);
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2758 dreg_stack[i]= dreg_stack[i]-REG_LVAR_OFFSET;
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2759 }
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2760 }
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2761 for(i=0;i<freg_sp;i++) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2762 if ((reg=freg_stack[i])>=0) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2763 code_dassign_lvar(
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2764 (freg_stack[i]=new_lvar(size_of_float)),reg,0);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2765 freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET;
fea1b499d47b fix register var save
kono
parents:
diff changeset
2766 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2767 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2768 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2769
fea1b499d47b fix register var save
kono
parents:
diff changeset
2770 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2771 emit_lib(char *p[])
fea1b499d47b fix register var save
kono
parents:
diff changeset
2772 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2773 while(*p) {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2774 printf("%s\n",*p++);
fea1b499d47b fix register var save
kono
parents:
diff changeset
2775 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2776 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2777
fea1b499d47b fix register var save
kono
parents:
diff changeset
2778 void
fea1b499d47b fix register var save
kono
parents:
diff changeset
2779 code_closing()
fea1b499d47b fix register var save
kono
parents:
diff changeset
2780 {
fea1b499d47b fix register var save
kono
parents:
diff changeset
2781 global_table();
fea1b499d47b fix register var save
kono
parents:
diff changeset
2782 /* printf("\t.ident \"Micro-C compiled\"\n"); */
149
0f36fdbcba9b mips no compile error
kono
parents: 148
diff changeset
2783 fclose(asi);
130
fea1b499d47b fix register var save
kono
parents:
diff changeset
2784 }
fea1b499d47b fix register var save
kono
parents:
diff changeset
2785
fea1b499d47b fix register var save
kono
parents:
diff changeset
2786 /* end */
fea1b499d47b fix register var save
kono
parents:
diff changeset
2787