annotate mc-code-ia32.c @ 283:230a3b98b843 mips-done

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