annotate mc-nop-386.c @ 320:183726ccd83d

asm minor fix. ia32 table jmp fix.
author kono
date Sat, 19 Jun 2004 00:13:36 +0900
parents 1c2a9232ea93
children
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) ;
50
kono
parents: 49
diff changeset
12 extern void code_enter1(int args);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
13 extern void code_init(void);
50
kono
parents: 49
diff changeset
14 extern void code_leave(char *name) ;
kono
parents: 49
diff changeset
15 extern void leave(int control,char *name) ;
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) ;
50
kono
parents: 49
diff changeset
20 extern void enter1() ;
18
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);
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
30 extern int assign_expr0(int e,int e1,int type,int type1);
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
31 extern int integral(int t);
50
kono
parents: 49
diff changeset
32 extern void tree_print_t(int e,int t);
kono
parents: 49
diff changeset
33 extern int rvalue_t(int e,int t);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
34
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
35 static int edx_setup() ;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
36 static int lvar(int l);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
37 static void jump(int e1, int env);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
38 static void data_mode(char *name);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
39 static void text_mode(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
40 static void assign(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
41 static void assop(int e1);
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
42 static void b_expr(int e1, char cond, int l1,int err);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
43 static void emit_push(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
44 static void free_register(int i);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
45 static void function(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
46 static void global_table(void) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
47 /* static void indexy(char *op, char *gvar); */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
48 /* static void jmp_eq_label(int l); */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
49 /* static void jmp_label(int l); */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
50 static void ld_indexx(int byte, int n, int xreg);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
51 static void local_table(void) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
52 static void machinop(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
53 static void rexpr(int e1, int l1, char *s);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
54 static void rindirect(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
55 static void sassign(int e1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
56 static void shift(char *op, int xreg) ;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
57 /* static void st_indexx(int byte, int n, int xreg); */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
58 static void string(int e1);
43
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
59 static void tosop(int op,int reg);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
60 static void edx_cleanup();
26
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
61 static void use_register(int virt, int real, int move);
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
62 static void emit_copy(int from,int to,int length,int offset,int value,int det);
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
63 static int is_same_type(int s,int t);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
64
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents: 58
diff changeset
65 extern void error(int n);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
66 extern int fwdlabel(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
67 extern void fwddef(int l);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
68 extern int backdef(void);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
69 extern int size(int t);
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
70 extern int list4(int e1, int e2, int e3,int e4);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
71 extern int list3(int e1, int e2, int e3);
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
72 extern int list2(int e1, int e2);
2
kono
parents: 1
diff changeset
73 extern int scalar(int);
kono
parents: 1
diff changeset
74 extern int reverse0(int);
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
75 extern void remove0(int *list,int element);
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
76 extern int append4(int target,int t,int ty,int e1);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
77
d35df41eac69 Initial revision
kono
parents:
diff changeset
78 #define TEXT_EMIT_MODE 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
79 #define DATA_EMIT_MODE 1
d35df41eac69 Initial revision
kono
parents:
diff changeset
80 #define RODATA_EMIT_MODE 2
d35df41eac69 Initial revision
kono
parents:
diff changeset
81
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
82 static int output_mode = TEXT_EMIT_MODE;
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
83 static int data_alignment = 0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
84
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
85 static int code_disp_label;
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
86 static int func_disp_label;
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
87
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
88 /*
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
89 -16 -8 local2
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
90 -12 -4 local1
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
91 -8 8 arg3
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
92 -4 4 arg2
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
93 0 0 arg1
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
94 local2 -20 4 0 (%edi)
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
95 local1 <-- -16 0 local variable 0 (%esi)
50
kono
parents: 49
diff changeset
96 %edi -12 <- disp_offset %ebp
kono
parents: 49
diff changeset
97 %esi -8
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
98 %ebx -4
d35df41eac69 Initial revision
kono
parents:
diff changeset
99 %ebp = %esp 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
100 %eip 4 <- arg_offset
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
101 arg1 8 0
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
102 arg2 12 4
50
kono
parents: 49
diff changeset
103 see enter/enter1/leave see code_enter
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
104 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
105 int arg_offset = 8;
3
kono
parents: 2
diff changeset
106 int disp_offset = -12;
kono
parents: 2
diff changeset
107 int func_disp_offset = -12;
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
108 int code_disp_offset = 0;
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
109 int jump_offset = 0;
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
110
3
kono
parents: 2
diff changeset
111 int size_of_int = 4;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
112 int endian = 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
113 int MAX_REGISTER=6; /* intel386¤Î¥ì¥¸¥¹¥¿¤ò4¤Ä¤Þ¤Ç»È¤¦*/
d35df41eac69 Initial revision
kono
parents:
diff changeset
114 int REAL_MAX_REGISTER=8; /* intel386¤Î¥ì¥¸¥¹¥¿¤¬8¤Ä¤È¤¤¤¦¤³¤È*/
d35df41eac69 Initial revision
kono
parents:
diff changeset
115 int MAX_DATA_REG=4;
d35df41eac69 Initial revision
kono
parents:
diff changeset
116 int MAX_POINTER=3;
d35df41eac69 Initial revision
kono
parents:
diff changeset
117 int MAX_REGISTGER_VAR=2;
d35df41eac69 Initial revision
kono
parents:
diff changeset
118
d35df41eac69 Initial revision
kono
parents:
diff changeset
119 static int creg; /* current register */
d35df41eac69 Initial revision
kono
parents:
diff changeset
120 static int dreg; /* temporary register */
d35df41eac69 Initial revision
kono
parents:
diff changeset
121 static int reg_sp; /* REGister Stack-Pointer */
d35df41eac69 Initial revision
kono
parents:
diff changeset
122
d35df41eac69 Initial revision
kono
parents:
diff changeset
123
d35df41eac69 Initial revision
kono
parents:
diff changeset
124 #define REG_EAX 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
125 #define REG_EBX 1
d35df41eac69 Initial revision
kono
parents:
diff changeset
126 #define REG_ECX 2
d35df41eac69 Initial revision
kono
parents:
diff changeset
127 #define REG_EDX 3
d35df41eac69 Initial revision
kono
parents:
diff changeset
128 #define REG_ESI 4
d35df41eac69 Initial revision
kono
parents:
diff changeset
129 #define REG_EDI 5
d35df41eac69 Initial revision
kono
parents:
diff changeset
130 #define REG_EBP 6
d35df41eac69 Initial revision
kono
parents:
diff changeset
131 #define REG_ESP 7
d35df41eac69 Initial revision
kono
parents:
diff changeset
132
d35df41eac69 Initial revision
kono
parents:
diff changeset
133
d35df41eac69 Initial revision
kono
parents:
diff changeset
134 #define DATA_REG 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
135 #define POINTER_REG 3
d35df41eac69 Initial revision
kono
parents:
diff changeset
136 static char *reg_name[8];
d35df41eac69 Initial revision
kono
parents:
diff changeset
137 static char *reg_name_l[4];
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
138 static char *reg_name_w[4];
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
139
d35df41eac69 Initial revision
kono
parents:
diff changeset
140 /*
d35df41eac69 Initial revision
kono
parents:
diff changeset
141 creg currrent virtual register
d35df41eac69 Initial revision
kono
parents:
diff changeset
142 dreg spare virtual register
d35df41eac69 Initial revision
kono
parents:
diff changeset
143
d35df41eac69 Initial revision
kono
parents:
diff changeset
144 rname[creg] currrent real register
d35df41eac69 Initial revision
kono
parents:
diff changeset
145 rname[dreg] spare real register
d35df41eac69 Initial revision
kono
parents:
diff changeset
146
d35df41eac69 Initial revision
kono
parents:
diff changeset
147 regs[] virtual register usage
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
148 regv[] value in virtual register flag
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
149
d35df41eac69 Initial revision
kono
parents:
diff changeset
150 reg_name[rname[creg]]
d35df41eac69 Initial revision
kono
parents:
diff changeset
151 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
152
d35df41eac69 Initial revision
kono
parents:
diff changeset
153 #define MAX_MAX 10
d35df41eac69 Initial revision
kono
parents:
diff changeset
154 static int rname[MAX_MAX];
d35df41eac69 Initial revision
kono
parents:
diff changeset
155 static int regs[MAX_MAX]; /* »È¤ï¤ì¤Æ¤¤¤ë¥ì¥¸¥¹¥¿¤ò¼¨¤¹¥Õ¥é¥° */
d35df41eac69 Initial revision
kono
parents:
diff changeset
156 static int reg_stack[MAX_MAX]; /* ¼ÂºÝ¤Î¥ì¥¸¥¹¥¿¤ÎÎΰè */
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
157 static int regv[MAX_MAX]; /* Ãͤ¬Æþ¤Ã¤Æ¤¤¤ë¤«¤É¤¦¤« */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
158
d35df41eac69 Initial revision
kono
parents:
diff changeset
159 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
160 code_init(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
161 {
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
162 arg_offset = 8;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
163 func_disp_offset = -12;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
164 disp_offset = -12;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
165 size_of_int = 4;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
166 endian = 0;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
167 MAX_REGISTER=6;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
168 MAX_DATA_REG=4;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
169 MAX_POINTER=3;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
170 MAX_REGISTER_VAR=2;
d35df41eac69 Initial revision
kono
parents:
diff changeset
171
d35df41eac69 Initial revision
kono
parents:
diff changeset
172 reg_name[REG_EAX] = "%eax";
d35df41eac69 Initial revision
kono
parents:
diff changeset
173 reg_name[REG_EBX] = "%ebx";
d35df41eac69 Initial revision
kono
parents:
diff changeset
174 reg_name[REG_ECX] = "%ecx";
d35df41eac69 Initial revision
kono
parents:
diff changeset
175 reg_name[REG_EDX] = "%edx";
d35df41eac69 Initial revision
kono
parents:
diff changeset
176 reg_name[REG_ESI] = "%esi";
d35df41eac69 Initial revision
kono
parents:
diff changeset
177 reg_name[REG_EDI] = "%edi";
d35df41eac69 Initial revision
kono
parents:
diff changeset
178 reg_name[REG_EBP] = "%ebp";
d35df41eac69 Initial revision
kono
parents:
diff changeset
179 reg_name[REG_ESP] = "%esp";
d35df41eac69 Initial revision
kono
parents:
diff changeset
180 reg_name_l[REG_EAX] = "%al";
d35df41eac69 Initial revision
kono
parents:
diff changeset
181 reg_name_l[REG_EBX] = "%bl";
d35df41eac69 Initial revision
kono
parents:
diff changeset
182 reg_name_l[REG_ECX] = "%cl";
d35df41eac69 Initial revision
kono
parents:
diff changeset
183 reg_name_l[REG_EDX] = "%dl";
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
184 reg_name_w[REG_EAX] = "%ax";
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
185 reg_name_w[REG_EBX] = "%bx";
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
186 reg_name_w[REG_ECX] = "%cx";
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
187 reg_name_w[REG_EDX] = "%dx";
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
188
d35df41eac69 Initial revision
kono
parents:
diff changeset
189 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
190
d35df41eac69 Initial revision
kono
parents:
diff changeset
191 char *
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
192 register_name(int i,int byte)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
193 {
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
194 if (i<0) {
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
195 error(REG_ERR);
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
196 return "%eax";
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
197 }
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
198 if (byte && rname[i] <= REG_EDX) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
199 return reg_name_l[rname[i]];
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
200 } else {
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
201 return reg_name[rname[i]]; /* should be error */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
202 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
203 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
204
d35df41eac69 Initial revision
kono
parents:
diff changeset
205 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
206 get_register(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
207 { /* »È¤ï¤ì¤Æ¤¤¤Ê¤¤¥ì¥¸¥¹¥¿¤òÄ´¤Ù¤ë */
d35df41eac69 Initial revision
kono
parents:
diff changeset
208 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
209 for(i=0;i<MAX_REGISTER;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
210 if (! regs[i]) { /* »È¤ï¤ì¤Æ¤¤¤Ê¤¤¤Ê¤é */
d35df41eac69 Initial revision
kono
parents:
diff changeset
211 regs[i]=1; /* ¤½¤Î¥ì¥¸¥¹¥¿¤ò»È¤¦¤³¤È¤òÀë¸À¤· */
d35df41eac69 Initial revision
kono
parents:
diff changeset
212 return i; /* ¤½¤Î¾ì½ê¤òɽ¤¹ÈÖ¹æ¤òÊÖ¤¹ */
d35df41eac69 Initial revision
kono
parents:
diff changeset
213 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
214 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
215 return -1; /* ¶õ¤¤¤Æ¤¤¤ë¾ì½ê¤¬¤Ê¤¤¤Ê¤é¡¢¤½¤ì¤òɽ¤¹ -1 ¤òÊÖ¤¹ */
d35df41eac69 Initial revision
kono
parents:
diff changeset
216 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
217
d35df41eac69 Initial revision
kono
parents:
diff changeset
218 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
219 free_register(int i) { /* ¤¤¤é¤Ê¤¯¤Ê¤Ã¤¿¥ì¥¸¥¹¥¿¤ò³«Êü */
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
220 regv[i]=regs[i]=0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
221 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
222
d35df41eac69 Initial revision
kono
parents:
diff changeset
223 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
224 register_full(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
225 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
226 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
227 for(i=0;i<MAX_REGISTER;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
228 if (! regs[i]) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
229 return 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
230 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
231 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
232 return 1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
233 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
234
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
235 static
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
236 int
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
237 free_register_count(void)
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
238 {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
239 int i,count;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
240 count = 0;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
241 for(i=0;i<MAX_REGISTER;i++) {
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
242 if (! regs[i] && ! regv[i]) count++;
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
243 }
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
244 return count;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
245 }
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
246
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
247 static void
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
248 free_all_register(void)
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
249 {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
250 int i;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
251 for(i=0;i<MAX_REGISTER;i++) {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
252 regs[i]=regv[i]=0;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
253 }
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
254 creg = get_register();
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
255 dreg = get_register();
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
256 return;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
257 }
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
258
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
259 void
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
260 use_register_var(int i) {
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
261 regv[i]=1;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
262 }
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
263
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
264 static int creg_regvar = -1;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
265 static int creg_regvar_back;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
266 static int creg_back;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
267
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
268 void
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
269 creg_destroy() {
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
270 creg_back = creg; creg_regvar_back = creg_regvar;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
271 if (creg_regvar>=0)
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
272 creg = creg_regvar;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
273 creg_regvar=-1;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
274 }
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
275
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
276 void
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
277 creg_un_destroy() {
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
278 creg = creg_back; creg_regvar = creg_regvar_back;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
279 }
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
280
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
281 void
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
282 register_usage(char *s)
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
283 {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
284 int i;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
285 printf("# %d: %s:",lineno,s);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
286 printf(" creg=%s dreg=%s ",register_name(creg,0),register_name(dreg,0));
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
287 for(i=0;i<MAX_REGISTER;i++) {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
288 printf("%d",regs[i]);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
289 }
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
290 printf(":");
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
291 for(i=0;i<MAX_REGISTER;i++) {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
292 printf("%d",regv[i]);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
293 }
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
294 #if 0
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
295 printf(" regs_stack",register_name(creg,0),register_name(dreg,0));
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
296 for(i=reg_sp;i>=0;i--) {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
297 if(reg_stack[i]>=0)
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
298 printf(" %s",register_name(reg_stack[i],0));
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
299 }
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
300 #endif
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
301 printf("\n");
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
302 }
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
303
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
304 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
305 gexpr_init(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
306 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
307 while(reg_sp > 0) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
308 free_register(reg_stack[--reg_sp]);
d35df41eac69 Initial revision
kono
parents:
diff changeset
309 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
310 text_mode();
26
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
311 use_register(creg,REG_EAX,0);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
312 regv[dreg]=0;
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
313 creg_regvar = -1;
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
314 register_usage("gexpr_init");
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
315 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
316
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
317
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
318 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
319 emit_init(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
320 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
321 int i;
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
322 for(i=0;i<REAL_MAX_REGISTER;i++) { regs[i]=0; regv[i]=0;rname[i]=i;}
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
323 free_all_register();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
324 reg_sp = 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
325 text_mode();
d35df41eac69 Initial revision
kono
parents:
diff changeset
326 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
327
d35df41eac69 Initial revision
kono
parents:
diff changeset
328 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
329 virtual(int real)
d35df41eac69 Initial revision
kono
parents:
diff changeset
330 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
331 int real_v,i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
332 real_v = -1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
333 for(i=0;i<MAX_REGISTER;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
334 if (rname[i]==real) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
335 real_v=i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
336 break;
d35df41eac69 Initial revision
kono
parents:
diff changeset
337 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
338 }
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
339 /* if (real_v == -1)
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
340 error(-1); */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
341 return real_v;
d35df41eac69 Initial revision
kono
parents:
diff changeset
342 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
343
d35df41eac69 Initial revision
kono
parents:
diff changeset
344 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
345 use_register(int virt, int real, int move)
d35df41eac69 Initial revision
kono
parents:
diff changeset
346 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
347 int real_v;
d35df41eac69 Initial revision
kono
parents:
diff changeset
348 char *move_op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
349 if (rname[virt]==real)
d35df41eac69 Initial revision
kono
parents:
diff changeset
350 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
351 real_v = virtual(real);
d35df41eac69 Initial revision
kono
parents:
diff changeset
352 move_op = regs[real_v]?"\txchg %s,%s\n":"\tmovl %s,%s\n";
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
353 if (move || (regv[real_v])) {
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
354 printf(move_op,reg_name[rname[virt]],reg_name[real]);
d35df41eac69 Initial revision
kono
parents:
diff changeset
355 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
356 rname[real_v] = rname[virt];
d35df41eac69 Initial revision
kono
parents:
diff changeset
357 rname[virt] = real;
d35df41eac69 Initial revision
kono
parents:
diff changeset
358 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
359
d35df41eac69 Initial revision
kono
parents:
diff changeset
360 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
361 use_pointer(int virt, int move)
d35df41eac69 Initial revision
kono
parents:
diff changeset
362 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
363 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
364 if (rname[virt]>=POINTER_REG)
d35df41eac69 Initial revision
kono
parents:
diff changeset
365 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
366 for(i=POINTER_REG;i<MAX_REGISTER;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
367 if (!regs[virtual(i)]) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
368 use_register(virt,i,move);
d35df41eac69 Initial revision
kono
parents:
diff changeset
369 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
370 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
371 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
372 /* we prefer EBX */
d35df41eac69 Initial revision
kono
parents:
diff changeset
373 use_register(virt,REG_EBX,move);
d35df41eac69 Initial revision
kono
parents:
diff changeset
374 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
375
d35df41eac69 Initial revision
kono
parents:
diff changeset
376 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
377 use_data_reg(int virt, int move)
d35df41eac69 Initial revision
kono
parents:
diff changeset
378 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
379 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
380 if (rname[virt]<MAX_DATA_REG)
d35df41eac69 Initial revision
kono
parents:
diff changeset
381 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
382 for(i=0;i<MAX_DATA_REG;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
383 if (!regs[virtual(i)]) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
384 use_register(virt,i,move);
d35df41eac69 Initial revision
kono
parents:
diff changeset
385 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
386 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
387 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
388 /* we prefer EBX */
d35df41eac69 Initial revision
kono
parents:
diff changeset
389 use_register(virt,REG_EBX,move);
d35df41eac69 Initial revision
kono
parents:
diff changeset
390 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
391
d35df41eac69 Initial revision
kono
parents:
diff changeset
392 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
393 pop_register(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
394 { /* ¥ì¥¸¥¹¥¿¤«¤éÃͤò¼è¤ê½Ð¤¹ */
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
395 return reg_stack[--reg_sp];
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
396 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
397
d35df41eac69 Initial revision
kono
parents:
diff changeset
398 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
399 stack_used(void) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
400 return reg_stack[--reg_sp]<0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
401 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
402
d35df41eac69 Initial revision
kono
parents:
diff changeset
403 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
404 emit_push(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
405 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
406 int new_reg;
d35df41eac69 Initial revision
kono
parents:
diff changeset
407 new_reg = get_register();
d35df41eac69 Initial revision
kono
parents:
diff changeset
408 if(new_reg<0) { /* ¤â¤¦¥ì¥¸¥¹¥¿¤¬¤Ê¤¤ */
d35df41eac69 Initial revision
kono
parents:
diff changeset
409 reg_stack[reg_sp++] = -1;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
410 printf("\tpushl %s\n",register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
411 /* creg is used soon, don't regv[creg]=0 */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
412 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
413 reg_stack[reg_sp++] = creg; /* push ¤¹¤ë¤«¤ï¤ê¤Ë¥ì¥¸¥¹¥¿¤ò»È¤¦ */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
414 creg = new_reg;
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
415 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
416 }
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
417 }
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
418
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
419 void
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
420 emit_push_x(int xreg)
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
421 {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
422 int new_reg;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
423 new_reg = get_register();
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
424 if(new_reg<0) { /* ¤â¤¦¥ì¥¸¥¹¥¿¤¬¤Ê¤¤ */
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
425 reg_stack[reg_sp++] = -1;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
426 printf("\tpushl %s\n",register_name(xreg,0));
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
427 /* creg is used soon, don't regv[xreg]=0 */
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
428 } else {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
429 reg_stack[reg_sp++] = xreg; /* push ¤¹¤ë¤«¤ï¤ê¤Ë¥ì¥¸¥¹¥¿¤ò»È¤¦ */
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
430 xreg = new_reg;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
431 regv[xreg]=1;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
432 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
433 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
434
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
435 int
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
436 emit_pop(int type)
d35df41eac69 Initial revision
kono
parents:
diff changeset
437 {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
438 int xreg;
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
439 if ((xreg=pop_register())==-1) {
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
440 if (type==POINTER_REG)
d35df41eac69 Initial revision
kono
parents:
diff changeset
441 use_pointer(dreg,0);
d35df41eac69 Initial revision
kono
parents:
diff changeset
442 else if (type==DATA_REG)
d35df41eac69 Initial revision
kono
parents:
diff changeset
443 use_data_reg(dreg,0);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
444 if (regv[dreg]) {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
445 printf("# emit_pop dreg conflict\n");
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
446 }
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
447 printf("\tpopl %s\n",register_name(dreg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
448 xreg = dreg;
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
449 regv[xreg]=1;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
450 }
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
451 return xreg;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
452 }
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
453
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
454 static void
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
455 emit_pop_free(int xreg)
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
456 {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
457 if (xreg==dreg) {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
458 regv[dreg]=0;
43
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
459 } else if (xreg!=-1) {
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
460 free_register(xreg);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
461 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
462 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
463
d35df41eac69 Initial revision
kono
parents:
diff changeset
464 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
465 get_register_var(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
466 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
467 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
468 for(i=REG_ESI;i<REG_ESP;i++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
469 if (! regs[i]) { /* »È¤ï¤ì¤Æ¤¤¤Ê¤¤¤Ê¤é */
d35df41eac69 Initial revision
kono
parents:
diff changeset
470 regs[i]=1; /* ¤½¤Î¥ì¥¸¥¹¥¿¤ò»È¤¦¤³¤È¤òÀë¸À¤· */
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
471 regv[i]=0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
472 return i; /* ¤½¤Î¾ì½ê¤òɽ¤¹ÈÖ¹æ¤òÊÖ¤¹ */
d35df41eac69 Initial revision
kono
parents:
diff changeset
473 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
474 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
475 return -1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
476 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
477
d35df41eac69 Initial revision
kono
parents:
diff changeset
478 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
479 gexpr(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
480 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
481 gexpr_init();
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
482 #if 0
32
b35787d8a442 macro initialization
kono
parents: 27
diff changeset
483 if(lineno==2862) {
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
484 g_expr(e1); /*break here*/
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
485 return;
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
486 }
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
487 #endif
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
488 g_expr(e1);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
489 }
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
490
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
491 int
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
492 csvalue()
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
493 {
61
8ffb8ca3fe34 separation of architecture dependent part.
kono
parents: 58
diff changeset
494 return rname[creg]; /* for switch value */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
495 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
496
d35df41eac69 Initial revision
kono
parents:
diff changeset
497 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
498 g_expr(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
499 {
22
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
500 int e2,e3/*,e4*/;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
501 char *xrn;
d35df41eac69 Initial revision
kono
parents:
diff changeset
502 NMTBL *n;
d35df41eac69 Initial revision
kono
parents:
diff changeset
503
d35df41eac69 Initial revision
kono
parents:
diff changeset
504 if (chk) return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
505 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
506 switch (car(e1)){
d35df41eac69 Initial revision
kono
parents:
diff changeset
507 case GVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
508 /* use_pointer(creg,0); */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
509 printf("\tmovl $%s,%s\n",(char *)caddr(e1),register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
510 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
511 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
512 case RGVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
513 /* use_pointer(creg,0); */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
514 printf("\tmovl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
515 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
516 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
517 case CRGVAR:
27
af0c69eaa433 *** empty log message ***
kono
parents: 26
diff changeset
518 printf("\tmovsbl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
519 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
520 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
521 case LVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
522 /* use_pointer(creg,0); */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
523 printf("\tlea %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
524 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
525 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
526 case REGISTER:
d35df41eac69 Initial revision
kono
parents:
diff changeset
527 /* this is of course redundant... */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
528 /* we can use rname for this? */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
529 /* or why not creg=e2? */
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
530 printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
531 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
532 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
533 case RLVAR:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
534 printf("\tmovl %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
535 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
536 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
537 case CRLVAR:
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
538 printf("\tmovsbl %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
539 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
540 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
541 case FNAME:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
542 printf("\tmovl $%s,%s\n",((NMTBL *)e2)->nm,register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
543 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
544 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
545 case CONST: /* ÂåÆþ¤¹¤ëÃͤ¬0¤Ç¤âÆÃÊ̤ʽèÍý¤Ï¤·¤Ê¤¤ */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
546 printf("\tmovl $%d,%s\n",e2,register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
547 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
548 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
549 case STRING:
d35df41eac69 Initial revision
kono
parents:
diff changeset
550 string(e1);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
551 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
552 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
553 case FUNCTION:
d35df41eac69 Initial revision
kono
parents:
diff changeset
554 function(e1);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
555 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
556 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
557 case CODE:
d35df41eac69 Initial revision
kono
parents:
diff changeset
558 jump(e2,caddr(e1));
d35df41eac69 Initial revision
kono
parents:
diff changeset
559 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
560 case INDIRECT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
561 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
562 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
563 case RINDIRECT: case CRINDIRECT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
564 rindirect(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
565 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
566 case ADDRESS:
d35df41eac69 Initial revision
kono
parents:
diff changeset
567 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
568 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
569 case MINUS: /* ¥ì¥¸¥¹¥¿¤ËÂФ·¡¢negl¤ò¼Â¹Ô¤¹¤ì¤Ð¼Â¸½²Äǽ */
d35df41eac69 Initial revision
kono
parents:
diff changeset
570 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
571 /* use_data_reg(creg,1); */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
572 printf("\tnegl %s\n", register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
573 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
574 case BNOT: /* ~ */
d35df41eac69 Initial revision
kono
parents:
diff changeset
575 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
576 /* use_data_reg(creg,1); */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
577 printf("\tnotl %s\n", register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
578 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
579 case LNOT: /* ! */
d35df41eac69 Initial revision
kono
parents:
diff changeset
580 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
581 use_data_reg(creg,1);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
582 xrn = register_name(creg,1);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
583 printf("\tcmpl $0,%s\n", register_name(creg,0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
584 printf("\tsete %s\n", xrn);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
585 printf("\tmovzbl %s,%s\n", xrn,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
586 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
587 case PREINC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
588 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
589 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
590 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
591 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
592 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
593 g_expr(e2);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
594 xrn = register_name(creg,0);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
595 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
596 printf("\tmovl (%s),%s\n",xrn,xrn);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
597 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
598 case POSTINC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
599 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
600 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
601 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
602 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
603 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
604 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
605 emit_push();
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
606 xrn = register_name((e2=emit_pop(0)),0);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
607 printf("\tmovl (%s),%s\n",xrn,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
608 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
609 emit_pop_free(e2);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
610 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
611 case CPOSTINC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
612 /* char *p; *p++ */
d35df41eac69 Initial revision
kono
parents:
diff changeset
613 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
614 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
615 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
616 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
617 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
618 g_expr(e2);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
619 emit_push();
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
620 xrn = register_name((e2=emit_pop(0)),1);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
621 printf("\tmovsbl (%s),%s\n",xrn,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
622 printf("\tincl (%s)\n",xrn);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
623 emit_pop_free(e2);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
624 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
625 case CPREINC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
626 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
627 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
628 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
629 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
630 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
631 g_expr(e2);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
632 printf("\tincl (%s)\n",register_name(creg,0));
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
633 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
634 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
635 case CPOSTDEC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
636 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
637 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
638 printf("\tdecl %s\n",register_name(cadr(e2),0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
639 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
640 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
641 g_expr(e2);
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
642 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
643 printf("\tdecl (%s)\n",register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
644 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
645 case CPREDEC:
d35df41eac69 Initial revision
kono
parents:
diff changeset
646 if (car(e2)==REGISTER) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
647 printf("\tdecl %s\n",register_name(cadr(e2),0));
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
648 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
649 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
650 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
651 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
652 emit_push();
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
653 e2 = emit_pop(0);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
654 printf("\tdecl (%s)\n",register_name(e2,0));
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
655 printf("\tmovsbl (%s),%s\n",register_name(e2,0),register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
656 emit_pop_free(e2);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
657 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
658 case MUL: case UMUL:
d35df41eac69 Initial revision
kono
parents:
diff changeset
659 case DIV: case UDIV:
d35df41eac69 Initial revision
kono
parents:
diff changeset
660 case MOD: case UMOD:
d35df41eac69 Initial revision
kono
parents:
diff changeset
661 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
662 case ADD: case SUB: case BAND: case EOR: case BOR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
663 machinop(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
664 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
665 case COND:
d35df41eac69 Initial revision
kono
parents:
diff changeset
666 e2=fwdlabel();
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
667 b_expr(cadr(e1),0,e2,0);
22
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
668 use_register(creg,REG_EAX,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
669 g_expr(caddr(e1));
22
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
670 /* e4 = rname[creg]; this is a bad idea */
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
671 use_register(creg,REG_EAX,1);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
672 jmp(e3=fwdlabel());
d35df41eac69 Initial revision
kono
parents:
diff changeset
673 fwddef(e2);
22
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
674 use_register(creg,REG_EAX,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
675 g_expr(cadddr(e1));
22
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
676 /* use_register(creg,e4,1); */
3fa41d00f658 *** empty log message ***
kono
parents: 21
diff changeset
677 use_register(creg,REG_EAX,1);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
678 fwddef(e3);
d35df41eac69 Initial revision
kono
parents:
diff changeset
679 return;
164
1c2a9232ea93 mc.h generation
kono
parents: 62
diff changeset
680 case STASS:
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
681 sassign(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
682 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
683 case ASS: case CASS:
d35df41eac69 Initial revision
kono
parents:
diff changeset
684 assign(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
685 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
686 case ASSOP: case CASSOP:
d35df41eac69 Initial revision
kono
parents:
diff changeset
687 assop(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
688 return;
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
689 case RSTRUCT:
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
690 g_expr(e2);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
691 return;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
692 case COMMA:
d35df41eac69 Initial revision
kono
parents:
diff changeset
693 g_expr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
694 g_expr(caddr(e1));
d35df41eac69 Initial revision
kono
parents:
diff changeset
695 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
696 case RETURN:
d35df41eac69 Initial revision
kono
parents:
diff changeset
697 n = (NMTBL *)e2;
d35df41eac69 Initial revision
kono
parents:
diff changeset
698 if (retcont==0)
d35df41eac69 Initial revision
kono
parents:
diff changeset
699 retcont=fwdlabel();
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
700 printf("\tleal _%d,%s\n",retcont,register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
701 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
702 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
703 case ENVIRONMENT:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
704 printf("\tmovl %%ebp,%s\n",register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
705 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
706 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
707 default:
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
708 b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
709 xrn = register_name(creg,0);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
710 printf("\txorl %s,%s\n",xrn,xrn);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
711 jmp(e3=fwdlabel());
d35df41eac69 Initial revision
kono
parents:
diff changeset
712 fwddef(e2);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
713 printf("\tmovl $1,%s\n",xrn);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
714 fwddef(e3);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
715 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
716 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
717 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
718
d35df41eac69 Initial revision
kono
parents:
diff changeset
719 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
720 bexpr(int e1, char cond, int l1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
721 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
722 gexpr_init();
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
723 b_expr(e1,cond,l1,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
724 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
725
d35df41eac69 Initial revision
kono
parents:
diff changeset
726 void
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
727 b_expr(int e1, char cond, int l1,int err)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
728 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
729 int e2,l2;
d35df41eac69 Initial revision
kono
parents:
diff changeset
730 if (chk) return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
731 e2=cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
732 switch(car(e1)) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
733 case LNOT:
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
734 b_expr(e2,!cond,l1,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
735 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
736 case GT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
737 rexpr(e1,l1,cond?"g":"le");
d35df41eac69 Initial revision
kono
parents:
diff changeset
738 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
739 case UGT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
740 rexpr(e1,l1,cond?"a":"be");
d35df41eac69 Initial revision
kono
parents:
diff changeset
741 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
742 case GE:
d35df41eac69 Initial revision
kono
parents:
diff changeset
743 rexpr(e1,l1,cond?"ge":"l");
d35df41eac69 Initial revision
kono
parents:
diff changeset
744 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
745 case UGE:
d35df41eac69 Initial revision
kono
parents:
diff changeset
746 rexpr(e1,l1,cond?"ae":"b");
d35df41eac69 Initial revision
kono
parents:
diff changeset
747 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
748 case LT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
749 rexpr(e1,l1,cond?"l":"ge");
d35df41eac69 Initial revision
kono
parents:
diff changeset
750 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
751 case ULT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
752 rexpr(e1,l1,cond?"b":"ae");
d35df41eac69 Initial revision
kono
parents:
diff changeset
753 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
754 case LE:
d35df41eac69 Initial revision
kono
parents:
diff changeset
755 rexpr(e1,l1,cond?"le":"g");
d35df41eac69 Initial revision
kono
parents:
diff changeset
756 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
757 case ULE:
d35df41eac69 Initial revision
kono
parents:
diff changeset
758 rexpr(e1,l1,cond?"be":"a");
d35df41eac69 Initial revision
kono
parents:
diff changeset
759 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
760 case EQ:
d35df41eac69 Initial revision
kono
parents:
diff changeset
761 rexpr(e1,l1,cond?"e":"ne");
d35df41eac69 Initial revision
kono
parents:
diff changeset
762 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
763 case NEQ:
d35df41eac69 Initial revision
kono
parents:
diff changeset
764 rexpr(e1,l1,cond?"ne":"e");
d35df41eac69 Initial revision
kono
parents:
diff changeset
765 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
766 case LAND:
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
767 b_expr(e2,0,cond?(l2=fwdlabel()):l1,0);
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
768 b_expr(caddr(e1),cond,l1,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
769 if(cond) fwddef(l2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
770 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
771 case LOR:
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
772 b_expr(e2,1,cond?l1:(l2=fwdlabel()),0);
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
773 b_expr(caddr(e1),cond,l1,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
774 if(!cond) fwddef(l2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
775 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
776 case CRGVAR:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
777 printf("\tcmpb $0,%s\n",(char *)caddr(e1));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
778 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
779 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
780 case CRLVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
781 printf("\tcmpb $0,%d(%%ebp)\n",lvar(e2));
d35df41eac69 Initial revision
kono
parents:
diff changeset
782 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
783 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
784 case RGVAR:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
785 printf("\tcmpl $0,%s\n",(char *)caddr(e1));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
786 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
787 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
788 case RLVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
789 printf("\tcmpl $0,%d(%%ebp)\n",lvar(e2));
d35df41eac69 Initial revision
kono
parents:
diff changeset
790 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
791 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
792 case REGISTER:
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
793 printf("\tcmpl $0,%s\n",register_name(e2,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
794 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
795 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
796 case CONST:
d35df41eac69 Initial revision
kono
parents:
diff changeset
797 if((cond&&e2)||(!cond&&!e2)) jmp(l1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
798 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
799 default:
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
800 if(err) {
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
801 error(-1); return; /* recursice g_expr/b_expr */
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
802 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
803 g_expr(e1);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
804 printf("\tcmpl $0,%s\n",register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
805 jcond(l1,cond);
d35df41eac69 Initial revision
kono
parents:
diff changeset
806 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
807 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
808 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
809
d35df41eac69 Initial revision
kono
parents:
diff changeset
810 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
811 ascii(char *s)
d35df41eac69 Initial revision
kono
parents:
diff changeset
812 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
813 printf("\t.string \"");
d35df41eac69 Initial revision
kono
parents:
diff changeset
814 while(*s) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
815 if (*s=='\n')
d35df41eac69 Initial revision
kono
parents:
diff changeset
816 printf("%cn",92);
d35df41eac69 Initial revision
kono
parents:
diff changeset
817 else if (*s<' ')
d35df41eac69 Initial revision
kono
parents:
diff changeset
818 printf("%c%03o",92,*s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
819 else if (*s==34)
d35df41eac69 Initial revision
kono
parents:
diff changeset
820 printf("%c%c",92,34);
d35df41eac69 Initial revision
kono
parents:
diff changeset
821 else
d35df41eac69 Initial revision
kono
parents:
diff changeset
822 printf("%c",*s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
823 s++;
d35df41eac69 Initial revision
kono
parents:
diff changeset
824 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
825 printf("%c\n",34);
d35df41eac69 Initial revision
kono
parents:
diff changeset
826 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
827
d35df41eac69 Initial revision
kono
parents:
diff changeset
828 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
829 string(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
830 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
831 char *s;
d35df41eac69 Initial revision
kono
parents:
diff changeset
832 int i,lb;
d35df41eac69 Initial revision
kono
parents:
diff changeset
833
d35df41eac69 Initial revision
kono
parents:
diff changeset
834 if (0) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
835 s=(char *)cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
836 lb=fwdlabel();
d35df41eac69 Initial revision
kono
parents:
diff changeset
837 printf("\tjmp _%d\n",lb);
d35df41eac69 Initial revision
kono
parents:
diff changeset
838 i=backdef();
d35df41eac69 Initial revision
kono
parents:
diff changeset
839 ascii(s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
840 printf("\t.align 2\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
841 fwddef(lb);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
842 printf("\tlea _%d,%s\n",i,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
843 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
844 s=(char *)cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
845 printf(".section\t.rodata\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
846 lb=fwdlabel();
d35df41eac69 Initial revision
kono
parents:
diff changeset
847 printf("_%d:\n",lb);
d35df41eac69 Initial revision
kono
parents:
diff changeset
848 ascii(s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
849 if (output_mode==TEXT_EMIT_MODE) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
850 printf(".text\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
851 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
852 text_mode();
d35df41eac69 Initial revision
kono
parents:
diff changeset
853 }
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
854 printf("\tlea _%d,%s\n",lb,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
855 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
856 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
857
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
858 #define MAX_COPY_LEN 20
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
859
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
860 void
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
861 emit_copy(int from,int to,int length,int offset,int value,int det)
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
862 {
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
863 int fix = 0;
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
864 /* length <0 means upward direction copy */
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
865 switch (length) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
866 case 0: break;
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
867 case 1: case -1:
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
868 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
869 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
870 break;
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
871 case 2: case -2:
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
872 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
873 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
874 break;
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
875 case 4: case -4:
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
876 printf("\tmovl %d(%s),%s\n",offset,register_name(from,0), register_name(dreg,0));
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
877 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
878 break;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
879 default:
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
880 if (-MAX_COPY_LEN<length && length <0) {
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
881 for(;length<=4;length+=4,offset-=4)
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
882 emit_copy(from,to,4,offset,0,det);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
883 for(;length<=2;length+=2,offset-=2)
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
884 emit_copy(from,to,2,offset,0,det);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
885 if(length>0)
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
886 emit_copy(from,to,length,offset,0,det);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
887 break;
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
888 } else if (length <=MAX_COPY_LEN) {
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
889 for(;length>=4;length-=4,offset+=4)
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
890 emit_copy(from,to,4,offset,0,det);
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
891 for(;length>=2;length-=2,offset+=2)
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
892 emit_copy(from,to,2,offset,0,det);
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
893 if(length>0)
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
894 emit_copy(from,to,length,offset,0,det);
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
895 break;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
896 }
58
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
897 if (det) {
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
898 /*
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
899 call bcopy
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
900 g_expr(list3(FUNCTION,,);
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
901 break;
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
902 */
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
903 }
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
904 use_register(from,REG_ESI,1);
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
905 use_register(to, REG_EDI,1);
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
906 use_register(dreg,REG_ECX,0);
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
907 if (length<0) {
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
908 printf("\tmovl $%d,%%ecx\n",-length/4);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
909 printf("\taddl $%d,%%esi\n",-length);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
910 printf("\taddl $%d,%%edi\n",-length);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
911 printf("\tstd\n\trep\n\tmovsl\n");
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
912 if(length%4) {
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
913 emit_copy(from,to,length,offset+length/4,0,det);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
914 }
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
915 } else {
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
916 printf("\tmovl $%d,%%ecx\n",length/4);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
917 fix = (length/4)*4;
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
918 printf("\tcld\n\trep\n\tmovsl\n");
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
919 if(length%4) {
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
920 emit_copy(from,to,length,offset+length/4,0,det);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
921 }
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
922 }
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
923 }
47
f6b5e4f1a962 *** empty log message ***
kono
parents: 46
diff changeset
924 if (value) {
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
925 /* creg must point top of the destination data */
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
926 /* this code is necessary for the value of assignment or function call */
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
927 /* otherwise we don't need this */
47
f6b5e4f1a962 *** empty log message ***
kono
parents: 46
diff changeset
928 if (fix) printf("\tsubl $%d,%s\n",fix,register_name(to,0));
f6b5e4f1a962 *** empty log message ***
kono
parents: 46
diff changeset
929 if(creg!=to) {
f6b5e4f1a962 *** empty log message ***
kono
parents: 46
diff changeset
930 if (to==dreg)
f6b5e4f1a962 *** empty log message ***
kono
parents: 46
diff changeset
931 printf("\tmovl %s,%s\n",register_name(to,0),register_name(creg,0));
f6b5e4f1a962 *** empty log message ***
kono
parents: 46
diff changeset
932 else {
f6b5e4f1a962 *** empty log message ***
kono
parents: 46
diff changeset
933 free_register(creg); creg=to;
f6b5e4f1a962 *** empty log message ***
kono
parents: 46
diff changeset
934 }
45
b9266c88495c *** empty log message ***
kono
parents: 44
diff changeset
935 }
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
936 }
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
937 regv[from]=regv[to]=regv[dreg]=0;
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
938 regv[creg]=1;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
939 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
940
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
941 int
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
942 struct_push(int e4,int t)
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
943 {
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
944 int length,xreg,save,lreg;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
945 g_expr(e4);
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
946 length=size(t);
77c0710a8729 struct copy
kono
parents: 13
diff changeset
947 if(length%size_of_int) {
77c0710a8729 struct copy
kono
parents: 13
diff changeset
948 length += size_of_int - (length%size_of_int);
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
949 }
40
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
950 if (length==4) {
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
951 printf("\tpushl (%s)\n",register_name(creg,0)); return 1;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
952 }
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
953 if (length==8) {
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
954 printf("\tpushl 4(%s)\n",register_name(creg,0));
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
955 printf("\tpushl (%s)\n",register_name(creg,0)); return 2;
060d1e549fec *** empty log message ***
kono
parents: 39
diff changeset
956 }
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
957 printf("\tsubl $%d,%%esp\n",length);
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
958 if (register_full()) {
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
959 save = 1;
46
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
960 for(lreg=0;lreg==creg||lreg==dreg;lreg++);
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
961 printf("\tpushl %s\n",register_name(lreg,0));
46
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
962 xreg = lreg; regv[xreg]=0;
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
963 } else {
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
964 save=0;
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
965 xreg = get_register();
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
966 }
46
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
967 if (save)
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
968 printf("\tlea %d(%%esp),%s\n",size_of_int,register_name(xreg,0));
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
969 else
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
970 printf("\tmovl %%esp,%s\n",register_name(xreg,0));
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
971 regv[xreg]=1;
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
972 /* downward direction copy */
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
973 emit_copy(creg,xreg,length,0,0,1);
46
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
974 /* we have value in creg, it may be changed */
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
975 if (save) {
46
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
976 if(creg==xreg) {
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
977 creg = get_register(); /* creg is freed in emit_copy */
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
978 }
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
979 printf("\tpopl %s\n",register_name(xreg,0));
b1c8ac8c308d fix cascading struct retrun. Now it should be compatible with gcc
kono
parents: 45
diff changeset
980 regv[xreg]=1;
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
981 } else
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
982 free_register(xreg);
14
77c0710a8729 struct copy
kono
parents: 13
diff changeset
983 return length/size_of_int;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
984 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
985
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
986 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
987 function(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
988 {
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
989 int e2,e3,e4,e5,nargs,t;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
990 NMTBL *n;
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
991 int save,saved;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
992 if (free_register_count()<1) {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
993 for(save = 0;save==dreg||save==creg;save++);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
994 printf("\tpushl %s\n",register_name(save,0));
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
995 saved = 1;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
996 } else {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
997 save = get_register();
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
998 saved = 0;
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
999 }
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1000 regv[save]=0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1001 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1002 nargs = 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1003 for (e3 = caddr(e1); e3; e3 = cadr(e3)) {
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1004 t=caddr(e3);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1005 n=(NMTBL *)(e5=(cadr(e4 = car(e3))));
58
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
1006 if(scalar(t)) {
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
1007 g_expr(e4);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1008 printf("\tpushl %s\n",register_name(creg,0));
58
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
1009 } else if (car(t)==STRUCT||car(t)==UNION) {
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
1010 nargs += struct_push(e4,t);
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
1011 continue;
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
1012 } else {
727c280bdd25 *** empty log message ***
kono
parents: 57
diff changeset
1013 error(TYERR);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1014 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1015 ++nargs;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1016 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1017 if (car(e2) == FNAME) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1018 n=(NMTBL *)cadr(e2);
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1019 } else {
44
c9293a6e40d2 *** empty log message ***
kono
parents: 43
diff changeset
1020 use_register(creg,REG_EAX,0);
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1021 g_expr(e2);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1022 }
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1023
26
85b8648de04f *** empty log message ***
kono
parents: 24
diff changeset
1024 /* we don't have to save creg nor dreg */
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1025 regs[creg]=0; regs[dreg]=0;
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1026 regv[creg]= regv[dreg]= regv[save]= 0;
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1027 use_register(creg,REG_EAX,0);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1028 use_register(dreg,REG_EDX,0); /* will be destroyed */
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1029 use_register(save,REG_ECX,0); /* will be destroyed */
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1030 regs[creg]=1; regs[dreg]=1;
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1031
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1032 if (car(e2) == FNAME) {
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1033 printf("\tcall\t%s\n",n->nm);
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1034 } else {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1035 printf("\tcall\t*%s\n",register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1036 }
6
bf602558130d continuation
kono
parents: 5
diff changeset
1037 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
1038 if (saved) {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1039 printf("\tpopl %s\n",register_name(save,0));
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1040 } else {
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1041 free_register(save);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1042 }
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1043 regv[save]=0;
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1044 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1045 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1046
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1047 /* goto arguments list */
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1048 /* target list4(list2(tag,disp),cdr,ty,source_expr) */
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1049 /* source expr=listn(tag,...) */
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1050 /* source (after) list2(tag,disp) */
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1051 /* source list list3(e,cdr,sz) */
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1052
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1053 #define DEBUG_PARALLEL_ASSIGN 1
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1054
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1055 int
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1056 overrap(int t,int sz,int source)
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1057 {
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1058 int s,s0,s1;
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1059 int t0=cadr(t);
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1060 int t1=t0+sz;
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1061 for(;source;source=cadr(source)) {
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1062 s=car(source); s0=cadr(s);
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1063 if(car(s)==REGISTER && car(t)==REGISTER) {
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1064 if(s0==t0) return s;
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1065 } else if (is_same_type(s,t)) {
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1066 s1=s0+caddr(source);
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1067 #if DEBUG_PARALLEL_ASSIGN>1
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1068 printf("# ovedrrap source %d t0 %d t1 %d\n",car(car(t)),t0,t1);
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1069 printf("# ovedrrap target %d s0 %d s1 %d\n",car(car(source)),s0,s1);
54
kono
parents: 53
diff changeset
1070 printf("# ovedrrap equal = %d\n",((t0<=s0&&s0<t1)||(t0<s1&&s1<=t1)));
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1071 #endif
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1072 if((t0<=s0&&s0<t1)||(t0<s1&&s1<=t1)) return s;
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1073 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1074 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1075 return 0;
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1076 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1077
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1078 void
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1079 remove_target(int *target,int t,int *use)
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1080 {
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1081 int use0=*use;
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1082 while(use0) {
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1083 if (car(use0)==t) {
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1084 free_register(caddr(use0));
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1085 break;
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1086 }
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1087 use0 = cadr(use0);
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1088 }
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1089 remove0(target,t);
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1090 }
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1091
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1092 void
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1093 save_target(int t,int s,int *target,int *use,int sz,int ty)
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1094 {
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1095 int e1;
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1096 /*¿·¤·¤¤¥ì¥¸¥¹¥¿(or ¥¹¥¿¥Ã¥¯)¤ò¼èÆÀ¤¹¤ë*/
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1097 if (sz==size_of_int && (e1=get_register())!=-1) {
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1098 *use=list3(t,*use,e1);
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1099 e1=list2(REGISTER,e1);
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1100 g_expr(assign_expr0(e1,s,ty,ty));
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1101 *target = append4(*target,t,ty,e1);
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1102 } else {
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1103 disp-=sz;
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1104 g_expr(assign_expr0((e1=list2(LVAR,disp)),s,ty,ty));
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1105 *target = append4(*target,t,ty,e1);
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1106 }
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1107 }
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1108
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1109 int
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1110 circular_dependency(int t,int s,int *target,int *source)
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1111 {
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1112 int target0=*target;
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1113 int t1,sz,ty,s1;
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1114 while(target0) {
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1115 if (cadddr(target0)==s) {
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1116 t1=car(target0);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1117 s=cadddr(target0);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1118 sz=size(ty=caddr(target0));
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1119 if(t==t1) {
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1120 #if DEBUG_PARALLEL_ASSIGN
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1121 printf("# circular dependency %d ty %d+%d sz %d\n",car(t1),ty,cadr(t1),sz);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1122 #endif
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1123 return 1;
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1124 }
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1125 if ((s1=overrap(t1,sz,*source))) {
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1126 /* another overrap start over */
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1127 return circular_dependency(t,s1,target,source);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1128 }
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1129 }
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1130 target0=cadr(target0);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1131 }
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1132 return 0;
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1133 }
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1134
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1135 void
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1136 parallel_assign(int *target,int *source,int *processing,int *use)
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1137 {
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1138 int t,s,sz,ty,target0,s1;
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1139 while(*target) {
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1140 target0=*target;
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1141 while(target0) {
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1142 t=car(target0); s=cadddr(target0);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1143 sz=size(ty=caddr(target0));
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1144 if(car(t)==car(s) && cadr(t)==cadr(s)) {
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1145 /*½ñ¤­¹þ¤ßÀ褬¼«Ê¬¼«¿È*/
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1146 #if DEBUG_PARALLEL_ASSIGN
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1147 printf("# remove same %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz);
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1148 #endif
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1149 remove_target(target,t,use);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1150 /* Ç˲õ¤µ¤ì¤Æ¤Ïº¤¤ë¤Î¤Ç¡¢source list¤«¤é¤Ï½ü¤«¤Ê¤¤ */
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1151 } else if (!(s1=overrap(t,sz,*source))) {
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1152 /* ½Å¤Ê¤Ã¤Æ¤Ê¤¤¤Î¤Ç°Â¿´¤·¤Æ½ñ¤­¹þ¤á¤ë */
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1153 #if DEBUG_PARALLEL_ASSIGN
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1154 printf("# normal assign %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz);
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1155 #endif
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1156 g_expr(assign_expr0(t,s,ty,ty));
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1157 remove_target(target,t,use); remove0(source,s);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1158 } else {
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1159 if(circular_dependency(t,s1,target,source)) {
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1160 #if DEBUG_PARALLEL_ASSIGN
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1161 printf("# saving %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz);
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1162 #endif
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1163 remove_target(target,t,use); remove0(source,s);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1164 save_target(t,s,target,use,sz,ty);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1165 }
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1166 }
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1167 target0=cadr(target0);
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1168 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1169 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1170 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1171
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1172 void
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1173 remove0(int *parent,int e)
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1174 {
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1175 int list;
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1176 while ((list=*parent)) {
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1177 if (car(list)==e) {
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1178 *parent= cadr(list); return;
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1179 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1180 parent=&cadr(list);
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1181 }
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1182 }
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1183 }
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1184
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1185 void
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1186 remove0_all(int *parent,int e)
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1187 {
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1188 int list;
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1189 while ((list=*parent)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1190 if (car(list)==e) {
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1191 *parent= cadr(list);
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1192 } else {
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1193 parent=&cadr(list);
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1194 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1195 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1196 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1197
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1198 int
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1199 is_simple(int e1)
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1200 {
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1201 return (
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1202 e1==CONST || e1==FNAME || e1==LVAR || e1==REGISTER ||
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1203 e1==GVAR || e1==RGVAR || e1==RLVAR || e1==CRLVAR || e1==CRGVAR
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1204 );
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1205 }
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1206
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1207 int
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1208 is_same_type(int e1,int e2)
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1209 {
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1210 int ce1=car(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1211 int ce2=car(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1212 return (
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1213 (ce1==LVAR && (ce2==RLVAR||ce2==CRLVAR))
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1214 || (ce2==LVAR && (ce1==RLVAR||ce1==CRLVAR))
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1215 || (ce1==GVAR && (ce2==RGVAR||ce2==CRGVAR))
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1216 || (ce2==GVAR && (ce1==RGVAR||ce1==CRGVAR))
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1217 );
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1218 }
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1219
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1220 int
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1221 is_memory(int e1)
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1222 {
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1223 int ce1=car(e1);
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1224 return (
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1225 ce1==LVAR ||ce1==RLVAR||ce1==CRLVAR ||
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1226 ce1==GVAR ||ce1==RGVAR||ce1==CRGVAR ||
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1227 ce1==REGISTER
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1228 );
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1229 }
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1230
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1231 void
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1232 jump(int e1, int env)
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1233 {
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1234 int e2,e3,e4,sz,arg_size,ty,max_regs,regs;
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1235 int t0,s0;
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1236 NMTBL *code0;
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1237 int target = 0;
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1238 int source = 0;
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1239 int processing = 0;
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1240 int use = 0;
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1241
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1242 /* ¤Þ¤º¡¢¥µ¥¤¥º¤ò·×»»¤·¤Ê¤¬¤é¡¢·è¤Þ¤Ã¤¿·Á¤ËÍ¡£ */
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1243
50
kono
parents: 49
diff changeset
1244 arg_size = 0; regs = 0; max_regs = MAX_REGISTER_VAR-1;
kono
parents: 49
diff changeset
1245 for (e3 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) {
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1246 e2 = car(e3); sz = size(ty=caddr(e3));
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1247 if (regs <= max_regs&&scalar(ty)) {
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1248 target=list4(list2(REGISTER,virtual((regs++)+REG_ESI)),
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1249 target,ty,e2);
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1250 } else {
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1251 target=list4(list2(LVAR,0),
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1252 target,ty,e2);
49
884c74e6a2f7 no compile error
kono
parents: 48
diff changeset
1253 arg_size += sz;
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1254 }
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1255 #if DEBUG_PARALLEL_ASSIGN
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1256 printf("# target %d ty %d+%d sz %d\n",car(car(target)),ty,cadr(car(target)),sz);
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1257 #endif
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1258 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1259
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1260 /* disp ¤òÈô¤ÓÀè»÷¹ç¤ï¤»¤Æ½¤Àµ */
50
kono
parents: 49
diff changeset
1261 if (fnptr->sc==CODE) {
kono
parents: 49
diff changeset
1262 if (-arg_size<disp) disp = -arg_size;
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1263 jump_offset = 0;
50
kono
parents: 49
diff changeset
1264 } else {
kono
parents: 49
diff changeset
1265 if (disp_offset-arg_size<disp) disp = disp_offset-arg_size;
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1266 jump_offset = 0;
50
kono
parents: 49
diff changeset
1267 }
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1268
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1269 /* Ê£»¨¤Ê¼°¤òÁ°¤â¤Ã¤Æ·×»»¤·¤Æ¤ª¤¯ */
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1270 /* ɬÍפʤé¶É½êÊÑ¿ô¤òÍѤ¤¤ë¡£ */
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1271 /* ¶É½êÊÑ¿ô¤Ø¤Î¥ª¥Õ¥»¥Ã¥È¤ò³Ð¤¨¤Æ¤ª¤¯ */
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1272
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1273 for (e2 = target; e2; e2 = cadr(e2)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1274 t0=car(e2); s0=cadddr(e2);
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1275 sz=size(ty=caddr(e2));
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1276 if(car(t0)==LVAR) {
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1277 /* ¤³¤³¤Ç¡¢½ñ¹þÀ襢¥É¥ì¥¹¤ò·è¤á¤ë */
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1278 cadr(t0)=-arg_size+jump_offset;
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1279 arg_size-=sz;
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1280 }
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1281 if (!is_simple(car(s0))) {
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1282 disp-=sz;
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1283 g_expr(assign_expr0((e4=list2(LVAR,disp)),s0,ty,ty));
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1284 cadddr(e2)=e4;
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1285 s0=e4;
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1286 } else if (is_same_type(t0,s0)) {
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1287 if(cadr(t0)==cadr(s0)) {
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1288 #if DEBUG_PARALLEL_ASSIGN
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1289 printf("# remove same memory %d ty %d+%d sz %d\n",car(t0),ty,cadr(t0),sz);
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1290 #endif
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1291 /* we should check size also (but currently useless */
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1292 remove0(&target,t0);
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1293 /* still we have source to avoid overwrite */
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1294 }
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1295 }
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1296 if(is_memory(s0)) {
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1297 source=list3(s0,source,sz);
56
5aa4528b6983 A little optimized parallel assignment
kono
parents: 55
diff changeset
1298 #if DEBUG_PARALLEL_ASSIGN
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1299 printf("# source %d ty %d+%d sz %d\n",car(car(source)),ty,cadr(car(source)),sz);
51
c2ef3a2fbe88 *** empty log message ***
kono
parents: 50
diff changeset
1300 #endif
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1301 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1302 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1303
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1304 /* compute jump address */
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1305 e2 = cadr(e1);
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1306 if (car(e2) == FNAME) {
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1307 code0=(NMTBL *)cadr(e2);
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1308 if (code0->sc!=CODE) {
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1309 error(TYERR); return;
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1310 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1311 } else { /* indirect */
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1312 g_expr(e2);
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1313 emit_push();
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1314 }
50
kono
parents: 49
diff changeset
1315 if (env) {
kono
parents: 49
diff changeset
1316 g_expr(env);
kono
parents: 49
diff changeset
1317 emit_push();
kono
parents: 49
diff changeset
1318 }
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1319
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1320 /* ÊÂÎóÂåÆþ¤ò¼Â¹Ô */
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1321
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1322 parallel_assign(&target,&source,&processing,&use);
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1323 while (use) {
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1324 free_register(caddr(use)); use=cadr(use);
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1325 }
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1326 if(target) error(-1);
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1327
50
kono
parents: 49
diff changeset
1328 if (env) {
kono
parents: 49
diff changeset
1329 /* change the frame pointer */
kono
parents: 49
diff changeset
1330 e3 = emit_pop(0);
kono
parents: 49
diff changeset
1331 printf("\tmovl %s,%%ebp\n",register_name(e3,0));
kono
parents: 49
diff changeset
1332 emit_pop_free(e3);
kono
parents: 49
diff changeset
1333 } else if (fnptr->sc==FUNCTION) {
kono
parents: 49
diff changeset
1334 printf("\tlea %d(%%ebp),%%ebp\n",disp_offset);
kono
parents: 49
diff changeset
1335 }
kono
parents: 49
diff changeset
1336
48
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1337 if (car(e2) == FNAME) {
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1338 printf("\tjmp %s\n",code0->nm);
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1339 } else {
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1340 e2 = emit_pop(0);
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1341 printf("\tjmp *%s\n",register_name(e2,0));
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1342 emit_pop_free(e2);
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1343 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1344 }
8575ec496cd4 jump with overrupped struct (first code)
kono
parents: 47
diff changeset
1345
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1346 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1347 machinop(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1348 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1349 int e2,e3,op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1350
d35df41eac69 Initial revision
kono
parents:
diff changeset
1351 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1352 op = car(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1353 e3 = caddr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1354 g_expr(e3);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1355 emit_push();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1356 g_expr(e2);
43
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1357 tosop(car(e1),(e2=pop_register()));
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1358 emit_pop_free(e2);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1359 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1360 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1361 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1362
d35df41eac69 Initial revision
kono
parents:
diff changeset
1363
d35df41eac69 Initial revision
kono
parents:
diff changeset
1364 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1365 rindirect(int e1) /* *(p +5 ) */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1366
d35df41eac69 Initial revision
kono
parents:
diff changeset
1367 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1368 char *op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1369 int e2,e3,byte;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1370
d35df41eac69 Initial revision
kono
parents:
diff changeset
1371 op = ((byte = (car(e1) == CRINDIRECT)) ? "movsbl" : "movl");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1372 e3 = cadr(e2 = cadr(e1));
d35df41eac69 Initial revision
kono
parents:
diff changeset
1373 g_expr(e2);
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1374 printf("\t%s (%s),%s\n",op,register_name(creg,0),register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1375 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1376
d35df41eac69 Initial revision
kono
parents:
diff changeset
1377 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1378 sassign(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1379 {
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1380 int e2,e3,e4,sz,xreg,det;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1381
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1382 /* structure assignment */
37
412ad2e6c2a2 struct copy
kono
parents: 36
diff changeset
1383 e2 = cadr(e1); /* pointer variable to the struct */
412ad2e6c2a2 struct copy
kono
parents: 36
diff changeset
1384 e3 = cadr(e2); /* offset of the variable (distination) */
39
c63c4fdeb9a7 struct done.
kono
parents: 38
diff changeset
1385 e4 = caddr(e1); /* right value (source) */
37
412ad2e6c2a2 struct copy
kono
parents: 36
diff changeset
1386 sz = cadddr(e1); /* size of struct or union */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1387 g_expr(e4);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1388 emit_push();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1389 g_expr(e2);
38
d48d952da354 struct copy continue
kono
parents: 37
diff changeset
1390 xreg = emit_pop(0);
57
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1391 /* °ìÈÌŪ¤Ë¤Ï¥³¥Ô¡¼¤Î¥ª¡¼¥Ð¥é¥Ã¥×¤Î¾õ¶·¤Ï¼Â¹Ô»þ¤Ë¤·¤«¤ï¤«¤é¤Ê¤¤ */
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1392 /* ¤·¤«¤·¡¢¤ï¤«¤ë¾ì¹ç¤â¤¢¤ë */
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1393 if (car(e4)==RSTRUCT) e4=cadr(e4);
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1394 if (is_same_type(e2,e4)) {
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1395 if(cadr(e2)<cadr(e4)) sz=-sz;
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1396 det=1;
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1397 } else {
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1398 det = 0;
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1399 }
3d7f199e99d0 struct handling
kono
parents: 56
diff changeset
1400 emit_copy(xreg,creg,sz,0,1,det);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1401 emit_pop_free(xreg);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1402 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1403 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1404
d35df41eac69 Initial revision
kono
parents:
diff changeset
1405 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1406 assign(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1407 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1408 char *op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1409 int e2,e3,e4,byte;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1410
d35df41eac69 Initial revision
kono
parents:
diff changeset
1411 op = ((byte=(car(e1) == CASS))? "movb" : "movl");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1412 /* e2=e4 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1413 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1414 e3 = cadr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1415 e4 = caddr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1416 switch(car(e2)) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1417 case GVAR: /* i=3 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1418 g_expr(e4);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1419 if (byte) use_data_reg(creg,1);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1420 printf("\t%s %s,%s\n",op,register_name(creg,byte),(char *)caddr(e2));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1421 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1422 case LVAR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1423 g_expr(e4);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1424 if (byte) use_data_reg(creg,1);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1425 printf("\t%s %s,%d(%%ebp)\n",op,register_name(creg,byte),lvar(cadr(e2)));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1426 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1427 case REGISTER:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1428 g_expr(e4);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1429 if (creg!=cadr(e2))
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1430 printf("\tmovl %s,%s\n",register_name(creg,0),register_name(cadr(e2),0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1431 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1432 }
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1433 g_expr(e2);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1434 emit_push();
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1435 use_data_reg(creg,0);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1436 g_expr(e4);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1437 if (byte) use_data_reg(creg,1);
23
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1438 e2 = emit_pop(0);
e605560e6146 Fix breaking edx,ecx on function call
kono
parents: 22
diff changeset
1439 printf("\t%s %s,(%s)\n",op,register_name(creg,byte),register_name(e2,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1440 emit_pop_free(e2);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1441 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1442 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1443 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1444
d35df41eac69 Initial revision
kono
parents:
diff changeset
1445 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1446 assop(int e1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1447 {
43
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1448 int e2,e3,byte,op,reg;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1449 char *xrn;
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1450 int xreg,edx;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1451
d35df41eac69 Initial revision
kono
parents:
diff changeset
1452 /* e2 op= e3 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1453 byte = (car(e1) == CASSOP);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1454 e2 = cadr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1455 if (car(e2)==INDIRECT) e2=cadr(e2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1456 e3 = caddr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1457 op = cadddr(e1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1458
d35df41eac69 Initial revision
kono
parents:
diff changeset
1459 g_expr(e3);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1460 if (car(e2)==REGISTER) {
43
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1461 xreg = creg;
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1462 creg = reg = cadr(e2);
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1463 tosop(op,xreg);
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1464 creg = xreg;
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1465 printf("\tmovl %s,%s\n",register_name(reg,0),register_name(creg,0));
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1466 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1467 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1468 }
43
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1469 emit_push();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1470 g_expr(e2);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1471 edx = edx_setup();
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1472 xrn = register_name(xreg = emit_pop(0),0); /* pop e3 value */
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1473 regv[xreg]=regs[xreg]=1;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1474 printf("\tmovl %s,%s # assop \n",register_name(creg,0),register_name(edx,0));
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1475 regv[edx]=1;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1476 ld_indexx(byte,0,edx);
43
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1477 tosop(op,xreg);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1478 printf("\t%s %s,(%s)\n",byte ? "movb" : "movl",register_name(creg,byte),register_name(edx,0));
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1479 edx_cleanup();
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1480 emit_pop_free(xreg);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1481 regv[creg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1482 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1483 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1484
d35df41eac69 Initial revision
kono
parents:
diff changeset
1485
d35df41eac69 Initial revision
kono
parents:
diff changeset
1486 void
43
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1487 tosop(int op,int oreg)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1488 {
43
a792cf69d698 *** empty log message ***
kono
parents: 42
diff changeset
1489 int dx;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1490 char *orn,*crn;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1491
d35df41eac69 Initial revision
kono
parents:
diff changeset
1492 switch(op) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1493 case LSHIFT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1494 case ULSHIFT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1495 shift("sall",oreg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1496 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1497 case RSHIFT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1498 shift("sarl",oreg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1499 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1500 case URSHIFT:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1501 shift("shrl",oreg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1502 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1503 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1504 if(oreg==-1) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1505 printf("\tpopl %s\n",register_name(dreg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1506 oreg = dreg;
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1507 regv[dreg]=1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1508 }
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1509 regv[oreg]=1; regs[oreg]=1;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1510 orn = register_name(oreg,0);
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1511 crn = register_name(creg,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1512 switch(op) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1513 case ADD:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1514 printf("\taddl %s,%s\n",orn,crn);
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1515 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1516 case SUB:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1517 printf("\tsubl %s,%s\n",orn,crn);
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1518 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1519 case BAND:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1520 printf("\tandl %s,%s\n",orn,crn);
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1521 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1522 case EOR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1523 printf("\txorl %s,%s\n",orn,crn);
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1524 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1525 case BOR:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1526 printf("\torl %s,%s\n",orn,crn);
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1527 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1528 case MUL:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1529 case UMUL:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1530 printf("\t%s %s,%s\n","imull",orn,crn);
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1531 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1532 case DIV:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1533 case UDIV:
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1534 use_register(creg,REG_EAX,1);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1535 edx_setup();
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1536 orn = register_name(oreg,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1537 if (op==DIV)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1538 printf("\tcltd\n\tdivl %s\n",orn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1539 else
d35df41eac69 Initial revision
kono
parents:
diff changeset
1540 printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1541 edx_cleanup();
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1542 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1543 case MOD:
d35df41eac69 Initial revision
kono
parents:
diff changeset
1544 case UMOD:
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1545 use_register(creg,REG_EAX,1);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1546 edx_setup();
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1547 orn = register_name(oreg,0);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1548 if (op==DIV)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1549 printf("\tcltd\n\tdivl %s\n",orn);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1550 else
d35df41eac69 Initial revision
kono
parents:
diff changeset
1551 printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1552 dx = virtual(REG_EDX);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1553 if (dx!=creg) {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1554 rname[dx]=rname[creg];
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1555 rname[creg]=REG_EDX;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1556 }
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1557 edx_cleanup();
41
886ca1f2cf15 *** empty log message ***
kono
parents: 40
diff changeset
1558 break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1559 }
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1560 if (oreg!=dreg&&oreg>=0)
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1561 free_register(oreg);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1562 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1563
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1564 static int edx_stack=0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1565
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1566 int
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1567 edx_setup()
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1568 {
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1569 int edx_save;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1570 /* make real EDX register empty */
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1571 if (free_register_count()<1) {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1572 for(edx_save = 0;edx_save==dreg||edx_save==creg;edx_save++);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1573 printf("\tpushl %s\n",register_name(edx_save,0));
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1574 edx_stack = list3(edx_save,edx_stack,0);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1575 } else {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1576 edx_save = get_register();
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1577 edx_stack = list3(edx_save,edx_stack,1);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1578 }
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1579 regv[edx_save]=0;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1580 use_register(edx_save,REG_EDX,0);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1581 return edx_save;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1582 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1583
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1584
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1585 void
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1586 edx_cleanup()
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1587 {
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1588 if (caddr(edx_stack)==0) {
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1589 printf("\tpopl %s\n",register_name(car(edx_stack),0));
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1590 } else
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1591 free_register(car(edx_stack));
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1592 edx_stack = cadr(edx_stack);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1593 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1594
d35df41eac69 Initial revision
kono
parents:
diff changeset
1595 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1596 shift(char *op, int reg)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1597 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1598 if (reg>=0) {
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1599 use_register(reg,REG_ECX,1);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1600 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1601 use_register(dreg,REG_ECX,0);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1602 printf("\tpopl %%ecx\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1603 }
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1604 printf("\t%s %%cl,%s\n",op,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1605 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1606
d35df41eac69 Initial revision
kono
parents:
diff changeset
1607 void
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1608 ld_indexx(int byte, int n, int xreg)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1609 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1610 char *op;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1611
d35df41eac69 Initial revision
kono
parents:
diff changeset
1612 op = byte ? "movsbl" : "movl";
d35df41eac69 Initial revision
kono
parents:
diff changeset
1613 if (n)
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1614 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
1615 else
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1616 printf("\t%s (%s),%s\n",op,register_name(xreg,0),register_name(creg,byte));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1617 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1618
d35df41eac69 Initial revision
kono
parents:
diff changeset
1619 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1620 cmpdimm(int e, int csreg)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1621 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1622 /* used in dosiwtch() */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1623 use_register(creg,csreg,0);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1624 printf("\tcmpl $%d,%s\n",e,register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1625 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1626
d35df41eac69 Initial revision
kono
parents:
diff changeset
1627 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1628 opening(char *filename)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1629 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1630 printf("\t.file \"%s\"\n",filename);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1631 printf("\t.version\t\"01.01\"\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1632 printf("gcc2_compiled.:\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1633 printf(".text\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1634 emit_init();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1635 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1636
d35df41eac69 Initial revision
kono
parents:
diff changeset
1637 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1638 closing(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1639 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1640 global_table();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1641 printf("\t.ident \"Micro-C compiled\"\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1642 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1643
d35df41eac69 Initial revision
kono
parents:
diff changeset
1644 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1645 rexpr(int e1, int l1, char *s)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1646 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1647 g_expr(list3(SUB,cadr(e1),caddr(e1)));
d35df41eac69 Initial revision
kono
parents:
diff changeset
1648 printf("\tj%s\t_%d\n",s,l1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1649 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1650
d35df41eac69 Initial revision
kono
parents:
diff changeset
1651 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1652 jcond(int l, char cond)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1653 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1654 printf("\tj%s\t_%d\n",cond?"ne":"e",l);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1655 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1656
d35df41eac69 Initial revision
kono
parents:
diff changeset
1657 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1658 jmp(int l)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1659 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1660 control=0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1661 printf("\tjmp\t_%d\n",l);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1662 /* align? */
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1663 /*
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1664 this is not allowed because of ? operator
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1665 regv[creg]=regv[dreg]=0;
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1666 use_register(creg,REG_EAX,0);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1667 use_register(dreg,REG_EBX,0);
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1668 */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1669 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1670
d35df41eac69 Initial revision
kono
parents:
diff changeset
1671 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
1672 fwdlabel(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1673 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1674 return labelno++;
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 fwddef(int l)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1679 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1680 control=1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1681 printf("_%d:\n",l);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1682 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1683
d35df41eac69 Initial revision
kono
parents:
diff changeset
1684 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
1685 backdef(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1686 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1687 control=1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1688 printf("_%d:\n",labelno);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1689 return labelno++;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1690 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1691
d35df41eac69 Initial revision
kono
parents:
diff changeset
1692 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1693 def_label(int cslabel, int dlabel)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1694 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1695 int fl;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1696
d35df41eac69 Initial revision
kono
parents:
diff changeset
1697 fl = 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1698 if (control) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1699 jmp(fl=fwdlabel());
d35df41eac69 Initial revision
kono
parents:
diff changeset
1700 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1701 fwddef(cslabel);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1702 if (dlabel)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1703 jmp(dlabel);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1704 if (fl) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1705 fwddef(fl);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1706 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1707 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1708
d35df41eac69 Initial revision
kono
parents:
diff changeset
1709 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1710 gen_comment(char *s)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1711 {
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1712 printf("## %s",s);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1713 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1714
d35df41eac69 Initial revision
kono
parents:
diff changeset
1715 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1716 gen_source(char *s)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1717 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1718 printf("%s",s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1719 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1720
d35df41eac69 Initial revision
kono
parents:
diff changeset
1721 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1722 code_enter(char *name)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1723 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1724 printf("\t.align 4\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1725 if (stmode!=STATIC)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1726 printf(".globl %s\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1727 printf("\t.type\t%s,@function\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1728 printf("%s:\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1729 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1730
d35df41eac69 Initial revision
kono
parents:
diff changeset
1731 void
50
kono
parents: 49
diff changeset
1732 code_enter1(int args)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1733 {
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1734 code_disp_label=fwdlabel();
50
kono
parents: 49
diff changeset
1735 printf("\tlea _%d(%%ebp),%%esp\n",code_disp_label);
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1736
21
f9f789aa7587 Linux version (Redhat 7.2)
kono
parents: 18
diff changeset
1737 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
1738 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1739
d35df41eac69 Initial revision
kono
parents:
diff changeset
1740 void
50
kono
parents: 49
diff changeset
1741 code_leave(char *name)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1742 {
62
129f4802b027 separation done
kono
parents: 61
diff changeset
1743 disp=(disp-(size_of_int-1))&(-(size_of_int-1));
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1744 printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1745 printf("_%d:\n",labelno);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1746 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1747 local_table();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1748 labelno++;
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1749 free_all_register();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1750 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1751
d35df41eac69 Initial revision
kono
parents:
diff changeset
1752 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1753 enter(char *name)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1754 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1755 printf("\t.align 2\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1756 if (stmode!=STATIC)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1757 printf(".globl %s\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1758 printf("%s:\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1759 printf("\t.type\t%s,@function\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1760 printf("\tpushl %%ebp\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1761 printf("\tmovl %%esp,%%ebp\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1762 printf("\tpushl %%ebx\n");
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
1763 printf("\tpushl %%esi\n");
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
1764 printf("\tpushl %%edi\n");
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1765 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1766
d35df41eac69 Initial revision
kono
parents:
diff changeset
1767 void
50
kono
parents: 49
diff changeset
1768 enter1()
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1769 {
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1770 func_disp_label=fwdlabel();
50
kono
parents: 49
diff changeset
1771 printf("\tlea _%d(%%ebp),%%esp\n",func_disp_label);
36
9f89cef85b41 *** empty log message ***
kono
parents: 33
diff changeset
1772 /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1773 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1774
d35df41eac69 Initial revision
kono
parents:
diff changeset
1775 void
50
kono
parents: 49
diff changeset
1776 leave(int control, char *name)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1777 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1778 if (control)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1779 use_register(creg,REG_EAX,1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1780 if (retcont) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1781 if (control)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1782 jmp(retlabel);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1783 fwddef(retcont);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1784 use_register(creg,REG_EAX,0);
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1785 printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0));
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1786 /* printf("\tleave\n"); */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1787 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1788 fwddef(retlabel);
42
a89cf0d6904f regv assop
kono
parents: 41
diff changeset
1789 /* use_register(creg,REG_EAX,0); too late */
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1790 /* if(disp) printf("\taddl $%d,%%esp\n",-disp); */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1791 printf("\tlea %d(%%ebp),%%esp\n",disp_offset);
24
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
1792 printf("\tpopl %%edi\n");
1df0bf7eb5da add esi/edi register. fix virtual register bug.
kono
parents: 23
diff changeset
1793 printf("\tpopl %%esi\n");
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1794 printf("\tpopl %%ebx\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1795 printf("\tleave\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1796 printf("\tret\n");
62
129f4802b027 separation done
kono
parents: 61
diff changeset
1797 disp=(disp-(size_of_int-1))&(-(size_of_int-1));
52
ddaa1aa5b49b parallel assignment done (not circular dependency)
kono
parents: 51
diff changeset
1798 printf("\t.set _%d,%d\n",func_disp_label,disp+disp_offset);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1799 printf("_%d:\n",labelno);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1800 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1801 local_table();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1802 labelno++;
55
94564b45c4f3 all save implementation of parallel assignment
kono
parents: 54
diff changeset
1803 free_all_register();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1804 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1805
d35df41eac69 Initial revision
kono
parents:
diff changeset
1806
d35df41eac69 Initial revision
kono
parents:
diff changeset
1807 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1808 ret(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1809 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1810 use_register(creg,REG_EAX,1);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1811 jmp(retlabel);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1812 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1813
d35df41eac69 Initial revision
kono
parents:
diff changeset
1814 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1815 gen_gdecl(char *n, int gpc)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1816 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1817 /*
d35df41eac69 Initial revision
kono
parents:
diff changeset
1818 if (stmode!=STATIC)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1819 printf(".globl %s\n",n);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1820 */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1821 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1822
d35df41eac69 Initial revision
kono
parents:
diff changeset
1823 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1824 align(int t)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1825 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1826 if (t!=CHAR) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1827 if (data_alignment & 1)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1828 printf("\t.align 2\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1829 data_alignment = 0;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1830 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1831 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1832
d35df41eac69 Initial revision
kono
parents:
diff changeset
1833 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1834 emit_data(int e, int t, NMTBL *n)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1835 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1836 int l;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1837 char *name;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1838 name = n->nm;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1839 if(mode!=GDECL) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1840 error(-1); return;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1841 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1842 if (n->dsp != -1) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1843 n->dsp = -1; /* initiallized flag */
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1844 printf(".globl\t%s\n",name);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1845 data_mode(name);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1846 align(t);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1847 printf("%s:\n",name);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1848 } else {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1849 data_mode(0);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1850 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1851 if(car(e)==CONST) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1852 if (t==CHAR) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1853 printf("\t.byte %d\n",cadr(e));
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1854 if (data_alignment>0)
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1855 data_alignment++;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1856 gpc += 1;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1857 } else {
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1858 printf("\t.long %d\n",cadr(e));
3
kono
parents: 2
diff changeset
1859 gpc += size_of_int;
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1860 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1861 } else if(t!=CHAR) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1862 gpc += size_of_int;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1863 if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1864 printf("\t.long %s\n",(char *)caddr(cadr(e)));
13
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1865 } else if(car(e)==FNAME) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1866 printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1867 } else if(car(e)==STRING) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1868 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) {
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1869 l = fwdlabel();
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1870 printf("\t.long _%d\n",l);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1871 printf(".section\t.rodata\n");
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1872 printf("_%d:\n",l);
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1873 output_mode = RODATA_EMIT_MODE;
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1874 }
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1875 ascii((char *)cadr(e));
a8a812dace23 struct local initialization
kono
parents: 12
diff changeset
1876 } else error(TYERR);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1877 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1878 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1879
d35df41eac69 Initial revision
kono
parents:
diff changeset
1880 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1881 emit_data_closing(NMTBL *n)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1882 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1883 int lb;
18
df7fa8cee67b pass -Wall
kono
parents: 15
diff changeset
1884 if (mode==GDECL) {
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1885 data_mode(0);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1886 lb=fwdlabel();
d35df41eac69 Initial revision
kono
parents:
diff changeset
1887 printf("_%d:\n",lb);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1888 printf("\t.size\t%s,_%d-%s\n",n->nm,lb,n->nm);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1889 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1890 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1891
d35df41eac69 Initial revision
kono
parents:
diff changeset
1892 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1893 global_table(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1894 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1895 NMTBL *n;
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1896 int init;
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1897 init=0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1898 for(n=ntable;n < &ntable[GSYMS];n++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1899 if (n->sc == GVAR && n->dsp != -1) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1900 /* n->dsp = -1 means initialized global */
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1901 if (init==0) {
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1902 data_mode(0);
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1903 init=1;
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1904 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1905 printf(".comm %s,%d\n",n->nm,size(n->ty));
d35df41eac69 Initial revision
kono
parents:
diff changeset
1906 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1907 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1908 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1909
d35df41eac69 Initial revision
kono
parents:
diff changeset
1910 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1911 local_table(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1912 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1913 NMTBL *n;
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1914 int init;
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1915 init=0;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1916 /* static local variables */
d35df41eac69 Initial revision
kono
parents:
diff changeset
1917 for(n=ntable+GSYMS;n < &ntable[GSYMS+LSYMS];n++) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1918 if (n->sc == GVAR) {
12
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1919 if (init==0) {
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1920 data_mode(0);
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1921 init=1;
f928bd330351 *** empty log message ***
kono
parents: 7
diff changeset
1922 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1923 printf(".lcomm %s,%d\n",n->nm,size(n->ty));
d35df41eac69 Initial revision
kono
parents:
diff changeset
1924 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1925 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1926 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1927
d35df41eac69 Initial revision
kono
parents:
diff changeset
1928 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1929 text_mode(void)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1930 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1931 if (output_mode!=TEXT_EMIT_MODE) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1932 printf(".text\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1933 printf("\t.align 2\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1934 output_mode = TEXT_EMIT_MODE;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1935 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1936 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1937
d35df41eac69 Initial revision
kono
parents:
diff changeset
1938 void
d35df41eac69 Initial revision
kono
parents:
diff changeset
1939 data_mode(char *name)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1940 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1941 if (output_mode!=DATA_EMIT_MODE) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
1942 printf(".data\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
1943 output_mode = DATA_EMIT_MODE;
d35df41eac69 Initial revision
kono
parents:
diff changeset
1944 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1945 if (name)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1946 printf("\t.type\t%s,@object\n",name);
d35df41eac69 Initial revision
kono
parents:
diff changeset
1947 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1948
d35df41eac69 Initial revision
kono
parents:
diff changeset
1949 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
1950 lvar(int l)
d35df41eac69 Initial revision
kono
parents:
diff changeset
1951 {
50
kono
parents: 49
diff changeset
1952 if (fnptr->sc==CODE) {
53
64a4e3789fd2 parallel assign works.
kono
parents: 52
diff changeset
1953 return l+code_disp_offset;
50
kono
parents: 49
diff changeset
1954 } else if (l<0) {
kono
parents: 49
diff changeset
1955 return l+disp_offset;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1956 } else {
50
kono
parents: 49
diff changeset
1957 return l+arg_offset;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1958 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1959 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
1960
50
kono
parents: 49
diff changeset
1961
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1962 /* end */