annotate mc-code-ia32.c @ 243:c311c26e006a

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