annotate mc-code-ia32.c @ 341:ca34f02b2056

ptr cache speed up
author kono
date Sat, 26 Jun 2004 11:09:11 +0900 (2004-06-26)
parents 0150de6a3244
children 2b3946ee4fc9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
326
e5d40f8c4cce bit-field continue.
kono
parents: 320
diff changeset
1 /* Micro-C Code Generation Part for intel386 */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2 /* $Id$ */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
3
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
4 #include <stdio.h>
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
5 #include "mc.h"
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
6 #include "mc-parse.h"
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
7 #include "mc-codegen.h"
93
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
8 #include "mc-code.h"
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
9
173
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
10 char *l_include_path[] = {
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
11 "/usr/include/",
182
e1e9ec8c96a7 some fix
kono
parents: 173
diff changeset
12 "/usr/include/linux/",
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
13 "/usr/include/diet/",
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
14 "/usr/lib/gcc-lib/i386-linux/2.95.4/include/",
183
1d80ad165831 recursive macros
kono
parents: 182
diff changeset
15 "/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/",
246
0dcc0ec81ed2 MIPS on going (90%)
kono
parents: 245
diff changeset
16 "/usr/lib/dietlibc/include/",
173
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
17 0
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
18 };
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
19
340
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
20 int data_alignment = 0;
173
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
21
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
22 #define SIZE_OF_INT 4
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
23 #define SIZE_OF_SHORT 2
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
24 #define SIZE_OF_FLOAT 4
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
25 #define SIZE_OF_DOUBLE 8
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
26 #define SIZE_OF_LONGLONG 8
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
27 #define ENDIAN 0
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
28
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
29 #define SAVE_STACKS 1
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
30
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
31 #define TEXT_EMIT_MODE 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
32 #define DATA_EMIT_MODE 1
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
33 #define RODATA_EMIT_MODE 2
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
34
340
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
35 #define DOT_SIZE 1
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
36
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
37 static int output_mode = TEXT_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
38
224
82a55cc6b5fc *** empty log message ***
kono
parents: 219
diff changeset
39 static int creg;
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
40 static int lreg;
224
82a55cc6b5fc *** empty log message ***
kono
parents: 219
diff changeset
41
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
42 int code_lassop_p = 0;
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
43
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
44 static int MAX_REGISTER=6; /* intel386�Υ쥸������6�ĤޤǻȤ�*/
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
45 #define REAL_MAX_REGISTER 8 /* intel386�Υ쥸������8�ĤȤ�������*/
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
46 static int MAX_DATA_REG=4;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
47 static int MAX_POINTER=3;
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
48 int MAX_REGISTER_VAR=2;
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
49 // static int MAX_FREGISTER=1;
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
50
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
51 #define MAX_FPU_STACK 7
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
52 #define REG_VAR 3
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
53
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
54 // static int MAX_INPUT_REGISTER_VAR = 0;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
55 static int MAX_CODE_INPUT_REGISTER_VAR = 2;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
56 // static int MAX_INPUT_DREGISTER_VAR = 0;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
57 // static int MAX_INPUT_FREGISTER_VAR = 0;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
58 // static int MAX_CODE_INPUT_DREGISTER_VAR = 0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
59
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
60 static int reg_sp; /* REGister Stack-Pointer */
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
61 static int reg_stack[MAX_MAX]; /* �ºݤΥ쥸�������ΰ� */
328
7ecb023d29b8 macro/codegen reorganization done.
kono
parents: 327
diff changeset
62 static int stack_depth = 0;
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
63
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
64 /* floating point registers */
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
65
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
66 static int freg_sp; /* floating point REGister Stack-Pointer */
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
67 static int freg_stack[MAX_MAX]; /* �ºݤΥ쥸�������ΰ� */
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
68
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
69 static int reg_var;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
70 static int regvar[2];
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
71
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
72
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
73 /*
128
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
74 -28 -8 local2
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
75 -24 -4 local1
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
76 -20 8 arg3
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
77 -16 4 arg2
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
78 -12 0 arg1
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
79 local2 -20 4 -8 (%edi)
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
80 local1 <-- -16 0 local variable -4 (%esi)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
81 %edi -12 <- disp_offset %ebp
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
82 %esi -8
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
83 %ebx -4
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
84 %ebp = %esp 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
85 %eip 4 <- arg_offset
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
86 arg1 8 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
87 arg2 12 4
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
88 see enter/enter1/leave see code_enter
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
89 */
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
90 static int arg_offset;
328
7ecb023d29b8 macro/codegen reorganization done.
kono
parents: 327
diff changeset
91 int disp_offset = -12;
244
39e28d6cfa56 ia32 long long done
kono
parents: 243
diff changeset
92 #define func_disp_offset -12
39e28d6cfa56 ia32 long long done
kono
parents: 243
diff changeset
93 #define code_disp_offset 0
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
94 // static int jump_offset = 0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
95
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
96 static int code_disp_label;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
97 static int func_disp_label;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
98
263
c922bade771d MIPS go on...
kono
parents: 258
diff changeset
99
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
100 static int
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
101 lvar(int l)
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
102 {
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
103 if (is_code(fnptr)) {
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
104 return l+code_disp_offset;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
105 } else if (l<0) {
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
106 return l+disp_offset;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
107 } else {
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
108 return l+arg_offset;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
109 }
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
110 }
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
111
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
112 /*
326
e5d40f8c4cce bit-field continue.
kono
parents: 320
diff changeset
113 creg current virtual register
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
114 dreg spare virtual register
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
115
326
e5d40f8c4cce bit-field continue.
kono
parents: 320
diff changeset
116 rname[creg] current real register
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
117 rname[dreg] spare real register
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
118
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
119 regs[] virtual register usage
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
120 regv[] value in virtual register flag
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
121
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
122 reg_name[rname[creg]]
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
123
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
124 freg current floating point register
326
e5d40f8c4cce bit-field continue.
kono
parents: 320
diff changeset
125 fregv value in floating point register
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
126 */
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
127
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
128 static int dreg; /* general temporal register */
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
129
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
130 #define REAL_MAX_LREGISTER 2
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
131 static int ia32regs[REAL_MAX_REGISTER+REAL_MAX_LREGISTER];
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
132 static int ia32regv[REAL_MAX_REGISTER+REAL_MAX_LREGISTER];
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
133 static int ia32rname[REAL_MAX_REGISTER+REAL_MAX_LREGISTER];
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
134
205
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
135 static int *regv = ia32regv;
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
136 static int *regs = ia32regs;
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
137 static int *rname = ia32rname;
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
138
205
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
139 static int ia32fregs[1];
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
140 static int ia32fregv[1];
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
141
205
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
142 static int freg;
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
143 static int *fregv = ia32fregv;
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
144 static int *fregs = ia32fregs;
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
145
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
146
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
147 #define REG_EAX 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
148 #define REG_EBX 1
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
149 #define REG_ECX 2
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
150 #define REG_EDX 3
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
151 #define REG_ESI 4
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
152 #define REG_EDI 5
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
153 #define REG_EBP 6
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
154 #define REG_ESP 7
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
155 #define is_int_reg(reg) (reg<REG_EBP)
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
156 #define REG_LCREG 8
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
157 #define REG_L 9
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
158
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
159
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
160 #define DATA_REG 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
161 #define POINTER_REG 3
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
162 static char *reg_name[8];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
163 static char *reg_name_l[4];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
164 static char *reg_name_w[4];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
165
93
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
166 static void use_register(int virt, int real, int move);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
167 static int virtual(int real);
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
168 static void shift(char *op, int reg,int creg);
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
169 static void ld_indexx(int byte, int n, int xreg,int reg,int sign);
93
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
170 static void data_mode(char *name);
263
c922bade771d MIPS go on...
kono
parents: 258
diff changeset
171 static void text_mode();
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
172 static int edx_setup(int rreg);
93
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
173 static void edx_cleanup();
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
174 static void local_table(void);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
175 #if FLOAT_CODE
93
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
176 static char * fload(int d);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
177 static int code_d1(double d);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
178 static int code_d2(double d);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
179 static void code_save_fstacks();
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
180 #endif
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
181 static void code_save_stacks();
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
182 static void jcond(int l, char cond);
340
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
183 #if LONGLONG_CODE
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
184 static int code_l1(long long d);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
185 static int code_l2(long long d);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
186 #endif
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
187
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
188 #define use_int(reg) if (reg==-1) reg=use_int0()
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
189 static int use_int0() { lreg = 0; if (!is_int_reg(creg)) { creg = virtual(REG_EBX); regs[creg]=1;} return creg; }
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
190
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
191 #define use_longlong(reg) reg=use_longlong0(reg)
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
192 static int
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
193 use_longlong0(int reg)
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
194 {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
195 int i;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
196 if (reg==USE_CREG)
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
197 reg = REG_LCREG;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
198 if (!lreg) {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
199 code_save_stacks();
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
200 // make edx,eax free
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
201 use_register(creg,REG_EBX,regv[creg]);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
202 use_register(dreg,REG_ECX,regv[dreg]);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
203 for(i=0;i<reg_var;i++)
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
204 use_register(regvar[i],REG_ESI+i,1);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
205 }
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
206 creg = lreg = reg;
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
207 return lreg;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
208 }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
209
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
210 char *
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
211 l_edx(int i) {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
212 return i==REG_L?"%edi":"%edx";
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
213 }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
214 char *
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
215 l_eax(int i) {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
216 return i==REG_L?"%esi":"%eax";
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
217 }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
218
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
219 static
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
220 char *init_src0 = "\
307
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
221 #define va_list int\n\
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
222 #define va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg))\n\
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
223 #define va_arg(ap,type) (*((type *)ap)++)\n\
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
224 #define va_end\n\
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
225 #define __i386__ 1\n\
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
226 #define __LITTLE_ENDIAN__ 1\n\
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
227 #define __STDC__ 1\n\
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
228 #define size_t int\n\
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
229 #define __externsion__\n\
315
84df3dd8cc3d minor fix
kono
parents: 313
diff changeset
230 #define __restrict\n\
84df3dd8cc3d minor fix
kono
parents: 313
diff changeset
231 #define __gnuc_va_list int\n\
307
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
232 #define __flexarr\n\
315
84df3dd8cc3d minor fix
kono
parents: 313
diff changeset
233 #define __const const\n\
84df3dd8cc3d minor fix
kono
parents: 313
diff changeset
234 #define __THORW\n\
84df3dd8cc3d minor fix
kono
parents: 313
diff changeset
235 #define __attribute__(a)\n\
307
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
236 #define wchar_t int\n\
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
237 #define __GNUC__ 2\n\
307
fda28752d301 stdarg (varargs done... PowerPC, IA32 checked)
kono
parents: 304
diff changeset
238 ";
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
239
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
240 extern void
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
241 code_init(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
242 {
173
3b33c7daae95 *** empty log message ***
kono
parents: 168
diff changeset
243
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
244 /* called only once */
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
245
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
246 init_src = init_src0;
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
247 size_of_int = SIZE_OF_INT;
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
248 size_of_short = SIZE_OF_SHORT;
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
249 size_of_float = SIZE_OF_FLOAT;
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
250 size_of_double = SIZE_OF_DOUBLE;
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
251 size_of_longlong = SIZE_OF_LONGLONG;
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
252 endian = ENDIAN;
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
253
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
254 arg_offset = 8;
244
39e28d6cfa56 ia32 long long done
kono
parents: 243
diff changeset
255 // func_disp_offset = -12;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
256 disp_offset = -12;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
257 MAX_REGISTER=6;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
258 MAX_DATA_REG=4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
259 MAX_POINTER=3;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
260 MAX_REGISTER_VAR=2;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
261
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
262 reg_name[REG_EAX] = "%eax";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
263 reg_name[REG_EBX] = "%ebx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
264 reg_name[REG_ECX] = "%ecx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
265 reg_name[REG_EDX] = "%edx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
266 reg_name[REG_ESI] = "%esi";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
267 reg_name[REG_EDI] = "%edi";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
268 reg_name[REG_EBP] = "%ebp";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
269 reg_name[REG_ESP] = "%esp";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
270 reg_name_l[REG_EAX] = "%al";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
271 reg_name_l[REG_EBX] = "%bl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
272 reg_name_l[REG_ECX] = "%cl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
273 reg_name_l[REG_EDX] = "%dl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
274 reg_name_w[REG_EAX] = "%ax";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
275 reg_name_w[REG_EBX] = "%bx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
276 reg_name_w[REG_ECX] = "%cx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
277 reg_name_w[REG_EDX] = "%dx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
278
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
279 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
280
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
281 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
282 emit_reinit()
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
283 {
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
284 /* called for each file */
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
285 }
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
286
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
287
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
288 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
289 register_name(int i,int byte)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
290 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
291 if (i<0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
292 error(REG_ERR);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
293 return "%eax";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
294 }
165
kono
parents: 163
diff changeset
295 if (byte==1 && rname[i] <= REG_EDX) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
296 return reg_name_l[rname[i]];
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
297 } else if (byte==SIZE_OF_SHORT && rname[i] <= REG_EDX) {
165
kono
parents: 163
diff changeset
298 return reg_name_w[rname[i]];
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
299 } else {
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
300 return reg_name[rname[i]]; /* 0 or 4 means int */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
301 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
302 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
303
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
304 /*
147
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
305 int use_int(int i) { return i;}
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
306 int use_float(int i) { return i;}
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
307 int use_double(int i) { return i;}
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
308 int use_longlong(int i) { return i; }
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
309 */
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
310
147
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
311
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
312 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
313 gexpr_code_init(void){
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
314 use_register(creg,REG_EAX,0);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
315 regv[creg]=0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
316 regv[dreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
317 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
318
147
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
319 void
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
320 code_gexpr(int e){
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
321 }
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
322
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
323 int
917947ffeb7c power pc version
kono
parents: 87
diff changeset
324 get_register(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
325 { /* �Ȥ��Ƥ��ʤ��쥸������Ĵ�٤� */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
326 int i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
327 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
328 if (! regs[i]) { /* �Ȥ��Ƥ��ʤ��ʤ� */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
329 regs[i]=1; /* ���Υ쥸������Ȥ����Ȥ������ */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
330 return i; /* ���ξ���ɽ���ֹ���֤� */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
331 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
332 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
333 return -1; /* �����Ƥ����꤬�ʤ��ʤ顢�����ɽ�� -1 ���֤� */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
334 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
335
917947ffeb7c power pc version
kono
parents: 87
diff changeset
336 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
337 free_register(int i) { /* ����ʤ��ʤä��쥸�������� */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
338 regv[i]=regs[i]=0;
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
339 if(i==REAL_MAX_REGISTER) {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
340 regv[virtual(REG_ESI)]=regv[virtual(REG_EDI)]=0;
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
341 }
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
342 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
343
341
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
344 extern void
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
345 use_ptr_cache(int r)
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
346 {
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
347 error(-1);
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
348 }
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
349
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
350 extern void
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
351 code_ptr_cache_def(int r,NMTBL *nptr)
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
352 {
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
353 error(-1);
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
354 }
ca34f02b2056 ptr cache speed up
kono
parents: 340
diff changeset
355
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
356 int
126
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
357 get_input_register_var(int i,NMTBL *nptr,int is_code)
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
358 {
126
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
359 if (is_code) {
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
360 if (i>=MAX_CODE_INPUT_REGISTER_VAR) return 0;
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
361 i = virtual(i+REG_ESI);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
362 regs[i]=regv[i]=INPUT_REG;
126
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
363 return list3(REGISTER,i,(int)nptr);
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
364 } else {
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
365 return 0;
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
366 }
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
367 }
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
368
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
369 int
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
370 get_input_dregister_var(int i,NMTBL *nptr,int is_code,int d)
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
371 {
126
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
372 return 0;
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
373 }
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
374
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
375 int
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
376 get_dregister(int d)
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
377 {
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
378 return -1;
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
379 }
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
380
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
381 int
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
382 get_lregister_var(NMTBL *n)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
383 {
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
384 int h,l;
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
385 h = virtual(REG_ESI);
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
386 l = virtual(REG_EDI);
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
387 if (regv[REAL_MAX_REGISTER]==0&&regs[h]==0&&regs[l]==0) {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
388 regs[h]=regs[l]=REG_VAR;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
389 regv[h]=regv[l]=REG_VAR;
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
390 regv[REAL_MAX_REGISTER]=1;
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
391 reg_var=2; regvar[0]=h; regvar[1]=l;
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
392 return list2(LREGISTER,REG_L);
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
393 }
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
394 return list2(LVAR,new_lvar(SIZE_OF_LONGLONG));
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
395 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
396
205
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
397 int
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
398 get_lregister()
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
399 {
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
400 return -1;
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
401 }
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
402
a50f90d0b63a *** empty log message ***
kono
parents: 204
diff changeset
403
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
404 int
917947ffeb7c power pc version
kono
parents: 87
diff changeset
405 register_full(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
406 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
407 int i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
408 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
409 if (! regs[i]) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
410 return 0;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
411 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
412 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
413 return 1;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
414 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
415
917947ffeb7c power pc version
kono
parents: 87
diff changeset
416 int
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
417 free_register_count(int d)
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
418 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
419 int i,count;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
420 count = 0;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
421 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
422 if (! regs[i] && ! regv[i]) count++;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
423 }
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
424 return d?0:count;
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
425 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
426
917947ffeb7c power pc version
kono
parents: 87
diff changeset
427 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
428 free_all_register(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
429 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
430 int i;
243
c311c26e006a *** empty log message ***
kono
parents: 242
diff changeset
431 for(i=0;i<MAX_REGISTER+REAL_MAX_LREGISTER;i++) {
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
432 regs[i]=regv[i]=0;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
433 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
434 creg = get_register();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
435 dreg = get_register();
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
436 reg_var = 0;
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
437 return;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
438 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
439
917947ffeb7c power pc version
kono
parents: 87
diff changeset
440
917947ffeb7c power pc version
kono
parents: 87
diff changeset
441 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
442 register_usage(char *s)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
443 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
444 int i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
445 if (chk) return;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
446 printf("# %d: %s:",lineno,s);
917947ffeb7c power pc version
kono
parents: 87
diff changeset
447 printf(" creg=%s dreg=%s ",register_name(creg,0),register_name(dreg,0));
917947ffeb7c power pc version
kono
parents: 87
diff changeset
448 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
449 printf("%d",regs[i]);
917947ffeb7c power pc version
kono
parents: 87
diff changeset
450 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
451 printf(":");
917947ffeb7c power pc version
kono
parents: 87
diff changeset
452 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
453 printf("%d",regv[i]);
917947ffeb7c power pc version
kono
parents: 87
diff changeset
454 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
455 #if 0
917947ffeb7c power pc version
kono
parents: 87
diff changeset
456 printf(" regs_stack",register_name(creg,0),register_name(dreg,0));
917947ffeb7c power pc version
kono
parents: 87
diff changeset
457 for(i=reg_sp;i>=0;i--) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
458 if(reg_stack[i]>=0)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
459 printf(" %s",register_name(reg_stack[i],0));
917947ffeb7c power pc version
kono
parents: 87
diff changeset
460 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
461 #endif
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
462 printf(" f:%d",freg_sp);
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
463 printf("\n");
917947ffeb7c power pc version
kono
parents: 87
diff changeset
464 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
465
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
466 void
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
467 code_arg_register(NMTBL *fnptr)
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
468 {
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
469 int args = fnptr->dsp;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
470 NMTBL *n;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
471 int reg_var = 0;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
472 int freg_var = 0;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
473 int type;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
474 int reg;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
475 int is_code0 = is_code(fnptr);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
476
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
477 while (args) {
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
478 /* process in reverse order */
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
479 n = (NMTBL*)caddr(args);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
480 type = n->ty;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
481 if (scalar(type)) {
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
482 if ((reg = get_input_register_var(reg_var,n,is_code0))) {
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
483 n->sc = REGISTER;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
484 n->dsp = cadr(reg);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
485 regv[n->dsp]= 1;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
486 regs[n->dsp]= INPUT_REG;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
487 reg_var++;
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
488 cadddr(args)=SIZE_OF_INT; /* why we need this? */
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
489 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
490 } else if (type==FLOAT||type==DOUBLE) {
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
491 if ((reg = get_input_dregister_var(freg_var,n,is_code0,1))) {
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
492 n->sc = DREGISTER;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
493 n->dsp = cadr(reg);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
494 fregv[n->dsp]= 1;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
495 fregs[n->dsp]= INPUT_REG;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
496 freg_var++;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
497 cadddr(args)=size(type); /* why we need this? */
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
498 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
499 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
500 args = cadr(args);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
501 }
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
502 }
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
503
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
504 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
505 gexpr_init(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
506 {
292
6d4231b6f9fe switch statement prepare
kono
parents: 291
diff changeset
507 if (reg_sp>0) error(-1);
6d4231b6f9fe switch statement prepare
kono
parents: 291
diff changeset
508 if (freg_sp>0) error(-1);
6d4231b6f9fe switch statement prepare
kono
parents: 291
diff changeset
509 reg_sp = 0;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
510 freg_sp = 0;
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
511 stack_depth = 0;
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
512 text_mode();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
513 gexpr_code_init();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
514 register_usage("gexpr_init");
917947ffeb7c power pc version
kono
parents: 87
diff changeset
515 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
516
917947ffeb7c power pc version
kono
parents: 87
diff changeset
517
917947ffeb7c power pc version
kono
parents: 87
diff changeset
518 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
519 emit_init(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
520 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
521 int i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
522 for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; regv[i]=0;rname[i]=i;}
917947ffeb7c power pc version
kono
parents: 87
diff changeset
523 free_all_register();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
524 reg_sp = 0;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
525 freg_sp = 0;
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
526 text_mode();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
527 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
528
917947ffeb7c power pc version
kono
parents: 87
diff changeset
529 int
917947ffeb7c power pc version
kono
parents: 87
diff changeset
530 virtual(int real)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
531 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
532 int real_v,i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
533 real_v = -1;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
534 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
535 if (rname[i]==real) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
536 real_v=i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
537 break;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
538 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
539 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
540 return real_v;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
541 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
542
917947ffeb7c power pc version
kono
parents: 87
diff changeset
543 int
917947ffeb7c power pc version
kono
parents: 87
diff changeset
544 pop_register(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
545 { /* �쥸���������ͤ���Ф� */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
546 return reg_stack[--reg_sp];
917947ffeb7c power pc version
kono
parents: 87
diff changeset
547 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
548
917947ffeb7c power pc version
kono
parents: 87
diff changeset
549 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
550 emit_pop_free(int xreg)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
551 {
159
b80e9737c3ce regs[creg]==0 in ia32
kono
parents: 156
diff changeset
552 if (xreg==dreg||xreg==creg) {
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
553 regv[dreg]=0;
98
07c2554e1cfa *** empty log message ***
kono
parents: 97
diff changeset
554 } else if (xreg>=0) {
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
555 free_register(xreg);
917947ffeb7c power pc version
kono
parents: 87
diff changeset
556 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
557 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
558
917947ffeb7c power pc version
kono
parents: 87
diff changeset
559
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
560 int
105
7e3d59e56a53 save register ( incomplete )
kono
parents: 104
diff changeset
561 get_register_var(NMTBL *nptr)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
562 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
563 int i;
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
564 for(i=REG_ESI;i<REG_EBP;i++) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
565 if (! regs[i]) { /* �Ȥ��Ƥ��ʤ��ʤ� */
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
566 regs[i]=REG_VAR; /* ���Υ쥸������Ȥ����Ȥ������ */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
567 regv[i]=0;
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
568 regvar[reg_var++]=i;
105
7e3d59e56a53 save register ( incomplete )
kono
parents: 104
diff changeset
569 return list3(REGISTER,i,(int)nptr); /* ���ξ���ɽ���ֹ���֤� */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
570 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
571 }
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
572 return list2(LVAR,new_lvar(SIZE_OF_INT));
104
c21aeb12b78b *** empty log message ***
kono
parents: 103
diff changeset
573 }
c21aeb12b78b *** empty log message ***
kono
parents: 103
diff changeset
574
c21aeb12b78b *** empty log message ***
kono
parents: 103
diff changeset
575 int
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
576 get_dregister_var(NMTBL *nptr,int d)
104
c21aeb12b78b *** empty log message ***
kono
parents: 103
diff changeset
577 {
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
578 return list2(LVAR,new_lvar(d?SIZE_OF_DOUBLE:SIZE_OF_FLOAT));
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
579 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
580
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
581 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
582 use_register(int virt, int real, int move)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
583 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
584 int real_v;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
585 char *move_op;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
586 if (rname[virt]==real)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
587 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
588 real_v = virtual(real);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
589 move_op = regs[real_v]?"\txchg %s,%s\n":"\tmovl %s,%s\n";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
590 if (move || (regv[real_v])) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
591 printf(move_op,reg_name[rname[virt]],reg_name[real]);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
592 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
593 rname[real_v] = rname[virt];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
594 rname[virt] = real;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
595 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
596
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
597 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
598 use_pointer(int virt, int move)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
599 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
600 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
601 if (rname[virt]>=POINTER_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
602 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
603 for(i=POINTER_REG;i<MAX_REGISTER;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
604 if (!regs[virtual(i)]) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
605 use_register(virt,i,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
606 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
607 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
608 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
609 /* we prefer EBX */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
610 use_register(virt,REG_EBX,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
611 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
612
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
613 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
614 use_data_reg(int virt, int move)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
615 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
616 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
617 if (rname[virt]<MAX_DATA_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
618 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
619 for(i=0;i<MAX_DATA_REG;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
620 if (!regs[virtual(i)]) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
621 use_register(virt,i,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
622 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
623 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
624 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
625 /* we prefer EBX */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
626 use_register(virt,REG_EBX,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
627 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
628
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
629
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
630 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
631 emit_push()
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
632 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
633 int new_reg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
634 new_reg = get_register();
159
b80e9737c3ce regs[creg]==0 in ia32
kono
parents: 156
diff changeset
635 if (new_reg==creg) error(-1);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
636 if(new_reg<0) { /* �⤦�쥸�������ʤ� */
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
637 if (reg_sp>=MAX_MAX) error(-1);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
638 reg_stack[reg_sp++] = -1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
639 printf("\tpushl %s\n",register_name(creg,0));
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
640 stack_depth += SIZE_OF_INT;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
641 /* creg is used soon, don't regv[creg]=0 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
642 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
643 reg_stack[reg_sp++] = creg; /* push ���뤫���˥쥸������Ȥ� */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
644 creg = new_reg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
645 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
646 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
647 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
648
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
649 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
650 emit_pop(int type)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
651 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
652 int xreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
653 if ((xreg=pop_register())==-1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
654 if (type==POINTER_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
655 use_pointer(dreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
656 else if (type==DATA_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
657 use_data_reg(dreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
658 if (regv[dreg]) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
659 printf("# emit_pop dreg conflict\n");
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
660 error(-1);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
661 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
662 printf("\tpopl %s\n",register_name(dreg,0));
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
663 regv[dreg]=1;
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
664 stack_depth -= SIZE_OF_INT;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
665 return dreg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
666 } else if (xreg<= -REG_LVAR_OFFSET) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
667 code_rlvar(xreg+REG_LVAR_OFFSET,dreg);
117
2d5a203cc3a6 lvar reuse
kono
parents: 116
diff changeset
668 free_lvar(xreg+REG_LVAR_OFFSET);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
669 regv[dreg]=1;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
670 return dreg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
671 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
672 return xreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
673 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
674
186
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
675 int
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
676 stack_top(int type)
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
677 {
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
678 int xreg;
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
679 if (type==INT) {
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
680 xreg = reg_stack[reg_sp];
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
681 if (xreg<= -REG_LVAR_OFFSET) {
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
682 return list2(LVAR,REG_LVAR_OFFSET+xreg);
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
683 } else {
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
684 return list2(REGISTER,xreg);
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
685 }
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
686 } else {
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
687 xreg = freg_stack[freg_sp];
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
688 if (xreg<= -REG_LVAR_OFFSET) {
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
689 return list2(LVAR,REG_LVAR_OFFSET+xreg);
187
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
690 } else {
186
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
691 return list2(DREGISTER,xreg);
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
692 }
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
693 }
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
694 return xreg;
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
695 }
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
696
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
697
6391432ca002 nkf binary fix
kono
parents: 183
diff changeset
698
92
e7f8515ba882 *** empty log message ***
kono
parents: 89
diff changeset
699 void
e7f8515ba882 *** empty log message ***
kono
parents: 89
diff changeset
700 code_label(int labelno)
e7f8515ba882 *** empty log message ***
kono
parents: 89
diff changeset
701 {
e7f8515ba882 *** empty log message ***
kono
parents: 89
diff changeset
702 printf("_%d:\n",labelno);
e7f8515ba882 *** empty log message ***
kono
parents: 89
diff changeset
703 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
704
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
705 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
706 code_gvar(int e1,int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
707 use_int(creg);
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
708 printf("\tmovl $%s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
709 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
710 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
711
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
712
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
713 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
714 code_rgvar(int e1,int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
715 use_int(creg);
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
716 printf("\tmovl %s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
717 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
718 }
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
719
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
720 static char *cload(int sign,int sz) { return sz==1?(sign?"movsbl":"movzbl"):sz==SIZE_OF_SHORT?(sign?"movswl":"movzwl"):"movl"; }
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
721
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
722 void
165
kono
parents: 163
diff changeset
723 code_crgvar(int e1,int creg,int sign,int sz){
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
724 use_int(creg);
165
kono
parents: 163
diff changeset
725 printf("\t%s %s,%s\n",cload(sign,sz),
163
fc8514c9d685 *** empty log message ***
kono
parents: 159
diff changeset
726 ((NMTBL*)cadr(e1))->nm,register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
727 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
728 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
729
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
730
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
731 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
732 code_lvar(int e2,int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
733 use_int(creg);
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
734 printf("\tlea %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
735 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
736 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
737
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
738
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
739 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
740 code_register(int e2,int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
741 use_int(creg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
742 printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
743 regv[creg]=1;
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
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
747 void
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
748 code_rlvar(int e2,int reg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
749 use_int(reg);
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
750 printf("\tmovl %d(%%ebp),%s\n",lvar(e2),register_name(reg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
751 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
752 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
753
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
754
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
755 void
165
kono
parents: 163
diff changeset
756 code_crlvar(int e2,int reg,int sign,int sz) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
757 use_int(reg);
165
kono
parents: 163
diff changeset
758 printf("\t%s %d(%%ebp),%s\n",cload(sign,sz),lvar(e2),register_name(reg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
759 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
760 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
761
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
762
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
763 void
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
764 code_fname(NMTBL *n,int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
765 use_int(creg);
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
766 printf("\tmovl $%s,%s\n",n->nm,register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
767 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
768 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
769
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
770
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
771 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
772 code_const(int e2,int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
773 use_int(creg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
774 printf("\tmovl $%d,%s\n",e2,register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
775 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
776 }
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 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
780 code_neg(int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
781 use_int(creg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
782 printf("\tnegl %s\n", register_name(creg,0));
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
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
787 code_not(int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
788 use_int(creg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
789 printf("\tnotl %s\n", register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
790 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
791
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
792
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
793 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
794 code_lnot(int creg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
795 char *xrn;
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
796 use_int(creg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
797 use_data_reg(creg,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
798 xrn = register_name(creg,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
799 printf("\tcmpl $0,%s\n", register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
800 printf("\tsete %s\n", xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
801 printf("\tmovzbl %s,%s\n", xrn,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
802 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
803
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
804 void
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
805 code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
806 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
807 if (car(e2)==REGISTER) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
808 use_int(reg);
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
809 printf("\taddl $%d,%s\n",dir,register_name(cadr(e2),0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
810 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0));
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
811 regv[reg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
812 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
813 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
814 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
815 xrn = register_name(creg,0);
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
816 use_int(reg);
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
817 printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==SIZE_OF_SHORT)?"addw":"addl",dir,xrn);
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
818 printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0));
61
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
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
822 void
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
823 code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
824 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
825 if (car(e2)==REGISTER) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
826 use_int(reg);
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
827 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0));
168
b1297c82e926 cpostinc removal
kono
parents: 167
diff changeset
828 printf("\taddl $%d,%s\n",dir,register_name(cadr(e2),0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
829 regv[reg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
830 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
831 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
832 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
833 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
834 xrn = register_name((e2=emit_pop(0)),0);
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
835 use_int(reg);
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
836 printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0));
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
837 printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==SIZE_OF_SHORT)?"addw":"addl",dir,xrn);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
838 emit_pop_free(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
839 }
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
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
844 code_return(int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
845 use_int(creg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
846 printf("\tleal _%d,%s\n",retcont,register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
847 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
848 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
849
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
850
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
851 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
852 code_environment(int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
853 use_int(creg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
854 printf("\tmovl %%ebp,%s\n",register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
855 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
856 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
857
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
858 static int rexpr_bool(int e1,int reg);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
859 static int drexpr_bool(int e1,int reg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
860
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
861 void
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
862 code_bool(int e1,int reg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
863 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
864 int e2,e3;
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
865 if (rexpr_bool(e1,reg)) return;
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
866 #if FLOAT_CODE
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
867 if (drexpr_bool(e1,reg)) return;
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
868 #endif
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
869 b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */
289
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
870 if (use) {
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
871 use_int(reg);
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
872 xrn = register_name(reg,0);
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
873 printf("\txorl %s,%s\n",xrn,xrn);
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
874 jmp(e3=fwdlabel());
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
875 fwddef(e2);
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
876 printf("\tmovl $1,%s\n",xrn);
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
877 fwddef(e3);
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
878 regv[reg]=1;
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
879 } else {
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
880 fwddef(e2);
55e611476cba *** empty log message ***
kono
parents: 287
diff changeset
881 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
882 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
883
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
884 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
885 code_gt(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
886 return (cond?"g":"le");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
887 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
888
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
889 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
890 code_ugt(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
891 return (cond?"a":"be");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
892 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
893
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
894 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
895 code_ge(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
896 return (cond?"ge":"l");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
897 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
898
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
899 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
900 code_uge(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
901 return (cond?"ae":"b");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
902 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
903
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
904 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
905 code_eq(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
906 return (cond?"e":"ne");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
907 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
908
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
909 void
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
910 code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
911 use_int(reg);
167
0197ca125567 mips short
kono
parents: 166
diff changeset
912 if (sz==1)
0197ca125567 mips short
kono
parents: 166
diff changeset
913 printf("\tcmpb $0,%s\n",((NMTBL*)cadr(e1))->nm);
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
914 else if (sz==SIZE_OF_SHORT)
167
0197ca125567 mips short
kono
parents: 166
diff changeset
915 printf("\tcmpw $0,%s\n",((NMTBL*)cadr(e1))->nm);
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
916 jcond(label,cond);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
917 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
918
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
919
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
920 void
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
921 code_cmp_crlvar(int e1,int reg,int sz,int label,int cond) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
922 use_int(reg);
167
0197ca125567 mips short
kono
parents: 166
diff changeset
923 if (sz==1)
0197ca125567 mips short
kono
parents: 166
diff changeset
924 printf("\tcmpb $0,%d(%%ebp)\n",lvar(e1));
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
925 else if (sz==SIZE_OF_SHORT)
167
0197ca125567 mips short
kono
parents: 166
diff changeset
926 printf("\tcmpw $0,%d(%%ebp)\n",lvar(e1));
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
927 jcond(label,cond);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
928 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
929
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
930
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
931 void
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
932 code_cmp_rgvar(int e1,int reg,int label,int cond) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
933 use_int(reg);
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
934 printf("\tcmpl $0,%s\n",((NMTBL*)cadr(e1))->nm);
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
935 jcond(label,cond);
61
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
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
939 void
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
940 code_cmp_rlvar(int e1,int reg,int label,int cond) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
941 use_int(reg);
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
942 printf("\tcmpl $0,%d(%%ebp)\n",lvar(e1));
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
943 jcond(label,cond);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
944 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
945
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
946
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
947 void
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
948 code_cmp_register(int e2,int label,int cond) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
949 use_int(e2);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
950 printf("\tcmpl $0,%s\n",register_name(e2,0));
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
951 jcond(label,cond);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
952 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
953
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
954
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
955 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
956 code_string(int e1,int creg)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
957 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
958 char *s;
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
959 int lb;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
960
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
961 use_int(creg);
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
962 s=(char *)cadr(e1);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
963 lb = emit_string_label();
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
964 ascii(s);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
965 if (output_mode==TEXT_EMIT_MODE) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
966 printf(".text\n");
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
967 } else {
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
968 text_mode();
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
969 }
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
970 printf("\tlea _%d,%s\n",lb,register_name(creg,0));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
971 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
972
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
973 #define MAX_COPY_LEN 20
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
974
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
975 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
976 emit_copy(int from,int to,int length,int offset,int value,int det)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
977 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
978 int fix = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
979 /* length <0 means upward direction copy */
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
980 use_int(from);
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
981 use_int(to);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
982 switch (length) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
983 case 0: break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
984 case 1: case -1:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
985 printf("\tmovb %d(%s),%s\n",offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
986 register_name(from,0), reg_name_l[rname[dreg]] );
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
987 printf("\tmovb %s,%d(%s)\n",reg_name_l[rname[dreg]] ,offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
988 register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
989 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
990 case 2: case -2:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
991 printf("\tmovw %d(%s),%s\n",offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
992 register_name(from,0), reg_name_w[rname[dreg]] );
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
993 printf("\tmovw %s,%d(%s)\n",reg_name_w[rname[dreg]] ,offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
994 register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
995 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
996 case 4: case -4:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
997 printf("\tmovl %d(%s),%s\n",offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
998 register_name(from,0), register_name(dreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
999 printf("\tmovl %s,%d(%s)\n",register_name(dreg,0), offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1000 register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1001 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1002 default:
258
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1003 if (length <0) {
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1004 if (length > -MAX_COPY_LEN) {
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1005 for(;length<=-4;length+=4,offset-=4)
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1006 emit_copy(from,to,-4,offset-4,0,det);
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1007 for(;length<=-2;length+=2,offset-=2)
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1008 emit_copy(from,to,-2,offset-2,0,det);
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1009 if(length<0)
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1010 emit_copy(from,to,length,offset-1,0,det);
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1011 break;
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1012 }
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1013 } else if (length <=MAX_COPY_LEN) {
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1014 for(;length>=4;length-=4,offset+=4)
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1015 emit_copy(from,to,4,offset,0,det);
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1016 for(;length>=2;length-=2,offset+=2)
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1017 emit_copy(from,to,2,offset,0,det);
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1018 if(length>0)
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1019 emit_copy(from,to,length,offset,0,det);
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1020 break;
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1021 }
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1022 /*
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1023 if (det) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1024 call bcopy
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1025 g_expr(list3(FUNCTION,,);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1026 break;
258
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1027 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1028 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1029 use_register(from,REG_ESI,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1030 use_register(to, REG_EDI,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1031 use_register(dreg,REG_ECX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1032 if (length<0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1033 printf("\tmovl $%d,%%ecx\n",-length/4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1034 printf("\taddl $%d,%%esi\n",-length);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1035 printf("\taddl $%d,%%edi\n",-length);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1036 printf("\tstd\n\trep\n\tmovsl\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1037 if(length%4) {
258
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1038 emit_copy(from,to,length,offset+length/SIZE_OF_INT,0,det);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1039 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1040 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1041 printf("\tmovl $%d,%%ecx\n",length/4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1042 fix = (length/4)*4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1043 printf("\tcld\n\trep\n\tmovsl\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1044 if(length%4) {
258
22949117768f Complex function argments. Struct is done. Long long is odd.
kono
parents: 254
diff changeset
1045 emit_copy(from,to,length,offset+length/SIZE_OF_INT,0,det);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1046 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1047 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1048 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1049 if (value) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1050 /* creg must point top of the destination data */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1051 /* this code is necessary for the value of assignment or function call */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1052 /* otherwise we don't need this */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1053 if (fix) printf("\tsubl $%d,%s\n",fix,register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1054 if(creg!=to) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1055 if (to==dreg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1056 printf("\tmovl %s,%s\n",register_name(to,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1057 else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1058 free_register(creg); creg=to;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1059 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1060 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1061 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1062 regv[from]=regv[to]=regv[dreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1063 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1064 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1065
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1066 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1067 struct_push(int e4,int t)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1068 {
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1069 int length,xreg,save,lreg,count;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1070 g_expr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1071 length=size(t);
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1072 if(length%SIZE_OF_INT) {
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1073 length += SIZE_OF_INT - (length%SIZE_OF_INT);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1074 }
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1075 for(count=0;length<MAX_COPY_LEN;count++,length-=SIZE_OF_INT) {
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1076 if (length==0) return count;
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1077 else {
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1078 printf("\tpushl %d(%s)\n",
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1079 length-SIZE_OF_INT,register_name(creg,0));
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1080 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1081 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1082 printf("\tsubl $%d,%%esp\n",length);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1083 if (register_full()) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1084 save = 1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1085 for(lreg=0;lreg==creg||lreg==dreg;lreg++);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1086 printf("\tpushl %s\n",register_name(lreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1087 xreg = lreg; regv[xreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1088 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1089 save=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1090 xreg = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1091 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1092 if (save)
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1093 printf("\tlea %d(%%esp),%s\n",SIZE_OF_INT,register_name(xreg,0));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1094 else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1095 printf("\tmovl %%esp,%s\n",register_name(xreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1096 regv[xreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1097 /* downward direction copy */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1098 emit_copy(creg,xreg,length,0,0,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1099 /* we have value in creg, it may be changed */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1100 if (save) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1101 if(creg==xreg) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1102 creg = get_register(); /* creg is freed in emit_copy */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1103 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1104 printf("\tpopl %s\n",register_name(xreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1105 regv[xreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1106 } else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1107 free_register(xreg);
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1108 stack_depth += length*SIZE_OF_INT;
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1109 return length/SIZE_OF_INT;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1110 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1111
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1112 int
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1113 function(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1114 {
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1115 int e2,e3,e4,nargs,t,ret_type;
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1116 NMTBL *n=0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1117 int save,saved;
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1118 int stack_depth_save = stack_depth;
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1119
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
1120 ret_type = cadr(cadddr(e1));
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
1121 if (ret_type==CHAR) ret_type=INT;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
1122
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1123 #ifdef SAVE_STACKS
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1124 code_save_stacks();
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1125 #if FLOAT_CODE
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1126 code_save_fstacks();
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1127 #endif
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1128 #endif
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
1129 if (free_register_count(0)<1) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1130 for(save = 0;save==dreg||save==creg;save++);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1131 printf("\tpushl %s\n",register_name(save,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1132 saved = 1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1133 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1134 save = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1135 saved = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1136 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1137 regv[save]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1138 e2 = cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1139 nargs = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1140 for (e3 = caddr(e1); e3; e3 = cadr(e3)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1141 t=caddr(e3);
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1142 e4 = car(e3);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1143 if(scalar(t)) {
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1144 if (car(e4)==REGISTER) {
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1145 printf("\tpushl %s\n",register_name(cadr(e4),0));
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1146 } else {
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1147 g_expr(e4);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1148 printf("\tpushl %s\n",register_name(creg,0));
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1149 }
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1150 stack_depth += SIZE_OF_INT;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1151 } else if (t==LONGLONG||t==ULONGLONG) {
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1152 if (car(e4)==LREGISTER) {
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1153 printf("\tpushl %s\n\tpushl %s\n",l_edx(cadr(e4)),l_eax(cadr(e4)));
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1154 } else {
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1155 g_expr(e4);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1156 printf("\tpushl %%edx\n\tpushl %%eax\n");
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1157 }
241
96b5ee862a41 *** empty log message ***
kono
parents: 240
diff changeset
1158 ++nargs;
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1159 stack_depth += SIZE_OF_INT*2;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1160 } else if (t==DOUBLE) {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1161 g_expr(e4);
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1162 printf("\tleal\t-8(%%esp),%%esp\n\tfstpl\t(%%esp)\n");
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1163 nargs += SIZE_OF_DOUBLE/SIZE_OF_INT;
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1164 fregv[freg]=0;
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1165 stack_depth += SIZE_OF_DOUBLE;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1166 continue;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1167 } else if (t==FLOAT) {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1168 g_expr(e4);
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1169 printf("\tleal\t-4(%%esp),%%esp\n\tfstps\t(%%esp)\n");
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1170 nargs += SIZE_OF_FLOAT/SIZE_OF_INT;
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1171 fregv[freg]=0;
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1172 stack_depth += SIZE_OF_FLOAT;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1173 continue;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1174 } else if (car(t)==STRUCT||car(t)==UNION) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1175 nargs += struct_push(e4,t);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1176 continue;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1177 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1178 error(TYERR);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1179 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1180 ++nargs;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1181 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1182 if (car(e2) == FNAME) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1183 n=(NMTBL *)cadr(e2);
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1184 regv[creg]=0;
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1185 use_register(creg,REG_EAX,0); /* will be destroyed */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1186 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1187 g_expr(e2);
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1188 regv[creg]=1;
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1189 use_register(creg,REG_EAX,1); /* will be destroyed */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1190 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1191
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1192 /* we don't have to save creg nor dreg */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1193 regs[creg]=0; regs[dreg]=0;
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1194 regv[dreg]= regv[save]= 0;
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1195 use_register(dreg,REG_EBX,0); /* will be destroyed */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1196 use_register(save,REG_ECX,0); /* will be destroyed */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1197 regs[creg]=1; regs[dreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1198
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1199 if (car(e2) == FNAME) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1200 printf("\tcall\t%s\n",n->nm);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1201 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1202 printf("\tcall\t*%s\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1203 }
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1204 if (nargs) printf("\taddl $%d,%%esp\n",SIZE_OF_INT*nargs);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1205 if (saved) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1206 printf("\tpopl %s\n",register_name(save,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1207 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1208 free_register(save);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1209 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1210 regv[save]=0;
105
7e3d59e56a53 save register ( incomplete )
kono
parents: 104
diff changeset
1211 if (ret_type==DOUBLE||ret_type==FLOAT) {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1212 } else if (ret_type==LONGLONG||ret_type==ULONGLONG) {
243
c311c26e006a *** empty log message ***
kono
parents: 242
diff changeset
1213 use_longlong0(USE_CREG);
c311c26e006a *** empty log message ***
kono
parents: 242
diff changeset
1214 regv[creg]=1;
105
7e3d59e56a53 save register ( incomplete )
kono
parents: 104
diff changeset
1215 } else if (ret_type==VOID) {
243
c311c26e006a *** empty log message ***
kono
parents: 242
diff changeset
1216 regv[freg]=0; regv[creg]=0;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1217 } else {
243
c311c26e006a *** empty log message ***
kono
parents: 242
diff changeset
1218 use_register(creg,REG_EAX,0);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1219 fregv[freg]=0; regv[creg]=1;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1220 }
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1221 stack_depth = stack_depth_save;
105
7e3d59e56a53 save register ( incomplete )
kono
parents: 104
diff changeset
1222 return ret_type;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1223 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1224
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1225 void
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1226 code_alloca(int e1,int reg)
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1227 {
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1228 char *crn,*drn;
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1229 int edx;
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1230
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1231 g_expr(list3(BAND,list3(ADD,e1,list2(CONST,15)),list2(CONST,~15)));
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1232 use_int(reg);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1233 if (stack_depth>0) {
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1234 edx = edx_setup(-1);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1235 crn = register_name(reg,0);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1236 drn = register_name(edx,0);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1237 printf("\tmovl %%esp,%s\n",drn);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1238 printf("\tsubl %s,%%esp\n",crn);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1239 printf("\tmovl %%esp,%s\n",crn);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1240 emit_copy(edx,creg,stack_depth,0,1,1);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1241 printf("\taddl $%d,%s\n",stack_depth,register_name(creg,0));
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1242 edx_cleanup();
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1243 } else {
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1244 crn = register_name(reg,0);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1245 printf("\tsubl %s,%%esp\n",crn);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1246 printf("\tmovl %%esp,%s\n",crn);
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1247 }
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1248 }
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1249
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1250 void
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1251 code_frame_pointer(int e3) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1252 use_int(e3);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1253 printf("\tmovl %s,%%ebp\n",register_name(e3,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1254 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1255
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1256
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1257 void
62
129f4802b027 separation done
kono
parents: 61
diff changeset
1258 code_fix_frame_pointer(int disp_offset) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1259 printf("\tlea %d(%%ebp),%%ebp\n",disp_offset);
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 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1264 code_jmp(char *s) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1265 printf("\tjmp %s\n",s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1266 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1267
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1268
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1269 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1270 code_indirect_jmp(int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1271 printf("\tjmp *%s\n",register_name(e2,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1272 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1273
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1274 int
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1275 code_rindirect(int e1, int reg,int offset, int sign)
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1276 {
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1277 char *crn,*op;
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1278 int byte;
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1279 g_expr(e1);
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1280 byte = 0; op="movl";
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1281 crn = register_name(creg,0);
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1282 use_int(reg);
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1283 printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0));
246
0dcc0ec81ed2 MIPS on going (90%)
kono
parents: 245
diff changeset
1284 return sign?INT:UNSIGNED;
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1285 }
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1286
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1287 int
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1288 code_crindirect(int e1, int reg,int offset, int sign)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1289 {
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1290 char *crn,*op;
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1291 int byte;
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1292 g_expr(e1);
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1293 byte = 0; op=sign?"movsbl":"movzbl";
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1294 crn = register_name(creg,0);
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1295 use_int(reg);
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1296 printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0));
246
0dcc0ec81ed2 MIPS on going (90%)
kono
parents: 245
diff changeset
1297 return sign?CHAR:UCHAR;
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1298 }
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1299
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1300 int
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1301 code_srindirect(int e1, int reg,int offset, int sign)
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1302 {
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1303 char *crn,*op;
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1304 int byte;
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1305 g_expr(e1);
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1306 byte = 0; op=sign?"movswl":"movzwl";
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1307 crn = register_name(creg,0);
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1308 use_int(reg);
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1309 printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0));
246
0dcc0ec81ed2 MIPS on going (90%)
kono
parents: 245
diff changeset
1310 return sign?SHORT:USHORT;
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1311 }
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1312
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
1313 #if FLOAT_CODE
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1314 int
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
1315 code_drindirect(int e1, int reg,int offset, int d)
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1316 {
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1317 g_expr(e1);
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1318 printf("\t%s (%s)\n",fload(d),register_name(creg,0));
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1319 return DOUBLE;
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1320 }
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
1321 #endif
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1322
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1323 #if LONGLONG_CODE
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1324
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1325 static void
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1326 lload(int creg,int offset,int reg)
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1327 {
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1328 char *crn = register_name(creg,0);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1329 use_longlong(reg);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1330 if((reg==REG_L&&rname[creg]==REG_ESI)||(rname[creg]==REG_EAX)) {
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1331 printf("\tmovl %d(%s),%s\n",offset+SIZE_OF_INT,crn,l_edx(reg));
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1332 printf("\tmovl %d(%s),%s\n",offset,crn,l_eax(reg));
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1333 } else {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1334 printf("\tmovl %d(%s),%s\n",offset,crn,l_eax(reg));
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1335 printf("\tmovl %d(%s),%s\n",offset+SIZE_OF_INT,crn,l_edx(reg));
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1336 }
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1337 }
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1338
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1339 int
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
1340 code_lrindirect(int e1, int reg, int offset, int us)
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1341 {
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1342 int reg0;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1343 g_expr(e1);
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1344 regv[reg0=creg]=1;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1345 use_longlong(reg);
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1346 lload(reg0,offset,reg);
203
28baf6cd9ad1 *** empty log message ***
kono
parents: 196
diff changeset
1347 return LONGLONG;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1348 }
196
5f70abd9453d *** empty log message ***
kono
parents: 195
diff changeset
1349 #endif
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1350
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1351 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1352 move(int byte)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1353 {
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1354 return byte==1?"movb":byte==SIZE_OF_SHORT?"movw":"movl";
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1355 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1356
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1357 void
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1358 code_assign_gvar(int e2,int creg,int byte) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1359 use_int(creg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1360 if (byte) use_data_reg(creg,1);
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
1361 printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),((NMTBL*)cadr(e2))->nm);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1362 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1363
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1364 void
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1365 code_assign_lvar(int e2,int creg,int byte) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1366 use_int(creg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1367 if (byte) use_data_reg(creg,1);
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1368 printf("\t%s %s,%d(%%ebp)\n",move(byte),register_name(creg,byte),lvar(e2));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1369 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1370
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1371 void
111
7aa449aff3e6 floating point
kono
parents: 109
diff changeset
1372 code_assign_register(int e2,int byte,int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1373 use_int(creg);
286
179e22f166ef register assop fix
kono
parents: 280
diff changeset
1374 if (creg!=e2)
179e22f166ef register assop fix
kono
parents: 280
diff changeset
1375 printf("\tmovl %s,%s\n",register_name(creg,0),register_name(e2,0));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1376 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1377
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1378 void
118
07b91b625f84 assignment optimization
kono
parents: 117
diff changeset
1379 code_assign(int e2,int byte,int creg) {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1380 use_int(e2);
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1381 use_int(creg);
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1382 if (byte) use_data_reg(creg,1);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1383 printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte),register_name(e2,0));
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1384 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1385 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1386
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1387 void
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
1388 code_register_assop(int e2,int reg0,int op,int byte) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1389 int reg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1390 int xreg = creg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1391 creg = reg = e2;
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
1392 tosop(op,reg,xreg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1393 creg = xreg;
286
179e22f166ef register assop fix
kono
parents: 280
diff changeset
1394 // printf("\tmovl %s,%s\n",register_name(reg,0),register_name(creg,0));
159
b80e9737c3ce regs[creg]==0 in ia32
kono
parents: 156
diff changeset
1395 regs[creg]=regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1396 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1397
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1398
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1399 void
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
1400 code_assop(int op,int reg,int byte,int sign) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1401 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1402 int xreg;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1403 int edx = edx_setup(-1);
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1404 use_int(reg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1405 xrn = register_name(xreg = emit_pop(0),0); /* pop e3 value */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1406 regv[xreg]=regs[xreg]=1;
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1407 printf("\tmovl %s,%s # assop \n",register_name(reg,0),register_name(edx,0));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1408 regv[edx]=1;
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1409 ld_indexx(byte,0,edx,reg,sign);
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
1410 tosop(op,reg,xreg);
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1411 printf("\t%s %s,(%s)\n",move(byte),register_name(reg,byte),register_name(edx,0));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1412 edx_cleanup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1413 emit_pop_free(xreg);
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1414 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1415 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1416
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1417
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1418 void
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
1419 tosop(int op,int reg,int oreg)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1420 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1421 int dx;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1422 char *orn,*crn;
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1423 use_int(reg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1424
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1425 switch(op) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1426 case LSHIFT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1427 case ULSHIFT:
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1428 shift("sall",oreg,reg);
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1429 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1430 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1431 case RSHIFT:
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1432 shift("sarl",oreg,reg);
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1433 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1434 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1435 case URSHIFT:
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1436 shift("shrl",oreg,reg);
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1437 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1438 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1439 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1440 if(oreg==-1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1441 printf("\tpopl %s\n",register_name(dreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1442 oreg = dreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1443 regv[dreg]=1;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1444 } else if (oreg<= -REG_LVAR_OFFSET) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1445 code_rlvar(oreg+REG_LVAR_OFFSET,dreg);
117
2d5a203cc3a6 lvar reuse
kono
parents: 116
diff changeset
1446 free_lvar(oreg+REG_LVAR_OFFSET);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1447 oreg = dreg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1448 regv[dreg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1449 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1450 regv[oreg]=1; regs[oreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1451 orn = register_name(oreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1452 crn = register_name(creg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1453 switch(op) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1454 case ADD:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1455 printf("\taddl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1456 break;
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
1457 case SUB: case CMP:
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1458 printf("\tsubl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1459 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1460 case BAND:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1461 printf("\tandl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1462 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1463 case EOR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1464 printf("\txorl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1465 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1466 case BOR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1467 printf("\torl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1468 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1469 case MUL:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1470 case UMUL:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1471 printf("\t%s %s,%s\n","imull",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1472 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1473 case DIV:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1474 case UDIV:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1475 use_register(creg,REG_EAX,1);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1476 edx_setup(REG_EDX);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1477 orn = register_name(oreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1478 if (op==DIV)
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1479 printf("\tcltd\n\tidivl %s\n",orn);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1480 else
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1481 printf("\txor %%edx,%%edx\n\tdivl %s\n",orn);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1482 edx_cleanup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1483 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1484 case MOD:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1485 case UMOD:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1486 use_register(creg,REG_EAX,1);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1487 edx_setup(REG_EDX);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1488 orn = register_name(oreg,0);
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1489 if (op==MOD)
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1490 printf("\tcltd\n\tidivl %s\n",orn);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1491 else
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1492 printf("\txor %%edx,%%edx\n\tdivl %s\n",orn);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1493 dx = virtual(REG_EDX);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1494 if (dx!=creg) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1495 rname[dx]=rname[creg];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1496 rname[creg]=REG_EDX;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1497 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1498 edx_cleanup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1499 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1500 }
159
b80e9737c3ce regs[creg]==0 in ia32
kono
parents: 156
diff changeset
1501 if (oreg!=dreg&&oreg!=creg&&oreg>=0)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1502 free_register(oreg);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1503 else if (oreg==dreg) regv[dreg]=0;
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1504 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1505 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1506
189
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1507 int
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1508 code_const_op_p(int op,int e)
189
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1509 {
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1510 if (car(e)!=CONST) return 0;
190
1b1c58483e67 minor fix
kono
parents: 189
diff changeset
1511 if (op==DIV||op==UDIV||op==MOD||op==UMOD) return 0;
189
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1512 else return 1;
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1513 }
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1514
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1515 void
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
1516 oprtc(int op,int reg,int orn)
189
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1517 {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1518 char *crn;
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1519 int datareg;
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1520 use_int(reg);
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1521 crn = register_name(reg,0);
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
1522 orn = cadr(orn);
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1523 datareg=(rname[reg]<MAX_DATA_REG);
189
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1524
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1525 switch(op) {
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1526 case LSHIFT:
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1527 case ULSHIFT:
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1528 printf("\tsall $%d,%s\n",orn,crn);
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1529 return;
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1530 case RSHIFT:
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1531 printf("\tsarl $%d,%s\n",orn,crn);
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1532 return;
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1533 case URSHIFT:
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1534 printf("\tshrl $%d,%s\n",orn,crn);
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1535 return;
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1536 case ADD:
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1537 printf("\taddl $%d,%s\n",orn,crn);
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1538 break;
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1539 case SUB: case CMP:
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1540 printf("\tsubl $%d,%s\n",orn,crn);
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1541 break;
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1542 case BAND:
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1543 if (datareg&&(orn & ~255)==~255)
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1544 printf("\tandb $%d,%s\n",orn,register_name(reg,1));
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1545 else if (datareg&&(orn & ~65535)==~65535)
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1546 printf("\tandw $%d,%s\n",orn,register_name(reg,2));
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1547 else
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1548 printf("\tandl $%d,%s\n",orn,crn);
189
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1549 break;
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1550 case EOR:
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1551 printf("\txorl $%d,%s\n",orn,crn);
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1552 break;
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1553 case BOR:
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1554 if (datareg&&(orn & ~255)==0)
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1555 printf("\tor $%d,%s\n",orn,register_name(reg,1));
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1556 else if (datareg&&(orn & ~65535)==0)
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1557 printf("\tor $%d,%s\n",orn,register_name(reg,2));
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1558 else
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
1559 printf("\torl $%d,%s\n",orn,crn);
189
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1560 break;
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1561 case MUL:
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1562 case UMUL:
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1563 printf("\t%s $%d,%s\n","imull",orn,crn);
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1564 break;
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1565 default:
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1566 error(-1);
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1567 }
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1568 }
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1569
f53d70110377 immediate instructions.
kono
parents: 187
diff changeset
1570
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1571 static int edx_stack=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1572
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1573 int
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1574 edx_setup(int rreg)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1575 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1576 int edx_save;
302
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
1577 /* make real EDX (or rreg) register empty */
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
1578 if (free_register_count(0)<1) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1579 for(edx_save = 0;edx_save==dreg||edx_save==creg;edx_save++);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1580 printf("\tpushl %s\n",register_name(edx_save,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1581 edx_stack = list3(edx_save,edx_stack,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1582 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1583 edx_save = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1584 edx_stack = list3(edx_save,edx_stack,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1585 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1586 regv[edx_save]=0;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1587 if (rreg!=-1)
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
1588 use_register(edx_save,rreg,0);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1589 return edx_save;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1590 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1591
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1592
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1593 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1594 edx_cleanup()
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1595 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1596 if (caddr(edx_stack)==0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1597 printf("\tpopl %s\n",register_name(car(edx_stack),0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1598 } else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1599 free_register(car(edx_stack));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1600 edx_stack = cadr(edx_stack);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1601 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1602
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1603 void
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1604 shift(char *op, int reg,int creg)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1605 {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1606 use_int(creg);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1607 if (reg>=0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1608 use_register(reg,REG_ECX,1);
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1609 } else if (reg<= -REG_LVAR_OFFSET) {
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1610 use_register(dreg,REG_ECX,0);
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1611 code_rlvar(reg+REG_LVAR_OFFSET,dreg);
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1612 reg = dreg;
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1613 regv[dreg]=0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1614 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1615 use_register(dreg,REG_ECX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1616 printf("\tpopl %%ecx\n");
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1617 regv[dreg]=0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1618 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1619 printf("\t%s %%cl,%s\n",op,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1620 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1621
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1622 void
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1623 ld_indexx(int byte, int n, int xreg,int reg,int sign)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1624 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1625 char *op;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1626
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1627 use_int(reg);
166
9e55cc5551fb *** empty log message ***
kono
parents: 165
diff changeset
1628 op = byte ? (sign?"movsbl":"movzbl") : "movl";
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1629 if (n)
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1630 printf("\t%s %d(%s),%s\n",op,n,
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1631 register_name(xreg,0),register_name(reg,byte));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1632 else
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1633 printf("\t%s (%s),%s\n",op,
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
1634 register_name(xreg,0),register_name(reg,byte));
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1635 }
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1636
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1637 int
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1638 code_csvalue()
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1639 {
123
5f180dc8d84e intel fix.
kono
parents: 119
diff changeset
1640 return rname[creg]; /* for switch value */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1641 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1642
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1643 void
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
1644 code_cmpdimm(int e, int csreg,int label,int cond)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1645 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1646 /* used in dosiwtch() */
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1647 if(chk) return;
123
5f180dc8d84e intel fix.
kono
parents: 119
diff changeset
1648 use_register(creg,csreg,0);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1649 printf("\tcmpl $%d,%s\n",e,register_name(creg,0));
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
1650 jcond(label,cond);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1651 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1652
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1653 void
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1654 code_opening(char *filename)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1655 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1656 printf("\t.file \"%s\"\n",filename);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1657 printf("\t.version\t\"01.01\"\n");
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1658 /* printf("gcc2_compiled.:\n"); */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1659 printf(".text\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1660 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1661
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1662 void
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1663 code_closing()
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1664 {
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1665 global_table();
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1666 printf("\t.ident \"Micro-C compiled\"\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1667 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1668
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1669 static char *
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1670 code_cond(int op,int cond)
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1671 {
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1672 switch(op) {
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1673 case GT: return code_gt(cond);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1674 case UGT: return code_ugt(cond);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1675 case GE: return code_ge(cond);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1676 case UGE: return code_uge(cond);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1677 case LT: return code_ge(!cond);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1678 case ULT: return code_uge(!cond);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1679 case LE: return code_gt(!cond);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1680 case ULE: return code_ugt(!cond);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1681 case EQ: return code_eq(cond);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1682 case NEQ: return code_eq(!cond);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1683 default: return 0;
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1684 }
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1685 }
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1686
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1687 static int
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1688 rexpr_bool(int e1,int reg)
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1689 {
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1690 char *s;
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1691 if (!(s=code_cond(car(e1),1))) return 0;
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1692 g_expr(list3(CMP,cadr(e1),caddr(e1)));
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1693 use_int(reg);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1694 use_data_reg(reg,0);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1695 printf("\tset%s\t%s\n",s,register_name(reg,1));
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1696 printf("\tmovzbl %s,%s\n",register_name(reg,1),register_name(reg,0));
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1697 return 1;
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1698 }
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1699
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1700 void
280
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
1701 rexpr(int e1, int l1, int cond,int t)
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
1702 {
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
1703 g_expr(list3(CMP,cadr(e1),caddr(e1)));
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
1704 printf("\tj%s\t_%d\n",code_cond(car(e1),cond),l1);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1705 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1706
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1707
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
1708 static void
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1709 jcond(int l, char cond)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1710 {
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1711 if (chk) return;
302
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
1712 printf("\tj%s\t_%d\n",cond==LT?code_ge(0):cond?"ne":"e",l);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1713 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1714
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1715 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1716 jmp(int l)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1717 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1718 control=0;
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1719 if (chk) return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1720 printf("\tjmp\t_%d\n",l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1721 /* align? */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1722 /*
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1723 this is not allowed because of ? operator
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1724 regv[creg]=regv[dreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1725 use_register(creg,REG_EAX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1726 use_register(dreg,REG_EBX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1727 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1728 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1729
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1730 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1731 gen_comment(char *s)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1732 {
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1733 if (chk) return;
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1734 printf("## %s",s);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1735 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1736
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1737
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1738 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1739 code_enter(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1740 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1741 printf("\t.align 4\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1742 if (stmode!=STATIC)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1743 printf(".globl %s\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1744 printf("\t.type\t%s,@function\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1745 printf("%s:\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1746 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1747
77
2b8ba655e572 fix arg type
kono
parents: 66
diff changeset
1748
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1749 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1750 code_enter1(int args)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1751 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1752 code_disp_label=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1753 printf("\tlea _%d(%%ebp),%%esp\n",code_disp_label);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1754
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
1755 printf("## args %d disp %d code_disp_offset=%d\n",args,disp,code_disp_offset);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1756 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1757
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1758 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1759 code_leave(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1760 {
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1761 disp &= -SIZE_OF_INT;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1762 printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1763 printf("_%d:\n",labelno);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1764 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1765 local_table();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1766 labelno++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1767 free_all_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1768 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1769
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1770 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1771 enter(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1772 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1773 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1774 if (stmode!=STATIC)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1775 printf(".globl %s\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1776 printf("%s:\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1777 printf("\t.type\t%s,@function\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1778 printf("\tpushl %%ebp\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1779 printf("\tmovl %%esp,%%ebp\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1780 printf("\tpushl %%ebx\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1781 printf("\tpushl %%esi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1782 printf("\tpushl %%edi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1783 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1784
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1785 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1786 enter1()
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1787 {
182
e1e9ec8c96a7 some fix
kono
parents: 173
diff changeset
1788 text_mode();
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1789 func_disp_label=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1790 printf("\tlea _%d(%%ebp),%%esp\n",func_disp_label);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1791 /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1792 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1793
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1794 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1795 leave(int control, char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1796 {
128
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1797 int sz;
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1798
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1799 disp &= -SIZE_OF_INT;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1800 if (control)
108
69e2e763cce5 object assemble first try.
kono
parents: 107
diff changeset
1801 code_set_return_register(1);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1802 if (retcont) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1803 if (control)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1804 jmp(retlabel);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1805 fwddef(retcont);
128
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1806 if (cadr(fnptr->ty)==FLOAT||cadr(fnptr->ty)==DOUBLE) {
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1807 printf("\tfldl %d(%%ebp)\n",-SIZE_OF_DOUBLE);
128
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1808 } else if (cadr(fnptr->ty)>0&&(
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1809 car(cadr(fnptr->ty))==STRUCT ||
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1810 car(cadr(fnptr->ty))==UNION)) {
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1811 sz = size(cadr(fnptr->ty));
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1812 printf("\tlea %d(%%ebp),%s\n",-sz,register_name(dreg,0));
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
1813 printf("\tmovl %d(%%ebp),%s\n",disp-SIZE_OF_INT,
128
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1814 register_name(creg,0));
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1815 emit_copy(dreg,creg,sz,0,1,1);
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1816 } else if (cadr(fnptr->ty)!=VOID) {
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1817 use_register(creg,REG_EAX,0);
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1818 printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0));
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1819 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1820 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1821 fwddef(retlabel);
63
e13486b2c12e stack alignment
kono
parents: 62
diff changeset
1822
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1823 printf("\tlea %d(%%ebp),%%esp\n",disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1824 printf("\tpopl %%edi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1825 printf("\tpopl %%esi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1826 printf("\tpopl %%ebx\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1827 printf("\tleave\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1828 printf("\tret\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1829 printf("\t.set _%d,%d\n",func_disp_label,disp+disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1830 printf("_%d:\n",labelno);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1831 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1832 local_table();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1833 labelno++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1834 free_all_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1835 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1836
187
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1837 int
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1838 code_get_fixed_creg(int reg,int type) {
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1839 if (type==FLOAT||type==DOUBLE) {
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1840 return 0;
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1841 } else if (type==LONGLONG||type==ULONGLONG) {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1842 use_longlong(reg);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1843 return reg;
187
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1844 } else {
236
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
1845 use_int(reg);
187
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1846 return rname[reg];
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1847 }
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1848 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1849
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1850 void
187
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1851 code_set_fixed_creg(int reg,int mode,int type) {
108
69e2e763cce5 object assemble first try.
kono
parents: 107
diff changeset
1852 if (type==FLOAT||type==DOUBLE) {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1853 } else if (type==LONGLONG||type==ULONGLONG) {
187
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1854 } else {
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1855 use_register(creg,reg,mode);
dffcccf8b1cb nested COND
kono
parents: 186
diff changeset
1856 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1857 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1858
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1859 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1860 code_set_return_register(int mode) {
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1861 if (fnptr->ty==DOUBLE||fnptr->ty==FLOAT) {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
1862 } else if (fnptr->ty==LONGLONG||fnptr->ty==ULONGLONG) {
243
c311c26e006a *** empty log message ***
kono
parents: 242
diff changeset
1863 use_longlong0(USE_CREG);
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1864 } else {
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1865 use_register(creg,REG_EAX,mode);
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1866 }
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1867 }
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1868
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1869 void
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1870 gen_gdecl(char *n, int gpc)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1871 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1872 /*
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1873 if (stmode!=STATIC)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1874 printf(".globl %s\n",n);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1875 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1876 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1877
340
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1878 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1879 ascii(char *s)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1880 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1881 printf("\t.string \"");
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1882 while(*s) {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1883 if (*s=='\n')
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1884 printf("%cn",92);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1885 else if (*s<' ')
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1886 printf("%c%03o",92,*s);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1887 else if (*s==34)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1888 printf("%c%c",92,34);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1889 else
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1890 printf("%c",*s);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1891 s++;
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1892 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1893 printf("%c\n",34);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1894 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1895
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1896 extern int
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1897 emit_string_label()
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1898 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1899 int lb;
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1900 printf(".section\t.rodata\n");
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1901 lb=fwdlabel();
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1902 printf("_%d:\n",lb);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1903 output_mode = RODATA_EMIT_MODE;
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1904 return lb;
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1905 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1906
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1907 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1908 align(int t)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1909 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1910 if (t!=CHAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1911 if (data_alignment & 1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1912 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1913 data_alignment = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1914 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1915 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1916
340
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1917 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1918 emit_global(char *name,int t)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1919 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1920 printf(".globl\t%s\n",name);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1921 data_mode(name);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1922 align(t);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1923 printf("%s:\n",name);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1924 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1925
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1926 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1927 emit_space(int sp)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1928 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1929 data_mode(0);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1930 printf("\t.space\t%d\n",sp);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1931 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1932
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1933 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1934 emit_char(int d)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1935 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1936 data_mode(0);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1937 printf("\t.byte %d\n",d);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1938 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1939
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1940 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1941 emit_short(int d)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1942 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1943 data_mode(0);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1944 printf("\t.short %d\n",d);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1945 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1946
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1947 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1948 emit_int(int d)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1949 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1950 data_mode(0);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1951 printf("\t.long %d\n",d);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1952 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1953
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1954 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1955 emit_longlong(int e)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1956 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1957 #if LONGLONG_CODE
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1958 long long ll = lcadr(e);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1959 data_mode(0);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1960 #if (ENDIAN==0)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1961 printf("\t.long\t0x%x,0x%x\n",code_l1(ll),code_l2(ll));
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1962 #else
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1963 printf("\t.long\t0x%x,0x%x\n",code_l2(ll),code_l1(ll));
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1964 #endif
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1965 #endif
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1966 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1967
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1968 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1969 emit_double(int e)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1970 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1971 #if FLOAT_CODE
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1972 double d = dcadr(e);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1973 data_mode(0);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1974 #if (ENDIAN==0)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1975 printf("\t.long\t0x%x,0x%x\n",code_d1(d),code_d2(d));
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1976 #else
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1977 printf("\t.long\t0x%x,0x%x\n",code_d2(d),code_d1(d));
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1978 #endif
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1979 #endif
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1980 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1981
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1982 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1983 emit_float(int e)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1984 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1985 #if FLOAT_CODE
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1986 float f = dcadr(e);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1987 data_mode(0);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1988 printf("\t.long\t0x%x\n",*(int *)&f);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1989 #endif
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1990 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1991
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1992 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1993 emit_address(char *s)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1994 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1995 data_mode(0);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1996 printf("\t.long %s\n",s);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1997 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1998
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
1999 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2000 emit_label(int labelno)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2001 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2002 data_mode(0);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2003 printf("\t.long _%d\n",labelno);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2004 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2005
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2006 extern void
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2007 emit_data_closing(NMTBL *n)
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2008 {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2009 #ifdef DOT_SIZE
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2010 int lb;
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2011 #endif
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2012 if (chk) return;
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2013 if (mode==GDECL) {
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2014 data_mode(0);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2015 #ifdef DOT_SIZE
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2016 lb=fwdlabel();
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2017 printf("_%d:\n",lb);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2018 printf("\t.size\t%s,_%d-%s\n",n->nm,lb,n->nm);
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2019 #endif
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2020 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2021 }
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2022
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2023 #if LONGLONG_CODE
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2024 static long long ll0 = 1LL;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2025
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2026 static int
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2027 code_l1(long long d)
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2028 {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2029 int *i = (int *)&ll0; int *j = (int *)&d;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2030 return (i[1] == 1)?j[1]:j[0];
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2031 }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2032
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2033 static int
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2034 code_l2(long long d)
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2035 {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2036 int *i = (int *)&ll0; int *j = (int *)&d;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2037 return (i[1] == 1)?j[0]:j[1];
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2038 }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2039 #endif
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2040
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2041 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2042 global_table(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2043 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2044 NMTBL *n;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2045 int init;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2046 init=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2047 for(n=ntable;n < &ntable[GSYMS];n++) {
117
2d5a203cc3a6 lvar reuse
kono
parents: 116
diff changeset
2048 if ((n->sc == GVAR||n->sc == STATIC) && n->dsp != -1) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2049 /* n->dsp = -1 means initialized global */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2050 if (init==0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2051 data_mode(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2052 init=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2053 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2054 printf(".comm %s,%d\n",n->nm,size(n->ty));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2055 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2056 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2057 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2058
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2059 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2060 local_table(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2061 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2062 NMTBL *n;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2063 int init;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2064 init=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2065 /* static local variables */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2066 for(n=ntable+GSYMS;n < &ntable[GSYMS+LSYMS];n++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2067 if (n->sc == GVAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2068 if (init==0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2069 data_mode(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2070 init=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2071 }
156
da529eab5618 static initialization
kono
parents: 147
diff changeset
2072 if (n->dsp!= -1) /* -1 means initialized global */
da529eab5618 static initialization
kono
parents: 147
diff changeset
2073 printf(".lcomm %s,%d\n",n->nm,size(n->ty));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2074 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2075 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2076 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2077
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2078 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2079 text_mode(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2080 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2081 if (output_mode!=TEXT_EMIT_MODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2082 printf(".text\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2083 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2084 output_mode = TEXT_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2085 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2086 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2087
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2088 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2089 data_mode(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2090 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2091 if (output_mode!=DATA_EMIT_MODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2092 printf(".data\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2093 output_mode = DATA_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2094 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2095 if (name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2096 printf("\t.type\t%s,@object\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2097 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
2098
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2099 #if FLOAT_CODE
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2100
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2101 /* floating point */
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2102
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2103
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2104 char *
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2105 fstore(int d)
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2106 {
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2107 return use?
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2108 (d?"fstl":"fsts"):
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2109 (d?"fstpl":"fstps")
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2110 ;
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2111 }
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2112
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2113 char *
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2114 fstore_u(int d)
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2115 {
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2116 return d?"fstpl":"fstps";
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2117 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2118
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2119 char *
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2120 fload(int d)
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2121 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2122 return d?"fldl":"flds";
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2123 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2124
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2125
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
2126 void code_dassign_gvar(int e2,int freg,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2127 {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
2128 printf("\t%s %s\n",fstore(d),((NMTBL*)cadr(e2))->nm);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2129 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2130
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
2131 void code_dassign_lvar(int e2,int freg,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2132 {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
2133 printf("\t%s %d(%%ebp)\n",fstore(d),lvar(e2));
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2134 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2135
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2136 void code_dassign_dregister(int e,int d,int freg)
111
7aa449aff3e6 floating point
kono
parents: 109
diff changeset
2137 {
7aa449aff3e6 floating point
kono
parents: 109
diff changeset
2138 error(-1);
7aa449aff3e6 floating point
kono
parents: 109
diff changeset
2139 }
7aa449aff3e6 floating point
kono
parents: 109
diff changeset
2140
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
2141 void code_dassign(int e2,int freg,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2142 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2143 printf("\t%s (%s)\n",fstore(d),register_name(e2,0));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2144 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2145
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2146 static double d0 = 1.0;
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2147
340
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2148 static int
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2149 code_d1(double d)
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2150 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2151 int *i = (int *)&d0; int *j = (int *)&d;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2152 return (i[1] == 0x3ff00000)?j[0]:j[1];
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2153 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2154
340
0150de6a3244 emit_data moved.
kono
parents: 338
diff changeset
2155 static int
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2156 code_d2(double d)
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2157 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2158 int *i = (int *)&d0; int *j = (int *)&d;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2159 return (i[1] == 0x3ff00000)?j[1]:j[0];
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2160 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2161
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2162 void code_dconst(int e2,int freg,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2163 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2164 int lb;
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2165 double value = dcadr(e2);
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2166
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2167 if (value==0.0) {
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2168 printf("\tfldz\n"); return;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2169 }
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2170 if (value==1.0) {
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2171 printf("\tfld1\n"); return;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2172 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2173 printf(" \t.section\t.rodata\n\t.align 8\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2174 lb=fwdlabel();
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2175 printf("_%d:\n",lb);
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2176 printf("\t.long\t0x%x,0x%x\n",code_d1(value),code_d2(value));
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2177 if (output_mode==TEXT_EMIT_MODE) {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2178 printf(".text\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2179 } else {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2180 text_mode();
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2181 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2182 printf("\tfldl _%d\n",lb);
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2183 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2184
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2185 void code_dneg(int freg,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2186 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2187 printf("\tfchs\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2188 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2189
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2190 void code_d2i(int reg)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2191 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2192 use_int(reg);
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2193 printf("\tlea -%d(%%esp),%%esp\n",SIZE_OF_INT*2);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2194 printf("\tfnstcw (%%esp)\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2195 printf("\tmovl (%%esp), %s\n",register_name(creg,0));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2196 printf("\tmovb $12, 1(%%esp)\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2197 printf("\tfldcw (%%esp)\n");
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2198 printf("\tfistpl %d(%%esp)\n",SIZE_OF_INT);
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
2199 printf("\tmovl %s, (%%esp)\n",register_name(creg,0));
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
2200 printf("\tfldcw (%%esp)\n");
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2201 printf("\tpopl %s\n",register_name(creg,0));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2202 printf("\tpopl %s\n",register_name(creg,0));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2203 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2204
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2205 void code_i2d(int reg)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2206 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2207 printf("\tpushl %s\n",register_name(creg,0));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2208 printf("\tfildl (%%esp)\n");
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2209 printf("\tlea %d(%%esp),%%esp\n",SIZE_OF_INT);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2210 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2211
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2212 void code_d2u(int reg)
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
2213 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2214 use_int(reg);
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2215 printf("\tlea -%d(%%esp),%%esp\n",SIZE_OF_INT*3);
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
2216 printf("\tfnstcw (%%esp)\n");
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2217 printf("\tmovl (%%esp), %s\n",register_name(reg,0));
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
2218 printf("\tmovb $12, 1(%%esp)\n");
3789aef7331d minor fix
kono
parents: 84
diff changeset
2219 printf("\tfldcw (%%esp)\n");
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2220 printf("\tmovl %s, (%%esp)\n",register_name(reg,0));
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2221 printf("\tfistpll %d(%%esp)\n",SIZE_OF_INT);
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
2222 printf("\tfldcw (%%esp)\n");
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2223 printf("\tmovl %d(%%esp),%s\n",SIZE_OF_INT,register_name(reg,0));
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2224 printf("\tlea %d(%%esp),%%esp\n",SIZE_OF_INT*3);
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
2225 }
3789aef7331d minor fix
kono
parents: 84
diff changeset
2226
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2227 void code_u2d(int reg)
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
2228 {
86
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
2229 printf("\tpushl %s\n",register_name(creg,0));
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
2230 printf("\tpushl %s\n",register_name(creg,0));
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2231 printf("\tmovl $0, %d(%%esp)\n",SIZE_OF_INT);
86
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
2232 printf("\tfildll (%%esp)\n");
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2233 printf("\tlea %d(%%esp),%%esp\n",SIZE_OF_INT*2);
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
2234 }
3789aef7331d minor fix
kono
parents: 84
diff changeset
2235
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2236 void code_d2f(int reg) { }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2237 void code_f2d(int reg) { }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2238 void code_f2i(int reg) { code_d2i(reg); }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2239 void code_f2u(int reg) { code_d2u(reg); }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2240 void code_i2f(int reg) { code_i2d(reg); }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2241 void code_u2f(int reg) { code_u2d(reg); }
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2242
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
2243 void code_drgvar(int e2,int d,int freg)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2244 {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
2245 printf("\t%s %s\n",fload(d),((NMTBL*)cadr(e2))->nm);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2246 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2247
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2248
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
2249 void code_drlvar(int e2,int d,int freg)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2250 {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
2251 printf("\t%s %d(%%ebp)\n",fload(d),lvar(e2));
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2252 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2253
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2254 void code_cmp_drgvar(int e2,int reg,int d,int label,int cond)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2255 {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
2256 printf("\tfcomp %s\n",((NMTBL*)cadr(e2))->nm);
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2257 jcond(label,cond);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2258 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2259
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2260 void code_cmp_drlvar(int e2,int reg,int d,int label,int cond)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2261 {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
2262 printf("\tfcomp %d(%%ebp)\n",lvar(e2));
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2263 jcond(label,cond);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2264 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2265
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
2266 void dtosop(int op,int reg,int e1)
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2267 {
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2268 switch(op) {
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2269 case FADD:
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2270 case DADD: printf("\tfaddp %%st,%%st(1)\n"); break;
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2271 case FSUB:
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
2272 case DSUB: printf("\tfsubp %%st,%%st(1)\n"); break;
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2273 case FDIV:
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
2274 case DDIV: printf("\tfdivp %%st,%%st(1)\n"); break;
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2275 case FMUL:
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2276 case DMUL: printf("\tfmulp %%st,%%st(1)\n"); break;
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2277 case FCMP:
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
2278 case DCMP:
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2279 printf("\tfucompp\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2280 printf("\tfnstsw\t%%ax\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2281 break;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2282 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2283 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2284
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2285 void
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
2286 code_dassop(int op,int reg,int d) {
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2287 /* we have lvalue in creg, applied floating value is in %st(0) */
102
3cf2f8c120b9 *** empty log message ***
kono
parents: 99
diff changeset
2288 emit_dpop(d); /* do nothing for 387 */
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2289 printf("\t%s (%s)\n",fload(d),register_name(creg,0));
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
2290 dtosop(op,reg,0);
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2291 printf("\t%s (%s)\n",fstore(d),register_name(creg,0));
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2292 }
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2293
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2294 void
219
6190d24e178c long long code generation level 4
kono
parents: 213
diff changeset
2295 code_register_dassop(int reg,int op,int d) {
6190d24e178c long long code generation level 4
kono
parents: 213
diff changeset
2296 error(-1);
6190d24e178c long long code generation level 4
kono
parents: 213
diff changeset
2297 }
6190d24e178c long long code generation level 4
kono
parents: 213
diff changeset
2298
6190d24e178c long long code generation level 4
kono
parents: 213
diff changeset
2299 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
2300 code_dpreinc(int e1,int e2,int d,int freg) {
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2301 g_expr(e2);
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2302 printf("\t%s (%s)\n",fload(d),register_name(creg,0));
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2303 printf("\tfld1\n");
87
1738f313f98b floating point (at most) done.
kono
parents: 86
diff changeset
2304 if (caddr(e1)>0)
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2305 printf("\tfaddp %%st,%%st(1)\n");
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2306 else
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2307 printf("\tfsubrp %%st,%%st(1)\n");
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2308 printf("\t%s (%s)\n",fstore(d),register_name(creg,0));
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2309 }
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2310
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2311 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
2312 code_dpostinc(int e1,int e2,int d,int freg) {
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2313 g_expr(e2);
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2314 printf("\t%s (%s)\n",fload(d),register_name(creg,0));
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2315 if (use)
86
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
2316 printf("\t%s (%s)\n",fload(d),register_name(creg,0));
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2317 printf("\tfld1\n");
87
1738f313f98b floating point (at most) done.
kono
parents: 86
diff changeset
2318 if (caddr(e1)>0)
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2319 printf("\tfaddp %%st,%%st(1)\n");
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2320 else
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2321 printf("\tfsubrp %%st,%%st(1)\n");
87
1738f313f98b floating point (at most) done.
kono
parents: 86
diff changeset
2322 printf("\t%s (%s)\n",(use?fstore_u(d):fstore(d)),register_name(creg,0));
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2323 }
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
2324
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2325 #define COND_BRANCH 1
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2326 #define COND_VALUE 2
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2327
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2328 int
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2329 drexpr0(int e1, int e2,int l1, int op,int cond,int reg,int mode)
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2330 {
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2331 char *s;
236
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2332 if (!cond) {
230
d60c6c31f63a *** empty log message ***
kono
parents: 225
diff changeset
2333 switch(op) {
236
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2334 case FOP+GT:
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2335 return drexpr0(e2,e1,l1,FOP+GE,1,reg,mode);
236
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2336 case FOP+GE:
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2337 return drexpr0(e2,e1,l1,FOP+GT,1,reg,mode);
236
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2338 case FOP+EQ:
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2339 op=FOP+NEQ; break;
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2340 case FOP+NEQ:
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2341 op=FOP+EQ; break;
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2342 case DOP+GT:
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2343 return drexpr0(e2,e1,l1,DOP+GE,1,reg,mode);
236
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2344 case DOP+GE:
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2345 return drexpr0(e2,e1,l1,DOP+GT,1,reg,mode);
236
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2346 case DOP+EQ:
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2347 op=DOP+NEQ; break;
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2348 case DOP+NEQ:
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2349 op=DOP+EQ; break;
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2350 default: return 0;
230
d60c6c31f63a *** empty log message ***
kono
parents: 225
diff changeset
2351 }
d60c6c31f63a *** empty log message ***
kono
parents: 225
diff changeset
2352 }
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2353 s = "e";
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2354 switch(op) {
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2355 case DOP+GE:
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2356 case FOP+GE:
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2357 g_expr(list3(DCMP,e1,e2));
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2358 printf("\ttestb\t$5,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2359 break;
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2360 case DOP+GT:
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2361 case FOP+GT:
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2362 g_expr(list3(DCMP,e1,e2));
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2363 printf("\ttestb\t$69,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2364 break;
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2365 case DOP+EQ:
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2366 case FOP+EQ:
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2367 g_expr(list3(DCMP,e1,e2));
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2368 printf("\tandb\t$69,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2369 printf("\txorb\t$64,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2370 break;
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2371 case DOP+NEQ:
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2372 case FOP+NEQ:
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2373 g_expr(list3(DCMP,e1,e2));
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2374 printf("\tandb\t$69,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2375 printf("\txorb\t$64,%%ah\n");
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2376 s = "ne";
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2377 break;
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2378 default:
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2379 return 0;
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2380 }
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2381 if (mode==COND_BRANCH) {
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2382 printf("\tj%s\t_%d\n",s,l1);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2383 } else {
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2384 use_int(reg); use_data_reg(reg,0);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2385 printf("\tset%s\t%s\n",s,register_name(reg,1));
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2386 printf("\tmovzbl\t%s,%s\n",
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2387 register_name(reg,1),register_name(reg,0));
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2388 }
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2389 return 1;
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2390 }
1a723130a2c7 condtional
kono
parents: 83
diff changeset
2391
291
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2392 void
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2393 drexpr(int e1, int e2,int l1, int op,int cond)
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2394 {
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2395 drexpr0(e1, e2,l1, op,cond,USE_CREG,COND_BRANCH);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2396 }
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2397
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2398 static int
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2399 drexpr_bool(int e1, int reg)
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2400 {
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2401 return drexpr0(cadr(e1), caddr(e1),0, car(e1),1,reg,COND_VALUE);
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2402 }
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2403
7b6df595b205 ia32 code_bool.
kono
parents: 289
diff changeset
2404
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2405 void
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2406 code_dregister(int e2,int freg,int d)
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2407 {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2408 error(-1);
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2409 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2410
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2411 void
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2412 code_cmp_dregister(int e2,int d,int label,int cond)
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2413 {
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
2414 if (e2!=USE_CREG)
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
2415 error(-1);
236
7353a818858c ia32 code creg fix done
kono
parents: 235
diff changeset
2416 printf("\tfldz\n");
235
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
2417 printf("\tfucompp\n");
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
2418 printf("\tfnstsw\t%%ax\n");
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
2419 printf("\tandb\t$69,%%ah\n");
c575422d8b6e *** empty log message ***
kono
parents: 230
diff changeset
2420 printf("\txorb\t$64,%%ah\n");
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2421 jcond(label,cond);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2422 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2423
97
6d42fcac07af *** empty log message ***
kono
parents: 96
diff changeset
2424 int pop_fregister()
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2425 {
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2426 if (freg_sp<0) { error(-1); return -1;}
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2427 printf("# fpop: %d\n",freg_sp-1);
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2428 return freg_stack[--freg_sp];
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2429 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2430
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2431 int
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2432 emit_dpop(int d)
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2433 {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2434 int xreg;
97
6d42fcac07af *** empty log message ***
kono
parents: 96
diff changeset
2435 if ((xreg=pop_fregister())==-1) {
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2436 } else if (xreg<= -REG_LVAR_OFFSET) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
2437 code_drlvar(REG_LVAR_OFFSET+xreg,1,freg);
117
2d5a203cc3a6 lvar reuse
kono
parents: 116
diff changeset
2438 free_lvar(xreg+REG_LVAR_OFFSET);
326
e5d40f8c4cce bit-field continue.
kono
parents: 320
diff changeset
2439 /* pushed order is reversed. We don't need this for commutable
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2440 operator, but it is ok to do this. */
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2441 printf("\tfxch\t%%st(1)\n");
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2442 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2443 return xreg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2444 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2445
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2446
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
2447 void emit_dpop_free(int e1,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2448 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2449 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
2450
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
2451 void emit_dpush(int type)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2452 {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
2453 if (freg_sp>=MAX_FPU_STACK) code_save_fstacks();
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2454 if (freg_sp>MAX_MAX) error(-1);
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
2455 freg_stack[freg_sp++]=-1;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2456 printf("# fpush:%d\n",freg_sp);
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2457 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2458
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2459 #endif
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2460
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2461 void
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2462 code_save_stacks()
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2463 {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2464 /* temporal registers or stacks in fpu are saved in local variable */
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2465 int xreg,sp,screg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2466 sp=reg_sp;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2467 while(sp-->0) {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2468 if ((xreg=reg_stack[sp])>=0) {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2469 screg=creg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2470 if(creg!=xreg) {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2471 if (xreg!=dreg) free_register(xreg);
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2472 creg = xreg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2473 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2474 code_assign_lvar(
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2475 (reg_stack[sp]=new_lvar(SIZE_OF_INT)),creg,0);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2476 reg_stack[sp]= reg_stack[sp]-REG_LVAR_OFFSET;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2477 regv[xreg]=0;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2478 creg=screg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2479 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2480 }
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
2481 }
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
2482
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2483 #if FLOAT_CODE
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
2484 void
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
2485 code_save_fstacks()
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
2486 {
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
2487 int xreg,sp,uses;
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
2488 uses = use; use = 0;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2489 sp=freg_sp;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2490 while(sp-->0) {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2491 if ((xreg=freg_stack[sp])==-1) {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2492 code_dassign_lvar(
245
8a72b0afccfc *** empty log message ***
kono
parents: 244
diff changeset
2493 (freg_stack[sp]=new_lvar(SIZE_OF_DOUBLE)),freg,1);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2494 freg_stack[sp]= freg_stack[sp]-REG_LVAR_OFFSET;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2495 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2496 }
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
2497 use = uses;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
2498 }
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2499 #endif
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2500
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2501
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2502
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2503 #if LONGLONG_CODE
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2504
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2505
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2506 /* 64bit int part */
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2507
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2508 static void
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2509 pcond(char *s,int l1)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2510 {
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2511 printf("\tj%s\t_%d\n",s,l1);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2512 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2513
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2514 void
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2515 lrexpr(int e1, int e2,int l1, int op,int cond)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2516 {
280
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2517 int l2;
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2518 code_save_stacks();
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2519 g_expr(e1);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2520 emit_lpush();
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2521 g_expr(e2);
280
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2522 // we are sure %ecx,%ebx is free
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2523 printf("\tpopl %%ecx\n"); // LSW
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2524 printf("\tpopl %%ebx\n"); // MSW
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2525 printf("\tsubl %%edx,%%ebx\n");
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2526 l2 = fwdlabel();
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2527 // cond==0 jump on false condtion ( if(x) => rexpr(.. cond=0 ...) )
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2528 switch(op) {
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2529 case LOP+GT:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2530 case LOP+GE:
280
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2531 pcond(code_gt(1),cond?l1:l2);
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2532 pcond(code_eq(0),cond?l2:l1);
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2533 break;
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2534 case LOP+UGT:
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2535 case LOP+UGE:
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2536 pcond(code_ugt(1),cond?l1:l2);
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2537 pcond(code_eq(0), cond?l2:l1);
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2538 break;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2539 case LOP+EQ:
280
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2540 pcond(code_eq(0),(cond?l2:l1));
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2541 pcond(code_eq(cond),l1);
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2542 break;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2543 case LOP+NEQ:
280
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2544 pcond(code_eq(0),(cond?l1:l2));
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2545 pcond(code_eq(!cond),l1);
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2546 break;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2547 default:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2548 error(-1);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2549 }
280
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2550 printf("\tsubl %%eax,%%ecx\n");
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2551 switch(op) {
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2552 case LOP+GT: pcond(code_gt(cond), l1); break;
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2553 case LOP+GE: pcond(code_ge(cond), l1); break;
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2554 case LOP+UGT: pcond(code_ugt(cond), l1); break;
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2555 case LOP+UGE: pcond(code_uge(cond), l1); break;
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2556 }
affb054fe920 lrexpr fix. rexpr in MIPS fix.
kono
parents: 263
diff changeset
2557 fwddef(l2);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2558 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2559
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2560 int emit_lpop()
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2561 {
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2562 return 0;
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2563 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2564
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2565 void code_lregister(int e2,int reg)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2566 {
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2567 use_longlong(reg);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2568 if (reg!=REG_L) {
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2569 printf("\tmovl %%esi,%s\n",l_eax(reg));
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2570 printf("\tmovl %%edi,%s\n",l_edx(reg));
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2571 }
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2572 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2573
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2574 void code_cmp_lregister(int reg,int label,int cond)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2575 {
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2576 char *crn;
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2577 use_int(reg);
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2578 crn = register_name(reg,0);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2579 printf("\tmovl %%esi,%s\n",crn);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2580 printf("\torl %%edi,%s\n",crn);
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2581 printf("\ttestl %s,%s\n",crn,crn);
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2582 jcond(label,cond);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2583 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2584
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2585 void code_cmp_lrgvar(int e1,int e2,int label,int cond)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2586 {
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2587 char *n,*crn;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2588 n = ((NMTBL*)cadr(e1))->nm;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2589 use_int(e2);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2590 crn = register_name(e2,0);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2591 printf("\tmovl %s,%s\n",n,crn);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2592 printf("\torl %s+4,%s\n",n,crn);
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2593 printf("\ttestl %s,%s\n",crn,crn);
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2594 jcond(label,cond);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2595 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2596
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2597 void code_cmp_lrlvar(int e1,int e2,int label,int cond)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2598 {
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2599 char *crn;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2600 use_int(e2);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2601 crn = register_name(e2,0);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2602 printf("\tmovl %d(%%ebp),%s\n",lvar(e1),crn);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2603 printf("\torl %d(%%ebp),%s\n",lvar(e1)+4,crn);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2604 printf("\ttestl %s,%s\n",crn,crn);
287
a0779a414855 *** empty log message ***
kono
parents: 286
diff changeset
2605 jcond(label,cond);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2606 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2607
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2608 void code_lassign(int e1,int e2)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2609 {
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2610 char *rn;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2611 // e1 = e2
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2612 use_longlong(e2);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2613 rn = register_name(e1,0);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2614 printf("\tmovl %s,(%s)\n",l_eax(e2),rn);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2615 printf("\tmovl %s,4(%s)\n",l_edx(e2),rn);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2616 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2617
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2618 void code_lassign_gvar(int e1,int e2)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2619 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2620 char *n;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2621 n = ((NMTBL*)cadr(e1))->nm;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2622 use_longlong(e2);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2623 printf("\tmovl %s,%s\n",l_eax(e2),n);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2624 printf("\tmovl %s,%s+4\n",l_edx(e2),n);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2625 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2626
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2627 void code_lassign_lvar(int e1,int e2)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2628 {
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2629 use_longlong(e2);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2630 printf("\tmovl %s,%d(%%ebp)\n",l_eax(e2),lvar(e1));
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2631 printf("\tmovl %s,%d(%%ebp)\n",l_edx(e2),lvar(e1)+4);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2632 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2633
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2634 void code_lassign_lregister(int e2,int reg)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2635 {
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2636 // e2 = reg
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2637 use_longlong(reg);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2638 if (e2!=reg) {
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2639 printf("\tmovl %s,%s\n",l_eax(reg),l_eax(e2));
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2640 printf("\tmovl %s,%s\n",l_edx(reg),l_edx(e2));
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2641 }
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2642 }
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2643
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2644 void
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2645 code_lconst(int e1,int creg)
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2646 {
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2647 use_longlong(creg);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2648 printf("\tmovl $%d,%s\n",code_l1(lcadr(e1)),l_eax(creg));
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2649 printf("\tmovl $%d,%s\n",code_l2(lcadr(e1)),l_edx(creg));
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2650 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2651
212
32f54ab63b35 *** empty log message ***
kono
parents: 205
diff changeset
2652 void code_lneg(int e1)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2653 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2654 use_longlong(e1);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2655 printf("\tnegl %s\n",l_eax(e1));
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2656 printf("\tadcl $0,%s\n",l_edx(e1));
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2657 printf("\tnegl %s\n",l_edx(e1));
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2658 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2659
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2660 void code_lrgvar(int e1,int e2)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2661 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2662 char *n;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2663 n = ((NMTBL*)cadr(e1))->nm;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2664 use_longlong(e2);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2665 printf("\tmovl %s,%s\n",n,l_eax(e2));
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2666 printf("\tmovl %s+4,%s\n",n,l_edx(e2));
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2667 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2668
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2669 void code_lrlvar(int e1,int e2)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2670 {
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2671 use_longlong(e2);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2672 printf("\tmovl %d(%%ebp),%s\n",lvar(e1),l_eax(e2));
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2673 printf("\tmovl %d(%%ebp),%s\n",lvar(e1)+4,l_edx(e2));
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2674 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2675
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2676 #define check_lreg(reg) if (reg==REG_L) code_lassign_lregister(reg,REG_LCREG)
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2677
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2678 void
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2679 ltosop(int op,int reg,int e2)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2680 {
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2681 char *opl,*oph,*call;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2682 int lb;
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2683
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2684 // e2 (operand) is on the top of the stack
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2685 use_longlong(reg);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2686 opl = 0; call=0;
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
2687 stack_depth -= SIZE_OF_INT * 2;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2688
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2689 switch(op) {
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2690 case LLSHIFT:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2691 case LULSHIFT:
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2692 printf("\tmovl %%ecx,4(%%esp)\n");
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2693 printf("\tpopl %%ecx\n");
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2694 printf("\tshldl %%eax,%%edx\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2695 printf("\tsall %%cl,%%eax\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2696 printf("\ttestb $32,%%cl\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2697 printf("\tje\t_%d\n",(lb=fwdlabel()));
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2698 printf("\tmovl %%eax,%%edx\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2699 printf("\txorl %%eax,%%eax\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2700 fwddef(lb);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2701 printf("\tpopl %%ecx\n");
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2702 check_lreg(reg);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2703 return;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2704 case LRSHIFT:
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2705 printf("\tmovl %%ecx,4(%%esp)\n");
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2706 printf("\tpopl %%ecx\n");
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2707 printf("\tshrdl %%edx,%%eax\n");
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2708 printf("\tsarl %%cl,%%eax\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2709 printf("\ttestb $32,%%cl\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2710 printf("\tje\t_%d\n",(lb=fwdlabel()));
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2711 printf("\tmovl %%edx,%%eax\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2712 printf("\tsarl $31,%%edx\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2713 fwddef(lb);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2714 printf("\tpopl %%ecx\n");
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2715 check_lreg(reg);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2716 return;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2717 case LURSHIFT:
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2718 printf("\tmovl %%ecx,4(%%esp)\n");
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2719 printf("\tpopl %%ecx\n");
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2720 printf("\tshrdl %%edx,%%eax\n");
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2721 printf("\tshrl %%cl,%%eax\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2722 printf("\ttestb $32,%%cl\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2723 printf("\tje\t_%d\n",(lb=fwdlabel()));
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2724 printf("\tmovl %%edx,%%eax\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2725 printf("\txorl %%edx,%%edx\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2726 fwddef(lb);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2727 printf("\tpopl %%ecx\n");
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2728 check_lreg(reg);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2729 return;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2730 }
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2731 switch(op) {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2732 case LADD: opl="addl";oph="adcl"; break;
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2733 case LSUB: opl="subl";oph="sbbl"; break;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2734 case LBAND: opl=oph="andl"; break;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2735 case LEOR: opl=oph="xorl"; break;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2736 case LBOR: opl=oph="orl"; break;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2737 case LMUL:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2738 case LUMUL:
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2739 printf("\tpushl %%edx\n");
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2740 printf("\tpushl %%eax\n");
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2741 printf("\tpushl %%ecx\n");
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2742 // 0 saved ecx
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2743 // 4 c_l
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2744 // 8 c_h
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2745 // 12 o_l
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2746 // 16 o_h
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2747 printf("\tmull 12(%%esp)\n"); // c_l*o_l -> %edx,%eax
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2748 printf("\tmovl 4(%%esp),%%ecx\n"); // c_l->%ecx
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2749 printf("\timull 16(%%esp),%%ecx\n"); // c_l*o_h->%ecx
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2750 printf("\taddl %%ecx,%%edx\n"); // %edx+%ecx->%edx
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2751 printf("\tmovl 8(%%esp),%%ecx\n"); // c_h->%ecx
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2752 printf("\timull 12(%%esp),%%ecx\n"); // c_h*o_l->%ecx
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2753 printf("\taddl %%ecx,%%edx\n"); // %edx+%ecx->%edx
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2754 printf("\tpopl %%ecx\n");
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2755 // printf("\taddl $8,%%esp\n");
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2756 printf("\tlea 16(%%esp),%%esp\n");
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2757 return;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2758 case LDIV: call="__divdi3"; break;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2759 case LUDIV: call="__udivdi3"; break;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2760 case LMOD: call="__moddi3"; break;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2761 case LUMOD: call="__umoddi3"; break;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2762 default: error(-1);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2763 }
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2764 if (opl) {
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2765 printf("\t%s (%%esp),%%eax\n\t%s 4(%%esp),%%edx\n",opl,oph);
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2766 printf("\tlea 8(%%esp),%%esp\n");
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2767 check_lreg(reg);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2768 } else if (call) {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2769 printf("\tpushl %%edx\n");
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2770 printf("\tpushl %%eax\n");
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2771 printf("\tcall %s\n",call);
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2772 // printf("\taddl $8,%%esp\n");
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2773 printf("\tlea 16(%%esp),%%esp\n");
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2774 check_lreg(reg);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2775 } else {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2776 error(-1);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2777 }
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2778 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2779
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2780 int code_lconst_op_p(int op,int e) {
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2781 long long l;
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2782 if (car(e)==CONST) l = cadr(e);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2783 else if (car(e)==LCONST) l = lcadr(e);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2784 else return 0;
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2785
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2786 switch(op) {
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2787 case LLSHIFT:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2788 case LULSHIFT:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2789 case LRSHIFT:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2790 case LURSHIFT:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2791 return (0<=l&&l<=32);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2792 case LADD:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2793 case LSUB:
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2794 case LBAND:
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2795 case LEOR:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2796 case LBOR:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2797 return 1;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2798 default:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2799 return 0;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2800 }
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2801 }
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2802
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2803 void loprtc(int op,int reg,int e) {
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2804 char *opl,*oph;
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2805 int vl;
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2806 int vh;
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2807 long long l;
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2808
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2809 if (car(e)==CONST) l = cadr(e);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2810 else if (car(e)==LCONST) l = lcadr(e);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2811 else error(-1);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2812
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2813 vl = code_l1(l);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2814 vh = code_l2(l);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2815
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2816 use_longlong(reg);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2817 opl = 0;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2818
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2819 switch(op) {
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2820 case LLSHIFT:
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2821 case LULSHIFT:
286
179e22f166ef register assop fix
kono
parents: 280
diff changeset
2822 printf("\tshldl $%d,%s,%s\n",vl,l_eax(reg),l_edx(reg));
179e22f166ef register assop fix
kono
parents: 280
diff changeset
2823 printf("\tsall $%d,%s\n",vl,l_eax(reg));
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2824 return;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2825 case LRSHIFT:
286
179e22f166ef register assop fix
kono
parents: 280
diff changeset
2826 printf("\tshrdl $%d,%s,%s\n",vl,l_edx(reg),l_eax(reg));
179e22f166ef register assop fix
kono
parents: 280
diff changeset
2827 printf("\tsarl $%d,%s\n",vl,l_edx(reg));
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2828 return;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2829 case LURSHIFT:
286
179e22f166ef register assop fix
kono
parents: 280
diff changeset
2830 printf("\tshrdl $%d,%s,%s\n",vl,l_edx(reg),l_eax(reg));
179e22f166ef register assop fix
kono
parents: 280
diff changeset
2831 printf("\tshrl $%d,%s\n",vl,l_edx(reg));
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2832 return;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2833 }
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2834 switch(op) {
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2835 case LADD: opl="addl";oph="adcl"; break;
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2836 case LSUB: opl="subl";oph="sbbl"; break;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2837 case LEOR: opl=oph="xorl"; break;
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2838 case LBOR: opl=oph="orl"; break;
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
2839 case LBAND: opl=oph="andl"; break;
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2840 default: error(-1);
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2841 }
286
179e22f166ef register assop fix
kono
parents: 280
diff changeset
2842 printf("\t%s $%d,%s\n\t%s $%d,%s\n",opl,vl,l_eax(reg),oph,vh,l_edx(reg));
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2843 }
213
kono
parents: 212
diff changeset
2844
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2845 void emit_lpop_free(int e1)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2846 {
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2847 // printf("\taddl $8,%%esp\n");
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2848 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2849
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2850 void emit_lpush()
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2851 {
313
f73b93de216a alloca done for ia32, powerpc, mips
kono
parents: 309
diff changeset
2852 stack_depth += SIZE_OF_INT * 2;
241
96b5ee862a41 *** empty log message ***
kono
parents: 240
diff changeset
2853 printf("\tpushl %%edx\n\tpushl %%eax\n");
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2854 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2855
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2856 void code_i2ll(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2857 {
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2858 int reg0 = USE_CREG;
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2859 use_register(creg,REG_EAX,1);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2860 regv[creg]=0;
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2861 use_longlong(reg0);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2862 printf("\tcltd\n");
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2863 check_lreg(reg);
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2864 lreg = creg = reg0;
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2865 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2866
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2867 void code_i2ull(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2868 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2869 code_i2ll(reg);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2870 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2871
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2872 void code_u2ll(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2873 {
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2874 int reg0 = USE_CREG;
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2875 use_register(creg,REG_EAX,1);
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2876 regv[creg]=0;
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2877 use_longlong(reg0);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2878 printf("\txorl %%edx,%%edx\n");
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2879 check_lreg(reg);
240
b59364f5b030 *** empty log message ***
kono
parents: 239
diff changeset
2880 lreg = creg = reg0;
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2881 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2882
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2883 void code_u2ull(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2884 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2885 code_u2ll(reg);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2886 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2887
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2888 void code_ll2i(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2889 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2890 use_int(reg);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2891 if (virtual(REG_EAX)!=reg)
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2892 printf("\tmovl %%eax,%s\n",register_name(creg,0));
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2893 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2894
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2895 void code_ll2u(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2896 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2897 code_ll2i(reg);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2898 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2899
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2900 void code_ull2i(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2901 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2902 code_ll2i(reg);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2903 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2904
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2905 void code_ull2u(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2906 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2907 code_ll2i(reg);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2908 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2909
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2910 #if FLOAT_CODE
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2911 void code_d2ll(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2912 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2913 use_longlong(reg);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2914 printf("\tsubl $40,%%esp\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2915 printf("\tfnstcw 2(%%esp)\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2916 printf("\tmovw 2(%%esp),%%ax\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2917 printf("\torw $3072,%%ax\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2918 printf("\tmovw %%ax,0(%%esp)\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2919 printf("\tfldcw 0(%%esp)\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2920 printf("\tfistpll 12(%%esp)\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2921 printf("\tfldcw 2(%%esp)\n");
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2922 printf("\tmovl 12(%%esp),%%eax\n");
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2923 printf("\tmovl 16(%%esp),%%edx\n");
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2924 printf("\taddl $40,%%esp\n");
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2925 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2926
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2927 void code_d2ull(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2928 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2929 use_longlong(reg);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2930 printf("\tsubl $16,%%esp\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2931 printf("\tfstpl (%%esp)\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2932 printf("\tcall __fixunsdfdi\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2933 printf("\taddl $16,%%esp\n");
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2934 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2935
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2936 void code_f2ll(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2937 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2938 code_d2ll(reg);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2939 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2940
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2941 void code_f2ull(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2942 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2943 use_longlong(reg);
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2944 printf("\tsubl $16,%%esp\n");
242
c68f618b71f9 ia32 long long done. some error remains.
kono
parents: 241
diff changeset
2945 printf("\tfstps (%%esp)\n");
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2946 printf("\tcall __fixunssfdi\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2947 printf("\taddl $16,%%esp\n");
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2948 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2949
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2950 void code_ll2d(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2951 {
237
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2952 printf("\tsubl $8,%%esp\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2953 printf("\tmovl %%eax,(%%esp)\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2954 printf("\tmovl %%edx,4(%%esp)\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2955 printf("\tfildll (%%esp)\n");
1933266f1efa long long ia32 (imcomplete)
kono
parents: 236
diff changeset
2956 printf("\taddl $8,%%esp\n");
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2957 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2958
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2959 void code_ll2f(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2960 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2961 code_ll2d(reg);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2962 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2963
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2964 void code_ull2d(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2965 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2966 code_ll2d(reg);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2967 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2968
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2969 void code_ull2f(int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2970 {
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2971 code_ll2d(reg);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2972 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2973
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2974 #endif
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2975
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2976
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2977 void code_lpreinc(int e1,int e2,int reg)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2978 {
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2979 int dir = caddr(e1);
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2980 int creg0;
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2981 char *crn;
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2982 if (car(e2)==LREGISTER) {
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2983 use_longlong(reg);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2984 printf("\taddl $%d,%%esi\n",dir);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2985 printf("\tadcl $%d,%%edi\n",dir>0?0:-1);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2986 if (reg!=REG_L) {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2987 code_lregister(REG_L,reg);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2988 }
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2989 return;
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2990 }
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2991 g_expr(e2);
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2992 crn = register_name(creg0=creg,0);
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2993 printf("\taddl $%d,(%s)\n",dir,crn);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2994 printf("\tadcl $%d,4(%s)\n",dir>0?0:-1,crn);
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
2995 use_longlong(reg);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
2996 lload(creg0,0,reg);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2997 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2998
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
2999 void code_lpostinc(int e1,int e2,int reg)
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
3000 {
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3001 int dir = caddr(e1);
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3002 int creg0;
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3003 char *crn;
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3004 if (car(e2)==LREGISTER) {
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3005 use_longlong(reg);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
3006 if (reg!=REG_L) {
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
3007 code_lregister(REG_L,reg);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
3008 }
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
3009 printf("\taddl $%d,%%esi\n",dir);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
3010 printf("\tadcl $%d,%%edi\n",dir>0?0:-1);
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3011 return;
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3012 }
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3013 g_expr(e2);
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3014 crn = register_name(creg0=creg,0);
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3015 printf("\taddl $%d,(%s)\n",dir,crn);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
3016 printf("\tadcl $%d,4(%s)\n",dir>0?0:-1,crn);
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3017 use_longlong(reg);
239
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
3018 lload(creg0,0,reg);
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
3019 printf("\taddl $%d,%s\n",-dir,l_eax(reg));
1849e0079f08 ia32 long long continue
kono
parents: 238
diff changeset
3020 printf("\tadcl $%d,%s\n",-dir>0?0:-1,l_edx(reg));
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
3021 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
3022
225
8675ea3d2c7f *** empty log message ***
kono
parents: 224
diff changeset
3023 void code_lassop(int op,int reg)
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
3024 {
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3025 error(-1);
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
3026 }
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
3027
219
6190d24e178c long long code generation level 4
kono
parents: 213
diff changeset
3028 void
6190d24e178c long long code generation level 4
kono
parents: 213
diff changeset
3029 code_register_lassop(int reg,int op) {
238
d64e9a6a66bd ia32 long long code written.
kono
parents: 237
diff changeset
3030 error(-1);
219
6190d24e178c long long code generation level 4
kono
parents: 213
diff changeset
3031 }
6190d24e178c long long code generation level 4
kono
parents: 213
diff changeset
3032
195
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
3033
c193120ee2a6 *** empty log message ***
kono
parents: 190
diff changeset
3034 #endif
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
3035
301
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3036
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3037
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3038
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3039
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3040 #if CASE_CODE
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3041
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3042 int
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3043 code_table_jump_p() { return 1; }
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3044
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3045 void
302
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3046 code_table_jump(int l,int csvalue,int delta,int max,int min,int dlabel)
301
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3047 {
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3048 char *crn;
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3049 use_register(creg,csvalue,0);
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3050 crn = register_name(creg,0);
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3051 printf("\tsubl\t$%d,%s\n",min,crn);
302
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3052 printf("\tcmpl\t$%d,%s\n",max-min,crn);
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3053 printf("\tja\t_%d\n",dlabel);
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3054 if (delta==1) {
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3055 printf("\tjmp\t*_%d(,%s,4)\n",l,crn);
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3056 return;
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3057 }
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3058 use_register(creg,REG_EAX,1);
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3059 edx_setup(-1);
301
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3060 switch(delta) {
302
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3061 case 2:
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3062 printf("\tmovl\t$1,%%edx\n");
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3063 printf("\tandl\t%%eax,%%edx\n");
302
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3064 printf("\tjne\t_%d\n",dlabel);
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3065 printf("\tjmp\t*_%d(,%%eax,2)\n",l); break;
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3066 case 4:
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3067 printf("\tmovl\t$3,%%edx\n");
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3068 printf("\tandl\t%%eax,%%edx\n");
302
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3069 printf("\tjne\t_%d\n",dlabel);
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3070 printf("\tjmp\t*_%d(%%eax)\n",l); break;
301
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3071 default:
302
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3072 printf("\tmovl $%d,%%ecx\n",delta);
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3073 printf("\txor %%edx,%%edx\n\tdivl %%ecx\n");
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3074 printf("\tandl\t%%edx,%%edx\n");
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3075 printf("\tjne\t_%d\n",dlabel);
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3076 printf("\tjmp\t*_%d(,%%eax,4)\n",l); break;
301
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3077 }
302
bea7ab2fb218 switch table jump finished.
kono
parents: 301
diff changeset
3078 edx_cleanup();
301
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3079 }
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3080
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3081 void
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3082 code_table_open(int l)
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3083 {
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3084 output_mode=DATA_EMIT_MODE;
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3085 printf(" \t.section\t.rodata\n\t.align 4\n");
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3086 fwddef(l);
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3087 }
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3088
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3089 void
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3090 code_table_value(int label,int table_top)
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3091 {
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3092 printf("\t.long _%d\n",label);
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3093 }
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3094
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3095 void
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3096 code_table_close()
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3097 {
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3098 text_mode();
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3099 }
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3100
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3101 #endif
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3102
60dba3ef1f69 ia32, mips case. incomplete.
kono
parents: 292
diff changeset
3103
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3104 #if ASM_CODE
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3105
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3106 /*
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3107 print an operand
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3108 */
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3109
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3110 static void
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3111 emit_asm_operand(int rstr)
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3112 {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3113 if (car(rstr)==REGISTER) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3114 printf("%s",register_name(cadr(rstr),0));
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3115 } else if (car(rstr)==CONST) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3116 printf("%d",cadr(rstr));
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3117 } else if (car(rstr)==FNAME) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3118 printf("%s",(char*)cadr(rstr));
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3119 } else if (car(rstr)==STRING) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3120 printf("_%d",cadr(rstr));
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3121 } else {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3122 error(-1);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3123 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3124 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3125
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3126 /*
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3127 prepare asm operands
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3128
326
e5d40f8c4cce bit-field continue.
kono
parents: 320
diff changeset
3129 char *constraints string
e5d40f8c4cce bit-field continue.
kono
parents: 320
diff changeset
3130 int operand expr
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3131 int mode (ASM_INPUT,ASM_OUTPUT)
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3132 int replacement list
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3133 int output operands count
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3134 int output operands replacement list
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3135
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3136 retrun replacement list
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3137 list3( operands, next, clobber )
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3138 0 can be shared in input/output
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3139 1 can't be used in input
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3140 */
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3141
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3142 int
328
7ecb023d29b8 macro/codegen reorganization done.
kono
parents: 327
diff changeset
3143 code_asm_operand(char *p,int e1,int mode,int repl,int n,int repl0)
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3144 {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3145 int r;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3146 int c;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3147 int val;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3148 int clobber = 0;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3149
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3150 printf("# constraint %s\n",p);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3151 if (*p=='=') {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3152 // output register
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3153 p++;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3154 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3155 if (*p=='&') {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3156 // earlyclobber
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3157 p++;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3158 clobber = 1;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3159 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3160 c = *p;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3161 if (c=='r') {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3162 if (mode==ASM_INPUT) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3163 for(;repl0;repl0 = cadr(repl0)) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3164 if (car(car(repl0))==REGISTER && caddr(repl0)==0) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3165 r = cadr(car(repl0));
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3166 caddr(repl0) = ASM_USED;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3167 break;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3168 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3169 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3170 r = get_register();
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3171 } else {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3172 r = get_register();
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3173 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3174 repl = list3(list2(REGISTER,r),repl,clobber);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3175 } else if (c=='m') {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3176 repl = list3(list2(0,0),repl,clobber);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3177 } else if (c=='i') {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3178 if (car(e1)==GVAR||car(e1)==FNAME) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3179 e1=list3(FNAME,(int)(((NMTBL *)cadr(e1))->nm),0);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3180 } else if (car(e1)==STRING) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3181 val = emit_string_label();
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3182 ascii((char*)cadr(e1));
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3183 e1=list3(STRING,val,0);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3184 } else if (car(e1)==CONST) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3185 } else error(-1);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3186 repl = list3(e1,repl,clobber);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3187 } else if (digit(c)) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3188 val = 0;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3189 do { val = val*10 + c-'0'; } while (digit(c=*p++));
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3190 if (val>MAX_ASM_REG) error(-1); // too large register
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3191 if (n-val<0) error(-1);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3192 repl = list3(car(nth(n-val-1,repl0)),repl,clobber);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3193 } else error(-1);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3194 return repl;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3195 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3196
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3197 void
328
7ecb023d29b8 macro/codegen reorganization done.
kono
parents: 327
diff changeset
3198 code_free_asm_operand(int repl)
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3199 {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3200 for(;repl;repl=cadr(repl)) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3201 if (car(car(repl))==REGISTER)
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3202 free_register(cadr(car(repl)));
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3203 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3204 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3205
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3206
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3207 extern void
328
7ecb023d29b8 macro/codegen reorganization done.
kono
parents: 327
diff changeset
3208 code_asm(char *asm_str,int repl)
320
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3209 {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3210 int c,i,rstr,val;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3211 char *p;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3212 int reg[MAX_ASM_REG];
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3213
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3214 text_mode();
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3215 c = *asm_str;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3216 if (c!='\t'&&c!=' ') printf("\t");
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3217 for(i=0;repl && i<MAX_ASM_REG;i++) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3218 reg[i] = car(repl);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3219 repl = cadr(repl);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3220 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3221 p = asm_str;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3222 while((c = *p++)) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3223 if (c=='%') {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3224 c = *p++;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3225 if (!c) { break;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3226 } else if (c=='%') {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3227 printf("%%"); continue;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3228 } else if (!digit(c)) {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3229 printf("%%%c",c); continue;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3230 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3231 val = 0;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3232 do { val = val*10 + c-'0'; } while (digit(c=*p++)) ;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3233 p--;
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3234 if (val>MAX_ASM_REG) error(-1); // too large register
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3235 rstr = reg[val];
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3236 emit_asm_operand(rstr);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3237 } else {
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3238 printf("%c",c);
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3239 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3240 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3241 printf("\n");
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3242 }
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3243
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3244 #endif
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3245
183726ccd83d asm minor fix. ia32 table jmp fix.
kono
parents: 315
diff changeset
3246
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3247 #if BIT_FIELD_CODE
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3248
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3249 /* bit field alignment calcuration */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3250
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3251 static void
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3252 set_bitsz(int type,int *psign,int *pbitsz,int *palign,int *pl)
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3253 {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3254 int sign=0,bitsz;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3255 int align,l=0;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3256 switch(cadr(type)) {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3257 case INT: sign=1; bitsz=32; align=4;break;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3258 case UNSIGNED: bitsz=32; align=4;break;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3259 case CHAR: sign=1; bitsz= 8; align=1;break;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3260 case UCHAR: bitsz= 8; align=1;break;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3261 case SHORT: sign=1; bitsz=16; align=2;break;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3262 case USHORT: sign=1; bitsz=16; align=2;break;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3263 case LONGLONG: sign=1; bitsz=64; align=4;l=1; break;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3264 case ULONGLONG: bitsz=64; align=4;l=1; break;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3265 default: error(-1);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3266 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3267 *psign = sign;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3268 *pbitsz = bitsz;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3269 *palign = align;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3270 *pl = l;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3271 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3272
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3273 /*
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3274 bit field alignment calcuration
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3275 this is architecture depenedent
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3276 */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3277
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3278 extern int
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3279 code_bit_field_disp(int type,int *poffset,int *bfd,int *sz)
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3280 {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3281 int sign,bitsz,align;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3282 int i;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3283 int bitpos = *bfd;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3284 int offset = *poffset;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3285 int l;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3286 int bitsize = cadddr(type);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3287 set_bitsz(type,&sign,&bitsz,&align,&l);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3288
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3289 if (bitsize>bitsz) { error(BTERR); bitsize = i; }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3290
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3291 /* bfd means previous bit field bit offset */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3292 if (bitpos) {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3293 /* previous field is bit field and spaces may remain */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3294 /* calc previsous offset */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3295
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3296 i= offset-(bitpos+7)/8;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3297
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3298 for(l = bitpos;l>0;l -= 8,i++) {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3299 if ((i & (align-1))==0 && l+bitsize <= bitsz) {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3300 /* alignment is correct and space remains */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3301 *poffset=offset=i;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3302 i = l+bitsize;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3303 *bfd = i;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3304 *sz = (i+7)/8;
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3305 // printf("# bitpos=%d bitsize=%d bitsz=%d offset=%d\n",l,bitsize,bitsz,*poffset);
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3306 return l;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3307 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3308 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3309 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3310
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3311 /* first bit-field */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3312
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3313 if ((i=(offset & (align-1)))) {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3314 *poffset = (offset += (align-i));
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3315 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3316 bitpos = 0;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3317 *bfd = bitsize;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3318 *sz = (bitsize+7)/8;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3319
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3320 // printf("# bitpos=%d bitsize=%d bitsz=%d offset=%d\n",bitpos,bitsize,bitsz,*poffset);
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3321 return bitpos;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3322 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3323
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3324 /* bit field value */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3325
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3326 /* reg contains container value, result should be in reg */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3327 extern void
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3328 code_bit_field(int type,int bitpos,int reg)
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3329 {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3330 int sign,bitsz,l,align;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3331 int bitsize = cadddr(type);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3332 int i;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3333 set_bitsz(type,&sign,&bitsz,&align,&l);
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3334 // printf("# %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz);
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3335 /* this implementation returns -1 for int i:1; */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3336 if (l==1) {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3337 use_longlong(reg);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3338 /* shift left */
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3339 if ((i=bitsz-bitsize-bitpos))
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3340 loprtc(LLSHIFT,reg,list2(CONST,i));
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3341 /* shift right */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3342 if ((i=bitsz-bitsize))
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3343 loprtc(sign?LRSHIFT:LURSHIFT,reg,list2(CONST,i));
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3344 } else {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3345 use_int(reg);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3346 /* shift left */
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3347 if ((i=32-bitsize-bitpos))
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3348 oprtc(LSHIFT,reg,list2(CONST,i));
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3349 /* shift right */
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3350 if ((i=32-bitsize))
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3351 oprtc(sign?RSHIFT:URSHIFT,reg,list2(CONST,i));
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3352 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3353 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3354
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3355 /* bit field replacement */
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3356
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3357 static void
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3358 make_mask_and_or(int mask,int reg,int lreg)
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3359 {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3360 printf("# mask 0x%08x ~0x%08x\n",mask,~mask);
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3361 printf("\tpushl %s\n",register_name(reg,0));
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3362 /* make and-mask */
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3363 oprtc(BOR,reg,list2(CONST,~mask));
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3364 /* do conjunction */
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3365 if (lreg==-1) {
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3366 printf("\tandl %s,4(%%esp)\n",register_name(reg,0));
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3367 } else if (lreg==-2) {
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3368 printf("\tandl %s,8(%%esp)\n",register_name(reg,0));
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3369 } else {
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3370 printf("\tandl %s,%s\n",register_name(reg,0),register_name(lreg,0));
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3371 }
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3372 /* make or-mask */
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3373 printf("\tpopl %s\n",register_name(reg,0));
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3374 oprtc(BAND,reg,list2(CONST,mask));
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3375 /* do disjunction */
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3376 if (lreg==-1) {
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3377 printf("\torl %s,0(%%esp)\n",register_name(reg,0));
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3378 } else if (lreg==-2) {
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3379 printf("\torl %s,4(%%esp)\n",register_name(reg,0));
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3380 } else {
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3381 printf("\torl %s,%s\n",register_name(reg,0),register_name(lreg,0));
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3382 printf("\txchg %s,%s\n",register_name(reg,0),register_name(lreg,0));
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3383 }
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3384 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3385
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3386 extern void
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3387 code_bit_replace(int value,int lvalue,int type,int bitpos)
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3388 {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3389 int sign,bitsz,l,align;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3390 int bitsize = cadddr(type);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3391 int mask = 0;
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3392 set_bitsz(type,&sign,&bitsz,&align,&l);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3393 // printf("# %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3394 if (l) {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3395 use_longlong(value);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3396 /* shift left */
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3397 if (bitpos)
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3398 loprtc(LLSHIFT,value,list2(CONST,bitpos));
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3399 if (bitpos+bitsize>=32) {
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3400 /* make and-mask upper */
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3401 mask = make_mask(64-bitpos-bitsize,bitpos>=32?63-bitpos:31);
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3402 make_mask_and_or(mask,virtual(value==REG_L?REG_EDI:REG_EDX),-2);
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3403 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3404 if (bitpos<32) {
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3405 /* make and-mask lower */
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3406 mask = make_mask(bitpos+bitsize>=32?0:32-bitpos-bitsize,31-bitpos);
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3407 make_mask_and_or(mask,virtual(value==REG_L?REG_ESI:REG_EAX),-1);
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3408 }
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3409 printf("\tpopl %s\n",l_eax(value));
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3410 printf("\tpopl %s\n",l_edx(value));
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3411 } else {
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3412 use_int(value);
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3413 /* shift left */
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3414 if (bitpos)
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3415 oprtc(LSHIFT,value,list2(CONST,bitpos));
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3416 /* make and-mask */
338
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3417 mask = make_mask(32-bitpos-bitsize,31-bitpos);
7fe7ce0a791f bit-field done for IA32, PowerPC, MIPS.
kono
parents: 336
diff changeset
3418 make_mask_and_or(mask,value,lvalue);
336
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3419 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3420 }
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3421
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3422 #endif
d488b72254fb bit-field done.
kono
parents: 328
diff changeset
3423
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
3424 /* end */