Mercurial > hg > CbC > old > device
comparison mc-nop-386.c @ 24:1df0bf7eb5da
add esi/edi register. fix virtual register bug.
author | kono |
---|---|
date | Tue, 04 Feb 2003 14:39:01 +0900 |
parents | e605560e6146 |
children | 85b8648de04f |
comparison
equal
deleted
inserted
replaced
23:e605560e6146 | 24:1df0bf7eb5da |
---|---|
1 /* Micro-C Code Generatation Part for intel386 */ | 1 /* Micro-C Code Generatation Part for intel386 */ |
2 /* $Id$ */ | 2 /* $Id$ */ |
3 | 3 |
4 #define EXTERN extern | 4 #define EXTERN extern |
5 #include "mc.h" | 5 #include "mc.h" |
6 | |
7 #define REGISTERS6 0 | |
8 | 6 |
9 extern int get_register_var(void); | 7 extern int get_register_var(void); |
10 extern void bexpr(int e1, char cond, int l1); | 8 extern void bexpr(int e1, char cond, int l1); |
11 extern void closing(void); | 9 extern void closing(void); |
12 extern void cmpdimm(int e, int csreg); | 10 extern void cmpdimm(int e, int csreg); |
143 static int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ | 141 static int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ |
144 | 142 |
145 void | 143 void |
146 code_init(void) | 144 code_init(void) |
147 { | 145 { |
148 if (REGISTERS6) { | 146 arg_offset = 8; |
149 arg_offset = 8; | 147 func_disp_offset = -12; |
150 func_disp_offset = -20; | 148 disp_offset = -12; |
151 disp_offset = -20; | 149 size_of_int = 4; |
152 size_of_int = 4; | 150 endian = 0; |
153 endian = 0; | 151 MAX_REGISTER=6; |
154 MAX_REGISTER=6; | 152 MAX_DATA_REG=4; |
155 MAX_DATA_REG=4; | 153 MAX_POINTER=3; |
156 MAX_POINTER=3; | |
157 } else { | |
158 arg_offset = 8; | |
159 func_disp_offset = -12; | |
160 disp_offset = -12; | |
161 size_of_int = 4; | |
162 endian = 0; | |
163 MAX_REGISTER=4; | |
164 MAX_DATA_REG=4; | |
165 MAX_POINTER=1; | |
166 } | |
167 MAX_REGISTER_VAR=2; | 154 MAX_REGISTER_VAR=2; |
168 | 155 |
169 reg_name[REG_EAX] = "%eax"; | 156 reg_name[REG_EAX] = "%eax"; |
170 reg_name[REG_EBX] = "%ebx"; | 157 reg_name[REG_EBX] = "%ebx"; |
171 reg_name[REG_ECX] = "%ecx"; | 158 reg_name[REG_ECX] = "%ecx"; |
186 } | 173 } |
187 | 174 |
188 char * | 175 char * |
189 register_name(int i,int byte) | 176 register_name(int i,int byte) |
190 { | 177 { |
191 if (byte && i <= REG_EDX) { | 178 if (byte && rname[i] <= REG_EDX) { |
192 return reg_name_l[rname[i]]; | 179 return reg_name_l[rname[i]]; |
193 } else { | 180 } else { |
194 return reg_name[rname[i]]; | 181 return reg_name[rname[i]]; /* should be error */ |
195 } | 182 } |
196 } | 183 } |
197 | 184 |
198 int | 185 int |
199 get_register(void) | 186 get_register(void) |
392 | 379 |
393 void | 380 void |
394 gexpr(int e1) | 381 gexpr(int e1) |
395 { | 382 { |
396 gexpr_init(); | 383 gexpr_init(); |
384 #if 0 | |
385 if(lineno==688) { | |
386 g_expr(e1); /*break here*/ | |
387 csvalue = rname[creg]; /* for siwtch value */ | |
388 return; | |
389 } | |
390 #endif | |
397 g_expr(e1); | 391 g_expr(e1); |
398 csvalue = rname[creg]; /* for siwtch value */ | 392 csvalue = rname[creg]; /* for siwtch value */ |
399 } | 393 } |
400 | 394 |
401 void | 395 void |
1494 printf("%s:\n",name); | 1488 printf("%s:\n",name); |
1495 printf("\t.type\t%s,@function\n",name); | 1489 printf("\t.type\t%s,@function\n",name); |
1496 printf("\tpushl %%ebp\n"); | 1490 printf("\tpushl %%ebp\n"); |
1497 printf("\tmovl %%esp,%%ebp\n"); | 1491 printf("\tmovl %%esp,%%ebp\n"); |
1498 printf("\tpushl %%ebx\n"); | 1492 printf("\tpushl %%ebx\n"); |
1499 printf("\tpushl %%ecx\n"); /* we don't need this now */ | 1493 printf("\tpushl %%esi\n"); |
1500 printf("\tpushl %%edx\n"); /* we don't need this now */ | 1494 printf("\tpushl %%edi\n"); |
1501 if (REGISTERS6) { | |
1502 printf("\tpushl %%edi\n"); | |
1503 printf("\tpushl %%esi\n"); | |
1504 } | |
1505 } | 1495 } |
1506 | 1496 |
1507 void | 1497 void |
1508 enter1(int disp) | 1498 enter1(int disp) |
1509 { | 1499 { |
1523 printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0)); | 1513 printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0)); |
1524 /* printf("\tleave\n"); */ | 1514 /* printf("\tleave\n"); */ |
1525 } | 1515 } |
1526 fwddef(retlabel); | 1516 fwddef(retlabel); |
1527 use_register(creg,REG_EAX,0); | 1517 use_register(creg,REG_EAX,0); |
1528 if (REGISTERS6) { | |
1529 printf("\tpopl %%esi\n"); | |
1530 printf("\tpopl %%edi\n"); | |
1531 } | |
1532 /* if(disp) printf("\taddl $%d,%%esp\n",-disp); */ | 1518 /* if(disp) printf("\taddl $%d,%%esp\n",-disp); */ |
1533 printf("\tlea %d(%%ebp),%%esp\n",disp_offset); | 1519 printf("\tlea %d(%%ebp),%%esp\n",disp_offset); |
1534 printf("\tpopl %%edx\n"); | 1520 printf("\tpopl %%edi\n"); |
1535 printf("\tpopl %%ecx\n"); | 1521 printf("\tpopl %%esi\n"); |
1536 printf("\tpopl %%ebx\n"); | 1522 printf("\tpopl %%ebx\n"); |
1537 printf("\tleave\n"); | 1523 printf("\tleave\n"); |
1538 printf("\tret\n"); | 1524 printf("\tret\n"); |
1539 printf("_%d:\n",labelno); | 1525 printf("_%d:\n",labelno); |
1540 printf("\t.size\t%s,_%d-%s\n",name,labelno,name); | 1526 printf("\t.size\t%s,_%d-%s\n",name,labelno,name); |