annotate mc-code-ia32.c @ 156:da529eab5618

static initialization powerpc static bug
author kono
date Tue, 05 Aug 2003 14:15:33 +0900
parents cb7aa0089681
children b80e9737c3ce
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
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
9 #define SAVE_STACKS 1
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
10
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
11 #define TEXT_EMIT_MODE 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
12 #define DATA_EMIT_MODE 1
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
13 #define RODATA_EMIT_MODE 2
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
14
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
15 static int output_mode = TEXT_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
16 static int data_alignment = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
17
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
18 int size_of_int = 4;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
19 int size_of_float = 4;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
20 int size_of_double = 8;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
21 int size_of_longlong = 8;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
22 int endian = 0;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
23 int MAX_REGISTER=6; /* intel386のレジスタを6つまで使う*/
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
24 #define REAL_MAX_REGISTER 8 /* intel386のレジスタが8つということ*/
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
25 int MAX_DATA_REG=4;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
26 int MAX_POINTER=3;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
27 int MAX_REGISTGER_VAR=2;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
28 int MAX_FREGISTER=1;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
29
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
30 #define MAX_FPU_STACK 7
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
31
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
32 int MAX_INPUT_REGISTER_VAR = 0;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
33 int MAX_CODE_INPUT_REGISTER_VAR = 2;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
34 int MAX_INPUT_DREGISTER_VAR = 0;
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
35 int MAX_INPUT_FREGISTER_VAR = 0;
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
36 int MAX_CODE_INPUT_DREGISTER_VAR = 0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
37
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
38 int reg_sp; /* REGister Stack-Pointer */
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
39 int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
40
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
41 /* floating point registers */
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
42
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
43 int freg_sp; /* floating point REGister Stack-Pointer */
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
44 int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
45
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
46
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
47 /*
128
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
48 -28 -8 local2
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
49 -24 -4 local1
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
50 -20 8 arg3
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
51 -16 4 arg2
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
52 -12 0 arg1
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
53 local2 -20 4 -8 (%edi)
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
54 local1 <-- -16 0 local variable -4 (%esi)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
55 %edi -12 <- disp_offset %ebp
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
56 %esi -8
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
57 %ebx -4
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
58 %ebp = %esp 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
59 %eip 4 <- arg_offset
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
60 arg1 8 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
61 arg2 12 4
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
62 see enter/enter1/leave see code_enter
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
63 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
64 int arg_offset = 8;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
65 int disp_offset = -12;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
66 int func_disp_offset = -12;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
67 int code_disp_offset = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
68 int jump_offset = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
69
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
70 static int code_disp_label;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
71 static int func_disp_label;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
72
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
73 static int
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
74 lvar(int l)
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
75 {
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
76 if (is_code(fnptr)) {
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
77 return l+code_disp_offset;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
78 } else if (l<0) {
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
79 return l+disp_offset;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
80 } else {
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
81 return l+arg_offset;
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
82 }
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
83 }
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
84
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
85 /*
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
86 creg currrent virtual register
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
87 dreg spare virtual register
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
88
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
89 rname[creg] currrent real register
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
90 rname[dreg] spare real register
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
91
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
92 regs[] virtual register usage
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
93 regv[] value in virtual register flag
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
94
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
95 reg_name[rname[creg]]
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
96
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
97 freg current floating point register
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
98 fregv calue in floating point register
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
99 */
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
100
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
101 static int dreg; /* general temporal register */
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
102
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
103 int ia32regs[REAL_MAX_REGISTER];
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
104 int ia32regv[REAL_MAX_REGISTER];
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
105 int ia32rname[REAL_MAX_REGISTER];
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
106
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
107 int *regv = ia32regv;
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
108 int *regs = ia32regs;
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
109 static int *rname = ia32rname;
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
110
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
111 int ia32fregs[1];
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
112 int ia32fregv[1];
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
113
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
114 int freg;
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
115 int *fregv = ia32fregv;
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
116 int *fregs = ia32fregs;
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
117
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
118
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
119 #define REG_EAX 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
120 #define REG_EBX 1
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
121 #define REG_ECX 2
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
122 #define REG_EDX 3
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
123 #define REG_ESI 4
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
124 #define REG_EDI 5
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
125 #define REG_EBP 6
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
126 #define REG_ESP 7
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
127
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
128
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
129 #define DATA_REG 0
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
130 #define POINTER_REG 3
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
131 static char *reg_name[8];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
132 static char *reg_name_l[4];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
133 static char *reg_name_w[4];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
134
93
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
135 static void use_register(int virt, int real, int move);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
136 static int virtual(int real);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
137 static void shift(char *op, int reg);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
138 static void ld_indexx(int byte, int n, int xreg);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
139 static void data_mode(char *name);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
140 static int edx_setup();
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
141 static void edx_cleanup();
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
142 static void local_table(void);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
143 static char * fload(int d);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
144 static int code_d1(double d);
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
145 static int code_d2(double d);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
146 static void code_save_stacks();
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
147 static void code_save_fstacks();
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
148
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
149 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
150 code_init(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
151 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
152 arg_offset = 8;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
153 func_disp_offset = -12;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
154 disp_offset = -12;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
155 size_of_int = 4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
156 endian = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
157 MAX_REGISTER=6;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
158 MAX_DATA_REG=4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
159 MAX_POINTER=3;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
160 MAX_REGISTER_VAR=2;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
161
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
162 reg_name[REG_EAX] = "%eax";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
163 reg_name[REG_EBX] = "%ebx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
164 reg_name[REG_ECX] = "%ecx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
165 reg_name[REG_EDX] = "%edx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
166 reg_name[REG_ESI] = "%esi";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
167 reg_name[REG_EDI] = "%edi";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
168 reg_name[REG_EBP] = "%ebp";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
169 reg_name[REG_ESP] = "%esp";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
170 reg_name_l[REG_EAX] = "%al";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
171 reg_name_l[REG_EBX] = "%bl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
172 reg_name_l[REG_ECX] = "%cl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
173 reg_name_l[REG_EDX] = "%dl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
174 reg_name_w[REG_EAX] = "%ax";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
175 reg_name_w[REG_EBX] = "%bx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
176 reg_name_w[REG_ECX] = "%cx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
177 reg_name_w[REG_EDX] = "%dx";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
178
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
179 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
180
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
181 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
182 register_name(int i,int byte)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
183 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
184 if (i<0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
185 error(REG_ERR);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
186 return "%eax";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
187 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
188 if (byte && rname[i] <= REG_EDX) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
189 return reg_name_l[rname[i]];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
190 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
191 return reg_name[rname[i]]; /* should be error */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
192 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
193 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
194
147
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
195 int use_int(int i) { return i;}
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
196 int use_float(int i) { return i;}
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
197 int use_double(int i) { return i;}
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
198
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
199 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
200 gexpr_code_init(void){
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
201 use_register(creg,REG_EAX,0);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
202 regv[creg]=0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
203 regv[dreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
204 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
205
147
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
206 void
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
207 code_gexpr(int e){
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
208 }
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
209
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
210 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
211 register_var(int r) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
212 return virtual(r+REG_ESI);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
213 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
214
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
215 int
917947ffeb7c power pc version
kono
parents: 87
diff changeset
216 get_register(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
217 { /* 使われていないレジスタを調べる */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
218 int i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
219 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
220 if (! regs[i]) { /* 使われていないなら */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
221 regs[i]=1; /* そのレジスタを使うことを宣言し */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
222 return i; /* その場所を表す番号を返す */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
223 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
224 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
225 return -1; /* 空いている場所がないなら、それを表す -1 を返す */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
226 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
227
917947ffeb7c power pc version
kono
parents: 87
diff changeset
228 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
229 free_register(int i) { /* いらなくなったレジスタを開放 */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
230 regv[i]=regs[i]=0;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
231 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
232
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
233 int
126
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
234 get_input_register_var(int i,NMTBL *nptr,int is_code)
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
235 {
126
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
236 if (is_code) {
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
237 if (i>=MAX_CODE_INPUT_REGISTER_VAR) return 0;
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
238 i = virtual(i+REG_ESI);
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
239 regs[i]=regv[i]=1;
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
240 return list3(REGISTER,i,(int)nptr);
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
241 } else {
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
242 return 0;
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
243 }
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
244 }
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
245
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
246 int
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
247 get_input_dregister_var(int i,NMTBL *nptr,int is_code,int d)
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
248 {
126
1d1612fe705a *** empty log message ***
kono
parents: 123
diff changeset
249 return 0;
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
250 }
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
251
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
252 int
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
253 get_dregister(int d)
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
254 {
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
255 return -1;
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
256 }
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
257
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
258 int
917947ffeb7c power pc version
kono
parents: 87
diff changeset
259 register_full(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
260 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
261 int i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
262 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
263 if (! regs[i]) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
264 return 0;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
265 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
266 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
267 return 1;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
268 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
269
917947ffeb7c power pc version
kono
parents: 87
diff changeset
270 int
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
271 free_register_count(int d)
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
272 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
273 int i,count;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
274 count = 0;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
275 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
276 if (! regs[i] && ! regv[i]) count++;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
277 }
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
278 return d?0:count;
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
279 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
280
917947ffeb7c power pc version
kono
parents: 87
diff changeset
281 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
282 free_all_register(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
283 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
284 int i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
285 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
286 regs[i]=regv[i]=0;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
287 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
288 creg = get_register();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
289 dreg = get_register();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
290 return;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
291 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
292
917947ffeb7c power pc version
kono
parents: 87
diff changeset
293
917947ffeb7c power pc version
kono
parents: 87
diff changeset
294 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
295 register_usage(char *s)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
296 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
297 int i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
298 if (chk) return;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
299 printf("# %d: %s:",lineno,s);
917947ffeb7c power pc version
kono
parents: 87
diff changeset
300 printf(" creg=%s dreg=%s ",register_name(creg,0),register_name(dreg,0));
917947ffeb7c power pc version
kono
parents: 87
diff changeset
301 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
302 printf("%d",regs[i]);
917947ffeb7c power pc version
kono
parents: 87
diff changeset
303 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
304 printf(":");
917947ffeb7c power pc version
kono
parents: 87
diff changeset
305 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
306 printf("%d",regv[i]);
917947ffeb7c power pc version
kono
parents: 87
diff changeset
307 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
308 #if 0
917947ffeb7c power pc version
kono
parents: 87
diff changeset
309 printf(" regs_stack",register_name(creg,0),register_name(dreg,0));
917947ffeb7c power pc version
kono
parents: 87
diff changeset
310 for(i=reg_sp;i>=0;i--) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
311 if(reg_stack[i]>=0)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
312 printf(" %s",register_name(reg_stack[i],0));
917947ffeb7c power pc version
kono
parents: 87
diff changeset
313 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
314 #endif
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
315 printf(" f:%d",freg_sp);
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
316 printf("\n");
917947ffeb7c power pc version
kono
parents: 87
diff changeset
317 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
318
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
319 void
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
320 code_arg_register(NMTBL *fnptr)
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
321 {
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
322 int args = fnptr->dsp;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
323 NMTBL *n;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
324 int reg_var = 0;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
325 int freg_var = 0;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
326 int type;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
327 int reg;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
328 int is_code0 = is_code(fnptr);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
329
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
330 while (args) {
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
331 /* process in reverse order */
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
332 n = (NMTBL*)caddr(args);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
333 type = n->ty;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
334 if (scalar(type)) {
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
335 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
336 n->sc = REGISTER;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
337 n->dsp = cadr(reg);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
338 regv[n->dsp]= 1;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
339 regs[n->dsp]= INPUT_REG;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
340 reg_var++;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
341 cadddr(args)=size_of_int; /* why we need this? */
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
342 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
343 } else if (type==FLOAT||type==DOUBLE) {
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
344 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
345 n->sc = DREGISTER;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
346 n->dsp = cadr(reg);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
347 fregv[n->dsp]= 1;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
348 fregs[n->dsp]= INPUT_REG;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
349 freg_var++;
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
350 cadddr(args)=size(type); /* why we need this? */
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
351 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
352 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
353 args = cadr(args);
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
354 }
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
355 }
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
356
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
357 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
358 gexpr_init(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
359 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
360 while(reg_sp > 0) {
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
361 if (reg_stack[--reg_sp]>=0)
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
362 free_register(reg_stack[reg_sp]);
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
363 }
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
364 freg_sp = 0;
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
365 text_mode();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
366 gexpr_code_init();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
367 register_usage("gexpr_init");
917947ffeb7c power pc version
kono
parents: 87
diff changeset
368 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
369
917947ffeb7c power pc version
kono
parents: 87
diff changeset
370
917947ffeb7c power pc version
kono
parents: 87
diff changeset
371 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
372 emit_init(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
373 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
374 int i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
375 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
376 free_all_register();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
377 reg_sp = 0;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
378 freg_sp = 0;
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
379 text_mode();
917947ffeb7c power pc version
kono
parents: 87
diff changeset
380 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
381
917947ffeb7c power pc version
kono
parents: 87
diff changeset
382 int
917947ffeb7c power pc version
kono
parents: 87
diff changeset
383 virtual(int real)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
384 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
385 int real_v,i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
386 real_v = -1;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
387 for(i=0;i<MAX_REGISTER;i++) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
388 if (rname[i]==real) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
389 real_v=i;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
390 break;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
391 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
392 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
393 return real_v;
917947ffeb7c power pc version
kono
parents: 87
diff changeset
394 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
395
917947ffeb7c power pc version
kono
parents: 87
diff changeset
396 int
917947ffeb7c power pc version
kono
parents: 87
diff changeset
397 pop_register(void)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
398 { /* レジスタから値を取り出す */
917947ffeb7c power pc version
kono
parents: 87
diff changeset
399 return reg_stack[--reg_sp];
917947ffeb7c power pc version
kono
parents: 87
diff changeset
400 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
401
917947ffeb7c power pc version
kono
parents: 87
diff changeset
402 void
917947ffeb7c power pc version
kono
parents: 87
diff changeset
403 emit_pop_free(int xreg)
917947ffeb7c power pc version
kono
parents: 87
diff changeset
404 {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
405 if (xreg==dreg) {
917947ffeb7c power pc version
kono
parents: 87
diff changeset
406 regv[dreg]=0;
98
07c2554e1cfa *** empty log message ***
kono
parents: 97
diff changeset
407 } else if (xreg>=0) {
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
408 free_register(xreg);
917947ffeb7c power pc version
kono
parents: 87
diff changeset
409 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
410 }
917947ffeb7c power pc version
kono
parents: 87
diff changeset
411
917947ffeb7c power pc version
kono
parents: 87
diff changeset
412
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
413 int
105
7e3d59e56a53 save register ( incomplete )
kono
parents: 104
diff changeset
414 get_register_var(NMTBL *nptr)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
415 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
416 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
417 for(i=REG_ESI;i<REG_ESP;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
418 if (! regs[i]) { /* 使われていないなら */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
419 regs[i]=1; /* そのレジスタを使うことを宣言し */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
420 regv[i]=0;
105
7e3d59e56a53 save register ( incomplete )
kono
parents: 104
diff changeset
421 return list3(REGISTER,i,(int)nptr); /* その場所を表す番号を返す */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
422 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
423 }
104
c21aeb12b78b *** empty log message ***
kono
parents: 103
diff changeset
424 return list2(LVAR,new_lvar(size_of_int));
c21aeb12b78b *** empty log message ***
kono
parents: 103
diff changeset
425 }
c21aeb12b78b *** empty log message ***
kono
parents: 103
diff changeset
426
c21aeb12b78b *** empty log message ***
kono
parents: 103
diff changeset
427 int
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
428 get_dregister_var(NMTBL *nptr,int d)
104
c21aeb12b78b *** empty log message ***
kono
parents: 103
diff changeset
429 {
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
430 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
431 }
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
432
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
433 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
434 use_register(int virt, int real, int move)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
435 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
436 int real_v;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
437 char *move_op;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
438 if (rname[virt]==real)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
439 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
440 real_v = virtual(real);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
441 move_op = regs[real_v]?"\txchg %s,%s\n":"\tmovl %s,%s\n";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
442 if (move || (regv[real_v])) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
443 printf(move_op,reg_name[rname[virt]],reg_name[real]);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
444 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
445 rname[real_v] = rname[virt];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
446 rname[virt] = real;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
447 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
448
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
449 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
450 use_pointer(int virt, int move)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
451 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
452 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
453 if (rname[virt]>=POINTER_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
454 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
455 for(i=POINTER_REG;i<MAX_REGISTER;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
456 if (!regs[virtual(i)]) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
457 use_register(virt,i,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
458 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
459 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
460 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
461 /* we prefer EBX */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
462 use_register(virt,REG_EBX,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
463 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
464
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
465 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
466 use_data_reg(int virt, int move)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
467 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
468 int i;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
469 if (rname[virt]<MAX_DATA_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
470 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
471 for(i=0;i<MAX_DATA_REG;i++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
472 if (!regs[virtual(i)]) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
473 use_register(virt,i,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
474 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
475 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
476 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
477 /* we prefer EBX */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
478 use_register(virt,REG_EBX,move);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
479 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
480
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
481
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
482 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
483 emit_push()
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
484 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
485 int new_reg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
486 new_reg = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
487 if(new_reg<0) { /* もうレジスタがない */
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
488 if (reg_sp>=MAX_MAX) error(-1);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
489 reg_stack[reg_sp++] = -1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
490 printf("\tpushl %s\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
491 /* creg is used soon, don't regv[creg]=0 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
492 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
493 reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
494 creg = new_reg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
495 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
496 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
497 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
498
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
499 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
500 emit_pop(int type)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
501 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
502 int xreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
503 if ((xreg=pop_register())==-1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
504 if (type==POINTER_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
505 use_pointer(dreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
506 else if (type==DATA_REG)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
507 use_data_reg(dreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
508 if (regv[dreg]) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
509 printf("# emit_pop dreg conflict\n");
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
510 error(-1);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
511 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
512 printf("\tpopl %s\n",register_name(dreg,0));
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
513 regv[dreg]=1;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
514 return dreg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
515 } else if (xreg<= -REG_LVAR_OFFSET) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
516 code_rlvar(xreg+REG_LVAR_OFFSET,dreg);
117
2d5a203cc3a6 lvar reuse
kono
parents: 116
diff changeset
517 free_lvar(xreg+REG_LVAR_OFFSET);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
518 regv[dreg]=1;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
519 return dreg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
520 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
521 return xreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
522 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
523
92
e7f8515ba882 *** empty log message ***
kono
parents: 89
diff changeset
524 void
e7f8515ba882 *** empty log message ***
kono
parents: 89
diff changeset
525 code_label(int labelno)
e7f8515ba882 *** empty log message ***
kono
parents: 89
diff changeset
526 {
e7f8515ba882 *** empty log message ***
kono
parents: 89
diff changeset
527 printf("_%d:\n",labelno);
e7f8515ba882 *** empty log message ***
kono
parents: 89
diff changeset
528 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
529
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
530 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
531 code_gvar(int e1,int creg) {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
532 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
533 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
534 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
535
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
536
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
537 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
538 code_rgvar(int e1,int creg) {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
539 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
540 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
541 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
542
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
543 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
544 code_crgvar(int e1,int creg){
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
545 printf("\tmovsbl %s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
546 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
547 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
548
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
549
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
550 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
551 code_lvar(int e2,int creg) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
552 printf("\tlea %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
553 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
554 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
555
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
556
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
557 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
558 code_register(int e2,int creg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
559 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
560 regv[creg]=1;
61
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
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
564 void
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
565 code_rlvar(int e2,int reg) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
566 printf("\tmovl %d(%%ebp),%s\n",lvar(e2),register_name(reg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
567 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
568 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
569
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
570
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
571 void
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
572 code_crlvar(int e2,int reg) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
573 printf("\tmovsbl %d(%%ebp),%s\n",lvar(e2),register_name(reg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
574 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
575 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
576
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
577
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
578 void
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
579 code_fname(NMTBL *n,int creg) {
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
580 printf("\tmovl $%s,%s\n",n->nm,register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
581 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
582 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
583
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
584
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
585 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
586 code_const(int e2,int creg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
587 printf("\tmovl $%d,%s\n",e2,register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
588 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
589 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
590
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
591
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
592 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
593 code_neg(int creg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
594 printf("\tnegl %s\n", register_name(creg,0));
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 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
599 code_not(int creg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
600 printf("\tnotl %s\n", register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
601 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
602
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
603
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
604 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
605 code_lnot(int creg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
606 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
607 use_data_reg(creg,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
608 xrn = register_name(creg,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
609 printf("\tcmpl $0,%s\n", register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
610 printf("\tsete %s\n", xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
611 printf("\tmovzbl %s,%s\n", xrn,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
612 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
613
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
614 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
615 code_preinc(int e1,int e2,int reg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
616 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
617 if (car(e2)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
618 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
619 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
620 regv[reg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
621 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
622 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
623 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
624 xrn = register_name(creg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
625 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
626 printf("\tmovl (%s),%s\n",xrn,xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
627 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
628
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
629
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
630 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
631 code_postinc(int e1,int e2,int reg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
632 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
633 if (car(e2)==REGISTER) {
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
634 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
635 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
636 regv[reg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
637 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
638 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
639 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
640 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
641 xrn = register_name((e2=emit_pop(0)),0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
642 printf("\tmovl (%s),%s\n",xrn,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
643 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
644 emit_pop_free(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
645 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
646
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
647
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
648 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
649 code_cpostinc(int e1,int e2,int reg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
650 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
651 if (car(e2)==REGISTER) {
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
652 printf("\tmovbl (%s),%s\n",register_name(cadr(e2),0),
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
653 register_name(reg,0));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
654 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
655 regv[reg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
656 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
657 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
658 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
659 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
660 xrn = register_name((e2=emit_pop(0)),1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
661 printf("\tmovsbl (%s),%s\n",xrn,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
662 printf("\tincl (%s)\n",xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
663 emit_pop_free(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
664 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
665
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
666
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
667 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
668 code_cpreinc(int e1,int e2,int reg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
669 if (car(e2)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
670 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
671 printf("\tmovsbl (%s),%s\n",register_name(cadr(e2),0),
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
672 register_name(reg,0));
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
673 regv[reg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
674 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
675 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
676 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
677 printf("\tincl (%s)\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
678 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
679 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
680
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
681
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
682 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
683 code_cpostdec(int e1,int e2,int reg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
684 if (car(e2)==REGISTER) {
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
685 printf("\tmovsbl (%s),%s\n",register_name(cadr(e2),0),
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
686 register_name(reg,0));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
687 printf("\tdecl %s\n",register_name(cadr(e2),0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
688 regv[reg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
689 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
690 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
691 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
692 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
693 printf("\tdecl (%s)\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
694 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
695
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
696
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
697 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
698 code_cpredec(int e1,int e2,int reg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
699 if (car(e2)==REGISTER) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
700 printf("\tdecl %s\n",register_name(cadr(e2),0));
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
701 printf("\tmovsbl (%s),%s\n",register_name(cadr(e2),0),
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
702 register_name(reg,0));
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
703 regv[reg]=1;
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
704 return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
705 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
706 g_expr(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
707 emit_push();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
708 e2 = emit_pop(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
709 printf("\tdecl (%s)\n",register_name(e2,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
710 printf("\tmovsbl (%s),%s\n",register_name(e2,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
711 emit_pop_free(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
712 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
713
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
714
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
715 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
716 code_return(int creg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
717 printf("\tleal _%d,%s\n",retcont,register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
718 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
719 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
720
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
721
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
722 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
723 code_environment(int creg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
724 printf("\tmovl %%ebp,%s\n",register_name(creg,0));
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
725 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
726 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
727
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
728
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
729 void
116
b14ff9671c90 register offset fix
kono
parents: 111
diff changeset
730 code_bool(int e1) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
731 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
732 int e2,e3;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
733 b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
734 xrn = register_name(creg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
735 printf("\txorl %s,%s\n",xrn,xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
736 jmp(e3=fwdlabel());
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
737 fwddef(e2);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
738 printf("\tmovl $1,%s\n",xrn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
739 fwddef(e3);
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
740 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
741 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
742
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
743 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
744 code_gt(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
745 return (cond?"g":"le");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
746 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
747
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
748 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
749 code_ugt(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
750 return (cond?"a":"be");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
751 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
752
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
753 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
754 code_ge(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
755 return (cond?"ge":"l");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
756 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
757
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
758 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
759 code_uge(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
760 return (cond?"ae":"b");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
761 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
762
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
763 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
764 code_eq(int cond) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
765 return (cond?"e":"ne");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
766 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
767
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
768 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
769 code_cmp_crgvar(int e1) {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
770 printf("\tcmpb $0,%s\n",((NMTBL*)cadr(e1))->nm);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
771 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
772
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
773
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
774 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
775 code_cmp_crlvar(int e1) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
776 printf("\tcmpb $0,%d(%%ebp)\n",lvar(e1));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
777 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
778
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
779
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
780 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
781 code_cmp_rgvar(int e1) {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
782 printf("\tcmpl $0,%s\n",((NMTBL*)cadr(e1))->nm);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
783 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
784
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
785
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
786 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
787 code_cmp_rlvar(int e1) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
788 printf("\tcmpl $0,%d(%%ebp)\n",lvar(e1));
61
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
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
792 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
793 code_cmp_register(int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
794 printf("\tcmpl $0,%s\n",register_name(e2,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
795 }
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 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
799 ascii(char *s)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
800 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
801 printf("\t.string \"");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
802 while(*s) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
803 if (*s=='\n')
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
804 printf("%cn",92);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
805 else if (*s<' ')
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
806 printf("%c%03o",92,*s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
807 else if (*s==34)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
808 printf("%c%c",92,34);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
809 else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
810 printf("%c",*s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
811 s++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
812 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
813 printf("%c\n",34);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
814 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
815
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
816 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
817 code_string(int e1,int creg)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
818 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
819 char *s;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
820 int i,lb;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
821
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
822 if (0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
823 s=(char *)cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
824 lb=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
825 printf("\tjmp _%d\n",lb);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
826 i=backdef();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
827 ascii(s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
828 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
829 fwddef(lb);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
830 printf("\tlea _%d,%s\n",i,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
831 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
832 s=(char *)cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
833 printf(".section\t.rodata\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
834 lb=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
835 printf("_%d:\n",lb);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
836 ascii(s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
837 if (output_mode==TEXT_EMIT_MODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
838 printf(".text\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
839 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
840 text_mode();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
841 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
842 printf("\tlea _%d,%s\n",lb,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
843 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
844 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
845
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
846 #define MAX_COPY_LEN 20
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
847
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
848 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
849 emit_copy(int from,int to,int length,int offset,int value,int det)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
850 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
851 int fix = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
852 /* length <0 means upward direction copy */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
853 switch (length) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
854 case 0: break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
855 case 1: case -1:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
856 printf("\tmovb %d(%s),%s\n",offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
857 register_name(from,0), reg_name_l[rname[dreg]] );
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
858 printf("\tmovb %s,%d(%s)\n",reg_name_l[rname[dreg]] ,offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
859 register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
860 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
861 case 2: case -2:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
862 printf("\tmovw %d(%s),%s\n",offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
863 register_name(from,0), reg_name_w[rname[dreg]] );
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
864 printf("\tmovw %s,%d(%s)\n",reg_name_w[rname[dreg]] ,offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
865 register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
866 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
867 case 4: case -4:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
868 printf("\tmovl %d(%s),%s\n",offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
869 register_name(from,0), register_name(dreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
870 printf("\tmovl %s,%d(%s)\n",register_name(dreg,0), offset,
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
871 register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
872 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
873 default:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
874 if (-MAX_COPY_LEN<length && length <0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
875 for(;length<=4;length+=4,offset-=4)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
876 emit_copy(from,to,4,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
877 for(;length<=2;length+=2,offset-=2)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
878 emit_copy(from,to,2,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
879 if(length>0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
880 emit_copy(from,to,length,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
881 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
882 } else if (length <=MAX_COPY_LEN) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
883 for(;length>=4;length-=4,offset+=4)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
884 emit_copy(from,to,4,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
885 for(;length>=2;length-=2,offset+=2)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
886 emit_copy(from,to,2,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
887 if(length>0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
888 emit_copy(from,to,length,offset,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
889 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
890 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
891 if (det) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
892 /*
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
893 call bcopy
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
894 g_expr(list3(FUNCTION,,);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
895 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
896 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
897 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
898 use_register(from,REG_ESI,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
899 use_register(to, REG_EDI,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
900 use_register(dreg,REG_ECX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
901 if (length<0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
902 printf("\tmovl $%d,%%ecx\n",-length/4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
903 printf("\taddl $%d,%%esi\n",-length);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
904 printf("\taddl $%d,%%edi\n",-length);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
905 printf("\tstd\n\trep\n\tmovsl\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
906 if(length%4) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
907 emit_copy(from,to,length,offset+length/4,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
908 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
909 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
910 printf("\tmovl $%d,%%ecx\n",length/4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
911 fix = (length/4)*4;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
912 printf("\tcld\n\trep\n\tmovsl\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
913 if(length%4) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
914 emit_copy(from,to,length,offset+length/4,0,det);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
915 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
916 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
917 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
918 if (value) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
919 /* creg must point top of the destination data */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
920 /* this code is necessary for the value of assignment or function call */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
921 /* otherwise we don't need this */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
922 if (fix) printf("\tsubl $%d,%s\n",fix,register_name(to,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
923 if(creg!=to) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
924 if (to==dreg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
925 printf("\tmovl %s,%s\n",register_name(to,0),register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
926 else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
927 free_register(creg); creg=to;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
928 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
929 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
930 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
931 regv[from]=regv[to]=regv[dreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
932 regv[creg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
933 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
934
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
935 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
936 struct_push(int e4,int t)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
937 {
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
938 int length,xreg,save,lreg,count;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
939 g_expr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
940 length=size(t);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
941 if(length%size_of_int) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
942 length += size_of_int - (length%size_of_int);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
943 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
944 for(count=0;length<MAX_COPY_LEN;count++,length-=size_of_int) {
f94ca1168520 float first try...
kono
parents: 78
diff changeset
945 if (length==0) return count;
f94ca1168520 float first try...
kono
parents: 78
diff changeset
946 else {
f94ca1168520 float first try...
kono
parents: 78
diff changeset
947 printf("\tpushl %d(%s)\n",
f94ca1168520 float first try...
kono
parents: 78
diff changeset
948 length-size_of_int,register_name(creg,0));
f94ca1168520 float first try...
kono
parents: 78
diff changeset
949 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
950 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
951 printf("\tsubl $%d,%%esp\n",length);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
952 if (register_full()) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
953 save = 1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
954 for(lreg=0;lreg==creg||lreg==dreg;lreg++);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
955 printf("\tpushl %s\n",register_name(lreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
956 xreg = lreg; regv[xreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
957 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
958 save=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
959 xreg = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
960 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
961 if (save)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
962 printf("\tlea %d(%%esp),%s\n",size_of_int,register_name(xreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
963 else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
964 printf("\tmovl %%esp,%s\n",register_name(xreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
965 regv[xreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
966 /* downward direction copy */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
967 emit_copy(creg,xreg,length,0,0,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
968 /* we have value in creg, it may be changed */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
969 if (save) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
970 if(creg==xreg) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
971 creg = get_register(); /* creg is freed in emit_copy */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
972 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
973 printf("\tpopl %s\n",register_name(xreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
974 regv[xreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
975 } else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
976 free_register(xreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
977 return length/size_of_int;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
978 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
979
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
980 int
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
981 function(int e1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
982 {
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
983 int e2,e3,e4,nargs,t,ret_type;
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
984 NMTBL *n=0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
985 int save,saved;
136
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
986 ret_type = cadr(cadddr(e1));
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
987 if (ret_type==CHAR) ret_type=INT;
069960078249 remove redundant funcall argument for prototyped code in PowerPC case.
kono
parents: 133
diff changeset
988
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
989 #ifdef SAVE_STACKS
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
990 code_save_stacks();
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
991 #endif
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
992 if (free_register_count(0)<1) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
993 for(save = 0;save==dreg||save==creg;save++);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
994 printf("\tpushl %s\n",register_name(save,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
995 saved = 1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
996 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
997 save = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
998 saved = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
999 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1000 regv[save]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1001 e2 = cadr(e1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1002 nargs = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1003 for (e3 = caddr(e1); e3; e3 = cadr(e3)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1004 t=caddr(e3);
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1005 e4 = car(e3);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1006 if(scalar(t)) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1007 g_expr(e4);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1008 printf("\tpushl %s\n",register_name(creg,0));
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1009 } else if (t==DOUBLE) {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1010 g_expr(e4);
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1011 printf("\tleal\t-8(%%esp),%%esp\n\tfstpl\t(%%esp)\n");
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1012 nargs += size_of_double/size_of_int;
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1013 fregv[freg]=0;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1014 continue;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1015 } else if (t==FLOAT) {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1016 g_expr(e4);
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1017 printf("\tleal\t-4(%%esp),%%esp\n\tfstps\t(%%esp)\n");
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1018 nargs += size_of_float/size_of_int;
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1019 fregv[freg]=0;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1020 continue;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1021 } else if (car(t)==STRUCT||car(t)==UNION) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1022 nargs += struct_push(e4,t);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1023 continue;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1024 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1025 error(TYERR);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1026 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1027 ++nargs;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1028 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1029 if (car(e2) == FNAME) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1030 n=(NMTBL *)cadr(e2);
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1031 regv[creg]=0;
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1032 use_register(creg,REG_EAX,0); /* will be destroyed */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1033 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1034 g_expr(e2);
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1035 regv[creg]=1;
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1036 use_register(creg,REG_EAX,1); /* will be destroyed */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1037 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1038
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1039 /* we don't have to save creg nor dreg */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1040 regs[creg]=0; regs[dreg]=0;
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1041 regv[dreg]= regv[save]= 0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1042 use_register(dreg,REG_EDX,0); /* will be destroyed */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1043 use_register(save,REG_ECX,0); /* will be destroyed */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1044 regs[creg]=1; regs[dreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1045
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1046 if (car(e2) == FNAME) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1047 printf("\tcall\t%s\n",n->nm);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1048 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1049 printf("\tcall\t*%s\n",register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1050 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1051 if (nargs) printf("\taddl $%d,%%esp\n",size_of_int*nargs);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1052 if (saved) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1053 printf("\tpopl %s\n",register_name(save,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1054 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1055 free_register(save);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1056 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1057 regv[save]=0;
105
7e3d59e56a53 save register ( incomplete )
kono
parents: 104
diff changeset
1058 if (ret_type==DOUBLE||ret_type==FLOAT) {
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1059 fregv[freg]=1; regv[creg]=0;
105
7e3d59e56a53 save register ( incomplete )
kono
parents: 104
diff changeset
1060 } else if (ret_type==VOID) {
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1061 fregv[freg]=0; regv[creg]=0;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1062 } else {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1063 fregv[freg]=0; regv[creg]=1;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1064 }
105
7e3d59e56a53 save register ( incomplete )
kono
parents: 104
diff changeset
1065 return ret_type;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1066 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1067
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1068 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1069 code_frame_pointer(int e3) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1070 printf("\tmovl %s,%%ebp\n",register_name(e3,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1071 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1072
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1073
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1074 void
62
129f4802b027 separation done
kono
parents: 61
diff changeset
1075 code_fix_frame_pointer(int disp_offset) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1076 printf("\tlea %d(%%ebp),%%ebp\n",disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1077 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1078
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1079
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1080 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1081 code_jmp(char *s) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1082 printf("\tjmp %s\n",s);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1083 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1084
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1085
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1086 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1087 code_indirect_jmp(int e2) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1088 printf("\tjmp *%s\n",register_name(e2,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1089 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1090
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1091 int
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1092 rindirect(int e1) /* *(p +5 ) */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1093 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1094 char *op;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1095 int e2,e3,byte,t;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1096 e3 = cadr(e2 = cadr(e1));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1097 g_expr(e2);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1098 switch (car(e1)) {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1099 case FRINDIRECT: case DRINDIRECT:
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1100 printf("\t%s (%s)\n",fload(car(e1)==DRINDIRECT),register_name(creg,0));
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1101 t=DOUBLE;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1102 break;
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1103 case CRINDIRECT: case RINDIRECT: default:
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1104 op = ((byte = (car(e1) == CRINDIRECT)) ? "movsbl" : "movl");
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1105 printf("\t%s (%s),%s\n",op,register_name(creg,0),register_name(creg,0));
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1106 t=byte?CHAR:INT;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1107 }
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1108 return t;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1109 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1110
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1111 char *
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1112 move(int byte)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1113 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1114 return byte?"movb":"movl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1115 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1116
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1117 void
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1118 code_assign_gvar(int e2,int creg,int byte) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1119 if (byte) use_data_reg(creg,1);
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
1120 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
1121 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1122
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1123 void
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1124 code_assign_lvar(int e2,int creg,int byte) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1125 if (byte) use_data_reg(creg,1);
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1126 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
1127 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1128
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1129 void
111
7aa449aff3e6 floating point
kono
parents: 109
diff changeset
1130 code_assign_register(int e2,int byte,int creg) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1131 printf("\tmovl %s,%s\n",register_name(creg,0),register_name(e2,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1132 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1133
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1134 void
118
07b91b625f84 assignment optimization
kono
parents: 117
diff changeset
1135 code_assign(int e2,int byte,int creg) {
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1136 if (byte) use_data_reg(creg,1);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1137 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
1138 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1139 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1140
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1141 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1142 code_register_assop(int e2,int op,int byte) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1143 int reg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1144 int xreg = creg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1145 creg = reg = e2;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1146 tosop(op,xreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1147 creg = xreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1148 printf("\tmovl %s,%s\n",register_name(reg,0),register_name(creg,0));
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1149 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1150 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1151
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1152
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1153 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1154 code_assop(int op,int byte) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1155 char *xrn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1156 int xreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1157 int edx = edx_setup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1158 xrn = register_name(xreg = emit_pop(0),0); /* pop e3 value */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1159 regv[xreg]=regs[xreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1160 printf("\tmovl %s,%s # assop \n",register_name(creg,0),register_name(edx,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1161 regv[edx]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1162 ld_indexx(byte,0,edx);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1163 tosop(op,xreg);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1164 printf("\t%s %s,(%s)\n",byte ? "movb" : "movl",register_name(creg,byte),register_name(edx,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1165 edx_cleanup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1166 emit_pop_free(xreg);
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1167 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1168 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1169
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1170
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1171 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1172 tosop(int op,int oreg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1173 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1174 int dx;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1175 char *orn,*crn;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1176
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1177 switch(op) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1178 case LSHIFT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1179 case ULSHIFT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1180 shift("sall",oreg);
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1181 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1182 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1183 case RSHIFT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1184 shift("sarl",oreg);
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1185 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1186 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1187 case URSHIFT:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1188 shift("shrl",oreg);
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1189 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1190 return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1191 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1192 if(oreg==-1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1193 printf("\tpopl %s\n",register_name(dreg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1194 oreg = dreg;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1195 regv[dreg]=1;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1196 } else if (oreg<= -REG_LVAR_OFFSET) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1197 code_rlvar(oreg+REG_LVAR_OFFSET,dreg);
117
2d5a203cc3a6 lvar reuse
kono
parents: 116
diff changeset
1198 free_lvar(oreg+REG_LVAR_OFFSET);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1199 oreg = dreg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1200 regv[dreg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1201 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1202 regv[oreg]=1; regs[oreg]=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1203 orn = register_name(oreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1204 crn = register_name(creg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1205 switch(op) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1206 case ADD:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1207 printf("\taddl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1208 break;
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
1209 case SUB: case CMP:
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1210 printf("\tsubl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1211 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1212 case BAND:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1213 printf("\tandl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1214 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1215 case EOR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1216 printf("\txorl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1217 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1218 case BOR:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1219 printf("\torl %s,%s\n",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1220 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1221 case MUL:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1222 case UMUL:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1223 printf("\t%s %s,%s\n","imull",orn,crn);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1224 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1225 case DIV:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1226 case UDIV:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1227 use_register(creg,REG_EAX,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1228 edx_setup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1229 orn = register_name(oreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1230 if (op==DIV)
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1231 printf("\tcltd\n\tidivl %s\n",orn);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1232 else
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1233 printf("\txor %%edx,%%edx\n\tdivl %s\n",orn);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1234 edx_cleanup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1235 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1236 case MOD:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1237 case UMOD:
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1238 use_register(creg,REG_EAX,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1239 edx_setup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1240 orn = register_name(oreg,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1241 if (op==DIV)
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1242 printf("\tcltd\n\tidivl %s\n",orn);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1243 else
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1244 printf("\txor %%edx,%%edx\n\tdivl %s\n",orn);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1245 dx = virtual(REG_EDX);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1246 if (dx!=creg) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1247 rname[dx]=rname[creg];
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1248 rname[creg]=REG_EDX;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1249 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1250 edx_cleanup();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1251 break;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1252 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1253 if (oreg!=dreg&&oreg>=0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1254 free_register(oreg);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1255 else if (oreg==dreg) regv[dreg]=0;
144
56211702f298 creg/freg continue
kono
parents: 139
diff changeset
1256 regv[creg]=1;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1257 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1258
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1259 static int edx_stack=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1260
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1261 int
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1262 edx_setup()
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1263 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1264 int edx_save;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1265 /* make real EDX register empty */
137
9fb09db54436 fix powerpc get_fregister_var's regs error.
kono
parents: 136
diff changeset
1266 if (free_register_count(0)<1) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1267 for(edx_save = 0;edx_save==dreg||edx_save==creg;edx_save++);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1268 printf("\tpushl %s\n",register_name(edx_save,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1269 edx_stack = list3(edx_save,edx_stack,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1270 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1271 edx_save = get_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1272 edx_stack = list3(edx_save,edx_stack,1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1273 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1274 regv[edx_save]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1275 use_register(edx_save,REG_EDX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1276 return edx_save;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1277 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1278
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1279
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1280 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1281 edx_cleanup()
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1282 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1283 if (caddr(edx_stack)==0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1284 printf("\tpopl %s\n",register_name(car(edx_stack),0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1285 } else
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1286 free_register(car(edx_stack));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1287 edx_stack = cadr(edx_stack);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1288 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1289
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1290 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1291 shift(char *op, int reg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1292 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1293 if (reg>=0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1294 use_register(reg,REG_ECX,1);
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1295 } else if (reg<= -REG_LVAR_OFFSET) {
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1296 use_register(dreg,REG_ECX,0);
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1297 code_rlvar(reg+REG_LVAR_OFFSET,dreg);
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1298 reg = dreg;
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1299 regv[dreg]=0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1300 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1301 use_register(dreg,REG_ECX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1302 printf("\tpopl %%ecx\n");
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1303 regv[dreg]=0;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1304 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1305 printf("\t%s %%cl,%s\n",op,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1306 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1307
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1308 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1309 ld_indexx(int byte, int n, int xreg)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1310 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1311 char *op;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1312
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1313 op = byte ? "movsbl" : "movl";
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1314 if (n)
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1315 printf("\t%s %d(%s),%s\n",op,n,
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1316 register_name(xreg,0),register_name(creg,byte));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1317 else
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1318 printf("\t%s (%s),%s\n",op,
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1319 register_name(xreg,0),register_name(creg,byte));
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1320 }
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1321
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1322 int
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1323 code_csvalue()
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1324 {
123
5f180dc8d84e intel fix.
kono
parents: 119
diff changeset
1325 return rname[creg]; /* for switch value */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1326 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1327
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1328 void
95
185d2cc6a3a9 *** empty log message ***
kono
parents: 94
diff changeset
1329 code_cmpdimm(int e, int csreg)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1330 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1331 /* used in dosiwtch() */
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1332 if(chk) return;
123
5f180dc8d84e intel fix.
kono
parents: 119
diff changeset
1333 use_register(creg,csreg,0);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1334 printf("\tcmpl $%d,%s\n",e,register_name(creg,0));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1335 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1336
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1337 void
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1338 code_opening(char *filename)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1339 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1340 printf("\t.file \"%s\"\n",filename);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1341 printf("\t.version\t\"01.01\"\n");
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1342 /* printf("gcc2_compiled.:\n"); */
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1343 printf(".text\n");
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
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1347 code_closing()
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1348 {
78
8418d4b7caa7 *** empty log message ***
kono
parents: 77
diff changeset
1349 global_table();
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1350 printf("\t.ident \"Micro-C compiled\"\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1351 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1352
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1353 void
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
1354 rexpr(int e1, int l1, char *s,int t)
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1355 {
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
1356 g_expr(list3(CMP,cadr(e1),caddr(e1)));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1357 printf("\tj%s\t_%d\n",s,l1);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1358 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1359
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1360
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1361 void
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1362 jcond(int l, char cond)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1363 {
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1364 if (chk) return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1365 printf("\tj%s\t_%d\n",cond?"ne":"e",l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1366 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1367
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1368 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1369 jmp(int l)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1370 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1371 control=0;
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1372 if (chk) return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1373 printf("\tjmp\t_%d\n",l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1374 /* align? */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1375 /*
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1376 this is not allowed because of ? operator
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1377 regv[creg]=regv[dreg]=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1378 use_register(creg,REG_EAX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1379 use_register(dreg,REG_EBX,0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1380 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1381 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1382
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1383 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1384 gen_comment(char *s)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1385 {
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1386 if (chk) return;
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1387 printf("## %s",s);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1388 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1389
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1390
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1391 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1392 code_enter(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1393 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1394 printf("\t.align 4\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1395 if (stmode!=STATIC)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1396 printf(".globl %s\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1397 printf("\t.type\t%s,@function\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1398 printf("%s:\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1399 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1400
77
2b8ba655e572 fix arg type
kono
parents: 66
diff changeset
1401
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1402 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1403 code_enter1(int args)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1404 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1405 code_disp_label=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1406 printf("\tlea _%d(%%ebp),%%esp\n",code_disp_label);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1407
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1408 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
1409 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1410
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1411 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1412 code_leave(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1413 {
63
e13486b2c12e stack alignment
kono
parents: 62
diff changeset
1414 disp&= -size_of_int;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1415 printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1416 printf("_%d:\n",labelno);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1417 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1418 local_table();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1419 labelno++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1420 free_all_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1421 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1422
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1423 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1424 enter(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1425 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1426 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1427 if (stmode!=STATIC)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1428 printf(".globl %s\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1429 printf("%s:\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1430 printf("\t.type\t%s,@function\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1431 printf("\tpushl %%ebp\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1432 printf("\tmovl %%esp,%%ebp\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1433 printf("\tpushl %%ebx\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1434 printf("\tpushl %%esi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1435 printf("\tpushl %%edi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1436 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1437
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1438 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1439 enter1()
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1440 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1441 func_disp_label=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1442 printf("\tlea _%d(%%ebp),%%esp\n",func_disp_label);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1443 /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1444 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1445
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1446 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1447 leave(int control, char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1448 {
128
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1449 int sz;
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1450
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1451 disp &= -size_of_int;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1452 if (control)
108
69e2e763cce5 object assemble first try.
kono
parents: 107
diff changeset
1453 code_set_return_register(1);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1454 if (retcont) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1455 if (control)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1456 jmp(retlabel);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1457 fwddef(retcont);
128
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1458 if (cadr(fnptr->ty)==FLOAT||cadr(fnptr->ty)==DOUBLE) {
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1459 printf("\tfldl %d(%%ebp)\n",-size_of_double);
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1460 } else if (cadr(fnptr->ty)>0&&(
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1461 car(cadr(fnptr->ty))==STRUCT ||
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1462 car(cadr(fnptr->ty))==UNION)) {
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1463 sz = size(cadr(fnptr->ty));
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1464 printf("\tlea %d(%%ebp),%s\n",-sz,register_name(dreg,0));
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1465 printf("\tmovl %d(%%ebp),%s\n",disp-size_of_int,
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1466 register_name(creg,0));
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1467 emit_copy(dreg,creg,sz,0,1,1);
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1468 } else if (cadr(fnptr->ty)!=VOID) {
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1469 use_register(creg,REG_EAX,0);
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1470 printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0));
d497c39add36 arg.c works (?)
kono
parents: 127
diff changeset
1471 }
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1472 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1473 fwddef(retlabel);
63
e13486b2c12e stack alignment
kono
parents: 62
diff changeset
1474
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1475 printf("\tlea %d(%%ebp),%%esp\n",disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1476 printf("\tpopl %%edi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1477 printf("\tpopl %%esi\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1478 printf("\tpopl %%ebx\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1479 printf("\tleave\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1480 printf("\tret\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1481 printf("\t.set _%d,%d\n",func_disp_label,disp+disp_offset);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1482 printf("_%d:\n",labelno);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1483 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1484 local_table();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1485 labelno++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1486 free_all_register();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1487 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1488
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1489
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1490 void
108
69e2e763cce5 object assemble first try.
kono
parents: 107
diff changeset
1491 code_set_fixed_creg(int mode,int type) {
69e2e763cce5 object assemble first try.
kono
parents: 107
diff changeset
1492 if (type==FLOAT||type==DOUBLE) {
69e2e763cce5 object assemble first try.
kono
parents: 107
diff changeset
1493 } else
69e2e763cce5 object assemble first try.
kono
parents: 107
diff changeset
1494 use_register(creg,REG_EAX,mode);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1495 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1496
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1497 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1498 code_set_return_register(int mode) {
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1499 if (fnptr->ty==DOUBLE||fnptr->ty==FLOAT) {
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1500 } else {
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1501 use_register(creg,REG_EAX,mode);
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1502 }
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1503 }
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1504
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1505 void
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1506 gen_gdecl(char *n, int gpc)
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 if (stmode!=STATIC)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1510 printf(".globl %s\n",n);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1511 */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1512 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1513
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1514 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1515 align(int t)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1516 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1517 if (t!=CHAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1518 if (data_alignment & 1)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1519 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1520 data_alignment = 0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1521 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1522 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1523
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1524 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1525 emit_data(int e, int t, NMTBL *n)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1526 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1527 int l;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1528 double d;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1529 float f;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1530 char *name;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1531 name = n->nm;
156
da529eab5618 static initialization
kono
parents: 147
diff changeset
1532 if(mode!=GDECL && mode!=STADECL) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1533 error(-1); return;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1534 }
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1535 if (chk) return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1536 if (n->dsp != -1) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1537 n->dsp = -1; /* initiallized flag */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1538 printf(".globl\t%s\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1539 data_mode(name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1540 align(t);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1541 printf("%s:\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1542 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1543 data_mode(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1544 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1545 if(car(e)==CONST) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1546 if (t==CHAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1547 printf("\t.byte %d\n",cadr(e));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1548 if (data_alignment>0)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1549 data_alignment++;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1550 gpc += 1;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1551 } else if (t==SHORT) {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1552 printf("\t.word %d\n",cadr(e));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1553 if (data_alignment>0) data_alignment++;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1554 gpc += 2;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1555 } else {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1556 printf("\t.long %d\n",cadr(e));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1557 gpc += size_of_int;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1558 }
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1559 } else if(t==DOUBLE) {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1560 d = dcadr(e);
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1561 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
1562 } else if(t==FLOAT) {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1563 f = dcadr(e);
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1564 printf("\t.long\t0x%x\n",*(int *)&f);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1565 } else if(t!=CHAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1566 gpc += size_of_int;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1567 if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
1568 printf("\t.long %s\n",((NMTBL *)cadr(cadr(e)))->nm);
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
1569 } else if(car(e)==GVAR) {
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
1570 printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1571 } else if(car(e)==FNAME) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1572 printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1573 } else if(car(e)==STRING) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1574 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1575 l = fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1576 printf("\t.long _%d\n",l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1577 printf(".section\t.rodata\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1578 printf("_%d:\n",l);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1579 output_mode = RODATA_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1580 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1581 ascii((char *)cadr(e));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1582 } else error(TYERR);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1583 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1584 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1585
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1586 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1587 emit_data_closing(NMTBL *n)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1588 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1589 int lb;
66
0b068058dd67 *** empty log message ***
kono
parents: 63
diff changeset
1590 if (chk) return;
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1591 if (mode==GDECL) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1592 data_mode(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1593 lb=fwdlabel();
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1594 printf("_%d:\n",lb);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1595 printf("\t.size\t%s,_%d-%s\n",n->nm,lb,n->nm);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1596 }
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 global_table(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1601 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1602 NMTBL *n;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1603 int init;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1604 init=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1605 for(n=ntable;n < &ntable[GSYMS];n++) {
117
2d5a203cc3a6 lvar reuse
kono
parents: 116
diff changeset
1606 if ((n->sc == GVAR||n->sc == STATIC) && n->dsp != -1) {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1607 /* n->dsp = -1 means initialized global */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1608 if (init==0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1609 data_mode(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1610 init=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1611 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1612 printf(".comm %s,%d\n",n->nm,size(n->ty));
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1613 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1614 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1615 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1616
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1617 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1618 local_table(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1619 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1620 NMTBL *n;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1621 int init;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1622 init=0;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1623 /* static local variables */
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1624 for(n=ntable+GSYMS;n < &ntable[GSYMS+LSYMS];n++) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1625 if (n->sc == GVAR) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1626 if (init==0) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1627 data_mode(0);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1628 init=1;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1629 }
156
da529eab5618 static initialization
kono
parents: 147
diff changeset
1630 if (n->dsp!= -1) /* -1 means initialized global */
da529eab5618 static initialization
kono
parents: 147
diff changeset
1631 printf(".lcomm %s,%d\n",n->nm,size(n->ty));
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1632 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1633 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1634 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1635
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1636 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1637 text_mode(void)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1638 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1639 if (output_mode!=TEXT_EMIT_MODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1640 printf(".text\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1641 printf("\t.align 2\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1642 output_mode = TEXT_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1643 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1644 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1645
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1646 void
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1647 data_mode(char *name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1648 {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1649 if (output_mode!=DATA_EMIT_MODE) {
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1650 printf(".data\n");
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1651 output_mode = DATA_EMIT_MODE;
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1652 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1653 if (name)
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1654 printf("\t.type\t%s,@object\n",name);
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1655 }
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1656
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1657 /* floating point */
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1658
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1659
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1660 char *
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1661 fstore(int d)
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1662 {
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1663 return use?
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1664 (d?"fstl":"fsts"):
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1665 (d?"fstpl":"fstps")
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1666 ;
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1667 }
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1668
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1669 char *
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1670 fstore_u(int d)
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1671 {
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1672 return d?"fstpl":"fstps";
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1673 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1674
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1675 char *
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1676 fload(int d)
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1677 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1678 return d?"fldl":"flds";
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1679 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1680
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1681
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1682 void code_dassign_gvar(int e2,int freg,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1683 {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
1684 printf("\t%s %s\n",fstore(d),((NMTBL*)cadr(e2))->nm);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1685 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1686
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1687 void code_dassign_lvar(int e2,int freg,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1688 {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1689 printf("\t%s %d(%%ebp)\n",fstore(d),lvar(e2));
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1690 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1691
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1692 void code_dassign_dregister(int e,int d,int freg)
111
7aa449aff3e6 floating point
kono
parents: 109
diff changeset
1693 {
7aa449aff3e6 floating point
kono
parents: 109
diff changeset
1694 error(-1);
7aa449aff3e6 floating point
kono
parents: 109
diff changeset
1695 }
7aa449aff3e6 floating point
kono
parents: 109
diff changeset
1696
103
f849af4b5ea9 *** empty log message ***
kono
parents: 102
diff changeset
1697 void code_dassign(int e2,int freg,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1698 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1699 printf("\t%s (%s)\n",fstore(d),register_name(e2,0));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1700 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1701
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1702 static double d0 = 1.0;
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1703
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1704 int
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1705 code_d1(double d)
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1706 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1707 int *i = (int *)&d0; int *j = (int *)&d;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1708 return (i[1] == 0x3ff00000)?j[0]:j[1];
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1709 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1710
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1711 int
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1712 code_d2(double d)
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1713 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1714 int *i = (int *)&d0; int *j = (int *)&d;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1715 return (i[1] == 0x3ff00000)?j[1]:j[0];
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1716 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1717
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1718 void code_dconst(int e2,int freg,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1719 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1720 int lb;
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1721 double value = dcadr(e2);
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1722
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1723 if (value==0.0) {
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1724 printf("\tfldz\n"); return;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1725 }
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1726 if (value==1.0) {
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1727 printf("\tfld1\n"); return;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1728 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1729 printf(" \t.section\t.rodata\n\t.align 8\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1730 lb=fwdlabel();
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1731 printf("_%d:\n",lb);
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1732 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
1733 if (output_mode==TEXT_EMIT_MODE) {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1734 printf(".text\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1735 } else {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1736 text_mode();
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1737 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1738 printf("\tfldl _%d\n",lb);
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1739 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1740
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1741 void code_dneg(int freg,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1742 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1743 printf("\tfchs\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1744 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1745
147
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
1746 void code_d2i(int freg)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1747 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1748 printf("\tlea -%d(%%esp),%%esp\n",size_of_int*2);
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1749 printf("\tfnstcw (%%esp)\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1750 printf("\tmovl (%%esp), %s\n",register_name(creg,0));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1751 printf("\tmovb $12, 1(%%esp)\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1752 printf("\tfldcw (%%esp)\n");
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1753 printf("\tfistpl %d(%%esp)\n",size_of_int);
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1754 printf("\tmovl %s, (%%esp)\n",register_name(creg,0));
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1755 printf("\tfldcw (%%esp)\n");
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1756 printf("\tpopl %s\n",register_name(creg,0));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1757 printf("\tpopl %s\n",register_name(creg,0));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1758 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1759
147
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
1760 void code_i2d(int creg)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1761 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1762 printf("\tpushl %s\n",register_name(creg,0));
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1763 printf("\tfildl (%%esp)\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1764 printf("\tlea %d(%%esp),%%esp\n",size_of_int);
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1765 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1766
147
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
1767 void code_d2u(int freg)
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1768 {
86
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
1769 printf("\tlea -%d(%%esp),%%esp\n",size_of_int*3);
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1770 printf("\tfnstcw (%%esp)\n");
3789aef7331d minor fix
kono
parents: 84
diff changeset
1771 printf("\tmovl (%%esp), %s\n",register_name(creg,0));
3789aef7331d minor fix
kono
parents: 84
diff changeset
1772 printf("\tmovb $12, 1(%%esp)\n");
3789aef7331d minor fix
kono
parents: 84
diff changeset
1773 printf("\tfldcw (%%esp)\n");
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1774 printf("\tmovl %s, (%%esp)\n",register_name(creg,0));
86
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
1775 printf("\tfistpll %d(%%esp)\n",size_of_int);
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1776 printf("\tfldcw (%%esp)\n");
86
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
1777 printf("\tmovl %d(%%esp),%s\n",size_of_int,register_name(creg,0));
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
1778 printf("\tlea %d(%%esp),%%esp\n",size_of_int*3);
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1779 }
3789aef7331d minor fix
kono
parents: 84
diff changeset
1780
147
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
1781 void code_u2d(int creg)
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1782 {
86
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
1783 printf("\tpushl %s\n",register_name(creg,0));
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
1784 printf("\tpushl %s\n",register_name(creg,0));
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
1785 printf("\tmovl $0, %d(%%esp)\n",size_of_int);
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
1786 printf("\tfildll (%%esp)\n");
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
1787 printf("\tlea %d(%%esp),%%esp\n",size_of_int*2);
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1788 }
3789aef7331d minor fix
kono
parents: 84
diff changeset
1789
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1790 void code_d2f(int freg) { }
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1791 void code_f2d(int freg) { }
147
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
1792 void code_f2i(int freg) { code_d2i(freg); }
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
1793 void code_f2u(int freg) { code_d2u(freg); }
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
1794 void code_i2f(int creg) { code_i2d(creg); }
cb7aa0089681 creg/ireg done for powerpc.
kono
parents: 144
diff changeset
1795 void code_u2f(int creg) { code_u2d(creg); }
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1796
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1797 void code_drgvar(int e2,int d,int freg)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1798 {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
1799 printf("\t%s %s\n",fload(d),((NMTBL*)cadr(e2))->nm);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1800 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1801
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1802
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1803 void code_drlvar(int e2,int d,int freg)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1804 {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1805 printf("\t%s %d(%%ebp)\n",fload(d),lvar(e2));
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1806 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1807
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1808 void code_cmp_drgvar(int e2,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1809 {
109
e09f9de6f5d3 *** empty log message ***
kono
parents: 108
diff changeset
1810 printf("\tfcomp %s\n",((NMTBL*)cadr(e2))->nm);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1811 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1812
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1813 void code_cmp_drlvar(int e2,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1814 {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1815 printf("\tfcomp %d(%%ebp)\n",lvar(e2));
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1816 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1817
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1818 void dtosop(int op,int e1)
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1819 {
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1820 switch(op) {
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1821 case FADD:
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1822 case DADD: printf("\tfaddp %%st,%%st(1)\n"); break;
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1823 case FSUB:
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1824 case DSUB: printf("\tfsubp %%st,%%st(1)\n"); break;
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1825 case FDIV:
85
3789aef7331d minor fix
kono
parents: 84
diff changeset
1826 case DDIV: printf("\tfdivp %%st,%%st(1)\n"); break;
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1827 case FMUL:
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1828 case DMUL: printf("\tfmulp %%st,%%st(1)\n"); break;
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1829 case FCMP:
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
1830 case DCMP:
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1831 printf("\tfucompp\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1832 printf("\tfnstsw\t%%ax\n");
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1833 break;
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1834 }
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1835 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1836
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1837 void
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1838 code_dassop(int op,int d) {
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1839 /* we have lvalue in creg, applied floating value is in %st(0) */
102
3cf2f8c120b9 *** empty log message ***
kono
parents: 99
diff changeset
1840 emit_dpop(d); /* do nothing for 387 */
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1841 printf("\t%s (%s)\n",fload(d),register_name(creg,0));
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1842 dtosop(op,0);
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1843 printf("\t%s (%s)\n",fstore(d),register_name(creg,0));
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1844 }
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1845
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1846 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1847 code_dpreinc(int e1,int e2,int d,int freg) {
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1848 g_expr(e2);
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1849 printf("\t%s (%s)\n",fload(d),register_name(creg,0));
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1850 printf("\tfld1\n");
87
1738f313f98b floating point (at most) done.
kono
parents: 86
diff changeset
1851 if (caddr(e1)>0)
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1852 printf("\tfaddp %%st,%%st(1)\n");
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1853 else
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1854 printf("\tfsubrp %%st,%%st(1)\n");
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1855 printf("\t%s (%s)\n",fstore(d),register_name(creg,0));
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1856 }
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1857
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1858 void
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1859 code_dpostinc(int e1,int e2,int d,int freg) {
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1860 g_expr(e2);
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1861 printf("\t%s (%s)\n",fload(d),register_name(creg,0));
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1862 if (use)
86
4d1275f8a5b5 *** empty log message ***
kono
parents: 85
diff changeset
1863 printf("\t%s (%s)\n",fload(d),register_name(creg,0));
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1864 printf("\tfld1\n");
87
1738f313f98b floating point (at most) done.
kono
parents: 86
diff changeset
1865 if (caddr(e1)>0)
83
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1866 printf("\tfaddp %%st,%%st(1)\n");
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1867 else
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1868 printf("\tfsubrp %%st,%%st(1)\n");
87
1738f313f98b floating point (at most) done.
kono
parents: 86
diff changeset
1869 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
1870 }
f3f75911d62c *** empty log message ***
kono
parents: 82
diff changeset
1871
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1872 void
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1873 drexpr(int e1, int e2,int l1, int op)
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1874 {
89
917947ffeb7c power pc version
kono
parents: 87
diff changeset
1875 g_expr(list3(DCMP,e1,e2));
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1876 switch(op) {
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1877 case DOP+GE:
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1878 case FOP+GE:
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1879 printf("\ttestb\t$5,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1880 printf("\tjne\t_%d\n",l1);
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1881 break;
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1882 case DOP+GT:
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1883 case FOP+GT:
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1884 printf("\ttestb\t$69,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1885 printf("\tjne\t_%d\n",l1);
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1886 break;
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1887 case DOP+EQ:
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1888 case FOP+EQ:
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1889 printf("\tandb\t$69,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1890 printf("\txorb\t$64,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1891 printf("\tjne\t_%d\n",l1);
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1892 break;
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1893 case DOP+NEQ:
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1894 case FOP+NEQ:
84
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1895 printf("\tandb\t$69,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1896 printf("\txorb\t$64,%%ah\n");
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1897 printf("\tje\t_%d\n",l1);
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1898 break;
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1899 }
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1900 }
1a723130a2c7 condtional
kono
parents: 83
diff changeset
1901
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1902 void
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1903 code_dregister(int e2,int freg,int d)
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1904 {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1905 error(-1);
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1906 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1907
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1908 void
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1909 code_cmp_dregister(int e2,int d)
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1910 {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1911 error(-1);
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1912 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1913
97
6d42fcac07af *** empty log message ***
kono
parents: 96
diff changeset
1914 int pop_fregister()
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1915 {
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1916 if (freg_sp<0) { error(-1); return -1;}
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1917 printf("# fpop: %d\n",freg_sp-1);
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1918 return freg_stack[--freg_sp];
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1919 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1920
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1921 int
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1922 emit_dpop(int d)
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1923 {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1924 int xreg;
97
6d42fcac07af *** empty log message ***
kono
parents: 96
diff changeset
1925 if ((xreg=pop_fregister())==-1) {
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1926 } else if (xreg<= -REG_LVAR_OFFSET) {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1927 code_drlvar(REG_LVAR_OFFSET+xreg,1,freg);
117
2d5a203cc3a6 lvar reuse
kono
parents: 116
diff changeset
1928 free_lvar(xreg+REG_LVAR_OFFSET);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1929 /* pushed order is reversed. We don't need this for comutable
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1930 operator, but it is ok to do this. */
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1931 printf("\tfxch\t%%st(1)\n");
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1932 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1933 return xreg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1934 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1935
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1936
138
e6e77af048a1 float/dobule configuration
kono
parents: 137
diff changeset
1937 void emit_dpop_free(int e1,int d)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1938 {
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1939 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1940
133
7d436c08e949 separate float / double flow
kono
parents: 128
diff changeset
1941 void emit_dpush(int type)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1942 {
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1943 if (freg_sp>=MAX_FPU_STACK) code_save_fstacks();
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1944 if (freg_sp>MAX_MAX) error(-1);
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1945 freg_stack[freg_sp++]=-1;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1946 printf("# fpush:%d\n",freg_sp);
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1947 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1948
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1949 void
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1950 code_save_stacks()
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1951 {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1952 /* temporal registers or stacks in fpu are saved in local variable */
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1953 int xreg,sp,screg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1954 sp=reg_sp;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1955 while(sp-->0) {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1956 if ((xreg=reg_stack[sp])>=0) {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1957 screg=creg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1958 if(creg!=xreg) {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1959 if (xreg!=dreg) free_register(xreg);
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1960 creg = xreg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1961 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1962 code_assign_lvar(
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1963 (reg_stack[sp]=new_lvar(size_of_int)),creg,0);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1964 reg_stack[sp]= reg_stack[sp]-REG_LVAR_OFFSET;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1965 regv[xreg]=0;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1966 creg=screg;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1967 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1968 }
107
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1969 code_save_fstacks();
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1970 }
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1971
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1972 void
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1973 code_save_fstacks()
06f72222d6b5 prevent destorying function argument (incomeplete)
kono
parents: 105
diff changeset
1974 {
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1975 int xreg,sp,uses;
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1976 uses = use; use = 0;
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1977 sp=freg_sp;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1978 while(sp-->0) {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1979 if ((xreg=freg_stack[sp])==-1) {
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1980 code_dassign_lvar(
119
b815fcd57b9d input var ( incomplete )
kono
parents: 118
diff changeset
1981 (freg_stack[sp]=new_lvar(size_of_double)),freg,1);
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1982 freg_stack[sp]= freg_stack[sp]-REG_LVAR_OFFSET;
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1983 }
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
1984 }
127
eb4d8975926c Intel float fix
kono
parents: 126
diff changeset
1985 use = uses;
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1986 }
81
f94ca1168520 float first try...
kono
parents: 78
diff changeset
1987
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents:
diff changeset
1988 /* end */