annotate mc-nop-386.c @ 40:060d1e549fec

*** empty log message ***
author kono
date Wed, 12 Feb 2003 04:45:53 +0900
parents c63c4fdeb9a7
children 886ca1f2cf15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1 /* Micro-C Code Generatation Part for intel386 */
1
0529f5abe9d0 *** empty log message ***
kono
parents: 0
diff changeset
2 /* $Id$ */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
3
d35df41eac69 Initial revision
kono
parents:
diff changeset
4 #define EXTERN extern
d35df41eac69 Initial revision
kono
parents:
diff changeset
5 #include "mc.h"
d35df41eac69 Initial revision
kono
parents:
diff changeset
6
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
7 extern int get_register_var(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
8 extern void bexpr(int e1, char cond, int l1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
9 extern void closing(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
10 extern void cmpdimm(int e, int csreg);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
11 extern void code_enter(char *name) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
12 extern void code_enter1(int disp0,int args);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
13 extern void code_init(void);
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
14 extern void code_leave(char *name,int disp) ;
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
15 extern void leave(int control,char *name,int disp0) ;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
16 extern void def_label(int cslabel, int dlabel) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
17 extern void emit_data(int e, int t, NMTBL *n);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
18 extern void emit_init(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
19 extern void enter(char *name) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
20 extern void enter1(int disp) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
21 extern void g_expr(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
22 extern void gen_comment(char *s);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
23 extern void gen_gdecl(char *n, int gpc) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
24 extern void gen_source(char *s);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
25 extern void gexpr(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
26 extern void jcond(int l, char cond);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
27 extern void jmp(int l);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
28 extern void opening(char *filename);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
29 extern void ret(void);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
30
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
31 static char *div_setup(int oreg) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
32 static int lvar(int l);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
33 static void jump(int e1, int env);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
34 static void data_mode(char *name);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
35 static void text_mode(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
36 static void assign(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
37 static void assop(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
38 static void b_expr(int e1, char cond, int l1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
39 static void emit_push(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
40 static void free_register(int i);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
41 static void function(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
42 static void global_table(void) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
43 /* static void indexy(char *op, char *gvar); */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
44 /* static void jmp_eq_label(int l); */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
45 /* static void jmp_label(int l); */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
46 static void ld_indexx(int byte, int n, int xreg);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
47 static void local_table(void) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
48 static void machinop(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
49 static void rexpr(int e1, int l1, char *s);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
50 static void rindirect(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
51 static void sassign(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
52 static void shift(char *op, int xreg) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
53 /* static void st_indexx(int byte, int n, int xreg); */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
54 static void string(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
55 static void tosop(int op);
26
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
56 static void div_cleanup(char *orn);
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
57 static void use_register(int virt, int real, int move);
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
58 static void emit_copy(int from,int to,int length,int offset);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
59
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
60 extern int error(int n);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
61 extern int fwdlabel(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
62 extern void fwddef(int l);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
63 extern int backdef(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
64 extern int size(int t);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
65 extern int list3(int e1, int e2, int e3);
2
kono
parents: 1
diff changeset
66 extern int scalar(int);
kono
parents: 1
diff changeset
67 extern int reverse0(int);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
68
d35df41eac69 Initial revision
kono
parents:
diff changeset
69 #define TEXT_EMIT_MODE 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
70 #define DATA_EMIT_MODE 1
d35df41eac69 Initial revision
kono
parents:
diff changeset
71 #define RODATA_EMIT_MODE 2
d35df41eac69 Initial revision
kono
parents:
diff changeset
72
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
73 static int output_mode = TEXT_EMIT_MODE;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
74 static int data_alignment = 0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
75
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
76 static int code_disp_label;
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
77 static int func_disp_label;
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
78
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
79 /*
d35df41eac69 Initial revision
kono
parents:
diff changeset
80 local1 <----24 local variable
d35df41eac69 Initial revision
kono
parents:
diff changeset
81 %esi -20 <- disp_offset
d35df41eac69 Initial revision
kono
parents:
diff changeset
82 %edi -16
d35df41eac69 Initial revision
kono
parents:
diff changeset
83 %edx -12
d35df41eac69 Initial revision
kono
parents:
diff changeset
84 %ecx -8
d35df41eac69 Initial revision
kono
parents:
diff changeset
85 %ebx -4
d35df41eac69 Initial revision
kono
parents:
diff changeset
86 %ebp = %esp 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
87 %eip 4 <- arg_offset
d35df41eac69 Initial revision
kono
parents:
diff changeset
88 arg1 8
d35df41eac69 Initial revision
kono
parents:
diff changeset
89 see enter/enter1/leave
d35df41eac69 Initial revision
kono
parents:
diff changeset
90 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
91 int arg_offset = 8;
6
bf602558130d continuation
kono
parents: 5
diff changeset
92 int code_arg_offset = -4;
3
kono
parents: 2
diff changeset
93 int disp_offset = -12;
kono
parents: 2
diff changeset
94 int func_disp_offset = -12;
kono
parents: 2
diff changeset
95 int code_disp_offset = -4;
kono
parents: 2
diff changeset
96 int size_of_int = 4;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
97 int endian = 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
98 int MAX_REGISTER=6; /* intel386のレジスタを4つまで使う*/
d35df41eac69 Initial revision
kono
parents:
diff changeset
99 int REAL_MAX_REGISTER=8; /* intel386のレジスタが8つということ*/
d35df41eac69 Initial revision
kono
parents:
diff changeset
100 int MAX_DATA_REG=4;
d35df41eac69 Initial revision
kono
parents:
diff changeset
101 int MAX_POINTER=3;
d35df41eac69 Initial revision
kono
parents:
diff changeset
102 int MAX_REGISTGER_VAR=2;
d35df41eac69 Initial revision
kono
parents:
diff changeset
103
d35df41eac69 Initial revision
kono
parents:
diff changeset
104 static int creg; /* current register */
d35df41eac69 Initial revision
kono
parents:
diff changeset
105 static int lreg; /* operand register */
d35df41eac69 Initial revision
kono
parents:
diff changeset
106 static int dreg; /* temporary register */
d35df41eac69 Initial revision
kono
parents:
diff changeset
107 static int reg_sp; /* REGister Stack-Pointer */
d35df41eac69 Initial revision
kono
parents:
diff changeset
108
d35df41eac69 Initial revision
kono
parents:
diff changeset
109
d35df41eac69 Initial revision
kono
parents:
diff changeset
110 #define REG_EAX 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
111 #define REG_EBX 1
d35df41eac69 Initial revision
kono
parents:
diff changeset
112 #define REG_ECX 2
d35df41eac69 Initial revision
kono
parents:
diff changeset
113 #define REG_EDX 3
d35df41eac69 Initial revision
kono
parents:
diff changeset
114 #define REG_ESI 4
d35df41eac69 Initial revision
kono
parents:
diff changeset
115 #define REG_EDI 5
d35df41eac69 Initial revision
kono
parents:
diff changeset
116 #define REG_EBP 6
d35df41eac69 Initial revision
kono
parents:
diff changeset
117 #define REG_ESP 7
d35df41eac69 Initial revision
kono
parents:
diff changeset
118
d35df41eac69 Initial revision
kono
parents:
diff changeset
119
d35df41eac69 Initial revision
kono
parents:
diff changeset
120 #define DATA_REG 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
121 #define POINTER_REG 3
d35df41eac69 Initial revision
kono
parents:
diff changeset
122 static char *reg_name[8];
d35df41eac69 Initial revision
kono
parents:
diff changeset
123 static char *reg_name_l[4];
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
124 static char *reg_name_w[4];
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
125
d35df41eac69 Initial revision
kono
parents:
diff changeset
126 /*
d35df41eac69 Initial revision
kono
parents:
diff changeset
127 creg currrent virtual register
d35df41eac69 Initial revision
kono
parents:
diff changeset
128 lreg operand virtual register
d35df41eac69 Initial revision
kono
parents:
diff changeset
129 dreg spare virtual register
d35df41eac69 Initial revision
kono
parents:
diff changeset
130
d35df41eac69 Initial revision
kono
parents:
diff changeset
131 rname[creg] currrent real register
d35df41eac69 Initial revision
kono
parents:
diff changeset
132 rname[lreg] operand real register
d35df41eac69 Initial revision
kono
parents:
diff changeset
133 rname[dreg] spare real register
d35df41eac69 Initial revision
kono
parents:
diff changeset
134
d35df41eac69 Initial revision
kono
parents:
diff changeset
135 regs[] virtual register usage
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
136 regv[] value in virtual register flag
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
137
d35df41eac69 Initial revision
kono
parents:
diff changeset
138 reg_name[rname[creg]]
d35df41eac69 Initial revision
kono
parents:
diff changeset
139 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
140
d35df41eac69 Initial revision
kono
parents:
diff changeset
141 #define MAX_MAX 10
d35df41eac69 Initial revision
kono
parents:
diff changeset
142 static int rname[MAX_MAX];
d35df41eac69 Initial revision
kono
parents:
diff changeset
143 static int regs[MAX_MAX]; /* 使われているレジスタを示すフラグ */
d35df41eac69 Initial revision
kono
parents:
diff changeset
144 static int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
145 static int regv[MAX_MAX]; /* 値が入っているかどうか */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
146
d35df41eac69 Initial revision
kono
parents:
diff changeset
147 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
148 code_init(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
149 {
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
150 arg_offset = 8;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
151 func_disp_offset = -12;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
152 disp_offset = -12;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
153 size_of_int = 4;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
154 endian = 0;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
155 MAX_REGISTER=6;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
156 MAX_DATA_REG=4;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
157 MAX_POINTER=3;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
158 MAX_REGISTER_VAR=2;
d35df41eac69 Initial revision
kono
parents:
diff changeset
159
d35df41eac69 Initial revision
kono
parents:
diff changeset
160 reg_name[REG_EAX] = "%eax";
d35df41eac69 Initial revision
kono
parents:
diff changeset
161 reg_name[REG_EBX] = "%ebx";
d35df41eac69 Initial revision
kono
parents:
diff changeset
162 reg_name[REG_ECX] = "%ecx";
d35df41eac69 Initial revision
kono
parents:
diff changeset
163 reg_name[REG_EDX] = "%edx";
d35df41eac69 Initial revision
kono
parents:
diff changeset
164 reg_name[REG_ESI] = "%esi";
d35df41eac69 Initial revision
kono
parents:
diff changeset
165 reg_name[REG_EDI] = "%edi";
d35df41eac69 Initial revision
kono
parents:
diff changeset
166 reg_name[REG_EBP] = "%ebp";
d35df41eac69 Initial revision
kono
parents:
diff changeset
167 reg_name[REG_ESP] = "%esp";
d35df41eac69 Initial revision
kono
parents:
diff changeset
168 reg_name_l[REG_EAX] = "%al";
d35df41eac69 Initial revision
kono
parents:
diff changeset
169 reg_name_l[REG_EBX] = "%bl";
d35df41eac69 Initial revision
kono
parents:
diff changeset
170 reg_name_l[REG_ECX] = "%cl";
d35df41eac69 Initial revision
kono
parents:
diff changeset
171 reg_name_l[REG_EDX] = "%dl";
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
172 reg_name_w[REG_EAX] = "%ax";
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
173 reg_name_w[REG_EBX] = "%bx";
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
174 reg_name_w[REG_ECX] = "%cx";
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
175 reg_name_w[REG_EDX] = "%dx";
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
176
d35df41eac69 Initial revision
kono
parents:
diff changeset
177 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
178
d35df41eac69 Initial revision
kono
parents:
diff changeset
179 char *
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
180 register_name(int i,int byte)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
181 {
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
182 if (i<0) {
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
183 error(REG_ERR);
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
184 return "%eax";
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
185 }
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
186 if (byte && rname[i] <= REG_EDX) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
187 return reg_name_l[rname[i]];
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
188 } else {
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
189 return reg_name[rname[i]]; /* should be error */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
190 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
191 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
192
d35df41eac69 Initial revision
kono
parents:
diff changeset
193 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
194 get_register(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
195 { /* 使われていないレジスタを調べる */
d35df41eac69 Initial revision
kono
parents:
diff changeset
196 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
197 for(i=0;i<MAX_REGISTER;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
198 if (! regs[i]) { /* 使われていないなら */
d35df41eac69 Initial revision
kono
parents:
diff changeset
199 regs[i]=1; /* そのレジスタを使うことを宣言し */
d35df41eac69 Initial revision
kono
parents:
diff changeset
200 return i; /* その場所を表す番号を返す */
d35df41eac69 Initial revision
kono
parents:
diff changeset
201 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
202 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
203 return -1; /* 空いている場所がないなら、それを表す -1 を返す */
d35df41eac69 Initial revision
kono
parents:
diff changeset
204 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
205
d35df41eac69 Initial revision
kono
parents:
diff changeset
206 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
207 free_register(int i) { /* いらなくなったレジスタを開放 */
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
208 regv[i]=regs[i]=0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
209 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
210
d35df41eac69 Initial revision
kono
parents:
diff changeset
211 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
212 register_full(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
213 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
214 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
215 for(i=0;i<MAX_REGISTER;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
216 if (! regs[i]) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
217 return 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
218 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
219 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
220 return 1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
221 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
222
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
223 static
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
224 int
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
225 free_register_count(void)
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
226 {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
227 int i,count;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
228 count = 0;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
229 for(i=0;i<MAX_REGISTER;i++) {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
230 if (! regs[i]) count++;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
231 }
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
232 return count;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
233 }
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
234
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
235 void
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
236 use_register_var(int i) {
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
237 regv[i]=1;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
238 }
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
239
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
240 static int creg_regvar = -1;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
241 static int creg_regvar_back;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
242 static int creg_back;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
243
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
244 void
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
245 creg_destroy() {
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
246 creg_back = creg; creg_regvar_back = creg_regvar;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
247 if (creg_regvar>=0)
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
248 creg = creg_regvar;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
249 creg_regvar=-1;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
250 }
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
251
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
252 void
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
253 creg_un_destroy() {
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
254 creg = creg_back; creg_regvar = creg_regvar_back;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
255 }
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
256
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
257
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
258 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
259 gexpr_init(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
260 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
261 while(reg_sp > 0) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
262 free_register(reg_stack[--reg_sp]);
d35df41eac69 Initial revision
kono
parents:
diff changeset
263 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
264 text_mode();
26
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
265 use_register(creg,REG_EAX,0);
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
266 /* use_register(dreg,REG_EDX,0); */
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
267 creg_regvar = -1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
268 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
269
d35df41eac69 Initial revision
kono
parents:
diff changeset
270 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
271 emit_init(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
272 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
273 int i;
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
274 for(i=0;i<REAL_MAX_REGISTER;i++) { regs[i]=0; regv[i]=0;rname[i]=i;}
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
275 creg = get_register(); /* must be EAX */
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
276 dreg = get_register(); /* must be EBX */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
277 reg_sp = 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
278 text_mode();
d35df41eac69 Initial revision
kono
parents:
diff changeset
279 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
280
d35df41eac69 Initial revision
kono
parents:
diff changeset
281 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
282 virtual(int real)
d35df41eac69 Initial revision
kono
parents:
diff changeset
283 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
284 int real_v,i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
285 real_v = -1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
286 for(i=0;i<MAX_REGISTER;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
287 if (rname[i]==real) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
288 real_v=i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
289 break;
d35df41eac69 Initial revision
kono
parents:
diff changeset
290 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
291 }
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
292 /* if (real_v == -1)
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
293 error(-1); */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
294 return real_v;
d35df41eac69 Initial revision
kono
parents:
diff changeset
295 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
296
d35df41eac69 Initial revision
kono
parents:
diff changeset
297 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
298 use_register(int virt, int real, int move)
d35df41eac69 Initial revision
kono
parents:
diff changeset
299 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
300 int real_v;
d35df41eac69 Initial revision
kono
parents:
diff changeset
301 char *move_op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
302 if (rname[virt]==real)
d35df41eac69 Initial revision
kono
parents:
diff changeset
303 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
304 real_v = virtual(real);
d35df41eac69 Initial revision
kono
parents:
diff changeset
305 move_op = regs[real_v]?"\txchg %s,%s\n":"\tmovl %s,%s\n";
d35df41eac69 Initial revision
kono
parents:
diff changeset
306 if (move || regs[real_v]) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
307 printf(move_op,reg_name[rname[virt]],reg_name[real]);
d35df41eac69 Initial revision
kono
parents:
diff changeset
308 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
309 rname[real_v] = rname[virt];
d35df41eac69 Initial revision
kono
parents:
diff changeset
310 rname[virt] = real;
d35df41eac69 Initial revision
kono
parents:
diff changeset
311 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
312
d35df41eac69 Initial revision
kono
parents:
diff changeset
313 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
314 use_pointer(int virt, int move)
d35df41eac69 Initial revision
kono
parents:
diff changeset
315 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
316 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
317 if (rname[virt]>=POINTER_REG)
d35df41eac69 Initial revision
kono
parents:
diff changeset
318 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
319 for(i=POINTER_REG;i<MAX_REGISTER;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
320 if (!regs[virtual(i)]) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
321 use_register(virt,i,move);
d35df41eac69 Initial revision
kono
parents:
diff changeset
322 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
323 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
324 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
325 /* we prefer EBX */
d35df41eac69 Initial revision
kono
parents:
diff changeset
326 use_register(virt,REG_EBX,move);
d35df41eac69 Initial revision
kono
parents:
diff changeset
327 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
328
d35df41eac69 Initial revision
kono
parents:
diff changeset
329 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
330 use_data_reg(int virt, int move)
d35df41eac69 Initial revision
kono
parents:
diff changeset
331 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
332 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
333 if (rname[virt]<MAX_DATA_REG)
d35df41eac69 Initial revision
kono
parents:
diff changeset
334 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
335 for(i=0;i<MAX_DATA_REG;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
336 if (!regs[virtual(i)]) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
337 use_register(virt,i,move);
d35df41eac69 Initial revision
kono
parents:
diff changeset
338 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
339 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
340 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
341 /* we prefer EBX */
d35df41eac69 Initial revision
kono
parents:
diff changeset
342 use_register(virt,REG_EBX,move);
d35df41eac69 Initial revision
kono
parents:
diff changeset
343 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
344
d35df41eac69 Initial revision
kono
parents:
diff changeset
345 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
346 pop_register(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
347 { /* レジスタから値を取り出す */
d35df41eac69 Initial revision
kono
parents:
diff changeset
348 int i,j;
d35df41eac69 Initial revision
kono
parents:
diff changeset
349
d35df41eac69 Initial revision
kono
parents:
diff changeset
350 j = creg;
d35df41eac69 Initial revision
kono
parents:
diff changeset
351 i = reg_stack[--reg_sp];
d35df41eac69 Initial revision
kono
parents:
diff changeset
352
d35df41eac69 Initial revision
kono
parents:
diff changeset
353 if(i<0) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
354 return i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
355 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
356 free_register(i);
d35df41eac69 Initial revision
kono
parents:
diff changeset
357 lreg = i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
358 regs[i]=0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
359 return lreg;
d35df41eac69 Initial revision
kono
parents:
diff changeset
360 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
361 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
362
d35df41eac69 Initial revision
kono
parents:
diff changeset
363 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
364 stack_used(void) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
365 return reg_stack[--reg_sp]<0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
366 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
367
d35df41eac69 Initial revision
kono
parents:
diff changeset
368 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
369 emit_push(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
370 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
371 int new_reg;
d35df41eac69 Initial revision
kono
parents:
diff changeset
372 new_reg = get_register();
d35df41eac69 Initial revision
kono
parents:
diff changeset
373 if(new_reg<0) { /* もうレジスタがない */
d35df41eac69 Initial revision
kono
parents:
diff changeset
374 reg_stack[reg_sp++] = -1;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
375 printf("\tpushl %s\n",register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
376 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
377 reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
378 creg = new_reg;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
379 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
380 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
381
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
382 int
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
383 emit_pop(int type)
d35df41eac69 Initial revision
kono
parents:
diff changeset
384 {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
385 int xreg;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
386 if (pop_register()==-1) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
387 if (type==POINTER_REG)
d35df41eac69 Initial revision
kono
parents:
diff changeset
388 use_pointer(dreg,0);
d35df41eac69 Initial revision
kono
parents:
diff changeset
389 else if (type==DATA_REG)
d35df41eac69 Initial revision
kono
parents:
diff changeset
390 use_data_reg(dreg,0);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
391 printf("\tpopl %s\n",register_name(dreg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
392 xreg = dreg;
d35df41eac69 Initial revision
kono
parents:
diff changeset
393 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
394 xreg = lreg;
d35df41eac69 Initial revision
kono
parents:
diff changeset
395 }
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
396 return xreg;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
397 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
398
d35df41eac69 Initial revision
kono
parents:
diff changeset
399 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
400 get_register_var(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
401 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
402 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
403 for(i=REG_ESI;i<REG_ESP;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
404 if (! regs[i]) { /* 使われていないなら */
d35df41eac69 Initial revision
kono
parents:
diff changeset
405 regs[i]=1; /* そのレジスタを使うことを宣言し */
d35df41eac69 Initial revision
kono
parents:
diff changeset
406 return i; /* その場所を表す番号を返す */
d35df41eac69 Initial revision
kono
parents:
diff changeset
407 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
408 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
409 return -1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
410 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
411
d35df41eac69 Initial revision
kono
parents:
diff changeset
412 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
413 gexpr(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
414 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
415 gexpr_init();
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
416 #if 0
32
b35787d8a442 macro initialization
kono
parents: 27
diff changeset
417 if(lineno==2862) {
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
418 g_expr(e1); /*break here*/
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
419 csvalue = rname[creg]; /* for siwtch value */
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
420 return;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
421 }
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
422 #endif
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
423 g_expr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
424 csvalue = rname[creg]; /* for siwtch value */
d35df41eac69 Initial revision
kono
parents:
diff changeset
425 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
426
d35df41eac69 Initial revision
kono
parents:
diff changeset
427 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
428 g_expr(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
429 {
22
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
430 int e2,e3/*,e4*/;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
431 char *xrn;
d35df41eac69 Initial revision
kono
parents:
diff changeset
432 NMTBL *n;
d35df41eac69 Initial revision
kono
parents:
diff changeset
433
d35df41eac69 Initial revision
kono
parents:
diff changeset
434 if (chk) return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
435 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
436 switch (car(e1)){
d35df41eac69 Initial revision
kono
parents:
diff changeset
437 case GVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
438 /* use_pointer(creg,0); */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
439 printf("\tmovl $%s,%s\n",(char *)caddr(e1),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
440 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
441 case RGVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
442 /* use_pointer(creg,0); */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
443 printf("\tmovl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
444 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
445 case CRGVAR:
27
af0c69eaa433 *** empty log message ***
kono
parents: 26
diff changeset
446 printf("\tmovsbl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
447 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
448 case LVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
449 /* use_pointer(creg,0); */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
450 printf("\tlea %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
451 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
452 case REGISTER:
d35df41eac69 Initial revision
kono
parents:
diff changeset
453 /* this is of course redundant... */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
454 /* we can use rname for this? */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
455 /* or why not creg=e2? */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
456 printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
457 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
458 case RLVAR:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
459 printf("\tmovl %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
460 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
461 case CRLVAR:
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
462 printf("\tmovsbl %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
463 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
464 case FNAME:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
465 printf("\tmovl $%s,%s\n",((NMTBL *)e2)->nm,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
466 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
467 case CONST: /* 代入する値が0でも特別な処理はしない */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
468 printf("\tmovl $%d,%s\n",e2,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
469 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
470 case STRING:
d35df41eac69 Initial revision
kono
parents:
diff changeset
471 string(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
472 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
473 case FUNCTION:
d35df41eac69 Initial revision
kono
parents:
diff changeset
474 function(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
475 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
476 case CODE:
d35df41eac69 Initial revision
kono
parents:
diff changeset
477 jump(e2,caddr(e1));
d35df41eac69 Initial revision
kono
parents:
diff changeset
478 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
479 case INDIRECT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
480 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
481 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
482 case RINDIRECT: case CRINDIRECT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
483 rindirect(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
484 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
485 case ADDRESS:
d35df41eac69 Initial revision
kono
parents:
diff changeset
486 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
487 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
488 case MINUS: /* レジスタに対し、neglを実行すれば実現可能 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
489 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
490 /* use_data_reg(creg,1); */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
491 printf("\tnegl %s\n", register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
492 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
493 case BNOT: /* ~ */
d35df41eac69 Initial revision
kono
parents:
diff changeset
494 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
495 /* use_data_reg(creg,1); */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
496 printf("\tnotl %s\n", register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
497 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
498 case LNOT: /* ! */
d35df41eac69 Initial revision
kono
parents:
diff changeset
499 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
500 use_data_reg(creg,1);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
501 xrn = register_name(creg,1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
502 printf("\tcmpl $0,%s\n", register_name(creg,0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
503 printf("\tsete %s\n", xrn);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
504 printf("\tmovzbl %s,%s\n", xrn,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
505 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
506 case PREINC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
507 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
508 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
509 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
510 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
511 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
512 g_expr(e2);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
513 xrn = register_name(creg,0);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
514 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
515 printf("\tmovl (%s),%s\n",xrn,xrn);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
516 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
517 case POSTINC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
518 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
519 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
520 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
521 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
522 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
523 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
524 emit_push();
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
525 /* in case of register full we should copy creg to dreg */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
526 xrn = register_name(emit_pop(0),0);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
527 printf("\tmovl (%s),%s\n",xrn,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
528 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
529 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
530 case CPOSTINC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
531 /* char *p; *p++ */
d35df41eac69 Initial revision
kono
parents:
diff changeset
532 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
533 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
534 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
535 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
536 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
537 g_expr(e2);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
538 emit_push(); /* in case of register full we should copy creg to dreg */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
539 xrn = register_name(emit_pop(0),1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
540 printf("\tmovsbl (%s),%s\n",xrn,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
541 printf("\tincl (%s)\n",xrn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
542 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
543 case CPREINC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
544 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
545 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
546 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
547 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
548 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
549 g_expr(e2);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
550 printf("\tincl (%s)\n",register_name(creg,0));
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
551 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
552 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
553 case CPOSTDEC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
554 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
555 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
556 printf("\tdecl %s\n",register_name(cadr(e2),0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
557 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
558 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
559 g_expr(e2);
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
560 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
561 printf("\tdecl (%s)\n",register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
562 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
563 case CPREDEC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
564 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
565 printf("\tdecl %s\n",register_name(cadr(e2),0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
566 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
567 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
568 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
569 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
570 emit_push();
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
571 e2 = emit_pop(0);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
572 printf("\tdecl (%s)\n",register_name(e2,0));
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
573 printf("\tmovsbl (%s),%s\n",register_name(e2,0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
574 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
575 case MUL: case UMUL:
d35df41eac69 Initial revision
kono
parents:
diff changeset
576 case DIV: case UDIV:
d35df41eac69 Initial revision
kono
parents:
diff changeset
577 case MOD: case UMOD:
d35df41eac69 Initial revision
kono
parents:
diff changeset
578 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
579 case ADD: case SUB: case BAND: case EOR: case BOR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
580 machinop(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
581 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
582 case COND:
d35df41eac69 Initial revision
kono
parents:
diff changeset
583 e2=fwdlabel();
d35df41eac69 Initial revision
kono
parents:
diff changeset
584 b_expr(cadr(e1),0,e2);
22
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
585 use_register(creg,REG_EAX,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
586 g_expr(caddr(e1));
22
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
587 /* e4 = rname[creg]; this is a bad idea */
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
588 use_register(creg,REG_EAX,1);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
589 jmp(e3=fwdlabel());
d35df41eac69 Initial revision
kono
parents:
diff changeset
590 fwddef(e2);
22
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
591 use_register(creg,REG_EAX,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
592 g_expr(cadddr(e1));
22
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
593 /* use_register(creg,e4,1); */
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
594 use_register(creg,REG_EAX,1);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
595 fwddef(e3);
d35df41eac69 Initial revision
kono
parents:
diff changeset
596 return;
37
412ad2e6c2a2 struct copy
kono
parents: 36
diff changeset
597 case RSTRUCT:
412ad2e6c2a2 struct copy
kono
parents: 36
diff changeset
598 g_expr(e2);
412ad2e6c2a2 struct copy
kono
parents: 36
diff changeset
599 return;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
600 case SASS:
d35df41eac69 Initial revision
kono
parents:
diff changeset
601 sassign(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
602 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
603 case ASS: case CASS:
d35df41eac69 Initial revision
kono
parents:
diff changeset
604 assign(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
605 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
606 case ASSOP: case CASSOP:
d35df41eac69 Initial revision
kono
parents:
diff changeset
607 assop(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
608 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
609 case COMMA:
d35df41eac69 Initial revision
kono
parents:
diff changeset
610 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
611 g_expr(caddr(e1));
d35df41eac69 Initial revision
kono
parents:
diff changeset
612 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
613 case RETURN:
d35df41eac69 Initial revision
kono
parents:
diff changeset
614 n = (NMTBL *)e2;
d35df41eac69 Initial revision
kono
parents:
diff changeset
615 if (retcont==0)
d35df41eac69 Initial revision
kono
parents:
diff changeset
616 retcont=fwdlabel();
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
617 printf("\tleal _%d,%s\n",retcont,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
618 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
619 case ENVIRONMENT:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
620 printf("\tmovl %%ebp,%s\n",register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
621 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
622 default:
d35df41eac69 Initial revision
kono
parents:
diff changeset
623 b_expr(e1,1,e2=fwdlabel()); /* including > < ... */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
624 xrn = register_name(creg,0);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
625 printf("\txorl %s,%s\n",xrn,xrn);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
626 jmp(e3=fwdlabel());
d35df41eac69 Initial revision
kono
parents:
diff changeset
627 fwddef(e2);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
628 printf("\tmovl $1,%s\n",xrn);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
629 fwddef(e3);
d35df41eac69 Initial revision
kono
parents:
diff changeset
630 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
631 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
632
d35df41eac69 Initial revision
kono
parents:
diff changeset
633 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
634 bexpr(int e1, char cond, int l1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
635 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
636 gexpr_init();
d35df41eac69 Initial revision
kono
parents:
diff changeset
637 b_expr(e1,cond,l1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
638 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
639
d35df41eac69 Initial revision
kono
parents:
diff changeset
640 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
641 b_expr(int e1, char cond, int l1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
642 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
643 int e2,l2;
d35df41eac69 Initial revision
kono
parents:
diff changeset
644 if (chk) return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
645 e2=cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
646 switch(car(e1)) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
647 case LNOT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
648 b_expr(e2,!cond,l1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
649 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
650 case GT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
651 rexpr(e1,l1,cond?"g":"le");
d35df41eac69 Initial revision
kono
parents:
diff changeset
652 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
653 case UGT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
654 rexpr(e1,l1,cond?"a":"be");
d35df41eac69 Initial revision
kono
parents:
diff changeset
655 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
656 case GE:
d35df41eac69 Initial revision
kono
parents:
diff changeset
657 rexpr(e1,l1,cond?"ge":"l");
d35df41eac69 Initial revision
kono
parents:
diff changeset
658 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
659 case UGE:
d35df41eac69 Initial revision
kono
parents:
diff changeset
660 rexpr(e1,l1,cond?"ae":"b");
d35df41eac69 Initial revision
kono
parents:
diff changeset
661 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
662 case LT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
663 rexpr(e1,l1,cond?"l":"ge");
d35df41eac69 Initial revision
kono
parents:
diff changeset
664 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
665 case ULT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
666 rexpr(e1,l1,cond?"b":"ae");
d35df41eac69 Initial revision
kono
parents:
diff changeset
667 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
668 case LE:
d35df41eac69 Initial revision
kono
parents:
diff changeset
669 rexpr(e1,l1,cond?"le":"g");
d35df41eac69 Initial revision
kono
parents:
diff changeset
670 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
671 case ULE:
d35df41eac69 Initial revision
kono
parents:
diff changeset
672 rexpr(e1,l1,cond?"be":"a");
d35df41eac69 Initial revision
kono
parents:
diff changeset
673 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
674 case EQ:
d35df41eac69 Initial revision
kono
parents:
diff changeset
675 rexpr(e1,l1,cond?"e":"ne");
d35df41eac69 Initial revision
kono
parents:
diff changeset
676 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
677 case NEQ:
d35df41eac69 Initial revision
kono
parents:
diff changeset
678 rexpr(e1,l1,cond?"ne":"e");
d35df41eac69 Initial revision
kono
parents:
diff changeset
679 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
680 case LAND:
d35df41eac69 Initial revision
kono
parents:
diff changeset
681 b_expr(e2,0,cond?(l2=fwdlabel()):l1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
682 b_expr(caddr(e1),cond,l1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
683 if(cond) fwddef(l2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
684 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
685 case LOR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
686 b_expr(e2,1,cond?l1:(l2=fwdlabel()));
d35df41eac69 Initial revision
kono
parents:
diff changeset
687 b_expr(caddr(e1),cond,l1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
688 if(!cond) fwddef(l2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
689 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
690 case CRGVAR:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
691 printf("\tcmpb $0,%s\n",(char *)caddr(e1));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
692 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
693 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
694 case CRLVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
695 printf("\tcmpb $0,%d(%%ebp)\n",lvar(e2));
d35df41eac69 Initial revision
kono
parents:
diff changeset
696 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
697 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
698 case RGVAR:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
699 printf("\tcmpl $0,%s\n",(char *)caddr(e1));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
700 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
701 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
702 case RLVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
703 printf("\tcmpl $0,%d(%%ebp)\n",lvar(e2));
d35df41eac69 Initial revision
kono
parents:
diff changeset
704 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
705 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
706 case REGISTER:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
707 printf("\tcmpl $0,%s\n",register_name(e2,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
708 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
709 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
710 case CONST:
d35df41eac69 Initial revision
kono
parents:
diff changeset
711 if((cond&&e2)||(!cond&&!e2)) jmp(l1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
712 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
713 default:
d35df41eac69 Initial revision
kono
parents:
diff changeset
714 g_expr(e1);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
715 printf("\tcmpl $0,%s\n",register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
716 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
717 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
718 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
719 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
720
d35df41eac69 Initial revision
kono
parents:
diff changeset
721 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
722 ascii(char *s)
d35df41eac69 Initial revision
kono
parents:
diff changeset
723 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
724 printf("\t.string \"");
d35df41eac69 Initial revision
kono
parents:
diff changeset
725 while(*s) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
726 if (*s=='\n')
d35df41eac69 Initial revision
kono
parents:
diff changeset
727 printf("%cn",92);
d35df41eac69 Initial revision
kono
parents:
diff changeset
728 else if (*s<' ')
d35df41eac69 Initial revision
kono
parents:
diff changeset
729 printf("%c%03o",92,*s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
730 else if (*s==34)
d35df41eac69 Initial revision
kono
parents:
diff changeset
731 printf("%c%c",92,34);
d35df41eac69 Initial revision
kono
parents:
diff changeset
732 else
d35df41eac69 Initial revision
kono
parents:
diff changeset
733 printf("%c",*s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
734 s++;
d35df41eac69 Initial revision
kono
parents:
diff changeset
735 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
736 printf("%c\n",34);
d35df41eac69 Initial revision
kono
parents:
diff changeset
737 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
738
d35df41eac69 Initial revision
kono
parents:
diff changeset
739 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
740 string(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
741 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
742 char *s;
d35df41eac69 Initial revision
kono
parents:
diff changeset
743 int i,lb;
d35df41eac69 Initial revision
kono
parents:
diff changeset
744
d35df41eac69 Initial revision
kono
parents:
diff changeset
745 if (0) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
746 s=(char *)cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
747 lb=fwdlabel();
d35df41eac69 Initial revision
kono
parents:
diff changeset
748 printf("\tjmp _%d\n",lb);
d35df41eac69 Initial revision
kono
parents:
diff changeset
749 i=backdef();
d35df41eac69 Initial revision
kono
parents:
diff changeset
750 ascii(s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
751 printf("\t.align 2\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
752 fwddef(lb);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
753 printf("\tlea _%d,%s\n",i,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
754 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
755 s=(char *)cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
756 printf(".section\t.rodata\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
757 lb=fwdlabel();
d35df41eac69 Initial revision
kono
parents:
diff changeset
758 printf("_%d:\n",lb);
d35df41eac69 Initial revision
kono
parents:
diff changeset
759 ascii(s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
760 if (output_mode==TEXT_EMIT_MODE) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
761 printf(".text\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
762 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
763 text_mode();
d35df41eac69 Initial revision
kono
parents:
diff changeset
764 }
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
765 printf("\tlea _%d,%s\n",lb,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
766 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
767 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
768
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
769 #define MAX_COPY_LEN 20
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
770
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
771 void
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
772 emit_copy(int from,int to,int length,int offset)
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
773 {
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
774 int fix = 0;
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
775 if (length<=0) return;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
776 switch (length) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
777 case 0: break;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
778 case 1:
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
779 printf("\tmovb %d(%s),%s\n",offset,register_name(from,0), reg_name_l[rname[dreg]] );
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
780 printf("\tmovb %s,%d(%s)\n",reg_name_l[rname[dreg]] ,offset,register_name(to,0));
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
781 break;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
782 case 2:
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
783 printf("\tmovw %d(%s),%s\n",offset,register_name(from,0), reg_name_w[rname[dreg]] );
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
784 printf("\tmovw %s,%d(%s)\n",reg_name_w[rname[dreg]] ,offset,register_name(to,0));
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
785 break;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
786 case 4:
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
787 printf("\tmovl %d(%s),%s\n",offset,register_name(from,0), register_name(dreg,0));
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
788 printf("\tmovl %s,%d(%s)\n",register_name(dreg,0), offset,register_name(to,0));
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
789 break;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
790 default:
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
791 if (length <=MAX_COPY_LEN) {
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
792 for(;length>=4;length-=4,offset+=4)
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
793 emit_copy(from,to,4,offset);
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
794 for(;length>=2;length-=2,offset+=2)
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
795 emit_copy(from,to,2,offset);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
796 if(length>0)
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
797 emit_copy(from,to,length,offset);
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
798 break;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
799 }
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
800 use_register(from,REG_ESI,1);
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
801 use_register(to, REG_EDI,1);
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
802 use_register(dreg,REG_ECX,0);
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
803 printf("\tmovl $%d,%%ecx\n",length/4);
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
804 fix = (length/4)*4;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
805 printf("\tcld\n\trep\n\tmovsl\n");
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
806 if(length%4) {
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
807 emit_copy(from,to,length,offset+length/4);
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
808 }
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
809 }
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
810 /* this code is necessary for the value of assignment or function call */
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
811 /* otherwise we don't need this */
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
812 if (fix) printf("\tsubl $%d,%s\n",fix,register_name(to,0));
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
813 if(creg!=to) {
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
814 free_register(creg); creg=to;
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
815 }
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
816 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
817
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
818 int
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
819 struct_push(int e4,int t)
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
820 {
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
821 int length,xreg,save;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
822 g_expr(e4);
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
823 length=size(t);
77c0710a8729 struct copy
kono
parents: 13
diff changeset
824 if(length%size_of_int) {
77c0710a8729 struct copy
kono
parents: 13
diff changeset
825 length += size_of_int - (length%size_of_int);
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
826 }
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
827 if (length==4) {
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
828 printf("\tpushl (%s)\n",register_name(creg,0)); return 1;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
829 }
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
830 if (length==8) {
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
831 printf("\tpushl 4(%s)\n",register_name(creg,0));
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
832 printf("\tpushl (%s)\n",register_name(creg,0)); return 2;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
833 }
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
834 /* I think, after g_expr, at least two registers are free */
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
835 printf("\tsubl $%d,%%esp\n",length);
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
836 if (register_full()) {
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
837 /* this is wrong assumption */
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
838 save = 1;
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
839 printf("\tpushl %s\n",register_name(lreg,0));
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
840 xreg = lreg;
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
841 } else {
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
842 save=0;
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
843 xreg = get_register();
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
844 }
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
845 printf("\tmovl %%esp,%s\n",register_name(xreg,0));
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
846 emit_copy(creg,xreg,length,0);
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
847 if (save) {
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
848 printf("\tpopl %s\n",register_name(lreg,0));
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
849 } else
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
850 free_register(xreg);
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
851 return length/size_of_int;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
852 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
853
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
854 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
855 function(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
856 {
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
857 int e2,e3,e4,e5,nargs,t;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
858 NMTBL *n;
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
859 int save,saved;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
860 if (free_register_count()<1) {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
861 for(save = 0;save==dreg||save==creg;save++);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
862 printf("\tpushl %s\n",register_name(save,0));
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
863 saved = 1;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
864 } else {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
865 save = get_register();
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
866 saved = 0;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
867 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
868 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
869 nargs = 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
870 for (e3 = caddr(e1); e3; e3 = cadr(e3)) {
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
871 t=caddr(e3);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
872 n=(NMTBL *)(e5=(cadr(e4 = car(e3))));
d35df41eac69 Initial revision
kono
parents:
diff changeset
873 switch(car(e4)) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
874 case FNAME:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
875 printf("\tlea %s,%s\n",n->nm,register_name(creg,0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
876 printf("\tpushl %s\n",register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
877 break;
d35df41eac69 Initial revision
kono
parents:
diff changeset
878 case ADDRESS:
d35df41eac69 Initial revision
kono
parents:
diff changeset
879 g_expr(e5);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
880 printf("\tpushl %s\n",register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
881 break;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
882 default:
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
883 if(scalar(t)) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
884 g_expr(e4);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
885 printf("\tpushl %s\n",register_name(creg,0));
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
886 } else if (car(t)==STRUCT||car(t)==UNION) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
887 nargs += struct_push(e4,t);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
888 continue;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
889 } else {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
890 error(TYERR);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
891 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
892 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
893 ++nargs;
d35df41eac69 Initial revision
kono
parents:
diff changeset
894 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
895 if (car(e2) == FNAME) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
896 n=(NMTBL *)cadr(e2);
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
897 } else {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
898 use_register(creg,REG_ECX,0);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
899 g_expr(e2);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
900 }
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
901
26
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
902 /* we don't have to save creg nor dreg */
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
903 regs[creg]=0;
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
904 regs[dreg]=0;
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
905 use_register(creg,REG_EAX,0);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
906 use_register(dreg,REG_EDX,0); /* will be destroyed */
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
907 use_register(save,REG_ECX,0); /* will be destroyed */
26
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
908 regs[creg]=1;
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
909 regs[dreg]=1;
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
910
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
911 if (car(e2) == FNAME) {
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
912 printf("\tcall\t%s\n",n->nm);
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
913 } else {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
914 printf("\tcall\t*%s\n",register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
915 }
6
bf602558130d continuation
kono
parents: 5
diff changeset
916 if (nargs) printf("\taddl $%d,%%esp\n",size_of_int*nargs);
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
917 if (saved) {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
918 printf("\tpopl %s\n",register_name(save,0));
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
919 } else {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
920 free_register(save);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
921 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
922 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
923
2
kono
parents: 1
diff changeset
924 int
3
kono
parents: 2
diff changeset
925 arg_size(int e3,int *nargs0)
2
kono
parents: 1
diff changeset
926 {
kono
parents: 1
diff changeset
927 int i,nargs,offset_list,e,t;
kono
parents: 1
diff changeset
928
kono
parents: 1
diff changeset
929 offset_list = 0;
kono
parents: 1
diff changeset
930 /* we should use prototypes's type */
kono
parents: 1
diff changeset
931 for (i = nargs = 0; e3;e3 =cadr(e3)) {
kono
parents: 1
diff changeset
932 e = car(e3); t = caddr(e3);
3
kono
parents: 2
diff changeset
933 if (i < MAX_REGISTER_VAR && scalar(t)) {
5
3db1b6d78412 *** empty log message ***
kono
parents: 4
diff changeset
934 offset_list = list3(-(REG_ESI+i++),offset_list,e);
2
kono
parents: 1
diff changeset
935 } else {
kono
parents: 1
diff changeset
936 offset_list =
5
3db1b6d78412 *** empty log message ***
kono
parents: 4
diff changeset
937 list3(nargs,offset_list,e);
3
kono
parents: 2
diff changeset
938 nargs += (car(e3)==CHAR?size_of_int:size(t));
2
kono
parents: 1
diff changeset
939 }
kono
parents: 1
diff changeset
940 }
3
kono
parents: 2
diff changeset
941 *nargs0 = -nargs;
2
kono
parents: 1
diff changeset
942 return offset_list;
kono
parents: 1
diff changeset
943 }
kono
parents: 1
diff changeset
944
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
945 int
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
946 is_simple(int e1)
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
947 {
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
948 int e2 = car(e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
949 return (
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
950 e2==FNAME || e2==LVAR || e2==CRLVAR || e2==REGISTER
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
951 );
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
952 }
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
953
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
954 void
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
955 jump_new(int e1, int env)
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
956 {
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
957 int e2;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
958 NMTBL *code0;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
959 /*
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
960 jump アドレスを計算する
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
961 */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
962 /* compute jump address */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
963 e2 = cadr(e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
964 if (car(e2) == FNAME) {
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
965 code0=(NMTBL *)cadr(e2);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
966 if (code0->sc!=CODE) {
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
967 error(STERR); return;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
968 }
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
969 } else { /* indirect */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
970 g_expr(e2);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
971 emit_push();
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
972 }
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
973 /*
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
974 まず、複雑な式を前もって単純な式に落す。
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
975 必要なら局所変数を用いる。
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
976 局所変数へのオフセットを覚えておく
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
977 */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
978 /*
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
979 スタックの位置を修正する
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
980 */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
981 /*
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
982 オフセットを用いて、
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
983 並べ変えを行う
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
984 */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
985 /*
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
986 スタックの位置を修正する
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
987 */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
988 /*
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
989 jump code を生成する
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
990 */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
991 }
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
992
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
993 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
994 jump(int e1, int env)
d35df41eac69 Initial revision
kono
parents:
diff changeset
995 {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
996 int i,args,e2,e3,e4,e5,nargs,regs;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
997 NMTBL *n,*code0;
6
bf602558130d continuation
kono
parents: 5
diff changeset
998 int new_disp,scode,disp1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
999 char *xrn;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1000
2
kono
parents: 1
diff changeset
1001 /* We need three passes. Compute Stack size, Compute Arg, Copy it. */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1002 /* count number of args */
2
kono
parents: 1
diff changeset
1003 args = caddr(e1);
3
kono
parents: 2
diff changeset
1004 args = reverse0(args);
kono
parents: 2
diff changeset
1005 nargs = arg_size(args,&new_disp); /* compute in normal order */
5
3db1b6d78412 *** empty log message ***
kono
parents: 4
diff changeset
1006 disp1 = (fnptr->sc==CODE)?0:-size_of_int;
3db1b6d78412 *** empty log message ***
kono
parents: 4
diff changeset
1007 if (new_disp+disp1 < disp) { /* have to extend stack */
6
bf602558130d continuation
kono
parents: 5
diff changeset
1008 if (fnptr->sc==CODE)
bf602558130d continuation
kono
parents: 5
diff changeset
1009 printf("\tleal %d(%%ebp),%%esp\n",new_disp-size_of_int);
bf602558130d continuation
kono
parents: 5
diff changeset
1010 else
bf602558130d continuation
kono
parents: 5
diff changeset
1011 printf("\tleal %d(%%ebp),%%esp\n",new_disp+disp_offset);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1012 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1013 /* compute jump address */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1014 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1015 if (car(e2) == FNAME) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1016 code0=(NMTBL *)cadr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1017 if (code0->sc!=CODE) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1018 error(STERR); return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1019 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1020 } else { /* indirect */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1021 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1022 emit_push();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1023 }
2
kono
parents: 1
diff changeset
1024 /* compute arguments in reverse order */
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1025 /* printf("## jump code_arg_offset=%d code_disp_offset=%d\n",code_arg_offset,code_disp_offset); */
2
kono
parents: 1
diff changeset
1026 regs = 0;
4
535bf528d68f copy free jump
kono
parents: 3
diff changeset
1027 i=MAX_REGISTER_VAR;
2
kono
parents: 1
diff changeset
1028 for (e3=nargs; e3;e3 =cadr(e3)) {
kono
parents: 1
diff changeset
1029 n=(NMTBL *)(e5=(cadr(e4 = caddr(e3))));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1030 switch(car(e4)) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1031 case FNAME:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1032 printf("\tlea %s,%s\n",n->nm,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1033 emit_push();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1034 break;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1035 case ADDRESS:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1036 g_expr(e5);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1037 emit_push();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1038 break;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1039 case RLVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1040 case CRLVAR:
4
535bf528d68f copy free jump
kono
parents: 3
diff changeset
1041 if (env==0 && fnptr->sc==CODE) {
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1042 /* printf("## e5=%d car(e3)=%d\n",e5,car(e3)); */
5
3db1b6d78412 *** empty log message ***
kono
parents: 4
diff changeset
1043 if (e5>=0 && e5==car(e3)) {
2
kono
parents: 1
diff changeset
1044 /* The same positioned local variable. No need to copy */
kono
parents: 1
diff changeset
1045 reg_stack[reg_sp++] = -2;
kono
parents: 1
diff changeset
1046 }
4
535bf528d68f copy free jump
kono
parents: 3
diff changeset
1047 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1048 }
3
kono
parents: 2
diff changeset
1049 g_expr(e4);
kono
parents: 2
diff changeset
1050 emit_push();
kono
parents: 2
diff changeset
1051 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1052 case REGISTER:
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1053 /* printf("## i=%d rname[e5]=%d\n",i,rname[e5]); */
4
535bf528d68f copy free jump
kono
parents: 3
diff changeset
1054 if (i>0 && rname[e5]==REG_ESI+ --i) {
3
kono
parents: 2
diff changeset
1055 /* The same register variable. No need to copy */
2
kono
parents: 1
diff changeset
1056 reg_stack[reg_sp++] = e5;
4
535bf528d68f copy free jump
kono
parents: 3
diff changeset
1057 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1058 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1059 default:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1060 g_expr(e4);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1061 emit_push();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1062 }
2
kono
parents: 1
diff changeset
1063 regs++;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1064 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1065 if (env) {
2
kono
parents: 1
diff changeset
1066 /* change the frame pointer */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1067 g_expr(env);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1068 printf("\tmovl %s,%%ebp\n",register_name(creg,0));
3
kono
parents: 2
diff changeset
1069 } else if (fnptr->sc==FUNCTION) {
kono
parents: 2
diff changeset
1070 printf("\tlea %d(%%ebp),%%ebp\n",disp_offset);
kono
parents: 2
diff changeset
1071 }
kono
parents: 2
diff changeset
1072 /* force lvar offset mode to CODE */
kono
parents: 2
diff changeset
1073 scode = fnptr->sc; fnptr->sc = CODE;
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1074 /* printf("## jump2 code_arg_offset=%d code_disp_offset=%d\n",code_arg_offset,code_disp_offset); */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1075 /* copy arguments to destination environment if necessary */
3
kono
parents: 2
diff changeset
1076 nargs = reverse0(nargs); /* pop in normal order */
kono
parents: 2
diff changeset
1077 i=0;
kono
parents: 2
diff changeset
1078 for (e3=nargs; e3;e3 =cadr(e3)) {
5
3db1b6d78412 *** empty log message ***
kono
parents: 4
diff changeset
1079 if ((e4=car(e3))<0) {
2
kono
parents: 1
diff changeset
1080 /* register case */
kono
parents: 1
diff changeset
1081 if (reg_stack[--reg_sp]>=REG_ESI) {
kono
parents: 1
diff changeset
1082 /* the same registger */
kono
parents: 1
diff changeset
1083 } else {
kono
parents: 1
diff changeset
1084 if(reg_stack[reg_sp]<0) {
5
3db1b6d78412 *** empty log message ***
kono
parents: 4
diff changeset
1085 printf("\tpopl %s\n",reg_name[rname[REG_ESI+i]]); /* e4? */
2
kono
parents: 1
diff changeset
1086 } else {
kono
parents: 1
diff changeset
1087 printf("\tmovl %s,%s\n",
kono
parents: 1
diff changeset
1088 reg_name[rname[reg_stack[reg_sp]]],
5
3db1b6d78412 *** empty log message ***
kono
parents: 4
diff changeset
1089 reg_name[rname[REG_ESI+i]]); /* e4? */
2
kono
parents: 1
diff changeset
1090 free_register(reg_stack[reg_sp]);
kono
parents: 1
diff changeset
1091 }
3
kono
parents: 2
diff changeset
1092 i++;
2
kono
parents: 1
diff changeset
1093 }
kono
parents: 1
diff changeset
1094 } else {
kono
parents: 1
diff changeset
1095 /* local variable case */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1096 if (reg_stack[reg_sp-1]== -2) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1097 /* same positioned variable */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1098 reg_sp--;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1099 } else {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1100 printf("\tmovl %s,%d(%%ebp)\n",register_name(emit_pop(0),0), lvar(e4));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1101 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1102 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1103 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1104 if (car(e2) != FNAME) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1105 xrn=register_name(emit_pop(0),0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1106 }
6
bf602558130d continuation
kono
parents: 5
diff changeset
1107 if (!env && new_disp+disp1>disp) {
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1108 /* shrink stack if necessary */
5
3db1b6d78412 *** empty log message ***
kono
parents: 4
diff changeset
1109 printf("\tleal %d(%%ebp),%%esp\n",new_disp-size_of_int);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1110 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1111 if (car(e2) == FNAME) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1112 printf("\tjmp %s\n",code0->nm);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1113 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1114 printf("\tjmp *%s\n",xrn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1115 }
3
kono
parents: 2
diff changeset
1116 fnptr->sc = scode;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1117 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1118
d35df41eac69 Initial revision
kono
parents:
diff changeset
1119
d35df41eac69 Initial revision
kono
parents:
diff changeset
1120 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1121 machinop(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1122 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1123 int e2,e3,op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1124
d35df41eac69 Initial revision
kono
parents:
diff changeset
1125 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1126 op = car(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1127 e3 = caddr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1128 g_expr(e3);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1129 emit_push();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1130 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1131 tosop(car(e1));
d35df41eac69 Initial revision
kono
parents:
diff changeset
1132 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1133 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1134
d35df41eac69 Initial revision
kono
parents:
diff changeset
1135
d35df41eac69 Initial revision
kono
parents:
diff changeset
1136 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1137 rindirect(int e1) /* *(p +5 ) */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1138
d35df41eac69 Initial revision
kono
parents:
diff changeset
1139 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1140 char *op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1141 int e2,e3,byte;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1142
d35df41eac69 Initial revision
kono
parents:
diff changeset
1143 op = ((byte = (car(e1) == CRINDIRECT)) ? "movsbl" : "movl");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1144 e3 = cadr(e2 = cadr(e1));
d35df41eac69 Initial revision
kono
parents:
diff changeset
1145 g_expr(e2);
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1146 printf("\t%s (%s),%s\n",op,register_name(creg,0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1147 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1148
d35df41eac69 Initial revision
kono
parents:
diff changeset
1149 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1150 sassign(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1151 {
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
1152 int e2,e3,e4,sz,xreg;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1153
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1154 /* structure assignment */
37
412ad2e6c2a2 struct copy
kono
parents: 36
diff changeset
1155 e2 = cadr(e1); /* pointer variable to the struct */
412ad2e6c2a2 struct copy
kono
parents: 36
diff changeset
1156 e3 = cadr(e2); /* offset of the variable (distination) */
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
1157 e4 = caddr(e1); /* right value (source) */
37
412ad2e6c2a2 struct copy
kono
parents: 36
diff changeset
1158 sz = cadddr(e1); /* size of struct or union */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1159 g_expr(e4);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1160 emit_push();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1161 g_expr(e2);
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
1162 xreg = emit_pop(0);
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
1163 emit_copy(xreg,creg,sz,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1164 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1165 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1166
d35df41eac69 Initial revision
kono
parents:
diff changeset
1167 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1168 assign(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1169 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1170 char *op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1171 int e2,e3,e4,byte;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1172
d35df41eac69 Initial revision
kono
parents:
diff changeset
1173 op = ((byte=(car(e1) == CASS))? "movb" : "movl");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1174 /* e2=e4 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1175 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1176 e3 = cadr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1177 e4 = caddr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1178 switch(car(e2)) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1179 case GVAR: /* i=3 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1180 g_expr(e4);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1181 if (byte) use_data_reg(creg,1);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1182 printf("\t%s %s,%s\n",op,register_name(creg,byte),(char *)caddr(e2));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1183 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1184 case LVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1185 g_expr(e4);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1186 if (byte) use_data_reg(creg,1);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1187 printf("\t%s %s,%d(%%ebp)\n",op,register_name(creg,byte),lvar(cadr(e2)));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1188 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1189 case REGISTER:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1190 g_expr(e4);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1191 if (creg!=cadr(e2))
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1192 printf("\tmovl %s,%s\n",register_name(creg,0),register_name(cadr(e2),0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1193 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1194 }
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1195 g_expr(e2);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1196 emit_push();
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1197 use_data_reg(creg,0);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1198 g_expr(e4);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1199 if (byte) use_data_reg(creg,1);
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1200 e2 = emit_pop(0);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1201 printf("\t%s %s,(%s)\n",op,register_name(creg,byte),register_name(e2,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1202 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1203 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1204
d35df41eac69 Initial revision
kono
parents:
diff changeset
1205 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1206 assop(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1207 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1208 int e2,e3,byte,op,new_reg;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1209 char *xrn;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1210 int xreg;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1211
d35df41eac69 Initial revision
kono
parents:
diff changeset
1212 /* e2 op= e3 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1213 byte = (car(e1) == CASSOP);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1214 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1215 if (car(e2)==INDIRECT) e2=cadr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1216 e3 = caddr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1217 op = cadddr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1218
d35df41eac69 Initial revision
kono
parents:
diff changeset
1219 g_expr(e3);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1220 emit_push();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1221 if (car(e2)==REGISTER) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1222 new_reg=creg;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1223 creg = cadr(e2);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1224 tosop(op);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1225 creg = new_reg;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1226 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1227 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1228 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1229 g_expr(e2);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1230 xrn = register_name(xreg = emit_pop(0),0); /* pop e3 value */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1231 printf("\tpushl %s # assop \n",register_name(creg,0)); /* push e2 address */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1232 ld_indexx(byte,0,creg);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1233 new_reg = get_register();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1234 /* push e3 value */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1235 if(new_reg<0) { /* もうレジスタがない */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1236 reg_stack[reg_sp++] = -1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1237 printf("\tpushl %s\n",xrn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1238 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1239 reg_stack[reg_sp++] = xreg; /* push するかわりにレジスタを使う */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1240 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1241 tosop(op);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1242 if(new_reg>=0) free_register(new_reg);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1243 printf("\tpopl %s # assop \n",register_name(dreg,0));
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1244 printf("\t%s %s,(%s)\n",byte ? "movb" : "movl",register_name(creg,byte),register_name(dreg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1245 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1246
d35df41eac69 Initial revision
kono
parents:
diff changeset
1247 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1248
d35df41eac69 Initial revision
kono
parents:
diff changeset
1249
d35df41eac69 Initial revision
kono
parents:
diff changeset
1250 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1251 tosop(int op)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1252 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1253 int oreg;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1254 char *orn,*crn;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1255
d35df41eac69 Initial revision
kono
parents:
diff changeset
1256 oreg = pop_register();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1257 switch(op) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1258 case LSHIFT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1259 case ULSHIFT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1260 shift("sall",oreg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1261 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1262 case RSHIFT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1263 shift("sarl",oreg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1264 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1265 case URSHIFT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1266 shift("shrl",oreg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1267 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1268 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1269 if(oreg==-1) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1270 printf("\tpopl %s\n",register_name(dreg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1271 oreg = dreg;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1272 }
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1273 orn = register_name(oreg,0);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1274 crn = register_name(creg,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1275 switch(op) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1276 case ADD:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1277 printf("\taddl %s,%s\n",orn,crn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1278 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1279 case SUB:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1280 printf("\tsubl %s,%s\n",orn,crn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1281 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1282 case BAND:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1283 printf("\tandl %s,%s\n",orn,crn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1284 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1285 case EOR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1286 printf("\txorl %s,%s\n",orn,crn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1287 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1288 case BOR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1289 printf("\torl %s,%s\n",orn,crn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1290 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1291 case MUL:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1292 case UMUL:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1293 /* use_register(dreg,REG_EDX,0); */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1294 printf("\t%s %s,%s\n","imull",orn,crn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1295 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1296 case DIV:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1297 case UDIV:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1298 orn = div_setup(oreg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1299 if (op==DIV)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1300 printf("\tcltd\n\tdivl %s\n",orn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1301 else
d35df41eac69 Initial revision
kono
parents:
diff changeset
1302 printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1303 div_cleanup(orn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1304 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1305 case MOD:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1306 case UMOD:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1307 orn = div_setup(oreg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1308 if (op==DIV)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1309 printf("\tcltd\n\tdivl %s\n",orn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1310 else
d35df41eac69 Initial revision
kono
parents:
diff changeset
1311 printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1312 rname[creg]=REG_EDX;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1313 rname[dreg]=REG_EAX;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1314 div_cleanup(orn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1315 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1316 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1317 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1318
d35df41eac69 Initial revision
kono
parents:
diff changeset
1319 static char *dvi_push = "(%esp)";
d35df41eac69 Initial revision
kono
parents:
diff changeset
1320
d35df41eac69 Initial revision
kono
parents:
diff changeset
1321 char *
d35df41eac69 Initial revision
kono
parents:
diff changeset
1322 div_setup(int oreg)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1323 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1324 if (oreg<0) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1325 use_register(creg,REG_EAX,1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1326 use_register(dreg,REG_EDX,0);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1327 return 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1328 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1329 if (register_full()) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1330 printf("\tpushl %s\n",register_name(oreg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1331 use_register(creg,REG_EAX,1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1332 use_register(oreg,REG_EDX,0);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1333 return dvi_push;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1334 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1335 regs[oreg]=1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1336 use_register(creg,REG_EAX,1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1337 use_register(dreg,REG_EDX,0);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1338 regs[oreg]=0;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1339 return register_name(oreg,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1340 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1341
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1342
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1343 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1344 div_cleanup(char *orn)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1345 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1346 if (orn==dvi_push)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1347 printf("\taddl $4,%%esp\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1348 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1349
d35df41eac69 Initial revision
kono
parents:
diff changeset
1350 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1351 shift(char *op, int reg)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1352 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1353 if (reg>=0) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1354 use_register(lreg,REG_ECX,1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1355 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1356 use_register(dreg,REG_ECX,0);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1357 printf("\tpopl %%ecx\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1358 }
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1359 printf("\t%s %%cl,%s\n",op,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1360 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1361
d35df41eac69 Initial revision
kono
parents:
diff changeset
1362 void
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1363 ld_indexx(int byte, int n, int xreg)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1364 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1365 char *op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1366
d35df41eac69 Initial revision
kono
parents:
diff changeset
1367 op = byte ? "movsbl" : "movl";
d35df41eac69 Initial revision
kono
parents:
diff changeset
1368 if (n)
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1369 printf("\t%s %d(%s),%s\n",op,n,register_name(xreg,0),register_name(creg,byte));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1370 else
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1371 printf("\t%s (%s),%s\n",op,register_name(xreg,0),register_name(creg,byte));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1372 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1373
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1374 /*
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1375 void
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1376 st_indexx(int byte, int n, int xreg)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1377 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1378 char *op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1379
d35df41eac69 Initial revision
kono
parents:
diff changeset
1380 op = byte ? "movb" : "movl";
d35df41eac69 Initial revision
kono
parents:
diff changeset
1381 if (n)
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1382 printf("\t%s %s,%d(%s)\n",op,register_name(creg,byte),n,register_name(xreg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1383 else
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1384 printf("\t%s %s,(%s)\n",op,register_name(creg,byte),register_name(xreg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1385 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1386
d35df41eac69 Initial revision
kono
parents:
diff changeset
1387 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1388 indexy(char *op, char *gvar)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1389 {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1390 printf("\t%s %s,%s\n",op,register_name(creg,0),gvar);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1391 }
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1392 */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1393
d35df41eac69 Initial revision
kono
parents:
diff changeset
1394 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1395 cmpdimm(int e, int csreg)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1396 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1397 /* used in dosiwtch() */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1398 use_register(creg,csreg,0);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1399 printf("\tcmpl $%d,%s\n",e,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1400 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1401
d35df41eac69 Initial revision
kono
parents:
diff changeset
1402 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1403 opening(char *filename)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1404 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1405 printf("\t.file \"%s\"\n",filename);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1406 printf("\t.version\t\"01.01\"\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1407 printf("gcc2_compiled.:\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1408 printf(".text\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1409 emit_init();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1410 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1411
d35df41eac69 Initial revision
kono
parents:
diff changeset
1412 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1413 closing(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1414 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1415 global_table();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1416 printf("\t.ident \"Micro-C compiled\"\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1417 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1418
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1419 /*
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1420 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1421 jmp_label(int l)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1422 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1423 printf("\tjmp\t_%d\n",l);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1424 }
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1425 */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1426
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1427 /*
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1428 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1429 jmp_eq_label(int l)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1430 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1431 printf("\tje\t_%d\n",l);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1432 }
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1433 */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1434
d35df41eac69 Initial revision
kono
parents:
diff changeset
1435 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1436 rexpr(int e1, int l1, char *s)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1437 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1438 g_expr(list3(SUB,cadr(e1),caddr(e1)));
d35df41eac69 Initial revision
kono
parents:
diff changeset
1439 printf("\tj%s\t_%d\n",s,l1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1440 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1441
d35df41eac69 Initial revision
kono
parents:
diff changeset
1442 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1443 jcond(int l, char cond)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1444 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1445 printf("\tj%s\t_%d\n",cond?"ne":"e",l);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1446 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1447
d35df41eac69 Initial revision
kono
parents:
diff changeset
1448 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1449 jmp(int l)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1450 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1451 control=0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1452 printf("\tjmp\t_%d\n",l);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1453 /* align? */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1454 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1455
d35df41eac69 Initial revision
kono
parents:
diff changeset
1456 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
1457 fwdlabel(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1458 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1459 return labelno++;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1460 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1461
d35df41eac69 Initial revision
kono
parents:
diff changeset
1462 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1463 fwddef(int l)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1464 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1465 control=1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1466 printf("_%d:\n",l);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1467 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1468
d35df41eac69 Initial revision
kono
parents:
diff changeset
1469 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
1470 backdef(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1471 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1472 control=1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1473 printf("_%d:\n",labelno);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1474 return labelno++;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1475 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1476
d35df41eac69 Initial revision
kono
parents:
diff changeset
1477 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1478 def_label(int cslabel, int dlabel)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1479 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1480 int fl;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1481
d35df41eac69 Initial revision
kono
parents:
diff changeset
1482 fl = 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1483 if (control) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1484 jmp(fl=fwdlabel());
d35df41eac69 Initial revision
kono
parents:
diff changeset
1485 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1486 fwddef(cslabel);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1487 if (dlabel)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1488 jmp(dlabel);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1489 if (fl) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1490 fwddef(fl);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1491 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1492 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1493
d35df41eac69 Initial revision
kono
parents:
diff changeset
1494 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1495 gen_comment(char *s)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1496 {
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1497 printf("## %s",s);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1498 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1499
d35df41eac69 Initial revision
kono
parents:
diff changeset
1500 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1501 gen_source(char *s)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1502 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1503 printf("%s",s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1504 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1505
d35df41eac69 Initial revision
kono
parents:
diff changeset
1506 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1507 code_enter(char *name)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1508 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1509 printf("\t.align 4\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1510 if (stmode!=STATIC)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1511 printf(".globl %s\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1512 printf("\t.type\t%s,@function\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1513 printf("%s:\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1514 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1515
d35df41eac69 Initial revision
kono
parents:
diff changeset
1516 void
6
bf602558130d continuation
kono
parents: 5
diff changeset
1517 code_enter1(int disp0,int args)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1518 {
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1519 code_disp_label=fwdlabel();
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1520 printf("\tsubl $_%d,%%esp\n",code_disp_label);
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1521 /*
6
bf602558130d continuation
kono
parents: 5
diff changeset
1522 if(disp0) {
bf602558130d continuation
kono
parents: 5
diff changeset
1523 printf("\tsubl $%d,%%esp\n",-disp0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1524 }
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1525 */
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1526 printf("## args %d disp %d code_arg_offset=%d code_disp_offset=%d\n",args,disp,code_arg_offset,code_disp_offset);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1527 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1528
d35df41eac69 Initial revision
kono
parents:
diff changeset
1529 void
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1530 code_leave(char *name,int disp0)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1531 {
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1532 printf("\t.set _%d,%d\n",code_disp_label,-disp0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1533 printf("_%d:\n",labelno);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1534 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1535 local_table();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1536 labelno++;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1537 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1538
d35df41eac69 Initial revision
kono
parents:
diff changeset
1539 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1540 enter(char *name)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1541 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1542 printf("\t.align 2\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1543 if (stmode!=STATIC)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1544 printf(".globl %s\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1545 printf("%s:\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1546 printf("\t.type\t%s,@function\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1547 printf("\tpushl %%ebp\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1548 printf("\tmovl %%esp,%%ebp\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1549 printf("\tpushl %%ebx\n");
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
1550 printf("\tpushl %%esi\n");
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
1551 printf("\tpushl %%edi\n");
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1552 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1553
d35df41eac69 Initial revision
kono
parents:
diff changeset
1554 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1555 enter1(int disp)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1556 {
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1557 func_disp_label=fwdlabel();
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1558 printf("\tsubl $_%d,%%esp\n",func_disp_label);
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1559 /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1560 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1561
d35df41eac69 Initial revision
kono
parents:
diff changeset
1562 void
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1563 leave(int control, char *name,int disp)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1564 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1565 if (control)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1566 use_register(creg,REG_EAX,1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1567 if (retcont) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1568 if (control)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1569 jmp(retlabel);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1570 fwddef(retcont);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1571 use_register(creg,REG_EAX,0);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1572 printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1573 /* printf("\tleave\n"); */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1574 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1575 fwddef(retlabel);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1576 use_register(creg,REG_EAX,0);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1577 /* if(disp) printf("\taddl $%d,%%esp\n",-disp); */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1578 printf("\tlea %d(%%ebp),%%esp\n",disp_offset);
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
1579 printf("\tpopl %%edi\n");
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
1580 printf("\tpopl %%esi\n");
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1581 printf("\tpopl %%ebx\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1582 printf("\tleave\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1583 printf("\tret\n");
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1584 printf("\t.set _%d,%d\n",func_disp_label,-disp);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1585 printf("_%d:\n",labelno);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1586 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1587 local_table();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1588 labelno++;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1589 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1590
d35df41eac69 Initial revision
kono
parents:
diff changeset
1591
d35df41eac69 Initial revision
kono
parents:
diff changeset
1592 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1593 ret(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1594 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1595 use_register(creg,REG_EAX,1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1596 jmp(retlabel);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1597 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1598
d35df41eac69 Initial revision
kono
parents:
diff changeset
1599 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1600 gen_gdecl(char *n, int gpc)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1601 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1602 /*
d35df41eac69 Initial revision
kono
parents:
diff changeset
1603 if (stmode!=STATIC)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1604 printf(".globl %s\n",n);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1605 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1606 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1607
d35df41eac69 Initial revision
kono
parents:
diff changeset
1608 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1609 align(int t)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1610 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1611 if (t!=CHAR) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1612 if (data_alignment & 1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1613 printf("\t.align 2\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1614 data_alignment = 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1615 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1616 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1617
d35df41eac69 Initial revision
kono
parents:
diff changeset
1618 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1619 emit_data(int e, int t, NMTBL *n)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1620 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1621 int l;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1622 char *name;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1623 name = n->nm;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1624 if(mode!=GDECL) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1625 error(-1); return;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1626 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1627 if (n->dsp != -1) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1628 n->dsp = -1; /* initiallized flag */
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1629 printf(".globl\t%s\n",name);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1630 data_mode(name);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1631 align(t);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1632 printf("%s:\n",name);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1633 } else {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1634 data_mode(0);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1635 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1636 if(car(e)==CONST) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1637 if (t==CHAR) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1638 printf("\t.byte %d\n",cadr(e));
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1639 if (data_alignment>0)
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1640 data_alignment++;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1641 gpc += 1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1642 } else {
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1643 printf("\t.long %d\n",cadr(e));
3
kono
parents: 2
diff changeset
1644 gpc += size_of_int;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1645 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1646 } else if(t!=CHAR) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1647 gpc += size_of_int;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1648 if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1649 printf("\t.long %s\n",(char *)caddr(cadr(e)));
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1650 } else if(car(e)==FNAME) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1651 printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1652 } else if(car(e)==STRING) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1653 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1654 l = fwdlabel();
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1655 printf("\t.long _%d\n",l);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1656 printf(".section\t.rodata\n");
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1657 printf("_%d:\n",l);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1658 output_mode = RODATA_EMIT_MODE;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1659 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1660 ascii((char *)cadr(e));
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1661 } else error(TYERR);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1662 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1663 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1664
d35df41eac69 Initial revision
kono
parents:
diff changeset
1665 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1666 emit_data_closing(NMTBL *n)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1667 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1668 int lb;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1669 if (mode==GDECL) {
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1670 data_mode(0);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1671 lb=fwdlabel();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1672 printf("_%d:\n",lb);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1673 printf("\t.size\t%s,_%d-%s\n",n->nm,lb,n->nm);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1674 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1675 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1676
d35df41eac69 Initial revision
kono
parents:
diff changeset
1677 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1678 global_table(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1679 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1680 NMTBL *n;
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1681 int init;
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1682 init=0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1683 for(n=ntable;n < &ntable[GSYMS];n++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1684 if (n->sc == GVAR && n->dsp != -1) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1685 /* n->dsp = -1 means initialized global */
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1686 if (init==0) {
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1687 data_mode(0);
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1688 init=1;
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1689 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1690 printf(".comm %s,%d\n",n->nm,size(n->ty));
d35df41eac69 Initial revision
kono
parents:
diff changeset
1691 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1692 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1693 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1694
d35df41eac69 Initial revision
kono
parents:
diff changeset
1695 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1696 local_table(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1697 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1698 NMTBL *n;
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1699 int init;
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1700 init=0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1701 /* static local variables */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1702 for(n=ntable+GSYMS;n < &ntable[GSYMS+LSYMS];n++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1703 if (n->sc == GVAR) {
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1704 if (init==0) {
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1705 data_mode(0);
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1706 init=1;
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1707 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1708 printf(".lcomm %s,%d\n",n->nm,size(n->ty));
d35df41eac69 Initial revision
kono
parents:
diff changeset
1709 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1710 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1711 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1712
d35df41eac69 Initial revision
kono
parents:
diff changeset
1713 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1714 text_mode(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1715 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1716 if (output_mode!=TEXT_EMIT_MODE) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1717 printf(".text\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1718 printf("\t.align 2\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1719 output_mode = TEXT_EMIT_MODE;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1720 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1721 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1722
d35df41eac69 Initial revision
kono
parents:
diff changeset
1723 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1724 data_mode(char *name)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1725 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1726 if (output_mode!=DATA_EMIT_MODE) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1727 printf(".data\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1728 output_mode = DATA_EMIT_MODE;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1729 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1730 if (name)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1731 printf("\t.type\t%s,@object\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1732 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1733
d35df41eac69 Initial revision
kono
parents:
diff changeset
1734 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
1735 lvar(int l)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1736 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1737 if (l<0) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1738 if (fnptr->sc==CODE)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1739 return l+code_disp_offset;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1740 else
d35df41eac69 Initial revision
kono
parents:
diff changeset
1741 return l+disp_offset;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1742 } else {
3
kono
parents: 2
diff changeset
1743 if (fnptr->sc==CODE)
5
3db1b6d78412 *** empty log message ***
kono
parents: 4
diff changeset
1744 return -l+code_arg_offset;
3
kono
parents: 2
diff changeset
1745 else
kono
parents: 2
diff changeset
1746 return l+arg_offset;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1747 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1748 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1749
d35df41eac69 Initial revision
kono
parents:
diff changeset
1750 /* end */