annotate mc-codegen.c @ 61:8ffb8ca3fe34

separation of architecture dependent part.
author kono
date Thu, 20 Feb 2003 03:29:15 +0900
parents
children 0b068058dd67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1 /* Micro-C Generic Code Generatation Part */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2 /* $Id$ */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
3
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
4 #define EXTERN extern
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
5 #include "mc.h"
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
6 #include "mc-codegen.h"
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
7 #include "mc-code.h"
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
8
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
9 int creg; /* current register */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
10 int dreg; /* temporary register */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
11 int reg_sp; /* REGister Stack-Pointer */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
12
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
13 /*
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
14 creg currrent virtual register
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
15 dreg spare virtual register
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
16
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
17 rname[creg] currrent real register
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
18 rname[dreg] spare real register
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
19
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
20 regs[] virtual register usage
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
21 regv[] value in virtual register flag
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
22
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
23 reg_name[rname[creg]]
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
24 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
25
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
26 void remove0(int *parent,int e) ;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
27 void remove0_all(int *parent,int e) ;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
28 int is_same_type(int e1,int e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
29 void jump(int e1, int env);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
30 void machinop(int e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
31 void sassign(int e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
32 void assign(int e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
33 void assop(int e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
34
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
35 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
36 get_register(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
37 { /* 使われていないレジスタを調べる */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
38 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
39 for(i=0;i<MAX_REGISTER;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
40 if (! regs[i]) { /* 使われていないなら */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
41 regs[i]=1; /* そのレジスタを使うことを宣言し */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
42 return i; /* その場所を表す番号を返す */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
43 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
44 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
45 return -1; /* 空いている場所がないなら、それを表す -1 を返す */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
46 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
47
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
48 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
49 free_register(int i) { /* いらなくなったレジスタを開放 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
50 regv[i]=regs[i]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
51 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
52
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
53 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
54 register_full(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
55 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
56 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
57 for(i=0;i<MAX_REGISTER;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
58 if (! regs[i]) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
59 return 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
60 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
61 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
62 return 1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
63 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
64
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
65 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
66 free_register_count(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
67 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
68 int i,count;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
69 count = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
70 for(i=0;i<MAX_REGISTER;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
71 if (! regs[i] && ! regv[i]) count++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
72 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
73 return count;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
74 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
75
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
76 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
77 free_all_register(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
78 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
79 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
80 for(i=0;i<MAX_REGISTER;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
81 regs[i]=regv[i]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
82 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
83 creg = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
84 dreg = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
85 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
86 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
87
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
88 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
89 use_register_var(int i) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
90 regv[i]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
91 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
92
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
93 int creg_regvar = -1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
94 static int creg_regvar_back;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
95 static int creg_back;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
96
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
97 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
98 creg_destroy() {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
99 creg_back = creg; creg_regvar_back = creg_regvar;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
100 if (creg_regvar>=0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
101 creg = creg_regvar;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
102 creg_regvar=-1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
103 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
104
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
105 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
106 creg_un_destroy() {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
107 creg = creg_back; creg_regvar = creg_regvar_back;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
108 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
109
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
110 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
111 register_usage(char *s)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
112 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
113 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
114 printf("# %d: %s:",lineno,s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
115 printf(" creg=%s dreg=%s ",register_name(creg,0),register_name(dreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
116 for(i=0;i<MAX_REGISTER;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
117 printf("%d",regs[i]);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
118 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
119 printf(":");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
120 for(i=0;i<MAX_REGISTER;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
121 printf("%d",regv[i]);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
122 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
123 #if 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
124 printf(" regs_stack",register_name(creg,0),register_name(dreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
125 for(i=reg_sp;i>=0;i--) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
126 if(reg_stack[i]>=0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
127 printf(" %s",register_name(reg_stack[i],0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
128 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
129 #endif
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
130 printf("\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
131 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
132
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
133 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
134 gexpr_init(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
135 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
136 while(reg_sp > 0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
137 free_register(reg_stack[--reg_sp]);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
138 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
139 text_mode();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
140 gexpr_code_init();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
141 register_usage("gexpr_init");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
142 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
143
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
144
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
145 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
146 emit_init(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
147 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
148 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
149 for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; regv[i]=0;rname[i]=i;}
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
150 free_all_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
151 reg_sp = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
152 text_mode();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
153 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
154
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
155 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
156 virtual(int real)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
157 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
158 int real_v,i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
159 real_v = -1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
160 for(i=0;i<MAX_REGISTER;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
161 if (rname[i]==real) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
162 real_v=i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
163 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
164 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
165 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
166 return real_v;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
167 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
168
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
169 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
170 pop_register(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
171 { /* レジスタから値を取り出す */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
172 return reg_stack[--reg_sp];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
173 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
174
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
175 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
176 stack_used(void) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
177 return reg_stack[--reg_sp]<0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
178 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
179
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
180 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
181 emit_pop_free(int xreg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
182 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
183 if (xreg==dreg) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
184 regv[dreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
185 } else if (xreg!=-1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
186 free_register(xreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
187 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
188 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
189
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
190 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
191 gexpr(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
192 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
193 gexpr_init();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
194 #if 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
195 if(lineno==2862) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
196 g_expr(e1); /*break here*/
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
197 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
198 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
199 #endif
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
200 g_expr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
201 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
202
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
203 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
204 csvalue()
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
205 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
206 return rname[creg]; /* for switch value */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
207 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
208
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
209 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
210 g_expr(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
211 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
212 int e2,e3/*,e4*/;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
213 NMTBL *n;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
214
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
215 if (chk) return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
216 e2 = cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
217 switch (car(e1)){
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
218 case GVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
219 code_gvar(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
220 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
221 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
222 case RGVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
223 code_rgvar(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
224 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
225 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
226 case CRGVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
227 code_crgvar(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
228 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
229 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
230 case LVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
231 code_lvar(lvar(e2));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
232 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
233 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
234 case REGISTER:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
235 /* this is of course redundant... */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
236 /* we can use rname for this? */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
237 /* or why not creg=e2? */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
238 code_register(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
239 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
240 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
241 case RLVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
242 code_rlvar(lvar(e2));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
243 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
244 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
245 case CRLVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
246 code_crlvar(lvar(e2));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
247 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
248 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
249 case FNAME:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
250 code_fname(((NMTBL *)(e2))->nm);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
251 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
252 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
253 case CONST: /* 代入する値が0でも特別な処理はしない */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
254 code_const(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
255 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
256 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
257 case STRING:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
258 string(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
259 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
260 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
261 case FUNCTION:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
262 function(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
263 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
264 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
265 case CODE:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
266 jump(e2,caddr(e1));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
267 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
268 case INDIRECT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
269 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
270 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
271 case RINDIRECT: case CRINDIRECT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
272 rindirect(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
273 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
274 case ADDRESS:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
275 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
276 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
277 case MINUS: /* レジスタに対し、neglを実行すれば実現可能 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
278 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
279 code_neg();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
280 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
281 case BNOT: /* ~ */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
282 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
283 code_not();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
284 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
285 case LNOT: /* ! */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
286 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
287 code_lnot();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
288 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
289 case PREINC:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
290 code_preinc(e1,e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
291 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
292 case POSTINC:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
293 code_postinc(e1,e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
294 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
295 case CPOSTINC:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
296 /* char *p; *p++ */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
297 code_cpostinc(e1,e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
298 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
299 case CPREINC:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
300 code_cpreinc(e1,e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
301 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
302 case CPOSTDEC:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
303 code_cpostdec(e1,e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
304 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
305 case CPREDEC:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
306 code_cpredec(e1,e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
307 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
308 case MUL: case UMUL:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
309 case DIV: case UDIV:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
310 case MOD: case UMOD:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
311 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
312 case ADD: case SUB: case BAND: case EOR: case BOR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
313 machinop(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
314 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
315 case COND:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
316 e2=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
317 b_expr(cadr(e1),0,e2,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
318 code_set_fixed_creg(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
319 g_expr(caddr(e1));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
320 /* e4 = rname[creg]; this is a bad idea */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
321 code_set_fixed_creg(1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
322 jmp(e3=fwdlabel());
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
323 fwddef(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
324 code_set_fixed_creg(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
325 g_expr(cadddr(e1));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
326 code_set_fixed_creg(1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
327 fwddef(e3);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
328 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
329 case SASS:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
330 sassign(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
331 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
332 case ASS: case CASS:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
333 assign(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
334 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
335 case ASSOP: case CASSOP:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
336 assop(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
337 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
338 case RSTRUCT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
339 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
340 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
341 case COMMA:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
342 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
343 g_expr(caddr(e1));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
344 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
345 case RETURN:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
346 n = (NMTBL *)e2;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
347 if (retcont==0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
348 retcont=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
349 code_return(creg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
350 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
351 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
352 case ENVIRONMENT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
353 code_environment(creg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
354 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
355 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
356 default:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
357 code_bool(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
358 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
359 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
360 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
361
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
362 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
363 bexpr(int e1, char cond, int l1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
364 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
365 gexpr_init();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
366 b_expr(e1,cond,l1,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
367 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
368
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
369 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
370 b_expr(int e1, char cond, int l1,int err)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
371 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
372 int e2,l2;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
373 if (chk) return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
374 e2=cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
375 switch(car(e1)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
376 case LNOT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
377 b_expr(e2,!cond,l1,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
378 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
379 case GT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
380 rexpr(e1,l1,code_gt(cond));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
381 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
382 case UGT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
383 rexpr(e1,l1,code_ugt(cond));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
384 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
385 case GE:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
386 rexpr(e1,l1,code_ge(cond));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
387 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
388 case UGE:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
389 rexpr(e1,l1,code_uge(cond));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
390 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
391 case LT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
392 rexpr(e1,l1,code_ge(!cond));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
393 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
394 case ULT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
395 rexpr(e1,l1,code_uge(!cond));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
396 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
397 case LE:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
398 rexpr(e1,l1,code_gt(!cond));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
399 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
400 case ULE:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
401 rexpr(e1,l1,code_ugt(!cond));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
402 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
403 case EQ:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
404 rexpr(e1,l1,code_eq(cond));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
405 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
406 case NEQ:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
407 rexpr(e1,l1,code_eq(!cond));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
408 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
409 case LAND:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
410 b_expr(e2,0,cond?(l2=fwdlabel()):l1,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
411 b_expr(caddr(e1),cond,l1,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
412 if(cond) fwddef(l2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
413 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
414 case LOR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
415 b_expr(e2,1,cond?l1:(l2=fwdlabel()),0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
416 b_expr(caddr(e1),cond,l1,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
417 if(!cond) fwddef(l2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
418 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
419 case CRGVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
420 code_cmp_crgvar(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
421 jcond(l1,cond);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
422 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
423 case CRLVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
424 code_cmp_crlvar(lvar(e2));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
425 jcond(l1,cond);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
426 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
427 case RGVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
428 code_cmp_rgvar(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
429 jcond(l1,cond);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
430 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
431 case RLVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
432 code_cmp_rlvar(lvar(e2));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
433 jcond(l1,cond);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
434 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
435 case REGISTER:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
436 code_cmp_register(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
437 jcond(l1,cond);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
438 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
439 case CONST:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
440 if((cond&&e2)||(!cond&&!e2)) jmp(l1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
441 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
442 default:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
443 if(err) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
444 error(-1); return; /* recursice g_expr/b_expr */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
445 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
446 g_expr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
447 code_cmp_register(creg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
448 jcond(l1,cond);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
449 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
450 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
451 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
452
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
453
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
454 /* goto arguments list */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
455 /* target list4(list2(tag,disp),cdr,ty,source_expr) */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
456 /* source expr=listn(tag,...) */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
457 /* source (after) list2(tag,disp) */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
458 /* source list list3(e,cdr,sz) */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
459
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
460 #define DEBUG_PARALLEL_ASSIGN 1
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
461
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
462 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
463 overrap(int t,int sz,int source)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
464 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
465 int s,s0,s1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
466 int t0=cadr(t);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
467 int t1=t0+sz;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
468 for(;source;source=cadr(source)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
469 s=car(source); s0=cadr(s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
470 if(car(s)==REGISTER && car(t)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
471 if(s0==t0) return s;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
472 } else if (is_same_type(s,t)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
473 s1=s0+caddr(source);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
474 #if DEBUG_PARALLEL_ASSIGN>1
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
475 printf("# ovedrrap source %d t0 %d t1 %d\n",car(car(t)),t0,t1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
476 printf("# ovedrrap target %d s0 %d s1 %d\n",car(car(source)),s0,s1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
477 printf("# ovedrrap equal = %d\n",((t0<=s0&&s0<t1)||(t0<s1&&s1<=t1)));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
478 #endif
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
479 if((t0<=s0&&s0<t1)||(t0<s1&&s1<=t1)) return s;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
480 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
481 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
482 return 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
483 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
484
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
485 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
486 remove_target(int *target,int t,int *use)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
487 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
488 int use0=*use;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
489 while(use0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
490 if (car(use0)==t) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
491 free_register(caddr(use0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
492 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
493 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
494 use0 = cadr(use0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
495 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
496 remove0(target,t);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
497 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
498
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
499 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
500 save_target(int t,int s,int *target,int *use,int sz,int ty)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
501 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
502 int e1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
503 /*新しいレジスタ(or スタック)を取得する*/
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
504 if (sz==size_of_int && (e1=get_register())!=-1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
505 *use=list3(t,*use,e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
506 e1=list2(REGISTER,e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
507 g_expr(assign_expr0(e1,s,ty,ty));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
508 *target = append4(*target,t,ty,e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
509 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
510 disp-=sz;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
511 g_expr(assign_expr0((e1=list2(LVAR,disp)),s,ty,ty));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
512 *target = append4(*target,t,ty,e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
513 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
514 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
515
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
516 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
517 circular_dependency(int t,int s,int *target,int *source)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
518 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
519 int target0=*target;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
520 int t1,sz,ty,s1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
521 while(target0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
522 if (cadddr(target0)==s) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
523 t1=car(target0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
524 s=cadddr(target0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
525 sz=size(ty=caddr(target0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
526 if(t==t1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
527 #if DEBUG_PARALLEL_ASSIGN
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
528 printf("# circular dependency %d ty %d+%d sz %d\n",car(t1),ty,cadr(t1),sz);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
529 #endif
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
530 return 1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
531 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
532 if ((s1=overrap(t1,sz,*source))) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
533 /* another overrap start over */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
534 return circular_dependency(t,s1,target,source);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
535 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
536 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
537 target0=cadr(target0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
538 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
539 return 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
540 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
541
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
542 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
543 parallel_assign(int *target,int *source,int *processing,int *use)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
544 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
545 int t,s,sz,ty,target0,s1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
546 while(*target) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
547 target0=*target;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
548 while(target0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
549 t=car(target0); s=cadddr(target0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
550 sz=size(ty=caddr(target0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
551 if(car(t)==car(s) && cadr(t)==cadr(s)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
552 /*書き込み先が自分自身*/
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
553 #if DEBUG_PARALLEL_ASSIGN
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
554 printf("# remove same %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
555 #endif
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
556 remove_target(target,t,use);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
557 /* 破壊されては困るので、source listからは除かない */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
558 } else if (!(s1=overrap(t,sz,*source))) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
559 /* 重なってないので安心して書き込める */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
560 #if DEBUG_PARALLEL_ASSIGN
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
561 printf("# normal assign %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
562 #endif
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
563 g_expr(assign_expr0(t,s,ty,ty));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
564 remove_target(target,t,use); remove0(source,s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
565 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
566 if(circular_dependency(t,s1,target,source)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
567 #if DEBUG_PARALLEL_ASSIGN
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
568 printf("# saving %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
569 #endif
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
570 remove_target(target,t,use); remove0(source,s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
571 save_target(t,s,target,use,sz,ty);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
572 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
573 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
574 target0=cadr(target0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
575 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
576 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
577 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
578
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
579 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
580 remove0(int *parent,int e)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
581 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
582 int list;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
583 while ((list=*parent)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
584 if (car(list)==e) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
585 *parent= cadr(list); return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
586 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
587 parent=&cadr(list);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
588 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
589 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
590 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
591
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
592 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
593 remove0_all(int *parent,int e)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
594 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
595 int list;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
596 while ((list=*parent)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
597 if (car(list)==e) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
598 *parent= cadr(list);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
599 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
600 parent=&cadr(list);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
601 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
602 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
603 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
604
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
605 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
606 is_simple(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
607 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
608 return (
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
609 e1==CONST || e1==FNAME || e1==LVAR || e1==REGISTER ||
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
610 e1==GVAR || e1==RGVAR || e1==RLVAR || e1==CRLVAR || e1==CRGVAR
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
611 );
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
612 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
613
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
614 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
615 is_same_type(int e1,int e2)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
616 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
617 int ce1=car(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
618 int ce2=car(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
619 return (
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
620 (ce1==LVAR && (ce2==RLVAR||ce2==CRLVAR))
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
621 || (ce2==LVAR && (ce1==RLVAR||ce1==CRLVAR))
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
622 || (ce1==GVAR && (ce2==RGVAR||ce2==CRGVAR))
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
623 || (ce2==GVAR && (ce1==RGVAR||ce1==CRGVAR))
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
624 );
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
625 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
626
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
627 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
628 is_memory(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
629 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
630 int ce1=car(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
631 return (
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
632 ce1==LVAR ||ce1==RLVAR||ce1==CRLVAR ||
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
633 ce1==GVAR ||ce1==RGVAR||ce1==CRGVAR ||
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
634 ce1==REGISTER
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
635 );
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
636 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
637
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
638 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
639 jump(int e1, int env)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
640 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
641 int e2,e3,e4,sz,arg_size,ty,max_regs,regs;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
642 int t0,s0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
643 NMTBL *code0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
644 int target = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
645 int source = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
646 int processing = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
647 int use = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
648
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
649 /* まず、サイズを計算しながら、決まった形に落す。 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
650
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
651 arg_size = 0; regs = 0; max_regs = MAX_REGISTER_VAR-1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
652 for (e3 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
653 e2 = car(e3); sz = size(ty=caddr(e3));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
654 if (regs <= max_regs&&scalar(ty)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
655 target=list4(list2(REGISTER,register_var(regs++)), target,ty,e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
656 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
657 target=list4(list2(LVAR,0), target,ty,e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
658 arg_size += sz;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
659 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
660 #if DEBUG_PARALLEL_ASSIGN
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
661 printf("# target %d ty %d+%d sz %d\n",car(car(target)),ty,cadr(car(target)),sz);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
662 #endif
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
663 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
664
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
665 /* disp を飛び先似合わせて修正 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
666 if (fnptr->sc==CODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
667 if (-arg_size<disp) disp = -arg_size;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
668 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
669 if (disp_offset-arg_size<disp) disp = disp_offset-arg_size;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
670 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
671
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
672 /* 複雑な式を前もって計算しておく */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
673 /* 必要なら局所変数を用いる。 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
674 /* 局所変数へのオフセットを覚えておく */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
675
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
676 for (e2 = target; e2; e2 = cadr(e2)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
677 t0=car(e2); s0=cadddr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
678 sz=size(ty=caddr(e2));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
679 if(car(t0)==LVAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
680 /* ここで、書込先アドレスを決める */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
681 cadr(t0)=-arg_size;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
682 arg_size-=sz;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
683 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
684 if (!is_simple(car(s0))) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
685 disp-=sz;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
686 g_expr(assign_expr0((e4=list2(LVAR,disp)),s0,ty,ty));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
687 cadddr(e2)=e4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
688 s0=e4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
689 } else if (is_same_type(t0,s0)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
690 if(cadr(t0)==cadr(s0)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
691 #if DEBUG_PARALLEL_ASSIGN
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
692 printf("# remove same memory %d ty %d+%d sz %d\n",car(t0),ty,cadr(t0),sz);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
693 #endif
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
694 /* we should check size also (but currently useless */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
695 remove0(&target,t0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
696 /* still we have source to avoid overwrite */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
697 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
698 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
699 if(is_memory(s0)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
700 source=list3(s0,source,sz);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
701 #if DEBUG_PARALLEL_ASSIGN
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
702 printf("# source %d ty %d+%d sz %d\n",car(car(source)),ty,cadr(car(source)),sz);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
703 #endif
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
704 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
705 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
706
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
707 /* compute jump address */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
708 e2 = cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
709 if (car(e2) == FNAME) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
710 code0=(NMTBL *)cadr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
711 if (code0->sc!=CODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
712 error(TYERR); return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
713 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
714 } else { /* indirect */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
715 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
716 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
717 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
718 if (env) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
719 g_expr(env);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
720 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
721 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
722
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
723 /* 並列代入を実行 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
724
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
725 parallel_assign(&target,&source,&processing,&use);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
726 while (use) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
727 free_register(caddr(use)); use=cadr(use);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
728 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
729 if(target) error(-1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
730
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
731 if (env) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
732 /* change the frame pointer */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
733 e3 = emit_pop(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
734 code_frame_pointer(e3);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
735 emit_pop_free(e3);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
736 } else if (fnptr->sc==FUNCTION) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
737 code_fix_frame_pointer(disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
738 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
739
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
740 if (car(e2) == FNAME) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
741 code_jmp(code0->nm);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
742 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
743 e2 = emit_pop(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
744 code_indirect_jmp(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
745 emit_pop_free(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
746 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
747 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
748
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
749 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
750 machinop(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
751 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
752 int e2,e3,op;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
753
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
754 e2 = cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
755 op = car(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
756 e3 = caddr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
757 g_expr(e3);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
758 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
759 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
760 tosop(car(e1),(e2=pop_register()));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
761 emit_pop_free(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
762 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
763 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
764 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
765
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
766
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
767 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
768 sassign(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
769 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
770 int e2,e3,e4,sz,xreg,det;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
771
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
772 /* structure assignment */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
773 e2 = cadr(e1); /* pointer variable to the struct */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
774 e3 = cadr(e2); /* offset of the variable (distination) */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
775 e4 = caddr(e1); /* right value (source) */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
776 sz = cadddr(e1); /* size of struct or union */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
777 g_expr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
778 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
779 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
780 xreg = emit_pop(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
781 /* 一般的にはコピーのオーバラップの状況は実行時にしかわからない */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
782 /* しかし、わかる場合もある */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
783 if (car(e4)==RSTRUCT) e4=cadr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
784 if (is_same_type(e2,e4)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
785 if(cadr(e2)<cadr(e4)) sz=-sz;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
786 det=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
787 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
788 det = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
789 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
790 emit_copy(xreg,creg,sz,0,1,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
791 emit_pop_free(xreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
792 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
793 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
794
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
795 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
796 assign(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
797 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
798 int e2,e3,e4,byte;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
799
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
800 byte=(car(e1) == CASS);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
801 /* e2=e4 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
802 e2 = cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
803 e3 = cadr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
804 e4 = caddr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
805 switch(car(e2)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
806 case GVAR: /* i=3 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
807 g_expr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
808 code_assign_gvar(e2,byte);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
809 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
810 case LVAR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
811 g_expr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
812 code_assign_lvar(lvar(cadr(e2)),byte);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
813 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
814 case REGISTER:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
815 g_expr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
816 if (creg!=cadr(e2))
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
817 code_assign_register(cadr(e2),byte);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
818 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
819 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
820 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
821 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
822 use_data_reg(creg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
823 g_expr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
824 if (byte) use_data_reg(creg,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
825 e2 = emit_pop(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
826 code_assign(e2,byte);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
827 emit_pop_free(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
828 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
829 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
830 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
831
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
832 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
833 assop(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
834 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
835 int e2,e3,byte,op;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
836
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
837 /* e2 op= e3 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
838 byte = (car(e1) == CASSOP);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
839 e2 = cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
840 if (car(e2)==INDIRECT) e2=cadr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
841 e3 = caddr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
842 op = cadddr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
843
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
844 g_expr(e3);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
845 if (car(e2)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
846 code_register_assop(cadr(e2),op,byte);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
847 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
848 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
849 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
850 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
851 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
852 code_assop(op,byte);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
853 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
854 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
855 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
856
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
857
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
858 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
859 fwdlabel(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
860 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
861 return labelno++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
862 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
863
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
864 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
865 fwddef(int l)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
866 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
867 control=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
868 printf("_%d:\n",l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
869 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
870
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
871 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
872 backdef(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
873 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
874 control=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
875 printf("_%d:\n",labelno);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
876 return labelno++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
877 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
878
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
879 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
880 def_label(int cslabel, int dlabel)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
881 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
882 int fl;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
883
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
884 fl = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
885 if (control) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
886 jmp(fl=fwdlabel());
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
887 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
888 fwddef(cslabel);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
889 if (dlabel)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
890 jmp(dlabel);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
891 if (fl) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
892 fwddef(fl);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
893 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
894 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
895
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
896 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
897 gen_source(char *s)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
898 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
899 printf("%s",s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
900 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
901
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
902 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
903 ret(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
904 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
905 code_set_fixed_creg(1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
906 jmp(retlabel);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
907 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
908
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
909 /* end */