annotate mc-code-ia32.c @ 310:5ae5857ded2c struct-partial-init

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