Mercurial > hg > CbC > old > device
annotate mc-code-ia32.c @ 292:6d4231b6f9fe
switch statement prepare
author | kono |
---|---|
date | Sat, 05 Jun 2004 00:08:09 +0900 |
parents | 7b6df595b205 |
children | 60dba3ef1f69 |
rev | line source |
---|---|
61 | 1 /* Micro-C Code Generatation Part for intel386 */ |
2 /* $Id$ */ | |
3 | |
4 #define EXTERN extern | |
5 #include "mc.h" | |
6 #include "mc-codegen.h" | |
93 | 7 #include "mc-code.h" |
61 | 8 |
173 | 9 char *l_include_path[] = { |
10 "/usr/include/", | |
182 | 11 "/usr/include/linux/", |
225 | 12 "/usr/include/diet/", |
13 "/usr/lib/gcc-lib/i386-linux/2.95.4/include/", | |
183 | 14 "/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/", |
246 | 15 "/usr/lib/dietlibc/include/", |
173 | 16 0 |
17 }; | |
18 | |
19 | |
245 | 20 #define SIZE_OF_INT 4 |
21 #define SIZE_OF_SHORT 2 | |
22 #define SIZE_OF_FLOAT 4 | |
23 #define SIZE_OF_DOUBLE 8 | |
24 #define SIZE_OF_LONGLONG 8 | |
25 #define ENDIAN 0 | |
26 | |
254 | 27 int size_of_int = SIZE_OF_INT; |
28 int size_of_short = SIZE_OF_SHORT; | |
29 int size_of_float = SIZE_OF_FLOAT; | |
30 int size_of_double = SIZE_OF_DOUBLE; | |
31 int size_of_longlong = SIZE_OF_LONGLONG; | |
32 int endian = ENDIAN; | |
245 | 33 |
94 | 34 #define SAVE_STACKS 1 |
35 | |
61 | 36 #define TEXT_EMIT_MODE 0 |
37 #define DATA_EMIT_MODE 1 | |
38 #define RODATA_EMIT_MODE 2 | |
39 | |
40 static int output_mode = TEXT_EMIT_MODE; | |
41 static int data_alignment = 0; | |
42 | |
224 | 43 static int creg; |
239 | 44 static int lreg; |
224 | 45 |
238 | 46 int code_lassop_p = 0; |
47 | |
239 | 48 static int MAX_REGISTER=6; /* intel386のレジスタを6つまで使う*/ |
119 | 49 #define REAL_MAX_REGISTER 8 /* intel386のレジスタが8つということ*/ |
239 | 50 static int MAX_DATA_REG=4; |
51 static int MAX_POINTER=3; | |
52 // static int MAX_REGISTGER_VAR=2; | |
53 // static int MAX_FREGISTER=1; | |
119 | 54 |
55 #define MAX_FPU_STACK 7 | |
239 | 56 #define REG_VAR 3 |
119 | 57 |
239 | 58 // static int MAX_INPUT_REGISTER_VAR = 0; |
59 static int MAX_CODE_INPUT_REGISTER_VAR = 2; | |
60 // static int MAX_INPUT_DREGISTER_VAR = 0; | |
61 // static int MAX_INPUT_FREGISTER_VAR = 0; | |
62 // static int MAX_CODE_INPUT_DREGISTER_VAR = 0; | |
61 | 63 |
239 | 64 static int reg_sp; /* REGister Stack-Pointer */ |
65 static int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ | |
138 | 66 |
67 /* floating point registers */ | |
68 | |
239 | 69 static int freg_sp; /* floating point REGister Stack-Pointer */ |
70 static int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ | |
71 | |
72 static int reg_var; | |
73 static int regvar[2]; | |
138 | 74 |
75 | |
61 | 76 /* |
128 | 77 -28 -8 local2 |
78 -24 -4 local1 | |
79 -20 8 arg3 | |
80 -16 4 arg2 | |
81 -12 0 arg1 | |
82 local2 -20 4 -8 (%edi) | |
83 local1 <-- -16 0 local variable -4 (%esi) | |
61 | 84 %edi -12 <- disp_offset %ebp |
85 %esi -8 | |
86 %ebx -4 | |
87 %ebp = %esp 0 | |
88 %eip 4 <- arg_offset | |
89 arg1 8 0 | |
90 arg2 12 4 | |
91 see enter/enter1/leave see code_enter | |
92 */ | |
244 | 93 // static int arg_offset = 8; |
94 // static int disp_offset = -12; | |
95 #define func_disp_offset -12 | |
96 #define code_disp_offset 0 | |
239 | 97 // static int jump_offset = 0; |
61 | 98 |
119 | 99 static int code_disp_label; |
100 static int func_disp_label; | |
61 | 101 |
263 | 102 |
119 | 103 static int |
104 lvar(int l) | |
105 { | |
106 if (is_code(fnptr)) { | |
107 return l+code_disp_offset; | |
108 } else if (l<0) { | |
109 return l+disp_offset; | |
110 } else { | |
111 return l+arg_offset; | |
112 } | |
113 } | |
99 | 114 |
95 | 115 /* |
116 creg currrent virtual register | |
117 dreg spare virtual register | |
118 | |
119 rname[creg] currrent real register | |
120 rname[dreg] spare real register | |
121 | |
122 regs[] virtual register usage | |
123 regv[] value in virtual register flag | |
124 | |
125 reg_name[rname[creg]] | |
126 | |
127 freg current floating point register | |
128 fregv calue in floating point register | |
129 */ | |
130 | |
131 static int dreg; /* general temporal register */ | |
132 | |
239 | 133 #define REAL_MAX_LREGISTER 2 |
238 | 134 static int ia32regs[REAL_MAX_REGISTER+REAL_MAX_LREGISTER]; |
135 static int ia32regv[REAL_MAX_REGISTER+REAL_MAX_LREGISTER]; | |
136 static int ia32rname[REAL_MAX_REGISTER+REAL_MAX_LREGISTER]; | |
95 | 137 |
205 | 138 static int *regv = ia32regv; |
139 static int *regs = ia32regs; | |
95 | 140 static int *rname = ia32rname; |
141 | |
205 | 142 static int ia32fregs[1]; |
143 static int ia32fregv[1]; | |
95 | 144 |
205 | 145 static int freg; |
146 static int *fregv = ia32fregv; | |
147 static int *fregs = ia32fregs; | |
95 | 148 |
61 | 149 |
150 #define REG_EAX 0 | |
151 #define REG_EBX 1 | |
152 #define REG_ECX 2 | |
153 #define REG_EDX 3 | |
154 #define REG_ESI 4 | |
155 #define REG_EDI 5 | |
156 #define REG_EBP 6 | |
157 #define REG_ESP 7 | |
239 | 158 #define is_int_reg(reg) (reg<REG_EBP) |
159 #define REG_LCREG 8 | |
160 #define REG_L 9 | |
61 | 161 |
162 | |
163 #define DATA_REG 0 | |
164 #define POINTER_REG 3 | |
165 static char *reg_name[8]; | |
166 static char *reg_name_l[4]; | |
167 static char *reg_name_w[4]; | |
168 | |
93 | 169 static void use_register(int virt, int real, int move); |
170 static int virtual(int real); | |
235 | 171 static void shift(char *op, int reg,int creg); |
172 static void ld_indexx(int byte, int n, int xreg,int reg,int sign); | |
93 | 173 static void data_mode(char *name); |
263 | 174 static void text_mode(); |
237 | 175 static int edx_setup(int rreg); |
93 | 176 static void edx_cleanup(); |
177 static void local_table(void); | |
195 | 178 #if FLOAT_CODE |
93 | 179 static char * fload(int d); |
180 static int code_d1(double d); | |
181 static int code_d2(double d); | |
195 | 182 static void code_save_fstacks(); |
183 #endif | |
94 | 184 static void code_save_stacks(); |
287 | 185 static void jcond(int l, char cond); |
82 | 186 |
235 | 187 #define use_int(reg) if (reg==-1) reg=use_int0() |
242 | 188 static int use_int0() { lreg = 0; if (!is_int_reg(creg)) { creg = virtual(REG_EBX); regs[creg]=1;} return creg; } |
239 | 189 |
190 #define use_longlong(reg) reg=use_longlong0(reg) | |
191 static int | |
192 use_longlong0(int reg) | |
193 { | |
194 int i; | |
195 if (reg==USE_CREG) | |
196 reg = REG_LCREG; | |
197 if (!lreg) { | |
198 code_save_stacks(); | |
199 // make edx,eax free | |
240 | 200 use_register(creg,REG_EBX,regv[creg]); |
201 use_register(dreg,REG_ECX,regv[dreg]); | |
239 | 202 for(i=0;i<reg_var;i++) |
203 use_register(regvar[i],REG_ESI+i,1); | |
204 } | |
240 | 205 creg = lreg = reg; |
239 | 206 return lreg; |
207 } | |
208 | |
209 char * | |
210 l_edx(int i) { | |
211 return i==REG_L?"%edi":"%edx"; | |
212 } | |
213 char * | |
214 l_eax(int i) { | |
215 return i==REG_L?"%esi":"%eax"; | |
216 } | |
217 | |
235 | 218 |
61 | 219 void |
220 code_init(void) | |
221 { | |
173 | 222 macro_define("__i386__ 1\n"); |
182 | 223 macro_define("__LITTLE_ENDIAN__ 1\n"); |
224 macro_define("__STDC__ 1\n"); | |
225 macro_define("size_t int\n"); | |
226 macro_define("__externsion__\n"); | |
227 macro_define("__flexarr\n"); | |
183 | 228 macro_define("__builtin_va_list int*\n"); |
229 macro_define("wchar_t int\n"); | |
235 | 230 // macro_define("__THROW\n"); |
231 macro_define("__gnuc_va_list int*\n"); | |
173 | 232 |
61 | 233 arg_offset = 8; |
244 | 234 // func_disp_offset = -12; |
61 | 235 disp_offset = -12; |
236 MAX_REGISTER=6; | |
237 MAX_DATA_REG=4; | |
238 MAX_POINTER=3; | |
239 MAX_REGISTER_VAR=2; | |
240 | |
241 reg_name[REG_EAX] = "%eax"; | |
242 reg_name[REG_EBX] = "%ebx"; | |
243 reg_name[REG_ECX] = "%ecx"; | |
244 reg_name[REG_EDX] = "%edx"; | |
245 reg_name[REG_ESI] = "%esi"; | |
246 reg_name[REG_EDI] = "%edi"; | |
247 reg_name[REG_EBP] = "%ebp"; | |
248 reg_name[REG_ESP] = "%esp"; | |
249 reg_name_l[REG_EAX] = "%al"; | |
250 reg_name_l[REG_EBX] = "%bl"; | |
251 reg_name_l[REG_ECX] = "%cl"; | |
252 reg_name_l[REG_EDX] = "%dl"; | |
253 reg_name_w[REG_EAX] = "%ax"; | |
254 reg_name_w[REG_EBX] = "%bx"; | |
255 reg_name_w[REG_ECX] = "%cx"; | |
256 reg_name_w[REG_EDX] = "%dx"; | |
257 | |
258 } | |
259 | |
260 char * | |
261 register_name(int i,int byte) | |
262 { | |
263 if (i<0) { | |
264 error(REG_ERR); | |
265 return "%eax"; | |
266 } | |
165 | 267 if (byte==1 && rname[i] <= REG_EDX) { |
61 | 268 return reg_name_l[rname[i]]; |
245 | 269 } else if (byte==SIZE_OF_SHORT && rname[i] <= REG_EDX) { |
165 | 270 return reg_name_w[rname[i]]; |
61 | 271 } else { |
168 | 272 return reg_name[rname[i]]; /* 0 or 4 means int */ |
61 | 273 } |
274 } | |
275 | |
235 | 276 /* |
147 | 277 int use_int(int i) { return i;} |
278 int use_float(int i) { return i;} | |
279 int use_double(int i) { return i;} | |
195 | 280 int use_longlong(int i) { return i; } |
235 | 281 */ |
195 | 282 |
147 | 283 |
61 | 284 void |
285 gexpr_code_init(void){ | |
286 use_register(creg,REG_EAX,0); | |
94 | 287 regv[creg]=0; |
61 | 288 regv[dreg]=0; |
289 } | |
290 | |
147 | 291 void |
292 code_gexpr(int e){ | |
293 } | |
294 | |
89 | 295 int |
296 get_register(void) | |
297 { /* 使われていないレジスタを調べる */ | |
298 int i; | |
299 for(i=0;i<MAX_REGISTER;i++) { | |
300 if (! regs[i]) { /* 使われていないなら */ | |
301 regs[i]=1; /* そのレジスタを使うことを宣言し */ | |
302 return i; /* その場所を表す番号を返す */ | |
303 } | |
304 } | |
305 return -1; /* 空いている場所がないなら、それを表す -1 を返す */ | |
306 } | |
307 | |
308 void | |
309 free_register(int i) { /* いらなくなったレジスタを開放 */ | |
310 regv[i]=regs[i]=0; | |
238 | 311 if(i==REAL_MAX_REGISTER) { |
239 | 312 regv[virtual(REG_ESI)]=regv[virtual(REG_EDI)]=0; |
238 | 313 } |
89 | 314 } |
315 | |
99 | 316 int |
126 | 317 get_input_register_var(int i,NMTBL *nptr,int is_code) |
99 | 318 { |
126 | 319 if (is_code) { |
320 if (i>=MAX_CODE_INPUT_REGISTER_VAR) return 0; | |
321 i = virtual(i+REG_ESI); | |
239 | 322 regs[i]=regv[i]=INPUT_REG; |
126 | 323 return list3(REGISTER,i,(int)nptr); |
324 } else { | |
325 return 0; | |
326 } | |
99 | 327 } |
103 | 328 |
99 | 329 int |
138 | 330 get_input_dregister_var(int i,NMTBL *nptr,int is_code,int d) |
99 | 331 { |
126 | 332 return 0; |
99 | 333 } |
334 | |
335 int | |
138 | 336 get_dregister(int d) |
99 | 337 { |
338 return -1; | |
339 } | |
340 | |
195 | 341 int |
342 get_lregister_var(NMTBL *n) | |
343 { | |
238 | 344 int h,l; |
345 h = virtual(REG_ESI); | |
346 l = virtual(REG_EDI); | |
347 if (regv[REAL_MAX_REGISTER]==0&®s[h]==0&®s[l]==0) { | |
239 | 348 regs[h]=regs[l]=REG_VAR; |
349 regv[h]=regv[l]=REG_VAR; | |
238 | 350 regv[REAL_MAX_REGISTER]=1; |
239 | 351 reg_var=2; regvar[0]=h; regvar[1]=l; |
240 | 352 return list2(LREGISTER,REG_L); |
238 | 353 } |
245 | 354 return list2(LVAR,new_lvar(SIZE_OF_LONGLONG)); |
195 | 355 } |
356 | |
205 | 357 int |
358 get_lregister() | |
359 { | |
360 return -1; | |
361 } | |
362 | |
363 | |
89 | 364 int |
365 register_full(void) | |
366 { | |
367 int i; | |
368 for(i=0;i<MAX_REGISTER;i++) { | |
369 if (! regs[i]) { | |
370 return 0; | |
371 } | |
372 } | |
373 return 1; | |
374 } | |
375 | |
376 int | |
137 | 377 free_register_count(int d) |
89 | 378 { |
379 int i,count; | |
380 count = 0; | |
381 for(i=0;i<MAX_REGISTER;i++) { | |
382 if (! regs[i] && ! regv[i]) count++; | |
383 } | |
137 | 384 return d?0:count; |
89 | 385 } |
386 | |
387 void | |
388 free_all_register(void) | |
389 { | |
390 int i; | |
243 | 391 for(i=0;i<MAX_REGISTER+REAL_MAX_LREGISTER;i++) { |
89 | 392 regs[i]=regv[i]=0; |
393 } | |
394 creg = get_register(); | |
395 dreg = get_register(); | |
239 | 396 reg_var = 0; |
89 | 397 return; |
398 } | |
399 | |
400 | |
401 void | |
402 register_usage(char *s) | |
403 { | |
404 int i; | |
405 if (chk) return; | |
406 printf("# %d: %s:",lineno,s); | |
407 printf(" creg=%s dreg=%s ",register_name(creg,0),register_name(dreg,0)); | |
408 for(i=0;i<MAX_REGISTER;i++) { | |
409 printf("%d",regs[i]); | |
410 } | |
411 printf(":"); | |
412 for(i=0;i<MAX_REGISTER;i++) { | |
413 printf("%d",regv[i]); | |
414 } | |
415 #if 0 | |
416 printf(" regs_stack",register_name(creg,0),register_name(dreg,0)); | |
417 for(i=reg_sp;i>=0;i--) { | |
418 if(reg_stack[i]>=0) | |
419 printf(" %s",register_name(reg_stack[i],0)); | |
420 } | |
421 #endif | |
94 | 422 printf(" f:%d",freg_sp); |
89 | 423 printf("\n"); |
424 } | |
425 | |
109 | 426 void |
137 | 427 code_arg_register(NMTBL *fnptr) |
109 | 428 { |
137 | 429 int args = fnptr->dsp; |
430 NMTBL *n; | |
431 int reg_var = 0; | |
432 int freg_var = 0; | |
433 int type; | |
434 int reg; | |
435 int is_code0 = is_code(fnptr); | |
436 | |
437 while (args) { | |
438 /* process in reverse order */ | |
439 n = (NMTBL*)caddr(args); | |
440 type = n->ty; | |
441 if (scalar(type)) { | |
442 if ((reg = get_input_register_var(reg_var,n,is_code0))) { | |
443 n->sc = REGISTER; | |
444 n->dsp = cadr(reg); | |
445 regv[n->dsp]= 1; | |
446 regs[n->dsp]= INPUT_REG; | |
447 reg_var++; | |
245 | 448 cadddr(args)=SIZE_OF_INT; /* why we need this? */ |
137 | 449 } |
450 } else if (type==FLOAT||type==DOUBLE) { | |
138 | 451 if ((reg = get_input_dregister_var(freg_var,n,is_code0,1))) { |
137 | 452 n->sc = DREGISTER; |
453 n->dsp = cadr(reg); | |
454 fregv[n->dsp]= 1; | |
455 fregs[n->dsp]= INPUT_REG; | |
456 freg_var++; | |
457 cadddr(args)=size(type); /* why we need this? */ | |
458 } | |
459 } | |
460 args = cadr(args); | |
461 } | |
109 | 462 } |
463 | |
89 | 464 void |
465 gexpr_init(void) | |
466 { | |
292 | 467 if (reg_sp>0) error(-1); |
468 if (freg_sp>0) error(-1); | |
469 reg_sp = 0; | |
94 | 470 freg_sp = 0; |
89 | 471 text_mode(); |
472 gexpr_code_init(); | |
473 register_usage("gexpr_init"); | |
474 } | |
475 | |
476 | |
477 void | |
478 emit_init(void) | |
479 { | |
480 int i; | |
481 for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; regv[i]=0;rname[i]=i;} | |
482 free_all_register(); | |
483 reg_sp = 0; | |
94 | 484 freg_sp = 0; |
89 | 485 text_mode(); |
486 } | |
487 | |
488 int | |
489 virtual(int real) | |
490 { | |
491 int real_v,i; | |
492 real_v = -1; | |
493 for(i=0;i<MAX_REGISTER;i++) { | |
494 if (rname[i]==real) { | |
495 real_v=i; | |
496 break; | |
497 } | |
498 } | |
499 return real_v; | |
500 } | |
501 | |
502 int | |
503 pop_register(void) | |
504 { /* レジスタから値を取り出す */ | |
505 return reg_stack[--reg_sp]; | |
506 } | |
507 | |
508 void | |
509 emit_pop_free(int xreg) | |
510 { | |
159 | 511 if (xreg==dreg||xreg==creg) { |
89 | 512 regv[dreg]=0; |
98 | 513 } else if (xreg>=0) { |
89 | 514 free_register(xreg); |
515 } | |
516 } | |
517 | |
518 | |
61 | 519 int |
105 | 520 get_register_var(NMTBL *nptr) |
61 | 521 { |
522 int i; | |
235 | 523 for(i=REG_ESI;i<REG_EBP;i++) { |
61 | 524 if (! regs[i]) { /* 使われていないなら */ |
239 | 525 regs[i]=REG_VAR; /* そのレジスタを使うことを宣言し */ |
61 | 526 regv[i]=0; |
239 | 527 regvar[reg_var++]=i; |
105 | 528 return list3(REGISTER,i,(int)nptr); /* その場所を表す番号を返す */ |
61 | 529 } |
530 } | |
245 | 531 return list2(LVAR,new_lvar(SIZE_OF_INT)); |
104 | 532 } |
533 | |
534 int | |
138 | 535 get_dregister_var(NMTBL *nptr,int d) |
104 | 536 { |
245 | 537 return list2(LVAR,new_lvar(d?SIZE_OF_DOUBLE:SIZE_OF_FLOAT)); |
137 | 538 } |
539 | |
61 | 540 void |
541 use_register(int virt, int real, int move) | |
542 { | |
543 int real_v; | |
544 char *move_op; | |
545 if (rname[virt]==real) | |
546 return; | |
547 real_v = virtual(real); | |
548 move_op = regs[real_v]?"\txchg %s,%s\n":"\tmovl %s,%s\n"; | |
549 if (move || (regv[real_v])) { | |
550 printf(move_op,reg_name[rname[virt]],reg_name[real]); | |
551 } | |
552 rname[real_v] = rname[virt]; | |
553 rname[virt] = real; | |
554 } | |
555 | |
556 void | |
557 use_pointer(int virt, int move) | |
558 { | |
559 int i; | |
560 if (rname[virt]>=POINTER_REG) | |
561 return; | |
562 for(i=POINTER_REG;i<MAX_REGISTER;i++) { | |
563 if (!regs[virtual(i)]) { | |
564 use_register(virt,i,move); | |
565 return; | |
566 } | |
567 } | |
568 /* we prefer EBX */ | |
569 use_register(virt,REG_EBX,move); | |
570 } | |
571 | |
572 void | |
573 use_data_reg(int virt, int move) | |
574 { | |
575 int i; | |
576 if (rname[virt]<MAX_DATA_REG) | |
577 return; | |
578 for(i=0;i<MAX_DATA_REG;i++) { | |
579 if (!regs[virtual(i)]) { | |
580 use_register(virt,i,move); | |
581 return; | |
582 } | |
583 } | |
584 /* we prefer EBX */ | |
585 use_register(virt,REG_EBX,move); | |
586 } | |
587 | |
588 | |
589 void | |
107 | 590 emit_push() |
61 | 591 { |
592 int new_reg; | |
593 new_reg = get_register(); | |
159 | 594 if (new_reg==creg) error(-1); |
61 | 595 if(new_reg<0) { /* もうレジスタがない */ |
83 | 596 if (reg_sp>=MAX_MAX) error(-1); |
61 | 597 reg_stack[reg_sp++] = -1; |
598 printf("\tpushl %s\n",register_name(creg,0)); | |
599 /* creg is used soon, don't regv[creg]=0 */ | |
600 } else { | |
601 reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */ | |
602 creg = new_reg; | |
603 regv[creg]=1; | |
604 } | |
605 } | |
606 | |
607 int | |
608 emit_pop(int type) | |
609 { | |
610 int xreg; | |
611 if ((xreg=pop_register())==-1) { | |
612 if (type==POINTER_REG) | |
613 use_pointer(dreg,0); | |
614 else if (type==DATA_REG) | |
615 use_data_reg(dreg,0); | |
616 if (regv[dreg]) { | |
617 printf("# emit_pop dreg conflict\n"); | |
94 | 618 error(-1); |
61 | 619 } |
620 printf("\tpopl %s\n",register_name(dreg,0)); | |
94 | 621 regv[dreg]=1; |
622 return dreg; | |
623 } else if (xreg<= -REG_LVAR_OFFSET) { | |
119 | 624 code_rlvar(xreg+REG_LVAR_OFFSET,dreg); |
117 | 625 free_lvar(xreg+REG_LVAR_OFFSET); |
94 | 626 regv[dreg]=1; |
627 return dreg; | |
628 } | |
61 | 629 return xreg; |
630 } | |
631 | |
186 | 632 int |
633 stack_top(int type) | |
634 { | |
635 int xreg; | |
636 if (type==INT) { | |
637 xreg = reg_stack[reg_sp]; | |
638 if (xreg<= -REG_LVAR_OFFSET) { | |
639 return list2(LVAR,REG_LVAR_OFFSET+xreg); | |
640 } else { | |
641 return list2(REGISTER,xreg); | |
642 } | |
643 } else { | |
644 xreg = freg_stack[freg_sp]; | |
645 if (xreg<= -REG_LVAR_OFFSET) { | |
646 return list2(LVAR,REG_LVAR_OFFSET+xreg); | |
187 | 647 } else { |
186 | 648 return list2(DREGISTER,xreg); |
649 } | |
650 } | |
651 return xreg; | |
652 } | |
653 | |
654 | |
655 | |
92 | 656 void |
657 code_label(int labelno) | |
658 { | |
659 printf("_%d:\n",labelno); | |
660 } | |
61 | 661 |
662 void | |
107 | 663 code_gvar(int e1,int creg) { |
235 | 664 use_int(creg); |
109 | 665 printf("\tmovl $%s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0)); |
107 | 666 regv[creg]=1; |
61 | 667 } |
668 | |
669 | |
670 void | |
107 | 671 code_rgvar(int e1,int creg) { |
235 | 672 use_int(creg); |
109 | 673 printf("\tmovl %s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0)); |
107 | 674 regv[creg]=1; |
61 | 675 } |
235 | 676 |
245 | 677 static char *cload(int sign,int sz) { return sz==1?(sign?"movsbl":"movzbl"):sz==SIZE_OF_SHORT?(sign?"movswl":"movzwl"):"movl"; } |
235 | 678 |
61 | 679 void |
165 | 680 code_crgvar(int e1,int creg,int sign,int sz){ |
235 | 681 use_int(creg); |
165 | 682 printf("\t%s %s,%s\n",cload(sign,sz), |
163 | 683 ((NMTBL*)cadr(e1))->nm,register_name(creg,0)); |
107 | 684 regv[creg]=1; |
61 | 685 } |
686 | |
687 | |
688 void | |
107 | 689 code_lvar(int e2,int creg) { |
235 | 690 use_int(creg); |
119 | 691 printf("\tlea %d(%%ebp),%s\n",lvar(e2),register_name(creg,0)); |
107 | 692 regv[creg]=1; |
61 | 693 } |
694 | |
695 | |
696 void | |
107 | 697 code_register(int e2,int creg) { |
235 | 698 use_int(creg); |
61 | 699 printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0)); |
107 | 700 regv[creg]=1; |
61 | 701 } |
702 | |
703 | |
704 void | |
94 | 705 code_rlvar(int e2,int reg) { |
235 | 706 use_int(reg); |
119 | 707 printf("\tmovl %d(%%ebp),%s\n",lvar(e2),register_name(reg,0)); |
107 | 708 regv[creg]=1; |
61 | 709 } |
710 | |
711 | |
712 void | |
165 | 713 code_crlvar(int e2,int reg,int sign,int sz) { |
235 | 714 use_int(reg); |
165 | 715 printf("\t%s %d(%%ebp),%s\n",cload(sign,sz),lvar(e2),register_name(reg,0)); |
107 | 716 regv[creg]=1; |
61 | 717 } |
718 | |
719 | |
720 void | |
109 | 721 code_fname(NMTBL *n,int creg) { |
235 | 722 use_int(creg); |
109 | 723 printf("\tmovl $%s,%s\n",n->nm,register_name(creg,0)); |
107 | 724 regv[creg]=1; |
61 | 725 } |
726 | |
727 | |
728 void | |
107 | 729 code_const(int e2,int creg) { |
235 | 730 use_int(creg); |
61 | 731 printf("\tmovl $%d,%s\n",e2,register_name(creg,0)); |
107 | 732 regv[creg]=1; |
61 | 733 } |
734 | |
735 | |
736 void | |
107 | 737 code_neg(int creg) { |
235 | 738 use_int(creg); |
61 | 739 printf("\tnegl %s\n", register_name(creg,0)); |
740 } | |
741 | |
742 | |
743 void | |
107 | 744 code_not(int creg) { |
235 | 745 use_int(creg); |
61 | 746 printf("\tnotl %s\n", register_name(creg,0)); |
747 } | |
748 | |
749 | |
750 void | |
107 | 751 code_lnot(int creg) { |
61 | 752 char *xrn; |
235 | 753 use_int(creg); |
61 | 754 use_data_reg(creg,1); |
755 xrn = register_name(creg,1); | |
756 printf("\tcmpl $0,%s\n", register_name(creg,0)); | |
757 printf("\tsete %s\n", xrn); | |
758 printf("\tmovzbl %s,%s\n", xrn,register_name(creg,0)); | |
759 } | |
760 | |
761 void | |
168 | 762 code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) { |
61 | 763 char *xrn; |
764 if (car(e2)==REGISTER) { | |
235 | 765 use_int(reg); |
168 | 766 printf("\taddl $%d,%s\n",dir,register_name(cadr(e2),0)); |
107 | 767 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0)); |
768 regv[reg]=1; | |
61 | 769 return; |
770 } | |
771 g_expr(e2); | |
772 xrn = register_name(creg,0); | |
235 | 773 use_int(reg); |
245 | 774 printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==SIZE_OF_SHORT)?"addw":"addl",dir,xrn); |
235 | 775 printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0)); |
61 | 776 } |
777 | |
778 | |
779 void | |
168 | 780 code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) { |
61 | 781 char *xrn; |
782 if (car(e2)==REGISTER) { | |
235 | 783 use_int(reg); |
107 | 784 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0)); |
168 | 785 printf("\taddl $%d,%s\n",dir,register_name(cadr(e2),0)); |
107 | 786 regv[reg]=1; |
61 | 787 return; |
788 } | |
789 g_expr(e2); | |
790 emit_push(); | |
791 xrn = register_name((e2=emit_pop(0)),0); | |
235 | 792 use_int(reg); |
793 printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0)); | |
245 | 794 printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==SIZE_OF_SHORT)?"addw":"addl",dir,xrn); |
61 | 795 emit_pop_free(e2); |
796 } | |
797 | |
798 | |
799 | |
800 void | |
107 | 801 code_return(int creg) { |
235 | 802 use_int(creg); |
61 | 803 printf("\tleal _%d,%s\n",retcont,register_name(creg,0)); |
107 | 804 regv[creg]=1; |
61 | 805 } |
806 | |
807 | |
808 void | |
107 | 809 code_environment(int creg) { |
235 | 810 use_int(creg); |
61 | 811 printf("\tmovl %%ebp,%s\n",register_name(creg,0)); |
107 | 812 regv[creg]=1; |
61 | 813 } |
814 | |
291 | 815 static int rexpr_bool(int e1,int reg); |
816 static int drexpr_bool(int e1,int reg); | |
61 | 817 |
818 void | |
225 | 819 code_bool(int e1,int reg) { |
61 | 820 char *xrn; |
821 int e2,e3; | |
291 | 822 if (rexpr_bool(e1,reg)) return; |
823 #if FLOAT_CODE | |
824 if (drexpr_bool(e1,reg)) return; | |
825 #endif | |
61 | 826 b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */ |
289 | 827 if (use) { |
828 use_int(reg); | |
829 xrn = register_name(reg,0); | |
830 printf("\txorl %s,%s\n",xrn,xrn); | |
831 jmp(e3=fwdlabel()); | |
832 fwddef(e2); | |
833 printf("\tmovl $1,%s\n",xrn); | |
834 fwddef(e3); | |
835 regv[reg]=1; | |
836 } else { | |
837 fwddef(e2); | |
838 } | |
61 | 839 } |
840 | |
841 char * | |
842 code_gt(int cond) { | |
843 return (cond?"g":"le"); | |
844 } | |
845 | |
846 char * | |
847 code_ugt(int cond) { | |
848 return (cond?"a":"be"); | |
849 } | |
850 | |
851 char * | |
852 code_ge(int cond) { | |
853 return (cond?"ge":"l"); | |
854 } | |
855 | |
856 char * | |
857 code_uge(int cond) { | |
858 return (cond?"ae":"b"); | |
859 } | |
860 | |
861 char * | |
862 code_eq(int cond) { | |
863 return (cond?"e":"ne"); | |
864 } | |
865 | |
866 void | |
287 | 867 code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) { |
235 | 868 use_int(reg); |
167 | 869 if (sz==1) |
870 printf("\tcmpb $0,%s\n",((NMTBL*)cadr(e1))->nm); | |
245 | 871 else if (sz==SIZE_OF_SHORT) |
167 | 872 printf("\tcmpw $0,%s\n",((NMTBL*)cadr(e1))->nm); |
287 | 873 jcond(label,cond); |
61 | 874 } |
875 | |
876 | |
877 void | |
287 | 878 code_cmp_crlvar(int e1,int reg,int sz,int label,int cond) { |
235 | 879 use_int(reg); |
167 | 880 if (sz==1) |
881 printf("\tcmpb $0,%d(%%ebp)\n",lvar(e1)); | |
245 | 882 else if (sz==SIZE_OF_SHORT) |
167 | 883 printf("\tcmpw $0,%d(%%ebp)\n",lvar(e1)); |
287 | 884 jcond(label,cond); |
61 | 885 } |
886 | |
887 | |
888 void | |
287 | 889 code_cmp_rgvar(int e1,int reg,int label,int cond) { |
235 | 890 use_int(reg); |
109 | 891 printf("\tcmpl $0,%s\n",((NMTBL*)cadr(e1))->nm); |
287 | 892 jcond(label,cond); |
61 | 893 } |
894 | |
895 | |
896 void | |
287 | 897 code_cmp_rlvar(int e1,int reg,int label,int cond) { |
235 | 898 use_int(reg); |
119 | 899 printf("\tcmpl $0,%d(%%ebp)\n",lvar(e1)); |
287 | 900 jcond(label,cond); |
61 | 901 } |
902 | |
903 | |
904 void | |
287 | 905 code_cmp_register(int e2,int label,int cond) { |
235 | 906 use_int(e2); |
61 | 907 printf("\tcmpl $0,%s\n",register_name(e2,0)); |
287 | 908 jcond(label,cond); |
61 | 909 } |
910 | |
911 | |
912 void | |
913 ascii(char *s) | |
914 { | |
915 printf("\t.string \""); | |
916 while(*s) { | |
917 if (*s=='\n') | |
918 printf("%cn",92); | |
919 else if (*s<' ') | |
920 printf("%c%03o",92,*s); | |
921 else if (*s==34) | |
922 printf("%c%c",92,34); | |
923 else | |
924 printf("%c",*s); | |
925 s++; | |
926 } | |
927 printf("%c\n",34); | |
928 } | |
929 | |
930 void | |
107 | 931 code_string(int e1,int creg) |
61 | 932 { |
933 char *s; | |
934 int i,lb; | |
935 | |
235 | 936 use_int(creg); |
61 | 937 if (0) { |
938 s=(char *)cadr(e1); | |
939 lb=fwdlabel(); | |
940 printf("\tjmp _%d\n",lb); | |
941 i=backdef(); | |
942 ascii(s); | |
943 printf("\t.align 2\n"); | |
944 fwddef(lb); | |
945 printf("\tlea _%d,%s\n",i,register_name(creg,0)); | |
946 } else { | |
947 s=(char *)cadr(e1); | |
948 printf(".section\t.rodata\n"); | |
949 lb=fwdlabel(); | |
950 printf("_%d:\n",lb); | |
951 ascii(s); | |
952 if (output_mode==TEXT_EMIT_MODE) { | |
953 printf(".text\n"); | |
954 } else { | |
955 text_mode(); | |
956 } | |
957 printf("\tlea _%d,%s\n",lb,register_name(creg,0)); | |
958 } | |
959 } | |
960 | |
961 #define MAX_COPY_LEN 20 | |
962 | |
963 void | |
964 emit_copy(int from,int to,int length,int offset,int value,int det) | |
965 { | |
966 int fix = 0; | |
967 /* length <0 means upward direction copy */ | |
235 | 968 use_int(from); |
969 use_int(to); | |
61 | 970 switch (length) { |
971 case 0: break; | |
972 case 1: case -1: | |
973 printf("\tmovb %d(%s),%s\n",offset, | |
974 register_name(from,0), reg_name_l[rname[dreg]] ); | |
975 printf("\tmovb %s,%d(%s)\n",reg_name_l[rname[dreg]] ,offset, | |
976 register_name(to,0)); | |
977 break; | |
978 case 2: case -2: | |
979 printf("\tmovw %d(%s),%s\n",offset, | |
980 register_name(from,0), reg_name_w[rname[dreg]] ); | |
981 printf("\tmovw %s,%d(%s)\n",reg_name_w[rname[dreg]] ,offset, | |
982 register_name(to,0)); | |
983 break; | |
984 case 4: case -4: | |
985 printf("\tmovl %d(%s),%s\n",offset, | |
986 register_name(from,0), register_name(dreg,0)); | |
987 printf("\tmovl %s,%d(%s)\n",register_name(dreg,0), offset, | |
988 register_name(to,0)); | |
989 break; | |
990 default: | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
991 if (length <0) { |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
992 if (length > -MAX_COPY_LEN) { |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
993 for(;length<=-4;length+=4,offset-=4) |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
994 emit_copy(from,to,-4,offset-4,0,det); |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
995 for(;length<=-2;length+=2,offset-=2) |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
996 emit_copy(from,to,-2,offset-2,0,det); |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
997 if(length<0) |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
998 emit_copy(from,to,length,offset-1,0,det); |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
999 break; |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1000 } |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1001 } else if (length <=MAX_COPY_LEN) { |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1002 for(;length>=4;length-=4,offset+=4) |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1003 emit_copy(from,to,4,offset,0,det); |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1004 for(;length>=2;length-=2,offset+=2) |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1005 emit_copy(from,to,2,offset,0,det); |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1006 if(length>0) |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1007 emit_copy(from,to,length,offset,0,det); |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1008 break; |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1009 } |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1010 /* |
61 | 1011 if (det) { |
1012 call bcopy | |
1013 g_expr(list3(FUNCTION,,); | |
1014 break; | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1015 } |
61 | 1016 */ |
1017 use_register(from,REG_ESI,1); | |
1018 use_register(to, REG_EDI,1); | |
1019 use_register(dreg,REG_ECX,0); | |
1020 if (length<0) { | |
1021 printf("\tmovl $%d,%%ecx\n",-length/4); | |
1022 printf("\taddl $%d,%%esi\n",-length); | |
1023 printf("\taddl $%d,%%edi\n",-length); | |
1024 printf("\tstd\n\trep\n\tmovsl\n"); | |
1025 if(length%4) { | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1026 emit_copy(from,to,length,offset+length/SIZE_OF_INT,0,det); |
61 | 1027 } |
1028 } else { | |
1029 printf("\tmovl $%d,%%ecx\n",length/4); | |
1030 fix = (length/4)*4; | |
1031 printf("\tcld\n\trep\n\tmovsl\n"); | |
1032 if(length%4) { | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
254
diff
changeset
|
1033 emit_copy(from,to,length,offset+length/SIZE_OF_INT,0,det); |
61 | 1034 } |
1035 } | |
1036 } | |
1037 if (value) { | |
1038 /* creg must point top of the destination data */ | |
1039 /* this code is necessary for the value of assignment or function call */ | |
1040 /* otherwise we don't need this */ | |
1041 if (fix) printf("\tsubl $%d,%s\n",fix,register_name(to,0)); | |
1042 if(creg!=to) { | |
1043 if (to==dreg) | |
1044 printf("\tmovl %s,%s\n",register_name(to,0),register_name(creg,0)); | |
1045 else { | |
1046 free_register(creg); creg=to; | |
1047 } | |
1048 } | |
1049 } | |
1050 regv[from]=regv[to]=regv[dreg]=0; | |
1051 regv[creg]=1; | |
1052 } | |
1053 | |
1054 int | |
1055 struct_push(int e4,int t) | |
1056 { | |
81 | 1057 int length,xreg,save,lreg,count; |
61 | 1058 g_expr(e4); |
1059 length=size(t); | |
245 | 1060 if(length%SIZE_OF_INT) { |
1061 length += SIZE_OF_INT - (length%SIZE_OF_INT); | |
61 | 1062 } |
245 | 1063 for(count=0;length<MAX_COPY_LEN;count++,length-=SIZE_OF_INT) { |
81 | 1064 if (length==0) return count; |
1065 else { | |
1066 printf("\tpushl %d(%s)\n", | |
245 | 1067 length-SIZE_OF_INT,register_name(creg,0)); |
81 | 1068 } |
61 | 1069 } |
1070 printf("\tsubl $%d,%%esp\n",length); | |
1071 if (register_full()) { | |
1072 save = 1; | |
1073 for(lreg=0;lreg==creg||lreg==dreg;lreg++); | |
1074 printf("\tpushl %s\n",register_name(lreg,0)); | |
1075 xreg = lreg; regv[xreg]=0; | |
1076 } else { | |
1077 save=0; | |
1078 xreg = get_register(); | |
1079 } | |
1080 if (save) | |
245 | 1081 printf("\tlea %d(%%esp),%s\n",SIZE_OF_INT,register_name(xreg,0)); |
61 | 1082 else |
1083 printf("\tmovl %%esp,%s\n",register_name(xreg,0)); | |
1084 regv[xreg]=1; | |
1085 /* downward direction copy */ | |
1086 emit_copy(creg,xreg,length,0,0,1); | |
1087 /* we have value in creg, it may be changed */ | |
1088 if (save) { | |
1089 if(creg==xreg) { | |
1090 creg = get_register(); /* creg is freed in emit_copy */ | |
1091 } | |
1092 printf("\tpopl %s\n",register_name(xreg,0)); | |
1093 regv[xreg]=1; | |
1094 } else | |
1095 free_register(xreg); | |
245 | 1096 return length/SIZE_OF_INT; |
61 | 1097 } |
1098 | |
94 | 1099 int |
61 | 1100 function(int e1) |
1101 { | |
127 | 1102 int e2,e3,e4,nargs,t,ret_type; |
1103 NMTBL *n=0; | |
61 | 1104 int save,saved; |
136
069960078249
remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents:
133
diff
changeset
|
1105 ret_type = cadr(cadddr(e1)); |
069960078249
remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents:
133
diff
changeset
|
1106 if (ret_type==CHAR) ret_type=INT; |
069960078249
remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents:
133
diff
changeset
|
1107 |
94 | 1108 #ifdef SAVE_STACKS |
1109 code_save_stacks(); | |
237 | 1110 #if FLOAT_CODE |
1111 code_save_fstacks(); | |
1112 #endif | |
94 | 1113 #endif |
137 | 1114 if (free_register_count(0)<1) { |
61 | 1115 for(save = 0;save==dreg||save==creg;save++); |
1116 printf("\tpushl %s\n",register_name(save,0)); | |
1117 saved = 1; | |
1118 } else { | |
1119 save = get_register(); | |
1120 saved = 0; | |
1121 } | |
1122 regv[save]=0; | |
1123 e2 = cadr(e1); | |
1124 nargs = 0; | |
1125 for (e3 = caddr(e1); e3; e3 = cadr(e3)) { | |
1126 t=caddr(e3); | |
127 | 1127 e4 = car(e3); |
61 | 1128 if(scalar(t)) { |
240 | 1129 if (car(e4)==REGISTER) { |
1130 printf("\tpushl %s\n",register_name(cadr(e4),0)); | |
1131 } else { | |
1132 g_expr(e4); | |
1133 printf("\tpushl %s\n",register_name(creg,0)); | |
1134 } | |
237 | 1135 } else if (t==LONGLONG||t==ULONGLONG) { |
240 | 1136 if (car(e4)==LREGISTER) { |
1137 printf("\tpushl %s\n\tpushl %s\n",l_edx(cadr(e4)),l_eax(cadr(e4))); | |
1138 } else { | |
1139 g_expr(e4); | |
1140 printf("\tpushl %%edx\n\tpushl %%eax\n"); | |
1141 } | |
241 | 1142 ++nargs; |
82 | 1143 } else if (t==DOUBLE) { |
1144 g_expr(e4); | |
1145 printf("\tleal\t-8(%%esp),%%esp\n\tfstpl\t(%%esp)\n"); | |
245 | 1146 nargs += SIZE_OF_DOUBLE/SIZE_OF_INT; |
83 | 1147 fregv[freg]=0; |
82 | 1148 continue; |
1149 } else if (t==FLOAT) { | |
1150 g_expr(e4); | |
1151 printf("\tleal\t-4(%%esp),%%esp\n\tfstps\t(%%esp)\n"); | |
245 | 1152 nargs += SIZE_OF_FLOAT/SIZE_OF_INT; |
83 | 1153 fregv[freg]=0; |
82 | 1154 continue; |
61 | 1155 } else if (car(t)==STRUCT||car(t)==UNION) { |
1156 nargs += struct_push(e4,t); | |
1157 continue; | |
1158 } else { | |
1159 error(TYERR); | |
1160 } | |
1161 ++nargs; | |
1162 } | |
1163 if (car(e2) == FNAME) { | |
1164 n=(NMTBL *)cadr(e2); | |
78 | 1165 regv[creg]=0; |
1166 use_register(creg,REG_EAX,0); /* will be destroyed */ | |
61 | 1167 } else { |
1168 g_expr(e2); | |
78 | 1169 regv[creg]=1; |
1170 use_register(creg,REG_EAX,1); /* will be destroyed */ | |
61 | 1171 } |
1172 | |
1173 /* we don't have to save creg nor dreg */ | |
1174 regs[creg]=0; regs[dreg]=0; | |
78 | 1175 regv[dreg]= regv[save]= 0; |
239 | 1176 use_register(dreg,REG_EBX,0); /* will be destroyed */ |
61 | 1177 use_register(save,REG_ECX,0); /* will be destroyed */ |
1178 regs[creg]=1; regs[dreg]=1; | |
1179 | |
1180 if (car(e2) == FNAME) { | |
1181 printf("\tcall\t%s\n",n->nm); | |
1182 } else { | |
1183 printf("\tcall\t*%s\n",register_name(creg,0)); | |
1184 } | |
245 | 1185 if (nargs) printf("\taddl $%d,%%esp\n",SIZE_OF_INT*nargs); |
61 | 1186 if (saved) { |
1187 printf("\tpopl %s\n",register_name(save,0)); | |
1188 } else { | |
1189 free_register(save); | |
1190 } | |
1191 regv[save]=0; | |
105 | 1192 if (ret_type==DOUBLE||ret_type==FLOAT) { |
239 | 1193 } else if (ret_type==LONGLONG||ret_type==ULONGLONG) { |
243 | 1194 use_longlong0(USE_CREG); |
1195 regv[creg]=1; | |
105 | 1196 } else if (ret_type==VOID) { |
243 | 1197 regv[freg]=0; regv[creg]=0; |
94 | 1198 } else { |
243 | 1199 use_register(creg,REG_EAX,0); |
94 | 1200 fregv[freg]=0; regv[creg]=1; |
1201 } | |
105 | 1202 return ret_type; |
61 | 1203 } |
1204 | |
1205 void | |
1206 code_frame_pointer(int e3) { | |
235 | 1207 use_int(e3); |
61 | 1208 printf("\tmovl %s,%%ebp\n",register_name(e3,0)); |
1209 } | |
1210 | |
1211 | |
1212 void | |
62 | 1213 code_fix_frame_pointer(int disp_offset) { |
61 | 1214 printf("\tlea %d(%%ebp),%%ebp\n",disp_offset); |
1215 } | |
1216 | |
1217 | |
1218 void | |
1219 code_jmp(char *s) { | |
1220 printf("\tjmp %s\n",s); | |
1221 } | |
1222 | |
1223 | |
1224 void | |
1225 code_indirect_jmp(int e2) { | |
1226 printf("\tjmp *%s\n",register_name(e2,0)); | |
1227 } | |
1228 | |
94 | 1229 int |
245 | 1230 code_rindirect(int e1, int reg,int offset, int sign) |
196 | 1231 { |
1232 char *crn,*op; | |
1233 int byte; | |
1234 g_expr(e1); | |
1235 byte = 0; op="movl"; | |
1236 crn = register_name(creg,0); | |
235 | 1237 use_int(reg); |
1238 printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0)); | |
246 | 1239 return sign?INT:UNSIGNED; |
196 | 1240 } |
1241 | |
1242 int | |
245 | 1243 code_crindirect(int e1, int reg,int offset, int sign) |
61 | 1244 { |
196 | 1245 char *crn,*op; |
1246 int byte; | |
1247 g_expr(e1); | |
245 | 1248 byte = 0; op=sign?"movsbl":"movzbl"; |
196 | 1249 crn = register_name(creg,0); |
235 | 1250 use_int(reg); |
1251 printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0)); | |
246 | 1252 return sign?CHAR:UCHAR; |
196 | 1253 } |
1254 | |
1255 int | |
245 | 1256 code_srindirect(int e1, int reg,int offset, int sign) |
196 | 1257 { |
1258 char *crn,*op; | |
1259 int byte; | |
1260 g_expr(e1); | |
245 | 1261 byte = 0; op=sign?"movswl":"movzwl"; |
196 | 1262 crn = register_name(creg,0); |
235 | 1263 use_int(reg); |
1264 printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0)); | |
246 | 1265 return sign?SHORT:USHORT; |
196 | 1266 } |
1267 | |
195 | 1268 #if FLOAT_CODE |
196 | 1269 int |
225 | 1270 code_drindirect(int e1, int reg,int offset, int d) |
196 | 1271 { |
1272 g_expr(e1); | |
1273 printf("\t%s (%s)\n",fload(d),register_name(creg,0)); | |
1274 return DOUBLE; | |
1275 } | |
195 | 1276 #endif |
196 | 1277 |
1278 #if LONGLONG_CODE | |
237 | 1279 |
1280 static void | |
239 | 1281 lload(int creg,int offset,int reg) |
237 | 1282 { |
1283 char *crn = register_name(creg,0); | |
239 | 1284 use_longlong(reg); |
1285 if((reg==REG_L&&rname[creg]==REG_ESI)||(rname[creg]==REG_EAX)) { | |
245 | 1286 printf("\tmovl %d(%s),%s\n",offset+SIZE_OF_INT,crn,l_edx(reg)); |
240 | 1287 printf("\tmovl %d(%s),%s\n",offset,crn,l_eax(reg)); |
237 | 1288 } else { |
239 | 1289 printf("\tmovl %d(%s),%s\n",offset,crn,l_eax(reg)); |
245 | 1290 printf("\tmovl %d(%s),%s\n",offset+SIZE_OF_INT,crn,l_edx(reg)); |
237 | 1291 } |
1292 } | |
1293 | |
196 | 1294 int |
225 | 1295 code_lrindirect(int e1, int reg, int offset, int us) |
196 | 1296 { |
240 | 1297 int reg0; |
237 | 1298 g_expr(e1); |
240 | 1299 regv[reg0=creg]=1; |
237 | 1300 use_longlong(reg); |
240 | 1301 lload(reg0,offset,reg); |
203 | 1302 return LONGLONG; |
61 | 1303 } |
196 | 1304 #endif |
61 | 1305 |
1306 char * | |
1307 move(int byte) | |
1308 { | |
245 | 1309 return byte==1?"movb":byte==SIZE_OF_SHORT?"movw":"movl"; |
61 | 1310 } |
1311 | |
1312 void | |
103 | 1313 code_assign_gvar(int e2,int creg,int byte) { |
235 | 1314 use_int(creg); |
61 | 1315 if (byte) use_data_reg(creg,1); |
109 | 1316 printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),((NMTBL*)cadr(e2))->nm); |
61 | 1317 } |
1318 | |
1319 void | |
103 | 1320 code_assign_lvar(int e2,int creg,int byte) { |
235 | 1321 use_int(creg); |
61 | 1322 if (byte) use_data_reg(creg,1); |
119 | 1323 printf("\t%s %s,%d(%%ebp)\n",move(byte),register_name(creg,byte),lvar(e2)); |
61 | 1324 } |
1325 | |
1326 void | |
111 | 1327 code_assign_register(int e2,int byte,int creg) { |
235 | 1328 use_int(creg); |
286 | 1329 if (creg!=e2) |
1330 printf("\tmovl %s,%s\n",register_name(creg,0),register_name(e2,0)); | |
61 | 1331 } |
1332 | |
1333 void | |
118 | 1334 code_assign(int e2,int byte,int creg) { |
235 | 1335 use_int(e2); |
1336 use_int(creg); | |
95 | 1337 if (byte) use_data_reg(creg,1); |
61 | 1338 printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte),register_name(e2,0)); |
144 | 1339 regv[creg]=1; |
61 | 1340 } |
1341 | |
1342 void | |
225 | 1343 code_register_assop(int e2,int reg0,int op,int byte) { |
61 | 1344 int reg; |
1345 int xreg = creg; | |
1346 creg = reg = e2; | |
225 | 1347 tosop(op,reg,xreg); |
61 | 1348 creg = xreg; |
286 | 1349 // printf("\tmovl %s,%s\n",register_name(reg,0),register_name(creg,0)); |
159 | 1350 regs[creg]=regv[creg]=1; |
61 | 1351 } |
1352 | |
1353 | |
1354 void | |
225 | 1355 code_assop(int op,int reg,int byte,int sign) { |
61 | 1356 char *xrn; |
1357 int xreg; | |
237 | 1358 int edx = edx_setup(-1); |
235 | 1359 use_int(reg); |
61 | 1360 xrn = register_name(xreg = emit_pop(0),0); /* pop e3 value */ |
1361 regv[xreg]=regs[xreg]=1; | |
235 | 1362 printf("\tmovl %s,%s # assop \n",register_name(reg,0),register_name(edx,0)); |
61 | 1363 regv[edx]=1; |
235 | 1364 ld_indexx(byte,0,edx,reg,sign); |
225 | 1365 tosop(op,reg,xreg); |
235 | 1366 printf("\t%s %s,(%s)\n",move(byte),register_name(reg,byte),register_name(edx,0)); |
61 | 1367 edx_cleanup(); |
1368 emit_pop_free(xreg); | |
144 | 1369 regv[creg]=1; |
61 | 1370 } |
1371 | |
1372 | |
1373 void | |
225 | 1374 tosop(int op,int reg,int oreg) |
61 | 1375 { |
1376 int dx; | |
1377 char *orn,*crn; | |
235 | 1378 use_int(reg); |
61 | 1379 |
1380 switch(op) { | |
1381 case LSHIFT: | |
1382 case ULSHIFT: | |
235 | 1383 shift("sall",oreg,reg); |
144 | 1384 regv[creg]=1; |
61 | 1385 return; |
1386 case RSHIFT: | |
235 | 1387 shift("sarl",oreg,reg); |
144 | 1388 regv[creg]=1; |
61 | 1389 return; |
1390 case URSHIFT: | |
235 | 1391 shift("shrl",oreg,reg); |
144 | 1392 regv[creg]=1; |
61 | 1393 return; |
1394 } | |
1395 if(oreg==-1) { | |
1396 printf("\tpopl %s\n",register_name(dreg,0)); | |
1397 oreg = dreg; | |
1398 regv[dreg]=1; | |
94 | 1399 } else if (oreg<= -REG_LVAR_OFFSET) { |
119 | 1400 code_rlvar(oreg+REG_LVAR_OFFSET,dreg); |
117 | 1401 free_lvar(oreg+REG_LVAR_OFFSET); |
94 | 1402 oreg = dreg; |
1403 regv[dreg]=1; | |
61 | 1404 } |
1405 regv[oreg]=1; regs[oreg]=1; | |
1406 orn = register_name(oreg,0); | |
1407 crn = register_name(creg,0); | |
1408 switch(op) { | |
1409 case ADD: | |
1410 printf("\taddl %s,%s\n",orn,crn); | |
1411 break; | |
89 | 1412 case SUB: case CMP: |
61 | 1413 printf("\tsubl %s,%s\n",orn,crn); |
1414 break; | |
1415 case BAND: | |
1416 printf("\tandl %s,%s\n",orn,crn); | |
1417 break; | |
1418 case EOR: | |
1419 printf("\txorl %s,%s\n",orn,crn); | |
1420 break; | |
1421 case BOR: | |
1422 printf("\torl %s,%s\n",orn,crn); | |
1423 break; | |
1424 case MUL: | |
1425 case UMUL: | |
1426 printf("\t%s %s,%s\n","imull",orn,crn); | |
1427 break; | |
1428 case DIV: | |
1429 case UDIV: | |
1430 use_register(creg,REG_EAX,1); | |
237 | 1431 edx_setup(REG_EDX); |
61 | 1432 orn = register_name(oreg,0); |
1433 if (op==DIV) | |
127 | 1434 printf("\tcltd\n\tidivl %s\n",orn); |
61 | 1435 else |
127 | 1436 printf("\txor %%edx,%%edx\n\tdivl %s\n",orn); |
61 | 1437 edx_cleanup(); |
1438 break; | |
1439 case MOD: | |
1440 case UMOD: | |
1441 use_register(creg,REG_EAX,1); | |
237 | 1442 edx_setup(REG_EDX); |
61 | 1443 orn = register_name(oreg,0); |
235 | 1444 if (op==MOD) |
127 | 1445 printf("\tcltd\n\tidivl %s\n",orn); |
61 | 1446 else |
127 | 1447 printf("\txor %%edx,%%edx\n\tdivl %s\n",orn); |
61 | 1448 dx = virtual(REG_EDX); |
1449 if (dx!=creg) { | |
1450 rname[dx]=rname[creg]; | |
1451 rname[creg]=REG_EDX; | |
1452 } | |
1453 edx_cleanup(); | |
1454 break; | |
1455 } | |
159 | 1456 if (oreg!=dreg&&oreg!=creg&&oreg>=0) |
61 | 1457 free_register(oreg); |
94 | 1458 else if (oreg==dreg) regv[dreg]=0; |
144 | 1459 regv[creg]=1; |
61 | 1460 } |
1461 | |
189 | 1462 int |
240 | 1463 code_const_op_p(int op,int e) |
189 | 1464 { |
240 | 1465 if (car(e)!=CONST) return 0; |
190 | 1466 if (op==DIV||op==UDIV||op==MOD||op==UMOD) return 0; |
189 | 1467 else return 1; |
1468 } | |
1469 | |
1470 void | |
225 | 1471 oprtc(int op,int reg,int orn) |
189 | 1472 { |
235 | 1473 char *crn; |
1474 use_int(reg); | |
1475 crn = register_name(reg,0); | |
240 | 1476 orn = cadr(orn); |
189 | 1477 |
1478 switch(op) { | |
1479 case LSHIFT: | |
1480 case ULSHIFT: | |
1481 printf("\tsall $%d,%s\n",orn,crn); | |
1482 return; | |
1483 case RSHIFT: | |
1484 printf("\tsarl $%d,%s\n",orn,crn); | |
1485 return; | |
1486 case URSHIFT: | |
1487 printf("\tshrl $%d,%s\n",orn,crn); | |
1488 return; | |
1489 case ADD: | |
1490 printf("\taddl $%d,%s\n",orn,crn); | |
1491 break; | |
1492 case SUB: case CMP: | |
1493 printf("\tsubl $%d,%s\n",orn,crn); | |
1494 break; | |
1495 case BAND: | |
1496 printf("\tandl $%d,%s\n",orn,crn); | |
1497 break; | |
1498 case EOR: | |
1499 printf("\txorl $%d,%s\n",orn,crn); | |
1500 break; | |
1501 case BOR: | |
1502 printf("\torl $%d,%s\n",orn,crn); | |
1503 break; | |
1504 case MUL: | |
1505 case UMUL: | |
1506 printf("\t%s $%d,%s\n","imull",orn,crn); | |
1507 break; | |
1508 default: | |
1509 error(-1); | |
1510 } | |
1511 } | |
1512 | |
1513 | |
61 | 1514 static int edx_stack=0; |
1515 | |
1516 int | |
237 | 1517 edx_setup(int rreg) |
61 | 1518 { |
1519 int edx_save; | |
1520 /* make real EDX register empty */ | |
137 | 1521 if (free_register_count(0)<1) { |
61 | 1522 for(edx_save = 0;edx_save==dreg||edx_save==creg;edx_save++); |
1523 printf("\tpushl %s\n",register_name(edx_save,0)); | |
1524 edx_stack = list3(edx_save,edx_stack,0); | |
1525 } else { | |
1526 edx_save = get_register(); | |
1527 edx_stack = list3(edx_save,edx_stack,1); | |
1528 } | |
1529 regv[edx_save]=0; | |
237 | 1530 if (rreg!=-1) |
1531 use_register(edx_save,rreg,0); | |
61 | 1532 return edx_save; |
1533 } | |
1534 | |
1535 | |
1536 void | |
1537 edx_cleanup() | |
1538 { | |
1539 if (caddr(edx_stack)==0) { | |
1540 printf("\tpopl %s\n",register_name(car(edx_stack),0)); | |
1541 } else | |
1542 free_register(car(edx_stack)); | |
1543 edx_stack = cadr(edx_stack); | |
1544 } | |
1545 | |
1546 void | |
235 | 1547 shift(char *op, int reg,int creg) |
61 | 1548 { |
235 | 1549 use_int(creg); |
61 | 1550 if (reg>=0) { |
1551 use_register(reg,REG_ECX,1); | |
103 | 1552 } else if (reg<= -REG_LVAR_OFFSET) { |
1553 use_register(dreg,REG_ECX,0); | |
119 | 1554 code_rlvar(reg+REG_LVAR_OFFSET,dreg); |
103 | 1555 reg = dreg; |
1556 regv[dreg]=0; | |
61 | 1557 } else { |
1558 use_register(dreg,REG_ECX,0); | |
1559 printf("\tpopl %%ecx\n"); | |
103 | 1560 regv[dreg]=0; |
61 | 1561 } |
1562 printf("\t%s %%cl,%s\n",op,register_name(creg,0)); | |
1563 } | |
1564 | |
1565 void | |
235 | 1566 ld_indexx(int byte, int n, int xreg,int reg,int sign) |
61 | 1567 { |
1568 char *op; | |
1569 | |
235 | 1570 use_int(reg); |
166 | 1571 op = byte ? (sign?"movsbl":"movzbl") : "movl"; |
61 | 1572 if (n) |
95 | 1573 printf("\t%s %d(%s),%s\n",op,n, |
235 | 1574 register_name(xreg,0),register_name(reg,byte)); |
61 | 1575 else |
95 | 1576 printf("\t%s (%s),%s\n",op, |
235 | 1577 register_name(xreg,0),register_name(reg,byte)); |
95 | 1578 } |
1579 | |
1580 int | |
1581 code_csvalue() | |
1582 { | |
123 | 1583 return rname[creg]; /* for switch value */ |
61 | 1584 } |
1585 | |
1586 void | |
287 | 1587 code_cmpdimm(int e, int csreg,int label,int cond) |
61 | 1588 { |
1589 /* used in dosiwtch() */ | |
66 | 1590 if(chk) return; |
123 | 1591 use_register(creg,csreg,0); |
61 | 1592 printf("\tcmpl $%d,%s\n",e,register_name(creg,0)); |
287 | 1593 jcond(label,cond); |
61 | 1594 } |
1595 | |
1596 void | |
66 | 1597 code_opening(char *filename) |
61 | 1598 { |
1599 printf("\t.file \"%s\"\n",filename); | |
1600 printf("\t.version\t\"01.01\"\n"); | |
66 | 1601 /* printf("gcc2_compiled.:\n"); */ |
61 | 1602 printf(".text\n"); |
1603 } | |
1604 | |
1605 void | |
66 | 1606 code_closing() |
61 | 1607 { |
78 | 1608 global_table(); |
61 | 1609 printf("\t.ident \"Micro-C compiled\"\n"); |
1610 } | |
1611 | |
291 | 1612 static char * |
1613 code_cond(int op,int cond) | |
1614 { | |
1615 switch(op) { | |
1616 case GT: return code_gt(cond); | |
1617 case UGT: return code_ugt(cond); | |
1618 case GE: return code_ge(cond); | |
1619 case UGE: return code_uge(cond); | |
1620 case LT: return code_ge(!cond); | |
1621 case ULT: return code_uge(!cond); | |
1622 case LE: return code_gt(!cond); | |
1623 case ULE: return code_ugt(!cond); | |
1624 case EQ: return code_eq(cond); | |
1625 case NEQ: return code_eq(!cond); | |
1626 default: return 0; | |
1627 } | |
1628 } | |
1629 | |
1630 static int | |
1631 rexpr_bool(int e1,int reg) | |
1632 { | |
1633 char *s; | |
1634 if (!(s=code_cond(car(e1),1))) return 0; | |
1635 g_expr(list3(CMP,cadr(e1),caddr(e1))); | |
1636 use_int(reg); | |
1637 use_data_reg(reg,0); | |
1638 printf("\tset%s\t%s\n",s,register_name(reg,1)); | |
1639 printf("\tmovzbl %s,%s\n",register_name(reg,1),register_name(reg,0)); | |
1640 return 1; | |
1641 } | |
1642 | |
61 | 1643 void |
280 | 1644 rexpr(int e1, int l1, int cond,int t) |
1645 { | |
89 | 1646 g_expr(list3(CMP,cadr(e1),caddr(e1))); |
291 | 1647 printf("\tj%s\t_%d\n",code_cond(car(e1),cond),l1); |
61 | 1648 } |
1649 | |
82 | 1650 |
287 | 1651 static void |
61 | 1652 jcond(int l, char cond) |
1653 { | |
66 | 1654 if (chk) return; |
61 | 1655 printf("\tj%s\t_%d\n",cond?"ne":"e",l); |
1656 } | |
1657 | |
1658 void | |
1659 jmp(int l) | |
1660 { | |
1661 control=0; | |
66 | 1662 if (chk) return; |
61 | 1663 printf("\tjmp\t_%d\n",l); |
1664 /* align? */ | |
1665 /* | |
1666 this is not allowed because of ? operator | |
1667 regv[creg]=regv[dreg]=0; | |
1668 use_register(creg,REG_EAX,0); | |
1669 use_register(dreg,REG_EBX,0); | |
1670 */ | |
1671 } | |
1672 | |
1673 void | |
1674 gen_comment(char *s) | |
1675 { | |
66 | 1676 if (chk) return; |
1677 printf("## %s",s); | |
61 | 1678 } |
1679 | |
1680 | |
1681 void | |
1682 code_enter(char *name) | |
1683 { | |
1684 printf("\t.align 4\n"); | |
1685 if (stmode!=STATIC) | |
1686 printf(".globl %s\n",name); | |
1687 printf("\t.type\t%s,@function\n",name); | |
1688 printf("%s:\n",name); | |
1689 } | |
1690 | |
77 | 1691 |
61 | 1692 void |
1693 code_enter1(int args) | |
1694 { | |
1695 code_disp_label=fwdlabel(); | |
1696 printf("\tlea _%d(%%ebp),%%esp\n",code_disp_label); | |
1697 | |
1698 printf("## args %d disp %d code_arg_offset=%d code_disp_offset=%d\n",args,disp,code_arg_offset,code_disp_offset); | |
1699 } | |
1700 | |
1701 void | |
1702 code_leave(char *name) | |
1703 { | |
245 | 1704 disp &= -SIZE_OF_INT; |
61 | 1705 printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset); |
1706 printf("_%d:\n",labelno); | |
1707 printf("\t.size\t%s,_%d-%s\n",name,labelno,name); | |
1708 local_table(); | |
1709 labelno++; | |
1710 free_all_register(); | |
1711 } | |
1712 | |
1713 void | |
1714 enter(char *name) | |
1715 { | |
1716 printf("\t.align 2\n"); | |
1717 if (stmode!=STATIC) | |
1718 printf(".globl %s\n",name); | |
1719 printf("%s:\n",name); | |
1720 printf("\t.type\t%s,@function\n",name); | |
1721 printf("\tpushl %%ebp\n"); | |
1722 printf("\tmovl %%esp,%%ebp\n"); | |
1723 printf("\tpushl %%ebx\n"); | |
1724 printf("\tpushl %%esi\n"); | |
1725 printf("\tpushl %%edi\n"); | |
1726 } | |
1727 | |
1728 void | |
1729 enter1() | |
1730 { | |
182 | 1731 text_mode(); |
61 | 1732 func_disp_label=fwdlabel(); |
1733 printf("\tlea _%d(%%ebp),%%esp\n",func_disp_label); | |
1734 /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */ | |
1735 } | |
1736 | |
1737 void | |
1738 leave(int control, char *name) | |
1739 { | |
128 | 1740 int sz; |
1741 | |
245 | 1742 disp &= -SIZE_OF_INT; |
61 | 1743 if (control) |
108 | 1744 code_set_return_register(1); |
61 | 1745 if (retcont) { |
1746 if (control) | |
1747 jmp(retlabel); | |
1748 fwddef(retcont); | |
128 | 1749 if (cadr(fnptr->ty)==FLOAT||cadr(fnptr->ty)==DOUBLE) { |
245 | 1750 printf("\tfldl %d(%%ebp)\n",-SIZE_OF_DOUBLE); |
128 | 1751 } else if (cadr(fnptr->ty)>0&&( |
1752 car(cadr(fnptr->ty))==STRUCT || | |
1753 car(cadr(fnptr->ty))==UNION)) { | |
1754 sz = size(cadr(fnptr->ty)); | |
1755 printf("\tlea %d(%%ebp),%s\n",-sz,register_name(dreg,0)); | |
245 | 1756 printf("\tmovl %d(%%ebp),%s\n",disp-SIZE_OF_INT, |
128 | 1757 register_name(creg,0)); |
1758 emit_copy(dreg,creg,sz,0,1,1); | |
1759 } else if (cadr(fnptr->ty)!=VOID) { | |
1760 use_register(creg,REG_EAX,0); | |
1761 printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0)); | |
1762 } | |
61 | 1763 } |
1764 fwddef(retlabel); | |
63 | 1765 |
61 | 1766 printf("\tlea %d(%%ebp),%%esp\n",disp_offset); |
1767 printf("\tpopl %%edi\n"); | |
1768 printf("\tpopl %%esi\n"); | |
1769 printf("\tpopl %%ebx\n"); | |
1770 printf("\tleave\n"); | |
1771 printf("\tret\n"); | |
1772 printf("\t.set _%d,%d\n",func_disp_label,disp+disp_offset); | |
1773 printf("_%d:\n",labelno); | |
1774 printf("\t.size\t%s,_%d-%s\n",name,labelno,name); | |
1775 local_table(); | |
1776 labelno++; | |
1777 free_all_register(); | |
1778 } | |
1779 | |
187 | 1780 int |
1781 code_get_fixed_creg(int reg,int type) { | |
1782 if (type==FLOAT||type==DOUBLE) { | |
1783 return 0; | |
239 | 1784 } else if (type==LONGLONG||type==ULONGLONG) { |
1785 use_longlong(reg); | |
1786 return reg; | |
187 | 1787 } else { |
236 | 1788 use_int(reg); |
187 | 1789 return rname[reg]; |
1790 } | |
1791 } | |
61 | 1792 |
1793 void | |
187 | 1794 code_set_fixed_creg(int reg,int mode,int type) { |
108 | 1795 if (type==FLOAT||type==DOUBLE) { |
239 | 1796 } else if (type==LONGLONG||type==ULONGLONG) { |
187 | 1797 } else { |
1798 use_register(creg,reg,mode); | |
1799 } | |
61 | 1800 } |
1801 | |
1802 void | |
107 | 1803 code_set_return_register(int mode) { |
1804 if (fnptr->ty==DOUBLE||fnptr->ty==FLOAT) { | |
239 | 1805 } else if (fnptr->ty==LONGLONG||fnptr->ty==ULONGLONG) { |
243 | 1806 use_longlong0(USE_CREG); |
107 | 1807 } else { |
1808 use_register(creg,REG_EAX,mode); | |
1809 } | |
1810 } | |
1811 | |
1812 void | |
61 | 1813 gen_gdecl(char *n, int gpc) |
1814 { | |
1815 /* | |
1816 if (stmode!=STATIC) | |
1817 printf(".globl %s\n",n); | |
1818 */ | |
1819 } | |
1820 | |
1821 void | |
1822 align(int t) | |
1823 { | |
1824 if (t!=CHAR) { | |
1825 if (data_alignment & 1) | |
1826 printf("\t.align 2\n"); | |
1827 data_alignment = 0; | |
1828 } | |
1829 } | |
1830 | |
239 | 1831 #if LONGLONG_CODE |
1832 static long long ll0 = 1LL; | |
1833 | |
1834 static int | |
1835 code_l1(long long d) | |
1836 { | |
1837 int *i = (int *)&ll0; int *j = (int *)&d; | |
1838 return (i[1] == 1)?j[1]:j[0]; | |
1839 } | |
1840 | |
1841 static int | |
1842 code_l2(long long d) | |
1843 { | |
1844 int *i = (int *)&ll0; int *j = (int *)&d; | |
1845 return (i[1] == 1)?j[0]:j[1]; | |
1846 } | |
1847 #endif | |
1848 | |
61 | 1849 void |
1850 emit_data(int e, int t, NMTBL *n) | |
1851 { | |
1852 int l; | |
195 | 1853 #if FLOAT_CODE |
82 | 1854 double d; |
1855 float f; | |
195 | 1856 #endif |
239 | 1857 #if LONGLONG_CODE |
1858 long long ll; | |
1859 #endif | |
61 | 1860 char *name; |
1861 name = n->nm; | |
156 | 1862 if(mode!=GDECL && mode!=STADECL) { |
61 | 1863 error(-1); return; |
1864 } | |
66 | 1865 if (chk) return; |
61 | 1866 if (n->dsp != -1) { |
1867 n->dsp = -1; /* initiallized flag */ | |
1868 printf(".globl\t%s\n",name); | |
1869 data_mode(name); | |
1870 align(t); | |
1871 printf("%s:\n",name); | |
1872 } else { | |
1873 data_mode(0); | |
1874 } | |
1875 if(car(e)==CONST) { | |
168 | 1876 if (t==CHAR||t==UCHAR) { |
61 | 1877 printf("\t.byte %d\n",cadr(e)); |
1878 if (data_alignment>0) | |
1879 data_alignment++; | |
1880 gpc += 1; | |
168 | 1881 } else if (t==SHORT||t==USHORT) { |
1882 printf("\t.short %d\n",cadr(e)); | |
82 | 1883 if (data_alignment>0) data_alignment++; |
245 | 1884 gpc += SIZE_OF_SHORT; |
61 | 1885 } else { |
1886 printf("\t.long %d\n",cadr(e)); | |
245 | 1887 gpc += SIZE_OF_INT; |
61 | 1888 } |
239 | 1889 #if LONGLONG_CODE |
1890 } else if(t==LONGLONG||t==ULONGLONG) { | |
1891 ll = lcadr(e); | |
243 | 1892 printf("\t.long\t0x%x,0x%x\n",code_l1(ll),code_l2(ll)); |
239 | 1893 #endif |
195 | 1894 #if FLOAT_CODE |
82 | 1895 } else if(t==DOUBLE) { |
1896 d = dcadr(e); | |
1897 printf("\t.long\t0x%x,0x%x\n",code_d1(d),code_d2(d)); | |
1898 } else if(t==FLOAT) { | |
1899 f = dcadr(e); | |
1900 printf("\t.long\t0x%x\n",*(int *)&f); | |
195 | 1901 #endif |
61 | 1902 } else if(t!=CHAR) { |
245 | 1903 gpc += SIZE_OF_INT; |
61 | 1904 if(car(e)==ADDRESS&&car(cadr(e))==GVAR) { |
109 | 1905 printf("\t.long %s\n",((NMTBL *)cadr(cadr(e)))->nm); |
1906 } else if(car(e)==GVAR) { | |
1907 printf("\t.long %s\n",((NMTBL *)cadr(e))->nm); | |
61 | 1908 } else if(car(e)==FNAME) { |
1909 printf("\t.long %s\n",((NMTBL *)cadr(e))->nm); | |
1910 } else if(car(e)==STRING) { | |
1911 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) { | |
1912 l = fwdlabel(); | |
1913 printf("\t.long _%d\n",l); | |
1914 printf(".section\t.rodata\n"); | |
1915 printf("_%d:\n",l); | |
1916 output_mode = RODATA_EMIT_MODE; | |
1917 } | |
1918 ascii((char *)cadr(e)); | |
1919 } else error(TYERR); | |
168 | 1920 } else error(TYERR); |
61 | 1921 } |
1922 | |
1923 void | |
1924 emit_data_closing(NMTBL *n) | |
1925 { | |
1926 int lb; | |
66 | 1927 if (chk) return; |
61 | 1928 if (mode==GDECL) { |
1929 data_mode(0); | |
1930 lb=fwdlabel(); | |
1931 printf("_%d:\n",lb); | |
1932 printf("\t.size\t%s,_%d-%s\n",n->nm,lb,n->nm); | |
1933 } | |
1934 } | |
1935 | |
1936 void | |
1937 global_table(void) | |
1938 { | |
1939 NMTBL *n; | |
1940 int init; | |
1941 init=0; | |
1942 for(n=ntable;n < &ntable[GSYMS];n++) { | |
117 | 1943 if ((n->sc == GVAR||n->sc == STATIC) && n->dsp != -1) { |
61 | 1944 /* n->dsp = -1 means initialized global */ |
1945 if (init==0) { | |
1946 data_mode(0); | |
1947 init=1; | |
1948 } | |
1949 printf(".comm %s,%d\n",n->nm,size(n->ty)); | |
1950 } | |
1951 } | |
1952 } | |
1953 | |
1954 void | |
1955 local_table(void) | |
1956 { | |
1957 NMTBL *n; | |
1958 int init; | |
1959 init=0; | |
1960 /* static local variables */ | |
1961 for(n=ntable+GSYMS;n < &ntable[GSYMS+LSYMS];n++) { | |
1962 if (n->sc == GVAR) { | |
1963 if (init==0) { | |
1964 data_mode(0); | |
1965 init=1; | |
1966 } | |
156 | 1967 if (n->dsp!= -1) /* -1 means initialized global */ |
1968 printf(".lcomm %s,%d\n",n->nm,size(n->ty)); | |
61 | 1969 } |
1970 } | |
1971 } | |
1972 | |
1973 void | |
1974 text_mode(void) | |
1975 { | |
1976 if (output_mode!=TEXT_EMIT_MODE) { | |
1977 printf(".text\n"); | |
1978 printf("\t.align 2\n"); | |
1979 output_mode = TEXT_EMIT_MODE; | |
1980 } | |
1981 } | |
1982 | |
1983 void | |
1984 data_mode(char *name) | |
1985 { | |
1986 if (output_mode!=DATA_EMIT_MODE) { | |
1987 printf(".data\n"); | |
1988 output_mode = DATA_EMIT_MODE; | |
1989 } | |
1990 if (name) | |
1991 printf("\t.type\t%s,@object\n",name); | |
1992 } | |
1993 | |
195 | 1994 #if FLOAT_CODE |
1995 | |
81 | 1996 /* floating point */ |
1997 | |
1998 | |
82 | 1999 char * |
2000 fstore(int d) | |
2001 { | |
83 | 2002 return use? |
2003 (d?"fstl":"fsts"): | |
2004 (d?"fstpl":"fstps") | |
2005 ; | |
2006 } | |
2007 | |
2008 char * | |
2009 fstore_u(int d) | |
2010 { | |
82 | 2011 return d?"fstpl":"fstps"; |
2012 } | |
81 | 2013 |
82 | 2014 char * |
2015 fload(int d) | |
2016 { | |
2017 return d?"fldl":"flds"; | |
2018 } | |
81 | 2019 |
2020 | |
103 | 2021 void code_dassign_gvar(int e2,int freg,int d) |
82 | 2022 { |
109 | 2023 printf("\t%s %s\n",fstore(d),((NMTBL*)cadr(e2))->nm); |
82 | 2024 } |
2025 | |
103 | 2026 void code_dassign_lvar(int e2,int freg,int d) |
82 | 2027 { |
119 | 2028 printf("\t%s %d(%%ebp)\n",fstore(d),lvar(e2)); |
82 | 2029 } |
2030 | |
138 | 2031 void code_dassign_dregister(int e,int d,int freg) |
111 | 2032 { |
2033 error(-1); | |
2034 } | |
2035 | |
103 | 2036 void code_dassign(int e2,int freg,int d) |
82 | 2037 { |
2038 printf("\t%s (%s)\n",fstore(d),register_name(e2,0)); | |
2039 } | |
2040 | |
2041 static double d0 = 1.0; | |
81 | 2042 |
82 | 2043 int |
2044 code_d1(double d) | |
2045 { | |
2046 int *i = (int *)&d0; int *j = (int *)&d; | |
2047 return (i[1] == 0x3ff00000)?j[0]:j[1]; | |
2048 } | |
2049 | |
2050 int | |
2051 code_d2(double d) | |
2052 { | |
2053 int *i = (int *)&d0; int *j = (int *)&d; | |
2054 return (i[1] == 0x3ff00000)?j[1]:j[0]; | |
2055 } | |
2056 | |
138 | 2057 void code_dconst(int e2,int freg,int d) |
82 | 2058 { |
2059 int lb; | |
138 | 2060 double value = dcadr(e2); |
81 | 2061 |
138 | 2062 if (value==0.0) { |
82 | 2063 printf("\tfldz\n"); return; |
2064 } | |
138 | 2065 if (value==1.0) { |
82 | 2066 printf("\tfld1\n"); return; |
2067 } | |
2068 printf(" \t.section\t.rodata\n\t.align 8\n"); | |
2069 lb=fwdlabel(); | |
2070 printf("_%d:\n",lb); | |
138 | 2071 printf("\t.long\t0x%x,0x%x\n",code_d1(value),code_d2(value)); |
82 | 2072 if (output_mode==TEXT_EMIT_MODE) { |
2073 printf(".text\n"); | |
2074 } else { | |
2075 text_mode(); | |
2076 } | |
2077 printf("\tfldl _%d\n",lb); | |
2078 } | |
2079 | |
138 | 2080 void code_dneg(int freg,int d) |
82 | 2081 { |
2082 printf("\tfchs\n"); | |
2083 } | |
81 | 2084 |
239 | 2085 void code_d2i(int reg) |
82 | 2086 { |
239 | 2087 use_int(reg); |
245 | 2088 printf("\tlea -%d(%%esp),%%esp\n",SIZE_OF_INT*2); |
82 | 2089 printf("\tfnstcw (%%esp)\n"); |
2090 printf("\tmovl (%%esp), %s\n",register_name(creg,0)); | |
2091 printf("\tmovb $12, 1(%%esp)\n"); | |
2092 printf("\tfldcw (%%esp)\n"); | |
245 | 2093 printf("\tfistpl %d(%%esp)\n",SIZE_OF_INT); |
127 | 2094 printf("\tmovl %s, (%%esp)\n",register_name(creg,0)); |
85 | 2095 printf("\tfldcw (%%esp)\n"); |
82 | 2096 printf("\tpopl %s\n",register_name(creg,0)); |
2097 printf("\tpopl %s\n",register_name(creg,0)); | |
2098 } | |
81 | 2099 |
239 | 2100 void code_i2d(int reg) |
82 | 2101 { |
2102 printf("\tpushl %s\n",register_name(creg,0)); | |
2103 printf("\tfildl (%%esp)\n"); | |
245 | 2104 printf("\tlea %d(%%esp),%%esp\n",SIZE_OF_INT); |
82 | 2105 } |
2106 | |
239 | 2107 void code_d2u(int reg) |
85 | 2108 { |
239 | 2109 use_int(reg); |
245 | 2110 printf("\tlea -%d(%%esp),%%esp\n",SIZE_OF_INT*3); |
85 | 2111 printf("\tfnstcw (%%esp)\n"); |
239 | 2112 printf("\tmovl (%%esp), %s\n",register_name(reg,0)); |
85 | 2113 printf("\tmovb $12, 1(%%esp)\n"); |
2114 printf("\tfldcw (%%esp)\n"); | |
239 | 2115 printf("\tmovl %s, (%%esp)\n",register_name(reg,0)); |
245 | 2116 printf("\tfistpll %d(%%esp)\n",SIZE_OF_INT); |
85 | 2117 printf("\tfldcw (%%esp)\n"); |
245 | 2118 printf("\tmovl %d(%%esp),%s\n",SIZE_OF_INT,register_name(reg,0)); |
2119 printf("\tlea %d(%%esp),%%esp\n",SIZE_OF_INT*3); | |
85 | 2120 } |
2121 | |
239 | 2122 void code_u2d(int reg) |
85 | 2123 { |
86 | 2124 printf("\tpushl %s\n",register_name(creg,0)); |
2125 printf("\tpushl %s\n",register_name(creg,0)); | |
245 | 2126 printf("\tmovl $0, %d(%%esp)\n",SIZE_OF_INT); |
86 | 2127 printf("\tfildll (%%esp)\n"); |
245 | 2128 printf("\tlea %d(%%esp),%%esp\n",SIZE_OF_INT*2); |
85 | 2129 } |
2130 | |
239 | 2131 void code_d2f(int reg) { } |
2132 void code_f2d(int reg) { } | |
2133 void code_f2i(int reg) { code_d2i(reg); } | |
2134 void code_f2u(int reg) { code_d2u(reg); } | |
2135 void code_i2f(int reg) { code_i2d(reg); } | |
2136 void code_u2f(int reg) { code_u2d(reg); } | |
133 | 2137 |
107 | 2138 void code_drgvar(int e2,int d,int freg) |
82 | 2139 { |
109 | 2140 printf("\t%s %s\n",fload(d),((NMTBL*)cadr(e2))->nm); |
82 | 2141 } |
81 | 2142 |
2143 | |
107 | 2144 void code_drlvar(int e2,int d,int freg) |
82 | 2145 { |
119 | 2146 printf("\t%s %d(%%ebp)\n",fload(d),lvar(e2)); |
82 | 2147 } |
2148 | |
287 | 2149 void code_cmp_drgvar(int e2,int reg,int d,int label,int cond) |
82 | 2150 { |
109 | 2151 printf("\tfcomp %s\n",((NMTBL*)cadr(e2))->nm); |
287 | 2152 jcond(label,cond); |
82 | 2153 } |
2154 | |
287 | 2155 void code_cmp_drlvar(int e2,int reg,int d,int label,int cond) |
82 | 2156 { |
119 | 2157 printf("\tfcomp %d(%%ebp)\n",lvar(e2)); |
287 | 2158 jcond(label,cond); |
82 | 2159 } |
2160 | |
225 | 2161 void dtosop(int op,int reg,int e1) |
94 | 2162 { |
82 | 2163 switch(op) { |
133 | 2164 case FADD: |
82 | 2165 case DADD: printf("\tfaddp %%st,%%st(1)\n"); break; |
133 | 2166 case FSUB: |
85 | 2167 case DSUB: printf("\tfsubp %%st,%%st(1)\n"); break; |
133 | 2168 case FDIV: |
85 | 2169 case DDIV: printf("\tfdivp %%st,%%st(1)\n"); break; |
133 | 2170 case FMUL: |
82 | 2171 case DMUL: printf("\tfmulp %%st,%%st(1)\n"); break; |
133 | 2172 case FCMP: |
89 | 2173 case DCMP: |
82 | 2174 printf("\tfucompp\n"); |
2175 printf("\tfnstsw\t%%ax\n"); | |
2176 break; | |
2177 } | |
2178 } | |
81 | 2179 |
83 | 2180 void |
225 | 2181 code_dassop(int op,int reg,int d) { |
83 | 2182 /* we have lvalue in creg, applied floating value is in %st(0) */ |
102 | 2183 emit_dpop(d); /* do nothing for 387 */ |
83 | 2184 printf("\t%s (%s)\n",fload(d),register_name(creg,0)); |
225 | 2185 dtosop(op,reg,0); |
83 | 2186 printf("\t%s (%s)\n",fstore(d),register_name(creg,0)); |
2187 } | |
2188 | |
2189 void | |
219 | 2190 code_register_dassop(int reg,int op,int d) { |
2191 error(-1); | |
2192 } | |
2193 | |
2194 void | |
107 | 2195 code_dpreinc(int e1,int e2,int d,int freg) { |
83 | 2196 g_expr(e2); |
2197 printf("\t%s (%s)\n",fload(d),register_name(creg,0)); | |
2198 printf("\tfld1\n"); | |
87 | 2199 if (caddr(e1)>0) |
83 | 2200 printf("\tfaddp %%st,%%st(1)\n"); |
2201 else | |
2202 printf("\tfsubrp %%st,%%st(1)\n"); | |
2203 printf("\t%s (%s)\n",fstore(d),register_name(creg,0)); | |
2204 } | |
2205 | |
2206 void | |
107 | 2207 code_dpostinc(int e1,int e2,int d,int freg) { |
83 | 2208 g_expr(e2); |
2209 printf("\t%s (%s)\n",fload(d),register_name(creg,0)); | |
2210 if (use) | |
86 | 2211 printf("\t%s (%s)\n",fload(d),register_name(creg,0)); |
83 | 2212 printf("\tfld1\n"); |
87 | 2213 if (caddr(e1)>0) |
83 | 2214 printf("\tfaddp %%st,%%st(1)\n"); |
2215 else | |
2216 printf("\tfsubrp %%st,%%st(1)\n"); | |
87 | 2217 printf("\t%s (%s)\n",(use?fstore_u(d):fstore(d)),register_name(creg,0)); |
83 | 2218 } |
2219 | |
291 | 2220 #define COND_BRANCH 1 |
2221 #define COND_VALUE 2 | |
2222 | |
2223 int | |
2224 drexpr0(int e1, int e2,int l1, int op,int cond,int reg,int mode) | |
84 | 2225 { |
291 | 2226 char *s; |
236 | 2227 if (!cond) { |
230 | 2228 switch(op) { |
236 | 2229 case FOP+GT: |
291 | 2230 return drexpr0(e2,e1,l1,FOP+GE,1,reg,mode); |
236 | 2231 case FOP+GE: |
291 | 2232 return drexpr0(e2,e1,l1,FOP+GT,1,reg,mode); |
236 | 2233 case FOP+EQ: |
2234 op=FOP+NEQ; break; | |
2235 case FOP+NEQ: | |
2236 op=FOP+EQ; break; | |
2237 case DOP+GT: | |
291 | 2238 return drexpr0(e2,e1,l1,DOP+GE,1,reg,mode); |
236 | 2239 case DOP+GE: |
291 | 2240 return drexpr0(e2,e1,l1,DOP+GT,1,reg,mode); |
236 | 2241 case DOP+EQ: |
2242 op=DOP+NEQ; break; | |
2243 case DOP+NEQ: | |
2244 op=DOP+EQ; break; | |
291 | 2245 default: return 0; |
230 | 2246 } |
2247 } | |
291 | 2248 s = "e"; |
84 | 2249 switch(op) { |
2250 case DOP+GE: | |
133 | 2251 case FOP+GE: |
291 | 2252 g_expr(list3(DCMP,e1,e2)); |
84 | 2253 printf("\ttestb\t$5,%%ah\n"); |
2254 break; | |
2255 case DOP+GT: | |
133 | 2256 case FOP+GT: |
291 | 2257 g_expr(list3(DCMP,e1,e2)); |
84 | 2258 printf("\ttestb\t$69,%%ah\n"); |
2259 break; | |
2260 case DOP+EQ: | |
133 | 2261 case FOP+EQ: |
291 | 2262 g_expr(list3(DCMP,e1,e2)); |
84 | 2263 printf("\tandb\t$69,%%ah\n"); |
2264 printf("\txorb\t$64,%%ah\n"); | |
2265 break; | |
2266 case DOP+NEQ: | |
133 | 2267 case FOP+NEQ: |
291 | 2268 g_expr(list3(DCMP,e1,e2)); |
84 | 2269 printf("\tandb\t$69,%%ah\n"); |
2270 printf("\txorb\t$64,%%ah\n"); | |
291 | 2271 s = "ne"; |
84 | 2272 break; |
291 | 2273 default: |
2274 return 0; | |
84 | 2275 } |
291 | 2276 if (mode==COND_BRANCH) { |
2277 printf("\tj%s\t_%d\n",s,l1); | |
2278 } else { | |
2279 use_int(reg); use_data_reg(reg,0); | |
2280 printf("\tset%s\t%s\n",s,register_name(reg,1)); | |
2281 printf("\tmovzbl\t%s,%s\n", | |
2282 register_name(reg,1),register_name(reg,0)); | |
2283 } | |
2284 return 1; | |
84 | 2285 } |
2286 | |
291 | 2287 void |
2288 drexpr(int e1, int e2,int l1, int op,int cond) | |
2289 { | |
2290 drexpr0(e1, e2,l1, op,cond,USE_CREG,COND_BRANCH); | |
2291 } | |
2292 | |
2293 static int | |
2294 drexpr_bool(int e1, int reg) | |
2295 { | |
2296 return drexpr0(cadr(e1), caddr(e1),0, car(e1),1,reg,COND_VALUE); | |
2297 } | |
2298 | |
2299 | |
94 | 2300 void |
138 | 2301 code_dregister(int e2,int freg,int d) |
94 | 2302 { |
2303 error(-1); | |
2304 } | |
2305 | |
138 | 2306 void |
287 | 2307 code_cmp_dregister(int e2,int d,int label,int cond) |
94 | 2308 { |
235 | 2309 if (e2!=USE_CREG) |
2310 error(-1); | |
236 | 2311 printf("\tfldz\n"); |
235 | 2312 printf("\tfucompp\n"); |
2313 printf("\tfnstsw\t%%ax\n"); | |
2314 printf("\tandb\t$69,%%ah\n"); | |
2315 printf("\txorb\t$64,%%ah\n"); | |
287 | 2316 jcond(label,cond); |
82 | 2317 } |
81 | 2318 |
97 | 2319 int pop_fregister() |
82 | 2320 { |
94 | 2321 if (freg_sp<0) { error(-1); return -1;} |
2322 printf("# fpop: %d\n",freg_sp-1); | |
2323 return freg_stack[--freg_sp]; | |
82 | 2324 } |
81 | 2325 |
94 | 2326 int |
138 | 2327 emit_dpop(int d) |
94 | 2328 { |
2329 int xreg; | |
97 | 2330 if ((xreg=pop_fregister())==-1) { |
94 | 2331 } else if (xreg<= -REG_LVAR_OFFSET) { |
119 | 2332 code_drlvar(REG_LVAR_OFFSET+xreg,1,freg); |
117 | 2333 free_lvar(xreg+REG_LVAR_OFFSET); |
94 | 2334 /* pushed order is reversed. We don't need this for comutable |
2335 operator, but it is ok to do this. */ | |
2336 printf("\tfxch\t%%st(1)\n"); | |
2337 } | |
2338 return xreg; | |
2339 } | |
2340 | |
2341 | |
138 | 2342 void emit_dpop_free(int e1,int d) |
82 | 2343 { |
2344 } | |
81 | 2345 |
133 | 2346 void emit_dpush(int type) |
82 | 2347 { |
119 | 2348 if (freg_sp>=MAX_FPU_STACK) code_save_fstacks(); |
94 | 2349 if (freg_sp>MAX_MAX) error(-1); |
107 | 2350 freg_stack[freg_sp++]=-1; |
94 | 2351 printf("# fpush:%d\n",freg_sp); |
2352 } | |
2353 | |
195 | 2354 #endif |
2355 | |
94 | 2356 void |
2357 code_save_stacks() | |
2358 { | |
2359 /* temporal registers or stacks in fpu are saved in local variable */ | |
2360 int xreg,sp,screg; | |
2361 sp=reg_sp; | |
2362 while(sp-->0) { | |
2363 if ((xreg=reg_stack[sp])>=0) { | |
2364 screg=creg; | |
2365 if(creg!=xreg) { | |
2366 if (xreg!=dreg) free_register(xreg); | |
2367 creg = xreg; | |
2368 } | |
2369 code_assign_lvar( | |
245 | 2370 (reg_stack[sp]=new_lvar(SIZE_OF_INT)),creg,0); |
94 | 2371 reg_stack[sp]= reg_stack[sp]-REG_LVAR_OFFSET; |
2372 regv[xreg]=0; | |
2373 creg=screg; | |
2374 } | |
2375 } | |
107 | 2376 } |
2377 | |
195 | 2378 #if FLOAT_CODE |
107 | 2379 void |
2380 code_save_fstacks() | |
2381 { | |
127 | 2382 int xreg,sp,uses; |
2383 uses = use; use = 0; | |
94 | 2384 sp=freg_sp; |
2385 while(sp-->0) { | |
2386 if ((xreg=freg_stack[sp])==-1) { | |
2387 code_dassign_lvar( | |
245 | 2388 (freg_stack[sp]=new_lvar(SIZE_OF_DOUBLE)),freg,1); |
94 | 2389 freg_stack[sp]= freg_stack[sp]-REG_LVAR_OFFSET; |
2390 } | |
2391 } | |
127 | 2392 use = uses; |
82 | 2393 } |
195 | 2394 #endif |
2395 | |
2396 | |
2397 | |
2398 #if LONGLONG_CODE | |
2399 | |
2400 | |
2401 /* 64bit int part */ | |
2402 | |
237 | 2403 static void |
2404 pcond(char *s,int l1) | |
195 | 2405 { |
237 | 2406 printf("\tj%s\t_%d\n",s,l1); |
195 | 2407 } |
2408 | |
240 | 2409 void |
2410 lrexpr(int e1, int e2,int l1, int op,int cond) | |
195 | 2411 { |
280 | 2412 int l2; |
2413 code_save_stacks(); | |
237 | 2414 g_expr(e1); |
2415 emit_lpush(); | |
2416 g_expr(e2); | |
280 | 2417 // we are sure %ecx,%ebx is free |
2418 printf("\tpopl %%ecx\n"); // LSW | |
2419 printf("\tpopl %%ebx\n"); // MSW | |
2420 printf("\tsubl %%edx,%%ebx\n"); | |
2421 l2 = fwdlabel(); | |
2422 // cond==0 jump on false condtion ( if(x) => rexpr(.. cond=0 ...) ) | |
237 | 2423 switch(op) { |
2424 case LOP+GT: | |
2425 case LOP+GE: | |
280 | 2426 pcond(code_gt(1),cond?l1:l2); |
2427 pcond(code_eq(0),cond?l2:l1); | |
2428 break; | |
2429 case LOP+UGT: | |
2430 case LOP+UGE: | |
2431 pcond(code_ugt(1),cond?l1:l2); | |
2432 pcond(code_eq(0), cond?l2:l1); | |
2433 break; | |
237 | 2434 case LOP+EQ: |
280 | 2435 pcond(code_eq(0),(cond?l2:l1)); |
2436 pcond(code_eq(cond),l1); | |
2437 break; | |
237 | 2438 case LOP+NEQ: |
280 | 2439 pcond(code_eq(0),(cond?l1:l2)); |
2440 pcond(code_eq(!cond),l1); | |
2441 break; | |
237 | 2442 default: |
2443 error(-1); | |
2444 } | |
280 | 2445 printf("\tsubl %%eax,%%ecx\n"); |
2446 switch(op) { | |
2447 case LOP+GT: pcond(code_gt(cond), l1); break; | |
2448 case LOP+GE: pcond(code_ge(cond), l1); break; | |
2449 case LOP+UGT: pcond(code_ugt(cond), l1); break; | |
2450 case LOP+UGE: pcond(code_uge(cond), l1); break; | |
2451 } | |
2452 fwddef(l2); | |
195 | 2453 } |
2454 | |
2455 int emit_lpop() | |
2456 { | |
237 | 2457 return 0; |
195 | 2458 } |
2459 | |
2460 void code_lregister(int e2,int reg) | |
2461 { | |
238 | 2462 use_longlong(reg); |
239 | 2463 if (reg!=REG_L) { |
240 | 2464 printf("\tmovl %%esi,%s\n",l_eax(reg)); |
239 | 2465 printf("\tmovl %%edi,%s\n",l_edx(reg)); |
2466 } | |
195 | 2467 } |
2468 | |
287 | 2469 void code_cmp_lregister(int reg,int label,int cond) |
195 | 2470 { |
238 | 2471 char *crn; |
2472 use_int(reg); | |
2473 crn = register_name(reg,0); | |
239 | 2474 printf("\tmovl %%esi,%s\n",crn); |
2475 printf("\torl %%edi,%s\n",crn); | |
238 | 2476 printf("\ttestl %s,%s\n",crn,crn); |
287 | 2477 jcond(label,cond); |
195 | 2478 } |
2479 | |
287 | 2480 void code_cmp_lrgvar(int e1,int e2,int label,int cond) |
195 | 2481 { |
237 | 2482 char *n,*crn; |
2483 n = ((NMTBL*)cadr(e1))->nm; | |
2484 use_int(e2); | |
2485 crn = register_name(e2,0); | |
2486 printf("\tmovl %s,%s\n",n,crn); | |
2487 printf("\torl %s+4,%s\n",n,crn); | |
238 | 2488 printf("\ttestl %s,%s\n",crn,crn); |
287 | 2489 jcond(label,cond); |
195 | 2490 } |
2491 | |
287 | 2492 void code_cmp_lrlvar(int e1,int e2,int label,int cond) |
195 | 2493 { |
237 | 2494 char *crn; |
2495 use_int(e2); | |
2496 crn = register_name(e2,0); | |
239 | 2497 printf("\tmovl %d(%%ebp),%s\n",lvar(e1),crn); |
2498 printf("\torl %d(%%ebp),%s\n",lvar(e1)+4,crn); | |
2499 printf("\ttestl %s,%s\n",crn,crn); | |
287 | 2500 jcond(label,cond); |
195 | 2501 } |
2502 | |
2503 void code_lassign(int e1,int e2) | |
2504 { | |
237 | 2505 char *rn; |
2506 // e1 = e2 | |
2507 use_longlong(e2); | |
239 | 2508 rn = register_name(e1,0); |
2509 printf("\tmovl %s,(%s)\n",l_eax(e2),rn); | |
2510 printf("\tmovl %s,4(%s)\n",l_edx(e2),rn); | |
195 | 2511 } |
2512 | |
2513 void code_lassign_gvar(int e1,int e2) | |
2514 { | |
239 | 2515 char *n; |
237 | 2516 n = ((NMTBL*)cadr(e1))->nm; |
2517 use_longlong(e2); | |
239 | 2518 printf("\tmovl %s,%s\n",l_eax(e2),n); |
2519 printf("\tmovl %s,%s+4\n",l_edx(e2),n); | |
195 | 2520 } |
2521 | |
2522 void code_lassign_lvar(int e1,int e2) | |
2523 { | |
237 | 2524 use_longlong(e2); |
239 | 2525 printf("\tmovl %s,%d(%%ebp)\n",l_eax(e2),lvar(e1)); |
2526 printf("\tmovl %s,%d(%%ebp)\n",l_edx(e2),lvar(e1)+4); | |
195 | 2527 } |
2528 | |
2529 void code_lassign_lregister(int e2,int reg) | |
2530 { | |
242 | 2531 // e2 = reg |
238 | 2532 use_longlong(reg); |
239 | 2533 if (e2!=reg) { |
242 | 2534 printf("\tmovl %s,%s\n",l_eax(reg),l_eax(e2)); |
2535 printf("\tmovl %s,%s\n",l_edx(reg),l_edx(e2)); | |
239 | 2536 } |
237 | 2537 } |
195 | 2538 |
237 | 2539 void |
2540 code_lconst(int e1,int creg) | |
2541 { | |
2542 use_longlong(creg); | |
239 | 2543 printf("\tmovl $%d,%s\n",code_l1(lcadr(e1)),l_eax(creg)); |
2544 printf("\tmovl $%d,%s\n",code_l2(lcadr(e1)),l_edx(creg)); | |
195 | 2545 } |
2546 | |
212 | 2547 void code_lneg(int e1) |
195 | 2548 { |
239 | 2549 use_longlong(e1); |
2550 printf("\tnegl %s\n",l_eax(e1)); | |
2551 printf("\tadcl $0,%s\n",l_edx(e1)); | |
2552 printf("\tnegl %s\n",l_edx(e1)); | |
195 | 2553 } |
2554 | |
2555 void code_lrgvar(int e1,int e2) | |
2556 { | |
239 | 2557 char *n; |
237 | 2558 n = ((NMTBL*)cadr(e1))->nm; |
2559 use_longlong(e2); | |
239 | 2560 printf("\tmovl %s,%s\n",n,l_eax(e2)); |
2561 printf("\tmovl %s+4,%s\n",n,l_edx(e2)); | |
195 | 2562 } |
2563 | |
2564 void code_lrlvar(int e1,int e2) | |
2565 { | |
237 | 2566 use_longlong(e2); |
239 | 2567 printf("\tmovl %d(%%ebp),%s\n",lvar(e1),l_eax(e2)); |
2568 printf("\tmovl %d(%%ebp),%s\n",lvar(e1)+4,l_edx(e2)); | |
195 | 2569 } |
2570 | |
242 | 2571 #define check_lreg(reg) if (reg==REG_L) code_lassign_lregister(reg,REG_LCREG) |
239 | 2572 |
240 | 2573 void |
2574 ltosop(int op,int reg,int e2) | |
195 | 2575 { |
237 | 2576 char *opl,*oph,*call; |
2577 int lb; | |
195 | 2578 |
239 | 2579 // e2 (operand) is on the top of the stack |
237 | 2580 use_longlong(reg); |
2581 opl = 0; call=0; | |
2582 | |
2583 switch(op) { | |
2584 case LLSHIFT: | |
2585 case LULSHIFT: | |
239 | 2586 printf("\tmovl %%ecx,4(%%esp)\n"); |
2587 printf("\tpopl %%ecx\n"); | |
237 | 2588 printf("\tshldl %%eax,%%edx\n"); |
2589 printf("\tsall %%cl,%%eax\n"); | |
2590 printf("\ttestb $32,%%cl\n"); | |
2591 printf("\tje\t_%d\n",(lb=fwdlabel())); | |
2592 printf("\tmovl %%eax,%%edx\n"); | |
2593 printf("\txorl %%eax,%%eax\n"); | |
2594 fwddef(lb); | |
2595 printf("\tpopl %%ecx\n"); | |
242 | 2596 check_lreg(reg); |
237 | 2597 return; |
2598 case LRSHIFT: | |
239 | 2599 printf("\tmovl %%ecx,4(%%esp)\n"); |
2600 printf("\tpopl %%ecx\n"); | |
240 | 2601 printf("\tshrdl %%edx,%%eax\n"); |
237 | 2602 printf("\tsarl %%cl,%%eax\n"); |
2603 printf("\ttestb $32,%%cl\n"); | |
2604 printf("\tje\t_%d\n",(lb=fwdlabel())); | |
2605 printf("\tmovl %%edx,%%eax\n"); | |
2606 printf("\tsarl $31,%%edx\n"); | |
2607 fwddef(lb); | |
2608 printf("\tpopl %%ecx\n"); | |
242 | 2609 check_lreg(reg); |
237 | 2610 return; |
2611 case LURSHIFT: | |
239 | 2612 printf("\tmovl %%ecx,4(%%esp)\n"); |
2613 printf("\tpopl %%ecx\n"); | |
240 | 2614 printf("\tshrdl %%edx,%%eax\n"); |
237 | 2615 printf("\tshrl %%cl,%%eax\n"); |
2616 printf("\ttestb $32,%%cl\n"); | |
2617 printf("\tje\t_%d\n",(lb=fwdlabel())); | |
2618 printf("\tmovl %%edx,%%eax\n"); | |
2619 printf("\txorl %%edx,%%edx\n"); | |
2620 fwddef(lb); | |
2621 printf("\tpopl %%ecx\n"); | |
242 | 2622 check_lreg(reg); |
237 | 2623 return; |
2624 } | |
2625 switch(op) { | |
239 | 2626 case LADD: opl="addl";oph="adcl"; break; |
2627 case LSUB: opl="subl";oph="sbbl"; break; | |
237 | 2628 case LBAND: opl=oph="andl"; break; |
2629 case LEOR: opl=oph="xorl"; break; | |
2630 case LBOR: opl=oph="orl"; break; | |
2631 case LMUL: | |
2632 case LUMUL: | |
239 | 2633 printf("\tpushl %%edx\n"); |
2634 printf("\tpushl %%eax\n"); | |
2635 printf("\tpushl %%ecx\n"); | |
242 | 2636 // 0 saved ecx |
237 | 2637 // 4 c_l |
2638 // 8 c_h | |
2639 // 12 o_l | |
2640 // 16 o_h | |
2641 printf("\tmull 12(%%esp)\n"); // c_l*o_l -> %edx,%eax | |
2642 printf("\tmovl 4(%%esp),%%ecx\n"); // c_l->%ecx | |
2643 printf("\timull 16(%%esp),%%ecx\n"); // c_l*o_h->%ecx | |
239 | 2644 printf("\taddl %%ecx,%%edx\n"); // %edx+%ecx->%edx |
237 | 2645 printf("\tmovl 8(%%esp),%%ecx\n"); // c_h->%ecx |
2646 printf("\timull 12(%%esp),%%ecx\n"); // c_h*o_l->%ecx | |
239 | 2647 printf("\taddl %%ecx,%%edx\n"); // %edx+%ecx->%edx |
237 | 2648 printf("\tpopl %%ecx\n"); |
242 | 2649 // printf("\taddl $8,%%esp\n"); |
2650 printf("\tlea 16(%%esp),%%esp\n"); | |
237 | 2651 return; |
2652 case LDIV: call="__divdi3"; break; | |
2653 case LUDIV: call="__udivdi3"; break; | |
2654 case LMOD: call="__moddi3"; break; | |
2655 case LUMOD: call="__umoddi3"; break; | |
2656 default: error(-1); | |
2657 } | |
2658 if (opl) { | |
2659 printf("\t%s (%%esp),%%eax\n\t%s 4(%%esp),%%edx\n",opl,oph); | |
242 | 2660 printf("\tlea 8(%%esp),%%esp\n"); |
2661 check_lreg(reg); | |
239 | 2662 } else if (call) { |
2663 printf("\tpushl %%edx\n"); | |
2664 printf("\tpushl %%eax\n"); | |
237 | 2665 printf("\tcall %s\n",call); |
242 | 2666 // printf("\taddl $8,%%esp\n"); |
2667 printf("\tlea 16(%%esp),%%esp\n"); | |
2668 check_lreg(reg); | |
239 | 2669 } else { |
2670 error(-1); | |
237 | 2671 } |
195 | 2672 } |
2673 | |
237 | 2674 int code_lconst_op_p(int op,int e) { |
240 | 2675 long long l; |
2676 if (car(e)==CONST) l = cadr(e); | |
2677 else if (car(e)==LCONST) l = lcadr(e); | |
2678 else return 0; | |
2679 | |
237 | 2680 switch(op) { |
2681 case LLSHIFT: | |
2682 case LULSHIFT: | |
2683 case LRSHIFT: | |
2684 case LURSHIFT: | |
2685 return (0<=l&&l<=32); | |
2686 case LADD: | |
2687 case LSUB: | |
239 | 2688 case LBAND: |
237 | 2689 case LEOR: |
2690 case LBOR: | |
2691 return 1; | |
2692 default: | |
2693 return 0; | |
2694 } | |
2695 } | |
2696 | |
2697 void loprtc(int op,int reg,int e) { | |
2698 char *opl,*oph; | |
240 | 2699 int vl; |
2700 int vh; | |
2701 long long l; | |
2702 | |
2703 if (car(e)==CONST) l = cadr(e); | |
2704 else if (car(e)==LCONST) l = lcadr(e); | |
2705 else error(-1); | |
2706 | |
2707 vl = code_l1(l); | |
2708 vh = code_l2(l); | |
237 | 2709 |
2710 use_longlong(reg); | |
2711 opl = 0; | |
2712 | |
2713 switch(op) { | |
2714 case LLSHIFT: | |
2715 case LULSHIFT: | |
286 | 2716 printf("\tshldl $%d,%s,%s\n",vl,l_eax(reg),l_edx(reg)); |
2717 printf("\tsall $%d,%s\n",vl,l_eax(reg)); | |
237 | 2718 return; |
2719 case LRSHIFT: | |
286 | 2720 printf("\tshrdl $%d,%s,%s\n",vl,l_edx(reg),l_eax(reg)); |
2721 printf("\tsarl $%d,%s\n",vl,l_edx(reg)); | |
237 | 2722 return; |
2723 case LURSHIFT: | |
286 | 2724 printf("\tshrdl $%d,%s,%s\n",vl,l_edx(reg),l_eax(reg)); |
2725 printf("\tshrl $%d,%s\n",vl,l_edx(reg)); | |
237 | 2726 return; |
2727 } | |
2728 switch(op) { | |
2729 case LADD: opl="addl";oph="adcl"; break; | |
239 | 2730 case LSUB: opl="subl";oph="sbbl"; break; |
237 | 2731 case LBAND: opl=oph="andl"; break; |
2732 case LEOR: opl=oph="xorl"; break; | |
2733 case LBOR: opl=oph="orl"; break; | |
2734 default: error(-1); | |
2735 } | |
286 | 2736 printf("\t%s $%d,%s\n\t%s $%d,%s\n",opl,vl,l_eax(reg),oph,vh,l_edx(reg)); |
237 | 2737 } |
213 | 2738 |
195 | 2739 void emit_lpop_free(int e1) |
2740 { | |
242 | 2741 // printf("\taddl $8,%%esp\n"); |
195 | 2742 } |
2743 | |
2744 void emit_lpush() | |
2745 { | |
241 | 2746 printf("\tpushl %%edx\n\tpushl %%eax\n"); |
195 | 2747 } |
2748 | |
239 | 2749 void code_i2ll(int reg) |
195 | 2750 { |
240 | 2751 int reg0 = USE_CREG; |
2752 use_register(creg,REG_EAX,1); | |
2753 regv[creg]=0; | |
2754 use_longlong(reg0); | |
237 | 2755 printf("\tcltd\n"); |
242 | 2756 check_lreg(reg); |
240 | 2757 lreg = creg = reg0; |
195 | 2758 } |
2759 | |
239 | 2760 void code_i2ull(int reg) |
195 | 2761 { |
239 | 2762 code_i2ll(reg); |
195 | 2763 } |
2764 | |
239 | 2765 void code_u2ll(int reg) |
195 | 2766 { |
240 | 2767 int reg0 = USE_CREG; |
2768 use_register(creg,REG_EAX,1); | |
2769 regv[creg]=0; | |
2770 use_longlong(reg0); | |
237 | 2771 printf("\txorl %%edx,%%edx\n"); |
242 | 2772 check_lreg(reg); |
240 | 2773 lreg = creg = reg0; |
195 | 2774 } |
2775 | |
239 | 2776 void code_u2ull(int reg) |
195 | 2777 { |
239 | 2778 code_u2ll(reg); |
195 | 2779 } |
2780 | |
239 | 2781 void code_ll2i(int reg) |
195 | 2782 { |
239 | 2783 use_int(reg); |
237 | 2784 if (virtual(REG_EAX)!=reg) |
2785 printf("\tmovl %%eax,%s\n",register_name(creg,0)); | |
195 | 2786 } |
2787 | |
239 | 2788 void code_ll2u(int reg) |
195 | 2789 { |
239 | 2790 code_ll2i(reg); |
195 | 2791 } |
2792 | |
239 | 2793 void code_ull2i(int reg) |
195 | 2794 { |
239 | 2795 code_ll2i(reg); |
195 | 2796 } |
2797 | |
239 | 2798 void code_ull2u(int reg) |
195 | 2799 { |
239 | 2800 code_ll2i(reg); |
195 | 2801 } |
2802 | |
2803 #if FLOAT_CODE | |
239 | 2804 void code_d2ll(int reg) |
195 | 2805 { |
239 | 2806 use_longlong(reg); |
237 | 2807 printf("\tsubl $40,%%esp\n"); |
2808 printf("\tfnstcw 2(%%esp)\n"); | |
2809 printf("\tmovw 2(%%esp),%%ax\n"); | |
2810 printf("\torw $3072,%%ax\n"); | |
2811 printf("\tmovw %%ax,0(%%esp)\n"); | |
2812 printf("\tfldcw 0(%%esp)\n"); | |
2813 printf("\tfistpll 12(%%esp)\n"); | |
2814 printf("\tfldcw 2(%%esp)\n"); | |
239 | 2815 printf("\tmovl 12(%%esp),%%eax\n"); |
2816 printf("\tmovl 16(%%esp),%%edx\n"); | |
237 | 2817 printf("\taddl $40,%%esp\n"); |
195 | 2818 } |
2819 | |
239 | 2820 void code_d2ull(int reg) |
195 | 2821 { |
239 | 2822 use_longlong(reg); |
237 | 2823 printf("\tsubl $16,%%esp\n"); |
2824 printf("\tfstpl (%%esp)\n"); | |
2825 printf("\tcall __fixunsdfdi\n"); | |
2826 printf("\taddl $16,%%esp\n"); | |
195 | 2827 } |
2828 | |
239 | 2829 void code_f2ll(int reg) |
195 | 2830 { |
239 | 2831 code_d2ll(reg); |
195 | 2832 } |
2833 | |
239 | 2834 void code_f2ull(int reg) |
195 | 2835 { |
239 | 2836 use_longlong(reg); |
237 | 2837 printf("\tsubl $16,%%esp\n"); |
242 | 2838 printf("\tfstps (%%esp)\n"); |
237 | 2839 printf("\tcall __fixunssfdi\n"); |
2840 printf("\taddl $16,%%esp\n"); | |
195 | 2841 } |
2842 | |
239 | 2843 void code_ll2d(int reg) |
195 | 2844 { |
237 | 2845 printf("\tsubl $8,%%esp\n"); |
2846 printf("\tmovl %%eax,(%%esp)\n"); | |
2847 printf("\tmovl %%edx,4(%%esp)\n"); | |
2848 printf("\tfildll (%%esp)\n"); | |
2849 printf("\taddl $8,%%esp\n"); | |
195 | 2850 } |
2851 | |
239 | 2852 void code_ll2f(int reg) |
195 | 2853 { |
239 | 2854 code_ll2d(reg); |
195 | 2855 } |
2856 | |
239 | 2857 void code_ull2d(int reg) |
195 | 2858 { |
239 | 2859 code_ll2d(reg); |
195 | 2860 } |
2861 | |
239 | 2862 void code_ull2f(int reg) |
195 | 2863 { |
239 | 2864 code_ll2d(reg); |
195 | 2865 } |
2866 | |
2867 #endif | |
2868 | |
2869 | |
2870 void code_lpreinc(int e1,int e2,int reg) | |
2871 { | |
238 | 2872 int dir = caddr(e1); |
2873 int creg0; | |
2874 char *crn; | |
2875 if (car(e2)==LREGISTER) { | |
2876 use_longlong(reg); | |
239 | 2877 printf("\taddl $%d,%%esi\n",dir); |
2878 printf("\tadcl $%d,%%edi\n",dir>0?0:-1); | |
2879 if (reg!=REG_L) { | |
2880 code_lregister(REG_L,reg); | |
2881 } | |
238 | 2882 return; |
2883 } | |
2884 g_expr(e2); | |
2885 crn = register_name(creg0=creg,0); | |
2886 printf("\taddl $%d,(%s)\n",dir,crn); | |
239 | 2887 printf("\tadcl $%d,4(%s)\n",dir>0?0:-1,crn); |
238 | 2888 use_longlong(reg); |
239 | 2889 lload(creg0,0,reg); |
195 | 2890 } |
2891 | |
2892 void code_lpostinc(int e1,int e2,int reg) | |
2893 { | |
238 | 2894 int dir = caddr(e1); |
2895 int creg0; | |
2896 char *crn; | |
2897 if (car(e2)==LREGISTER) { | |
2898 use_longlong(reg); | |
239 | 2899 if (reg!=REG_L) { |
2900 code_lregister(REG_L,reg); | |
2901 } | |
2902 printf("\taddl $%d,%%esi\n",dir); | |
2903 printf("\tadcl $%d,%%edi\n",dir>0?0:-1); | |
238 | 2904 return; |
2905 } | |
2906 g_expr(e2); | |
2907 crn = register_name(creg0=creg,0); | |
2908 printf("\taddl $%d,(%s)\n",dir,crn); | |
239 | 2909 printf("\tadcl $%d,4(%s)\n",dir>0?0:-1,crn); |
238 | 2910 use_longlong(reg); |
239 | 2911 lload(creg0,0,reg); |
2912 printf("\taddl $%d,%s\n",-dir,l_eax(reg)); | |
2913 printf("\tadcl $%d,%s\n",-dir>0?0:-1,l_edx(reg)); | |
195 | 2914 } |
2915 | |
225 | 2916 void code_lassop(int op,int reg) |
195 | 2917 { |
238 | 2918 error(-1); |
195 | 2919 } |
2920 | |
219 | 2921 void |
2922 code_register_lassop(int reg,int op) { | |
238 | 2923 error(-1); |
219 | 2924 } |
2925 | |
195 | 2926 |
2927 #endif | |
81 | 2928 |
61 | 2929 /* end */ |
195 | 2930 |