Mercurial > hg > CbC > old > device
comparison mc-code-ia32.c @ 327:da2e3f2d127d
macro/codegen reorganization
author | kono |
---|---|
date | Mon, 21 Jun 2004 23:50:34 +0900 |
parents | e5d40f8c4cce |
children | 7ecb023d29b8 |
comparison
equal
deleted
inserted
replaced
326:e5d40f8c4cce | 327:da2e3f2d127d |
---|---|
1 /* Micro-C Code Generation Part for intel386 */ | 1 /* Micro-C Code Generation Part for intel386 */ |
2 /* $Id$ */ | 2 /* $Id$ */ |
3 | 3 |
4 #define EXTERN extern | 4 #include <stdio.h> |
5 #include "mc.h" | 5 #include "mc.h" |
6 #include "mc-parse.h" | |
6 #include "mc-codegen.h" | 7 #include "mc-codegen.h" |
7 #include "mc-code.h" | 8 #include "mc-code.h" |
8 | 9 |
9 char *l_include_path[] = { | 10 char *l_include_path[] = { |
10 "/usr/include/", | 11 "/usr/include/", |
22 #define SIZE_OF_FLOAT 4 | 23 #define SIZE_OF_FLOAT 4 |
23 #define SIZE_OF_DOUBLE 8 | 24 #define SIZE_OF_DOUBLE 8 |
24 #define SIZE_OF_LONGLONG 8 | 25 #define SIZE_OF_LONGLONG 8 |
25 #define ENDIAN 0 | 26 #define ENDIAN 0 |
26 | 27 |
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; | |
33 | |
34 #define SAVE_STACKS 1 | 28 #define SAVE_STACKS 1 |
35 | 29 |
36 #define TEXT_EMIT_MODE 0 | 30 #define TEXT_EMIT_MODE 0 |
37 #define DATA_EMIT_MODE 1 | 31 #define DATA_EMIT_MODE 1 |
38 #define RODATA_EMIT_MODE 2 | 32 #define RODATA_EMIT_MODE 2 |
47 | 41 |
48 static int MAX_REGISTER=6; /* intel386のレジスタを6つまで使う*/ | 42 static int MAX_REGISTER=6; /* intel386のレジスタを6つまで使う*/ |
49 #define REAL_MAX_REGISTER 8 /* intel386のレジスタが8つということ*/ | 43 #define REAL_MAX_REGISTER 8 /* intel386のレジスタが8つということ*/ |
50 static int MAX_DATA_REG=4; | 44 static int MAX_DATA_REG=4; |
51 static int MAX_POINTER=3; | 45 static int MAX_POINTER=3; |
52 // static int MAX_REGISTGER_VAR=2; | 46 int MAX_REGISTER_VAR=2; |
53 // static int MAX_FREGISTER=1; | 47 // static int MAX_FREGISTER=1; |
54 | 48 |
55 #define MAX_FPU_STACK 7 | 49 #define MAX_FPU_STACK 7 |
56 #define REG_VAR 3 | 50 #define REG_VAR 3 |
57 | 51 |
89 %eip 4 <- arg_offset | 83 %eip 4 <- arg_offset |
90 arg1 8 0 | 84 arg1 8 0 |
91 arg2 12 4 | 85 arg2 12 4 |
92 see enter/enter1/leave see code_enter | 86 see enter/enter1/leave see code_enter |
93 */ | 87 */ |
94 // static int arg_offset = 8; | 88 static int arg_offset; |
95 // static int disp_offset = -12; | 89 // static int disp_offset = -12; |
96 #define func_disp_offset -12 | 90 #define func_disp_offset -12 |
97 #define code_disp_offset 0 | 91 #define code_disp_offset 0 |
98 // static int jump_offset = 0; | 92 // static int jump_offset = 0; |
99 | 93 |
214 char * | 208 char * |
215 l_eax(int i) { | 209 l_eax(int i) { |
216 return i==REG_L?"%esi":"%eax"; | 210 return i==REG_L?"%esi":"%eax"; |
217 } | 211 } |
218 | 212 |
219 char *init_src = "\ | 213 static |
214 char *init_src0 = "\ | |
220 #define va_list int\n\ | 215 #define va_list int\n\ |
221 #define va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg))\n\ | 216 #define va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg))\n\ |
222 #define va_arg(ap,type) (*((type *)ap)++)\n\ | 217 #define va_arg(ap,type) (*((type *)ap)++)\n\ |
223 #define va_end\n\ | 218 #define va_end\n\ |
224 #define __i386__ 1\n\ | 219 #define __i386__ 1\n\ |
234 #define __attribute__(a)\n\ | 229 #define __attribute__(a)\n\ |
235 #define wchar_t int\n\ | 230 #define wchar_t int\n\ |
236 #define __GNUC__ 2\n\ | 231 #define __GNUC__ 2\n\ |
237 "; | 232 "; |
238 | 233 |
239 void | 234 extern void |
240 code_init(void) | 235 code_init(void) |
241 { | 236 { |
237 | |
238 /* called only once */ | |
239 | |
240 init_src = init_src0; | |
241 size_of_int = SIZE_OF_INT; | |
242 size_of_short = SIZE_OF_SHORT; | |
243 size_of_float = SIZE_OF_FLOAT; | |
244 size_of_double = SIZE_OF_DOUBLE; | |
245 size_of_longlong = SIZE_OF_LONGLONG; | |
246 endian = ENDIAN; | |
242 | 247 |
243 arg_offset = 8; | 248 arg_offset = 8; |
244 // func_disp_offset = -12; | 249 // func_disp_offset = -12; |
245 disp_offset = -12; | 250 disp_offset = -12; |
246 MAX_REGISTER=6; | 251 MAX_REGISTER=6; |
264 reg_name_w[REG_EBX] = "%bx"; | 269 reg_name_w[REG_EBX] = "%bx"; |
265 reg_name_w[REG_ECX] = "%cx"; | 270 reg_name_w[REG_ECX] = "%cx"; |
266 reg_name_w[REG_EDX] = "%dx"; | 271 reg_name_w[REG_EDX] = "%dx"; |
267 | 272 |
268 } | 273 } |
274 | |
275 extern void | |
276 emit_reinit() | |
277 { | |
278 /* called for each file */ | |
279 } | |
280 | |
269 | 281 |
270 char * | 282 char * |
271 register_name(int i,int byte) | 283 register_name(int i,int byte) |
272 { | 284 { |
273 if (i<0) { | 285 if (i<0) { |
1749 code_enter1(int args) | 1761 code_enter1(int args) |
1750 { | 1762 { |
1751 code_disp_label=fwdlabel(); | 1763 code_disp_label=fwdlabel(); |
1752 printf("\tlea _%d(%%ebp),%%esp\n",code_disp_label); | 1764 printf("\tlea _%d(%%ebp),%%esp\n",code_disp_label); |
1753 | 1765 |
1754 printf("## args %d disp %d code_arg_offset=%d code_disp_offset=%d\n",args,disp,code_arg_offset,code_disp_offset); | 1766 printf("## args %d disp %d code_disp_offset=%d\n",args,disp,code_disp_offset); |
1755 } | 1767 } |
1756 | 1768 |
1757 void | 1769 void |
1758 code_leave(char *name) | 1770 code_leave(char *name) |
1759 { | 1771 { |