annotate mc-code-ia32.c @ 81:f94ca1168520

float first try...
author kono
date Mon, 03 Mar 2003 20:59:51 +0900
parents 8418d4b7caa7
children 25654dc29ecc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1 /* Micro-C Code Generatation Part for intel386 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2 /* $Id$ */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
3
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
4 #define EXTERN extern
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
5 #include "mc.h"
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
6 #include "mc-codegen.h"
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
7
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
8 #define TEXT_EMIT_MODE 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
9 #define DATA_EMIT_MODE 1
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
10 #define RODATA_EMIT_MODE 2
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
11
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
12 static int output_mode = TEXT_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
13 static int data_alignment = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
14
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
15 static int code_disp_label;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
16 static int func_disp_label;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
17
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
18 /*
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
19 -16 -8 local2
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
20 -12 -4 local1
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
21 -8 8 arg3
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
22 -4 4 arg2
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
23 0 0 arg1
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
24 local2 -20 4 0 (%edi)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
25 local1 <-- -16 0 local variable 0 (%esi)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
26 %edi -12 <- disp_offset %ebp
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
27 %esi -8
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
28 %ebx -4
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
29 %ebp = %esp 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
30 %eip 4 <- arg_offset
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
31 arg1 8 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
32 arg2 12 4
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
33 see enter/enter1/leave see code_enter
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
34 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
35 int arg_offset = 8;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
36 int disp_offset = -12;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
37 int func_disp_offset = -12;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
38 int code_disp_offset = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
39 int jump_offset = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
40
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
41 int size_of_int = 4;
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
42 int size_of_float = 4;
f94ca1168520 float first try...
kono
parents: 78
diff changeset
43 int size_of_dobule = 8;
f94ca1168520 float first try...
kono
parents: 78
diff changeset
44 int size_of_longlong = 8;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
45 int endian = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
46 int MAX_REGISTER=6; /* intel386のレジスタを4つまで使う*/
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
47 int REAL_MAX_REGISTER=8; /* intel386のレジスタが8つということ*/
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
48 int MAX_DATA_REG=4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
49 int MAX_POINTER=3;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
50 int MAX_REGISTGER_VAR=2;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
51
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
52 EXTERN int creg; /* current register */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
53 EXTERN int dreg; /* temporary register */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
54 EXTERN int reg_sp; /* REGister Stack-Pointer */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
55
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
56
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
57 #define REG_EAX 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
58 #define REG_EBX 1
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
59 #define REG_ECX 2
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
60 #define REG_EDX 3
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
61 #define REG_ESI 4
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
62 #define REG_EDI 5
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
63 #define REG_EBP 6
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
64 #define REG_ESP 7
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
65
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
66
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
67 #define DATA_REG 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
68 #define POINTER_REG 3
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
69 static char *reg_name[8];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
70 static char *reg_name_l[4];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
71 static char *reg_name_w[4];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
72
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
73 extern int creg; /* current register */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
74 extern int dreg; /* temporary register */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
75 extern int reg_sp; /* REGister Stack-Pointer */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
76
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
77 #define MAX_MAX 10
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
78 int rname[MAX_MAX];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
79 int regs[MAX_MAX]; /* 使われているレジスタを示すフラグ */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
80 int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
81 int regv[MAX_MAX]; /* 値が入っているかどうか */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
82
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
83
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
84 void use_register(int virt, int real, int move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
85 void code_preinc(int e1,int e2) ;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
86 void code_cmp_register(int e2) ;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
87 void code_assign_gvar(int e2,int byte) ;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
88 void tosop(int op,int oreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
89 void edx_cleanup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
90 void shift(char *op, int reg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
91 void ld_indexx(int byte, int n, int xreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
92 void jmp(int l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
93 void local_table(void);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
94 void text_mode(void);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
95 void data_mode(char *name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
96
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
97 char *register_name(int i,int byte);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
98 int register_var(int r);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
99 int get_register_var(void);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
100 void emit_push(void);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
101 int emit_pop(int type);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
102 void code_crlvar(int e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
103 void code_preinc(int e1,int e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
104 void code_postinc(int e1,int e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
105 void code_bool(int e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
106 void string(int e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
107 void emit_copy(int from,int to,int length,int offset,int value,int det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
108 int struct_push(int e4,int t);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
109 void function(int e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
110 void code_assop(int op,int byte);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
111 int edx_setup();
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
112 void code_opening(char *filename);
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
113 void code_closing();
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
114 void code_leave(char *name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
115 int lvar(int l);
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
116 void global_table(void);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
117
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
118 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
119 code_init(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
120 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
121 arg_offset = 8;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
122 func_disp_offset = -12;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
123 disp_offset = -12;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
124 size_of_int = 4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
125 endian = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
126 MAX_REGISTER=6;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
127 MAX_DATA_REG=4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
128 MAX_POINTER=3;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
129 MAX_REGISTER_VAR=2;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
130
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
131 reg_name[REG_EAX] = "%eax";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
132 reg_name[REG_EBX] = "%ebx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
133 reg_name[REG_ECX] = "%ecx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
134 reg_name[REG_EDX] = "%edx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
135 reg_name[REG_ESI] = "%esi";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
136 reg_name[REG_EDI] = "%edi";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
137 reg_name[REG_EBP] = "%ebp";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
138 reg_name[REG_ESP] = "%esp";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
139 reg_name_l[REG_EAX] = "%al";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
140 reg_name_l[REG_EBX] = "%bl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
141 reg_name_l[REG_ECX] = "%cl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
142 reg_name_l[REG_EDX] = "%dl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
143 reg_name_w[REG_EAX] = "%ax";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
144 reg_name_w[REG_EBX] = "%bx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
145 reg_name_w[REG_ECX] = "%cx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
146 reg_name_w[REG_EDX] = "%dx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
147
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
148 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
149
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
150 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
151 register_name(int i,int byte)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
152 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
153 if (i<0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
154 error(REG_ERR);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
155 return "%eax";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
156 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
157 if (byte && rname[i] <= REG_EDX) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
158 return reg_name_l[rname[i]];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
159 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
160 return reg_name[rname[i]]; /* should be error */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
161 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
162 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
163
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
164 extern int creg_regvar;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
165
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
166 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
167 gexpr_code_init(void){
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
168 use_register(creg,REG_EAX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
169 regv[dreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
170 creg_regvar = -1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
171 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
172
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
173 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
174 register_var(int r) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
175 return virtual(r+REG_ESI);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
176 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
177
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
178 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
179 get_register_var(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
180 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
181 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
182 for(i=REG_ESI;i<REG_ESP;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
183 if (! regs[i]) { /* 使われていないなら */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
184 regs[i]=1; /* そのレジスタを使うことを宣言し */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
185 regv[i]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
186 return i; /* その場所を表す番号を返す */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
187 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
188 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
189 return -1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
190 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
191
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
192 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
193 use_register(int virt, int real, int move)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
194 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
195 int real_v;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
196 char *move_op;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
197 if (rname[virt]==real)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
198 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
199 real_v = virtual(real);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
200 move_op = regs[real_v]?"\txchg %s,%s\n":"\tmovl %s,%s\n";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
201 if (move || (regv[real_v])) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
202 printf(move_op,reg_name[rname[virt]],reg_name[real]);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
203 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
204 rname[real_v] = rname[virt];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
205 rname[virt] = real;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
206 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
207
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
208 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
209 use_pointer(int virt, int move)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
210 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
211 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
212 if (rname[virt]>=POINTER_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
213 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
214 for(i=POINTER_REG;i<MAX_REGISTER;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
215 if (!regs[virtual(i)]) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
216 use_register(virt,i,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
217 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
218 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
219 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
220 /* we prefer EBX */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
221 use_register(virt,REG_EBX,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
222 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
223
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
224 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
225 use_data_reg(int virt, int move)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
226 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
227 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
228 if (rname[virt]<MAX_DATA_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
229 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
230 for(i=0;i<MAX_DATA_REG;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
231 if (!regs[virtual(i)]) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
232 use_register(virt,i,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
233 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
234 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
235 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
236 /* we prefer EBX */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
237 use_register(virt,REG_EBX,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
238 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
239
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
240
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
241 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
242 emit_push(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
243 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
244 int new_reg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
245 new_reg = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
246 if(new_reg<0) { /* もうレジスタがない */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
247 reg_stack[reg_sp++] = -1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
248 printf("\tpushl %s\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
249 /* creg is used soon, don't regv[creg]=0 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
250 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
251 reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
252 creg = new_reg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
253 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
254 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
255 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
256
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
257 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
258 emit_pop(int type)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
259 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
260 int xreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
261 if ((xreg=pop_register())==-1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
262 if (type==POINTER_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
263 use_pointer(dreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
264 else if (type==DATA_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
265 use_data_reg(dreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
266 if (regv[dreg]) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
267 printf("# emit_pop dreg conflict\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
268 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
269 printf("\tpopl %s\n",register_name(dreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
270 xreg = dreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
271 regv[xreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
272 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
273 return xreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
274 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
275
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
276
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
277 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
278 code_gvar(int e1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
279 printf("\tmovl $%s,%s\n",(char *)caddr(e1),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
280 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
281
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
282
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
283 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
284 code_rgvar(int e1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
285 printf("\tmovl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
286 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
287
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
288 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
289 code_crgvar(e1){
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
290 printf("\tmovsbl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
291 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
292
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
293
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
294 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
295 code_lvar(int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
296 printf("\tlea %d(%%ebp),%s\n",e2,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
297 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
298
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
299
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
300 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
301 code_register(int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
302 printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
303 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
304
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
305
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
306 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
307 code_rlvar(int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
308 printf("\tmovl %d(%%ebp),%s\n",e2,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
309 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
310
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
311
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
312 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
313 code_crlvar(int e2) {
62
129f4802b027 separation done
kono
parents: 61
diff changeset
314 printf("\tmovsbl %d(%%ebp),%s\n",e2,register_name(creg,0));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
315 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
316
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
317
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
318 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
319 code_fname(char *e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
320 printf("\tmovl $%s,%s\n",e2,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
321 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
322
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
323
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
324 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
325 code_const(int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
326 printf("\tmovl $%d,%s\n",e2,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
327 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
328
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
329
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
330 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
331 code_neg() {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
332 printf("\tnegl %s\n", register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
333 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
334
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
335
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
336 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
337 code_not() {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
338 printf("\tnotl %s\n", register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
339 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
340
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
341
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
342 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
343 code_lnot() {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
344 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
345 use_data_reg(creg,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
346 xrn = register_name(creg,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
347 printf("\tcmpl $0,%s\n", register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
348 printf("\tsete %s\n", xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
349 printf("\tmovzbl %s,%s\n", xrn,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
350 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
351
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
352 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
353 code_preinc(int e1,int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
354 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
355 if (car(e2)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
356 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
357 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
358 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
359 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
360 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
361 xrn = register_name(creg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
362 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
363 printf("\tmovl (%s),%s\n",xrn,xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
364 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
365
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
366
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
367 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
368 code_postinc(int e1,int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
369 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
370 if (car(e2)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
371 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
372 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
373 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
374 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
375 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
376 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
377 xrn = register_name((e2=emit_pop(0)),0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
378 printf("\tmovl (%s),%s\n",xrn,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
379 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
380 emit_pop_free(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
381 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
382
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
383
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
384 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
385 code_cpostinc(int e1,int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
386 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
387 if (car(e2)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
388 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
389 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
390 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
391 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
392 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
393 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
394 xrn = register_name((e2=emit_pop(0)),1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
395 printf("\tmovsbl (%s),%s\n",xrn,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
396 printf("\tincl (%s)\n",xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
397 emit_pop_free(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
398 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
399
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
400
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
401 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
402 code_cpreinc(int e1,int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
403 if (car(e2)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
404 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
405 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
406 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
407 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
408 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
409 printf("\tincl (%s)\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
410 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
411 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
412
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
413
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
414 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
415 code_cpostdec(int e1,int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
416 if (car(e2)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
417 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
418 printf("\tdecl %s\n",register_name(cadr(e2),0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
419 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
420 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
421 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
422 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
423 printf("\tdecl (%s)\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
424 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
425
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
426
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
427 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
428 code_cpredec(int e1,int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
429 if (car(e2)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
430 printf("\tdecl %s\n",register_name(cadr(e2),0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
431 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
432 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
433 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
434 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
435 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
436 e2 = emit_pop(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
437 printf("\tdecl (%s)\n",register_name(e2,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
438 printf("\tmovsbl (%s),%s\n",register_name(e2,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
439 emit_pop_free(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
440 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
441
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
442
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
443 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
444 code_return() {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
445 printf("\tleal _%d,%s\n",retcont,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
446 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
447
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
448
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
449 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
450 code_environment() {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
451 printf("\tmovl %%ebp,%s\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
452 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
453
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
454
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
455 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
456 code_bool(int e1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
457 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
458 int e2,e3;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
459 b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
460 xrn = register_name(creg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
461 printf("\txorl %s,%s\n",xrn,xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
462 jmp(e3=fwdlabel());
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
463 fwddef(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
464 printf("\tmovl $1,%s\n",xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
465 fwddef(e3);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
466 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
467
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
468 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
469 code_gt(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
470 return (cond?"g":"le");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
471 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
472
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
473 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
474 code_ugt(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
475 return (cond?"a":"be");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
476 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
477
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
478 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
479 code_ge(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
480 return (cond?"ge":"l");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
481 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
482
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
483 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
484 code_uge(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
485 return (cond?"ae":"b");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
486 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
487
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
488 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
489 code_eq(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
490 return (cond?"e":"ne");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
491 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
492
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
493 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
494 code_cmp_crgvar(int e1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
495 printf("\tcmpb $0,%s\n",(char *)caddr(e1));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
496 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
497
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
498
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
499 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
500 code_cmp_crlvar(int e1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
501 printf("\tcmpb $0,%d(%%ebp)\n",e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
502 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
503
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
504
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
505 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
506 code_cmp_rgvar(int e1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
507 printf("\tcmpl $0,%s\n",(char *)caddr(e1));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
508 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
509
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
510
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
511 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
512 code_cmp_rlvar(int e1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
513 printf("\tcmpl $0,%d(%%ebp)\n",e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
514 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
515
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
516
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
517 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
518 code_cmp_register(int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
519 printf("\tcmpl $0,%s\n",register_name(e2,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
520 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
521
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
522
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
523 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
524 ascii(char *s)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
525 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
526 printf("\t.string \"");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
527 while(*s) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
528 if (*s=='\n')
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
529 printf("%cn",92);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
530 else if (*s<' ')
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
531 printf("%c%03o",92,*s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
532 else if (*s==34)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
533 printf("%c%c",92,34);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
534 else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
535 printf("%c",*s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
536 s++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
537 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
538 printf("%c\n",34);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
539 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
540
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
541 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
542 string(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
543 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
544 char *s;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
545 int i,lb;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
546
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
547 if (0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
548 s=(char *)cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
549 lb=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
550 printf("\tjmp _%d\n",lb);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
551 i=backdef();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
552 ascii(s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
553 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
554 fwddef(lb);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
555 printf("\tlea _%d,%s\n",i,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
556 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
557 s=(char *)cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
558 printf(".section\t.rodata\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
559 lb=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
560 printf("_%d:\n",lb);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
561 ascii(s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
562 if (output_mode==TEXT_EMIT_MODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
563 printf(".text\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
564 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
565 text_mode();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
566 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
567 printf("\tlea _%d,%s\n",lb,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
568 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
569 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
570
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
571 #define MAX_COPY_LEN 20
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
572
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
573 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
574 emit_copy(int from,int to,int length,int offset,int value,int det)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
575 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
576 int fix = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
577 /* length <0 means upward direction copy */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
578 switch (length) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
579 case 0: break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
580 case 1: case -1:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
581 printf("\tmovb %d(%s),%s\n",offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
582 register_name(from,0), reg_name_l[rname[dreg]] );
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
583 printf("\tmovb %s,%d(%s)\n",reg_name_l[rname[dreg]] ,offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
584 register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
585 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
586 case 2: case -2:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
587 printf("\tmovw %d(%s),%s\n",offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
588 register_name(from,0), reg_name_w[rname[dreg]] );
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
589 printf("\tmovw %s,%d(%s)\n",reg_name_w[rname[dreg]] ,offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
590 register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
591 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
592 case 4: case -4:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
593 printf("\tmovl %d(%s),%s\n",offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
594 register_name(from,0), register_name(dreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
595 printf("\tmovl %s,%d(%s)\n",register_name(dreg,0), offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
596 register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
597 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
598 default:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
599 if (-MAX_COPY_LEN<length && length <0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
600 for(;length<=4;length+=4,offset-=4)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
601 emit_copy(from,to,4,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
602 for(;length<=2;length+=2,offset-=2)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
603 emit_copy(from,to,2,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
604 if(length>0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
605 emit_copy(from,to,length,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
606 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
607 } else if (length <=MAX_COPY_LEN) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
608 for(;length>=4;length-=4,offset+=4)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
609 emit_copy(from,to,4,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
610 for(;length>=2;length-=2,offset+=2)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
611 emit_copy(from,to,2,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
612 if(length>0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
613 emit_copy(from,to,length,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
614 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
615 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
616 if (det) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
617 /*
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
618 call bcopy
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
619 g_expr(list3(FUNCTION,,);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
620 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
621 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
622 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
623 use_register(from,REG_ESI,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
624 use_register(to, REG_EDI,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
625 use_register(dreg,REG_ECX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
626 if (length<0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
627 printf("\tmovl $%d,%%ecx\n",-length/4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
628 printf("\taddl $%d,%%esi\n",-length);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
629 printf("\taddl $%d,%%edi\n",-length);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
630 printf("\tstd\n\trep\n\tmovsl\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
631 if(length%4) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
632 emit_copy(from,to,length,offset+length/4,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
633 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
634 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
635 printf("\tmovl $%d,%%ecx\n",length/4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
636 fix = (length/4)*4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
637 printf("\tcld\n\trep\n\tmovsl\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
638 if(length%4) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
639 emit_copy(from,to,length,offset+length/4,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
640 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
641 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
642 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
643 if (value) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
644 /* creg must point top of the destination data */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
645 /* this code is necessary for the value of assignment or function call */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
646 /* otherwise we don't need this */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
647 if (fix) printf("\tsubl $%d,%s\n",fix,register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
648 if(creg!=to) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
649 if (to==dreg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
650 printf("\tmovl %s,%s\n",register_name(to,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
651 else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
652 free_register(creg); creg=to;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
653 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
654 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
655 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
656 regv[from]=regv[to]=regv[dreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
657 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
658 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
659
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
660 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
661 struct_push(int e4,int t)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
662 {
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
663 int length,xreg,save,lreg,count;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
664 g_expr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
665 length=size(t);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
666 if(length%size_of_int) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
667 length += size_of_int - (length%size_of_int);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
668 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
669 for(count=0;length<MAX_COPY_LEN;count++,length-=size_of_int) {
f94ca1168520 float first try...
kono
parents: 78
diff changeset
670 if (length==0) return count;
f94ca1168520 float first try...
kono
parents: 78
diff changeset
671 else {
f94ca1168520 float first try...
kono
parents: 78
diff changeset
672 printf("\tpushl %d(%s)\n",
f94ca1168520 float first try...
kono
parents: 78
diff changeset
673 length-size_of_int,register_name(creg,0));
f94ca1168520 float first try...
kono
parents: 78
diff changeset
674 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
675 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
676 printf("\tsubl $%d,%%esp\n",length);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
677 if (register_full()) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
678 save = 1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
679 for(lreg=0;lreg==creg||lreg==dreg;lreg++);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
680 printf("\tpushl %s\n",register_name(lreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
681 xreg = lreg; regv[xreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
682 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
683 save=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
684 xreg = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
685 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
686 if (save)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
687 printf("\tlea %d(%%esp),%s\n",size_of_int,register_name(xreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
688 else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
689 printf("\tmovl %%esp,%s\n",register_name(xreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
690 regv[xreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
691 /* downward direction copy */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
692 emit_copy(creg,xreg,length,0,0,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
693 /* we have value in creg, it may be changed */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
694 if (save) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
695 if(creg==xreg) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
696 creg = get_register(); /* creg is freed in emit_copy */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
697 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
698 printf("\tpopl %s\n",register_name(xreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
699 regv[xreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
700 } else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
701 free_register(xreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
702 return length/size_of_int;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
703 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
704
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
705 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
706 function(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
707 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
708 int e2,e3,e4,e5,nargs,t;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
709 NMTBL *n;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
710 int save,saved;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
711 if (free_register_count()<1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
712 for(save = 0;save==dreg||save==creg;save++);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
713 printf("\tpushl %s\n",register_name(save,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
714 saved = 1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
715 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
716 save = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
717 saved = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
718 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
719 regv[save]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
720 e2 = cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
721 nargs = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
722 for (e3 = caddr(e1); e3; e3 = cadr(e3)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
723 t=caddr(e3);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
724 n=(NMTBL *)(e5=(cadr(e4 = car(e3))));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
725 if(scalar(t)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
726 g_expr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
727 printf("\tpushl %s\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
728 } else if (car(t)==STRUCT||car(t)==UNION) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
729 nargs += struct_push(e4,t);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
730 continue;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
731 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
732 error(TYERR);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
733 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
734 ++nargs;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
735 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
736 if (car(e2) == FNAME) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
737 n=(NMTBL *)cadr(e2);
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
738 regv[creg]=0;
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
739 use_register(creg,REG_EAX,0); /* will be destroyed */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
740 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
741 g_expr(e2);
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
742 regv[creg]=1;
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
743 use_register(creg,REG_EAX,1); /* will be destroyed */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
744 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
745
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
746 /* we don't have to save creg nor dreg */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
747 regs[creg]=0; regs[dreg]=0;
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
748 regv[dreg]= regv[save]= 0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
749 use_register(dreg,REG_EDX,0); /* will be destroyed */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
750 use_register(save,REG_ECX,0); /* will be destroyed */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
751 regs[creg]=1; regs[dreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
752
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
753 if (car(e2) == FNAME) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
754 printf("\tcall\t%s\n",n->nm);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
755 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
756 printf("\tcall\t*%s\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
757 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
758 if (nargs) printf("\taddl $%d,%%esp\n",size_of_int*nargs);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
759 if (saved) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
760 printf("\tpopl %s\n",register_name(save,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
761 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
762 free_register(save);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
763 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
764 regv[save]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
765 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
766 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
767
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
768 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
769 code_frame_pointer(int e3) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
770 printf("\tmovl %s,%%ebp\n",register_name(e3,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
771 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
772
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
773
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
774 void
62
129f4802b027 separation done
kono
parents: 61
diff changeset
775 code_fix_frame_pointer(int disp_offset) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
776 printf("\tlea %d(%%ebp),%%ebp\n",disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
777 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
778
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
779
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
780 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
781 code_jmp(char *s) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
782 printf("\tjmp %s\n",s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
783 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
784
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
785
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
786 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
787 code_indirect_jmp(int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
788 printf("\tjmp *%s\n",register_name(e2,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
789 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
790
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
791 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
792 rindirect(int e1) /* *(p +5 ) */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
793 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
794 char *op;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
795 int e2,e3,byte;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
796
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
797 op = ((byte = (car(e1) == CRINDIRECT)) ? "movsbl" : "movl");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
798 e3 = cadr(e2 = cadr(e1));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
799 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
800 printf("\t%s (%s),%s\n",op,register_name(creg,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
801 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
802
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
803 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
804 move(int byte)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
805 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
806 return byte?"movb":"movl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
807 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
808
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
809 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
810 code_assign_gvar(int e2,int byte) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
811 if (byte) use_data_reg(creg,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
812 printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),(char *)caddr(e2));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
813 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
814
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
815 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
816 code_assign_lvar(int e2,int byte) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
817 if (byte) use_data_reg(creg,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
818 printf("\t%s %s,%d(%%ebp)\n",move(byte),register_name(creg,byte),e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
819 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
820
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
821 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
822 code_assign_register(int e2,int byte) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
823 printf("\tmovl %s,%s\n",register_name(creg,0),register_name(e2,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
824 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
825
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
826 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
827 code_assign(int e2,int byte) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
828 printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte),register_name(e2,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
829 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
830
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
831
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
832 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
833 code_register_assop(int e2,int op,int byte) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
834 int reg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
835 int xreg = creg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
836 creg = reg = e2;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
837 tosop(op,xreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
838 creg = xreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
839 printf("\tmovl %s,%s\n",register_name(reg,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
840 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
841
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
842
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
843 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
844 code_assop(int op,int byte) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
845 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
846 int xreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
847 int edx = edx_setup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
848 xrn = register_name(xreg = emit_pop(0),0); /* pop e3 value */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
849 regv[xreg]=regs[xreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
850 printf("\tmovl %s,%s # assop \n",register_name(creg,0),register_name(edx,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
851 regv[edx]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
852 ld_indexx(byte,0,edx);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
853 tosop(op,xreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
854 printf("\t%s %s,(%s)\n",byte ? "movb" : "movl",register_name(creg,byte),register_name(edx,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
855 edx_cleanup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
856 emit_pop_free(xreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
857 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
858
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
859
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
860 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
861 tosop(int op,int oreg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
862 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
863 int dx;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
864 char *orn,*crn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
865
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
866 switch(op) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
867 case LSHIFT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
868 case ULSHIFT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
869 shift("sall",oreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
870 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
871 case RSHIFT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
872 shift("sarl",oreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
873 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
874 case URSHIFT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
875 shift("shrl",oreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
876 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
877 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
878 if(oreg==-1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
879 printf("\tpopl %s\n",register_name(dreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
880 oreg = dreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
881 regv[dreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
882 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
883 regv[oreg]=1; regs[oreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
884 orn = register_name(oreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
885 crn = register_name(creg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
886 switch(op) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
887 case ADD:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
888 printf("\taddl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
889 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
890 case SUB:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
891 printf("\tsubl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
892 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
893 case BAND:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
894 printf("\tandl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
895 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
896 case EOR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
897 printf("\txorl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
898 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
899 case BOR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
900 printf("\torl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
901 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
902 case MUL:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
903 case UMUL:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
904 printf("\t%s %s,%s\n","imull",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
905 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
906 case DIV:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
907 case UDIV:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
908 use_register(creg,REG_EAX,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
909 edx_setup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
910 orn = register_name(oreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
911 if (op==DIV)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
912 printf("\tcltd\n\tdivl %s\n",orn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
913 else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
914 printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
915 edx_cleanup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
916 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
917 case MOD:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
918 case UMOD:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
919 use_register(creg,REG_EAX,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
920 edx_setup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
921 orn = register_name(oreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
922 if (op==DIV)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
923 printf("\tcltd\n\tdivl %s\n",orn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
924 else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
925 printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
926 dx = virtual(REG_EDX);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
927 if (dx!=creg) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
928 rname[dx]=rname[creg];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
929 rname[creg]=REG_EDX;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
930 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
931 edx_cleanup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
932 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
933 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
934 if (oreg!=dreg&&oreg>=0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
935 free_register(oreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
936 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
937
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
938 static int edx_stack=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
939
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
940 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
941 edx_setup()
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
942 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
943 int edx_save;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
944 /* make real EDX register empty */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
945 if (free_register_count()<1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
946 for(edx_save = 0;edx_save==dreg||edx_save==creg;edx_save++);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
947 printf("\tpushl %s\n",register_name(edx_save,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
948 edx_stack = list3(edx_save,edx_stack,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
949 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
950 edx_save = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
951 edx_stack = list3(edx_save,edx_stack,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
952 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
953 regv[edx_save]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
954 use_register(edx_save,REG_EDX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
955 return edx_save;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
956 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
957
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
958
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
959 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
960 edx_cleanup()
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
961 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
962 if (caddr(edx_stack)==0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
963 printf("\tpopl %s\n",register_name(car(edx_stack),0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
964 } else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
965 free_register(car(edx_stack));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
966 edx_stack = cadr(edx_stack);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
967 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
968
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
969 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
970 shift(char *op, int reg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
971 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
972 if (reg>=0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
973 use_register(reg,REG_ECX,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
974 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
975 use_register(dreg,REG_ECX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
976 printf("\tpopl %%ecx\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
977 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
978 printf("\t%s %%cl,%s\n",op,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
979 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
980
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
981 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
982 ld_indexx(int byte, int n, int xreg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
983 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
984 char *op;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
985
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
986 op = byte ? "movsbl" : "movl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
987 if (n)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
988 printf("\t%s %d(%s),%s\n",op,n,register_name(xreg,0),register_name(creg,byte));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
989 else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
990 printf("\t%s (%s),%s\n",op,register_name(xreg,0),register_name(creg,byte));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
991 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
992
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
993 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
994 cmpdimm(int e, int csreg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
995 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
996 /* used in dosiwtch() */
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
997 if(chk) return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
998 use_register(creg,csreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
999 printf("\tcmpl $%d,%s\n",e,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1000 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1001
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1002 void
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1003 code_opening(char *filename)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1004 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1005 printf("\t.file \"%s\"\n",filename);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1006 printf("\t.version\t\"01.01\"\n");
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1007 /* printf("gcc2_compiled.:\n"); */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1008 printf(".text\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1009 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1010
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1011 void
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1012 code_closing()
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1013 {
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1014 global_table();
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1015 printf("\t.ident \"Micro-C compiled\"\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1016 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1017
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1018 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1019 rexpr(int e1, int l1, char *s)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1020 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1021 g_expr(list3(SUB,cadr(e1),caddr(e1)));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1022 printf("\tj%s\t_%d\n",s,l1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1023 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1024
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1025 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1026 jcond(int l, char cond)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1027 {
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1028 if (chk) return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1029 printf("\tj%s\t_%d\n",cond?"ne":"e",l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1030 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1031
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1032 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1033 jmp(int l)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1034 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1035 control=0;
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1036 if (chk) return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1037 printf("\tjmp\t_%d\n",l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1038 /* align? */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1039 /*
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1040 this is not allowed because of ? operator
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1041 regv[creg]=regv[dreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1042 use_register(creg,REG_EAX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1043 use_register(dreg,REG_EBX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1044 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1045 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1046
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1047 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1048 gen_comment(char *s)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1049 {
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1050 if (chk) return;
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1051 printf("## %s",s);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1052 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1053
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1054
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1055 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1056 code_enter(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1057 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1058 printf("\t.align 4\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1059 if (stmode!=STATIC)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1060 printf(".globl %s\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1061 printf("\t.type\t%s,@function\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1062 printf("%s:\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1063 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1064
77
2b8ba655e572 fix arg type
kono
parents: 66
diff changeset
1065
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1066 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1067 code_enter1(int args)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1068 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1069 code_disp_label=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1070 printf("\tlea _%d(%%ebp),%%esp\n",code_disp_label);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1071
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1072 printf("## args %d disp %d code_arg_offset=%d code_disp_offset=%d\n",args,disp,code_arg_offset,code_disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1073 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1074
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1075 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1076 code_leave(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1077 {
63
e13486b2c12e stack alignment
kono
parents: 62
diff changeset
1078 disp&= -size_of_int;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1079 printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1080 printf("_%d:\n",labelno);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1081 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1082 local_table();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1083 labelno++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1084 free_all_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1085 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1086
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1087 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1088 enter(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1089 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1090 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1091 if (stmode!=STATIC)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1092 printf(".globl %s\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1093 printf("%s:\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1094 printf("\t.type\t%s,@function\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1095 printf("\tpushl %%ebp\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1096 printf("\tmovl %%esp,%%ebp\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1097 printf("\tpushl %%ebx\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1098 printf("\tpushl %%esi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1099 printf("\tpushl %%edi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1100 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1101
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1102 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1103 enter1()
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1104 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1105 func_disp_label=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1106 printf("\tlea _%d(%%ebp),%%esp\n",func_disp_label);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1107 /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1108 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1109
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1110 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1111 leave(int control, char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1112 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1113 if (control)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1114 use_register(creg,REG_EAX,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1115 if (retcont) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1116 if (control)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1117 jmp(retlabel);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1118 fwddef(retcont);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1119 use_register(creg,REG_EAX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1120 printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1121 /* printf("\tleave\n"); */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1122 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1123 fwddef(retlabel);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1124 /* use_register(creg,REG_EAX,0); too late */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1125 /* if(disp) printf("\taddl $%d,%%esp\n",-disp); */
63
e13486b2c12e stack alignment
kono
parents: 62
diff changeset
1126 disp&= -size_of_int;
e13486b2c12e stack alignment
kono
parents: 62
diff changeset
1127
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1128 printf("\tlea %d(%%ebp),%%esp\n",disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1129 printf("\tpopl %%edi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1130 printf("\tpopl %%esi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1131 printf("\tpopl %%ebx\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1132 printf("\tleave\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1133 printf("\tret\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1134 printf("\t.set _%d,%d\n",func_disp_label,disp+disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1135 printf("_%d:\n",labelno);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1136 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1137 local_table();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1138 labelno++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1139 free_all_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1140 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1141
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1142
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1143 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1144 code_set_fixed_creg(int mode) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1145 use_register(creg,REG_EAX,mode);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1146 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1147
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1148 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1149 gen_gdecl(char *n, int gpc)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1150 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1151 /*
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1152 if (stmode!=STATIC)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1153 printf(".globl %s\n",n);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1154 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1155 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1156
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1157 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1158 align(int t)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1159 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1160 if (t!=CHAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1161 if (data_alignment & 1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1162 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1163 data_alignment = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1164 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1165 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1166
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1167 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1168 emit_data(int e, int t, NMTBL *n)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1169 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1170 int l;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1171 char *name;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1172 name = n->nm;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1173 if(mode!=GDECL) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1174 error(-1); return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1175 }
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1176 if (chk) return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1177 if (n->dsp != -1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1178 n->dsp = -1; /* initiallized flag */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1179 printf(".globl\t%s\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1180 data_mode(name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1181 align(t);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1182 printf("%s:\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1183 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1184 data_mode(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1185 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1186 if(car(e)==CONST) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1187 if (t==CHAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1188 printf("\t.byte %d\n",cadr(e));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1189 if (data_alignment>0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1190 data_alignment++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1191 gpc += 1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1192 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1193 printf("\t.long %d\n",cadr(e));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1194 gpc += size_of_int;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1195 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1196 } else if(t!=CHAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1197 gpc += size_of_int;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1198 if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1199 printf("\t.long %s\n",(char *)caddr(cadr(e)));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1200 } else if(car(e)==FNAME) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1201 printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1202 } else if(car(e)==STRING) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1203 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1204 l = fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1205 printf("\t.long _%d\n",l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1206 printf(".section\t.rodata\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1207 printf("_%d:\n",l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1208 output_mode = RODATA_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1209 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1210 ascii((char *)cadr(e));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1211 } else error(TYERR);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1212 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1213 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1214
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1215 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1216 emit_data_closing(NMTBL *n)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1217 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1218 int lb;
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1219 if (chk) return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1220 if (mode==GDECL) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1221 data_mode(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1222 lb=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1223 printf("_%d:\n",lb);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1224 printf("\t.size\t%s,_%d-%s\n",n->nm,lb,n->nm);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1225 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1226 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1227
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1228 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1229 global_table(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1230 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1231 NMTBL *n;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1232 int init;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1233 init=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1234 for(n=ntable;n < &ntable[GSYMS];n++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1235 if (n->sc == GVAR && n->dsp != -1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1236 /* n->dsp = -1 means initialized global */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1237 if (init==0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1238 data_mode(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1239 init=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1240 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1241 printf(".comm %s,%d\n",n->nm,size(n->ty));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1242 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1243 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1244 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1245
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1246 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1247 local_table(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1248 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1249 NMTBL *n;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1250 int init;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1251 init=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1252 /* static local variables */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1253 for(n=ntable+GSYMS;n < &ntable[GSYMS+LSYMS];n++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1254 if (n->sc == GVAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1255 if (init==0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1256 data_mode(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1257 init=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1258 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1259 printf(".lcomm %s,%d\n",n->nm,size(n->ty));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1260 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1261 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1262 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1263
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1264 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1265 text_mode(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1266 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1267 if (output_mode!=TEXT_EMIT_MODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1268 printf(".text\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1269 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1270 output_mode = TEXT_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1271 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1272 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1273
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1274 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1275 data_mode(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1276 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1277 if (output_mode!=DATA_EMIT_MODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1278 printf(".data\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1279 output_mode = DATA_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1280 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1281 if (name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1282 printf("\t.type\t%s,@object\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1283 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1284
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1285 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1286 lvar(int l)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1287 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1288 if (fnptr->sc==CODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1289 return l+code_disp_offset;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1290 } else if (l<0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1291 return l+disp_offset;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1292 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1293 return l+arg_offset;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1294 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1295 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1296
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1297 /* floating point */
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1298
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1299
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1300 void code_cmp_drgvar(int e)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1301 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1302
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1303
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1304 void code_cmp_drlvar(int e)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1305 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1306
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1307
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1308 void code_dassign_gvar(int e2,int byte)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1309 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1310
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1311
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1312 void code_dassign_lvar(int e,int byte)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1313 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1314
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1315 void code_dassign(int e)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1316 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1317
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1318
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1319 void code_dconst(int e2)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1320 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1321
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1322
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1323 void code_dneg()
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1324 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1325
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1326
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1327 void code_drgvar(int e1)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1328 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1329
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1330
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1331 void code_drlvar(int e1)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1332 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1333
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1334
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1335 void code_frgvar(int e1)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1336 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1337
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1338
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1339 void code_frlvar(int e1)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1340 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1341
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1342
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1343 void dtosop(int e,int e1)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1344 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1345
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1346 int dpop_register()
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1347 { return 1;}
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1348
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1349 int emit_dpop(int e1)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1350 { return 1;}
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1351
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1352 void emit_dpop_free(int e1)
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1353 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1354
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1355 void emit_dpush()
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1356 { }
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1357
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1358
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1359
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1360 /* end */