annotate mc-mips.c @ 491:a379da780856

cond signed/unsigned
author kono
date Wed, 21 Dec 2005 11:33:53 +0900
parents 1c2a9232ea93
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1 /* Micro-C Code Generatation Part for Mips */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
2
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
3 #define EXTERN extern
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
4 #include "mc.h"
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
5
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
6 #define REGISTERS6 0
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
7
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
8 void code_init(void);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
9 void free_register(int i);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
10 void emit_init(void);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
11 void emit_push(void);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
12 void gexpr(int e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
13 void g_expr(int e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
14 void bexpr(int e1, char cond, int l1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
15 void b_expr(int e1, char cond, int l1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
16 void string(int e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
17 void function(int e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
18 void machinop(int e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
19 void rindirect(int e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
20 void assign(int e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
21 void sassign(int e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
22 void assop(int e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
23 void tosop(int op);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
24 void shift(char *op, int reg) ;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
25 void ld_indexx(int byte, int n, char *xrn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
26 void st_indexx(int byte, int n, char *xrn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
27 void indexy(char *op, char *gvar);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
28 void cmpdimm(int e, int csreg);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
29 void global_table(void) ;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
30 void local_table(void) ;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
31 void opening(char *filename);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
32 void closing(void);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
33 void gen_gdecl(char *n, int gpc) ;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
34 void jmp_label(int l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
35 void jmp_eq_label(int l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
36 void rexpr(int e1, int l1, char *s);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
37 void jcond(int l, char cond);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
38 void jmp(int l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
39 void def_label(int cslabel, int dlabel) ;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
40 void gen_comment(char *s);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
41 void gen_source(char *s);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
42 void code_enter(char *name) ;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
43 void code_leave(char *name) ;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
44 void enter(char *name, int disp) ;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
45 void enter_no(char *name,int disp);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
46 void enter1(int disp) ;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
47 void ret(void);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
48 void emit_data(int e, int t, NMTBL *n);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
49 void text_mode(void);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
50 void data_mode(char *name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
51 int get_register_var(void);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
52 void jump(int e1, int env);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
53 int lvar(int l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
54
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
55 int cadr(int e);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
56 int car(int e);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
57 int caddr(int e);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
58 int fwdlabel(void);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
59 void fwddef(int l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
60 int cadddr(int e);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
61 int backdef(void);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
62 int error(int n);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
63 int size(int t);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
64 int list3(int e1, int e2, int e3);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
65 extern int scalar(int);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
66 extern int reverse0(int);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
67
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
68 #define TEXT_EMIT_MODE 0
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
69 #define DATA_EMIT_MODE 1
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
70 #define RODATA_EMIT_MODE 2
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
71
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
72 static output_mode = TEXT_EMIT_MODE;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
73 static data_alignment = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
74
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
75 /*
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
76 local1 <----24 local variable
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
77 -20 <- disp_offset
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
78 saved register
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
79 .mask 0...0,-8
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
80 .fmask 0
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
81 $fp = $sp 0
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
82 $ip 4 <- arg_offset
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
83 arg1 8
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
84 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
85 int arg_offset = 8;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
86 int code_arg_offset = -4;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
87 int disp_offset = -12;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
88 int func_disp_offset = -12;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
89 int code_disp_offset = -4;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
90 int size_of_int = 4;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
91 int endian = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
92 int MAX_REGISTER=32; /* Mipsのレジスタを32つまで使う*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
93 int REAL_MAX_REGISTER=32; /* Mipsのレジスタが32つということ*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
94 int MAX_REGISTGER_VAR=20;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
95
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
96 int save_reg = 0; /*saveされたレジスタの回数*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
97 int save_reg1 = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
98
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
99 static int creg; /* current register */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
100 static char *crn; /* current register name */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
101 static int lreg; /* operand register */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
102 static char *lrn; /* operand register name */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
103 static int dreg; /* temporary register */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
104 static char *drn; /* temporary register name */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
105 static int xreg; /* pointer register */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
106 static int reg_sp; /* REGister Stack-Pointer */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
107
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
108
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
109 #define REG_00 0
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
110 #define REG_01 1
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
111 #define REG_02 2
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
112 #define REG_03 3
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
113 #define REG_04 4
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
114 #define REG_05 5
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
115 #define REG_06 6
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
116 #define REG_07 7
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
117 #define REG_08 8
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
118 #define REG_09 9
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
119 #define REG_10 10
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
120 #define REG_11 11
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
121 #define REG_12 12
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
122 #define REG_13 13
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
123 #define REG_14 14
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
124 #define REG_15 15
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
125 #define REG_16 16
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
126 #define REG_17 17
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
127 #define REG_18 18
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
128 #define REG_19 19
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
129 #define REG_20 20
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
130 #define REG_21 21
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
131 #define REG_22 22
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
132 #define REG_23 23
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
133 #define REG_24 24
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
134 #define REG_25 25
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
135 #define REG_26 26
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
136 #define REG_27 27
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
137 #define REG_28 28
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
138 #define REG_29 29
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
139 #define REG_30 30
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
140 #define REG_31 31
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
141
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
142 static char *reg_name[32];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
143
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
144 /*
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
145 creg currrent virtual register
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
146 lreg operand virtual register
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
147 dreg spare virtual register
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
148
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
149 rname[creg] currrent real register
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
150 rname[lreg] operand real register
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
151 rname[dreg] spare real register
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
152
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
153 regs[] virtual register usage
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
154
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
155 reg_name[rname[creg]]
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
156 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
157
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
158 #define MAX_MAX 40
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
159 static int rname[MAX_MAX];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
160 static int regs[MAX_MAX]; /* 使われているレジスタを示すフラグ */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
161 static int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
162
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
163 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
164 code_init(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
165 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
166 int i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
167
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
168 if (REGISTERS6) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
169 arg_offset = 8;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
170 func_disp_offset = -20;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
171 disp_offset = -20;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
172 size_of_int = 4;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
173 endian = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
174 MAX_REGISTER=32;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
175 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
176 arg_offset = 8;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
177 func_disp_offset = -12;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
178 disp_offset = -12;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
179 size_of_int = 4;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
180 endian = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
181 MAX_REGISTER=32;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
182 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
183 MAX_REGISTER_VAR=2;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
184
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
185 reg_name[REG_00] = "$0";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
186 reg_name[REG_01] = "$1";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
187 reg_name[REG_02] = "$2";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
188 reg_name[REG_03] = "$3";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
189 reg_name[REG_04] = "$4";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
190 reg_name[REG_05] = "$5";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
191 reg_name[REG_06] = "$6";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
192 reg_name[REG_07] = "$7";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
193 reg_name[REG_08] = "$8";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
194 reg_name[REG_09] = "$9";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
195 reg_name[REG_10] = "$10";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
196 reg_name[REG_11] = "$11";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
197 reg_name[REG_12] = "$12";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
198 reg_name[REG_13] = "$13";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
199 reg_name[REG_14] = "$14";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
200 reg_name[REG_15] = "$15";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
201 reg_name[REG_16] = "$16";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
202 reg_name[REG_17] = "$17";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
203 reg_name[REG_18] = "$18";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
204 reg_name[REG_19] = "$19";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
205 reg_name[REG_20] = "$20";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
206 reg_name[REG_21] = "$21";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
207 reg_name[REG_22] = "$22";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
208 reg_name[REG_23] = "$23";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
209 reg_name[REG_24] = "$24";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
210 reg_name[REG_25] = "$25";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
211 reg_name[REG_26] = "$26";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
212 reg_name[REG_27] = "$27";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
213 reg_name[REG_28] = "$28";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
214 reg_name[REG_29] = "$29";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
215 reg_name[REG_30] = "$30";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
216 reg_name[REG_31] = "$31";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
217
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
218 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
219
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
220 char *
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
221 register_name(int i)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
222 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
223 return reg_name[rname[i]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
224 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
225
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
226 int
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
227 get_register(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
228 { /* 使われていないレジスタを調べる */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
229 int i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
230 for(i=0;i<MAX_REGISTER;i++) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
231 if (! regs[i]) { /* 使われていないなら */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
232 regs[i]=1; /* そのレジスタを使うことを宣言し */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
233 return i; /* その場所を表す番号を返す */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
234 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
235 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
236
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
237 return -1; /* 空いている場所がないなら、それを表す -1 を返す */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
238 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
239
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
240 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
241 free_register(int i) { /* いらなくなったレジスタを開放 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
242 regs[i]=0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
243 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
244
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
245 int
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
246 register_full(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
247 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
248 int i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
249 for(i=0;i<MAX_REGISTER;i++) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
250 if (! regs[i]) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
251 return 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
252 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
253 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
254 return 1;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
255 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
256
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
257 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
258 gexpr_init(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
259 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
260 int i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
261 while(reg_sp > 0) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
262 free_register(reg_stack[--reg_sp]);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
263 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
264 text_mode();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
265 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
266
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
267 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
268 emit_init(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
269 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
270 int i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
271 for(i=0;i<REAL_MAX_REGISTER;i++) regs[i]=0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
272 for(i=0;i<REAL_MAX_REGISTER;i++) rname[i]=i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
273 regs[REG_00] = 1; /* reserved */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
274 regs[REG_01] = 1; /* reserved */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
275 regs[REG_02] = 1; /* $v0 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
276 regs[REG_03] = 1; /* $v1 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
277 regs[REG_28] = 1; /* reserved */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
278 regs[REG_29] = 1; /* reserved */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
279 regs[REG_30] = 1; /* reserved */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
280 regs[REG_31] = 1; /* reserved */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
281 creg = get_register();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
282 crn = reg_name[rname[creg]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
283 dreg = get_register();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
284 drn = reg_name[rname[dreg]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
285 reg_sp = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
286 text_mode();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
287 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
288
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
289 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
290 set_crn(int i)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
291 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
292 creg = i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
293 crn = reg_name[rname[creg]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
294 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
295
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
296 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
297 set_drn(int i)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
298 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
299 dreg = i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
300 drn = reg_name[rname[dreg]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
301 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
302
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
303 int
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
304 virtual(int real)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
305 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
306 int real_v,i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
307 real_v = -1;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
308 for(i=0;i<MAX_REGISTER;i++) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
309 if (rname[i]==real) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
310 real_v=i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
311 break;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
312 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
313 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
314 if (real_v == -1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
315 error(-1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
316 return real_v;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
317 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
318
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
319 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
320 use_register(int virt, int real, int move)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
321 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
322 int real_v;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
323 char *move_op,*a,*b;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
324 if (rname[virt]==real)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
325 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
326 real_v = virtual(real);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
327 if (move || regs[real_v]) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
328 if(regs[real_v]) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
329 a=reg_name[real];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
330 b=reg_name[rname[virt]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
331 printf("\txor \t%s,%s,%s\n",a,a,b);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
332 printf("\txor \t%s,%s,%s\n",b,a,b);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
333 printf("\txor \t%s,%s,%s\n",a,a,b);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
334 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
335 printf("\tmove \t%s,%s\n",reg_name[real],reg_name[rname[virt]]);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
336 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
337 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
338 rname[real_v] = rname[virt];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
339 rname[virt] = real;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
340 crn = reg_name[rname[creg]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
341 drn = reg_name[rname[dreg]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
342 lrn = reg_name[rname[lreg]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
343
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
344 save_reg++;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
345 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
346
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
347 int
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
348 pop_register(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
349 { /* レジスタから値を取り出す */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
350 int i,j;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
351
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
352 j = creg;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
353 i = reg_stack[--reg_sp];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
354
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
355 if(i<0) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
356 return i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
357 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
358 free_register(i);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
359 lreg = i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
360 lrn = reg_name[rname[lreg]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
361 regs[i]=0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
362 return lreg;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
363 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
364 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
365
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
366 int
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
367 stack_used(void) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
368 return reg_stack[--reg_sp]<0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
369 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
370
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
371 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
372 emit_push(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
373 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
374 int new_reg;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
375 new_reg = get_register();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
376 if(new_reg<0) { /* もうレジスタがない */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
377 reg_stack[reg_sp++] = -1;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
378 printf("\tsubu $sp,$sp,%d\n",size_of_int);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
379 printf("\tsw \t%s,0($sp)\n",crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
380 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
381 reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
382 set_crn(new_reg);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
383 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
384 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
385
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
386 char *
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
387 emit_pop(int type)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
388 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
389 char *xrn;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
390 if (pop_register()==-1) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
391 printf("\tlw %s,0($sp)\n",drn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
392 printf("\taddu $sp,$sp,%d\n",size_of_int);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
393 xrn = drn;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
394 xreg = dreg;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
395 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
396 xrn = lrn;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
397 xreg = lreg;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
398 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
399 return xrn;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
400 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
401
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
402 int
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
403 get_register_var(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
404 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
405 int i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
406 for(i=REG_05;i<REG_31;i++) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
407 if (! regs[i]) { /* 使われていないなら */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
408 regs[i]=1; /* そのレジスタを使うことを宣言し */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
409 return i; /* その場所を表す番号を返す */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
410 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
411 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
412 return -1;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
413 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
414
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
415 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
416 gexpr(int e1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
417 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
418 gexpr_init();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
419 g_expr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
420 csvalue = rname[creg]; /* for siwtch value */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
421 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
422
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
423 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
424 g_expr(int e1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
425 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
426 int e2,e3,e4;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
427 char *xrn;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
428 NMTBL *n;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
429
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
430 if (chk) return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
431 e2 = cadr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
432 switch (car(e1)){
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
433 case GVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
434 printf("\tla\t%s,%s\n",crn,caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
435 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
436 case RGVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
437 printf("\tlw\t%s,%s\n",crn,caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
438 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
439 case CRGVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
440 printf("\tlb\t%s,%s\n",crn,caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
441 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
442 case LVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
443 printf("\taddu\t%s,$fp,%d\n",crn,lvar(e2));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
444 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
445 case REGISTER:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
446 /* this is of course redundant... */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
447 printf("\tmove\t%s,%s\n",crn,register_name(e2));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
448 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
449 case RLVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
450 printf("\tlw\t%s,%d($fp)\n",crn,lvar(e2));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
451 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
452 case CRLVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
453 printf("\tlb\t%s,%d($fp)\n",crn,lvar(e2));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
454 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
455 case FNAME:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
456 printf("\tla\t%s,%s\n",crn,((NMTBL *)e2)->nm);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
457 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
458 case CONST: /* 代入する値が0でも特別な処理はしない */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
459 printf("\tli\t%s,%d\n",crn,e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
460 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
461 case STRING:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
462 string(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
463 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
464 case FUNCTION:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
465 function(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
466 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
467 case CODE:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
468 jump(e2,caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
469 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
470 case INDIRECT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
471 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
472 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
473 case RINDIRECT: case CRINDIRECT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
474 rindirect(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
475 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
476 case ADDRESS:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
477 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
478 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
479 case MINUS: /* レジスタに対し、引き算を実行すれば実現可能 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
480 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
481 printf("\tsubu\t%s,$0,%s\n",crn,crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
482 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
483 case BNOT: /* ~ */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
484 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
485 /* use_data_reg(creg,1); */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
486 printf("\tnor\t%s,$0,%s\n",crn,crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
487 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
488 case LNOT: /* ! */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
489 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
490 /*use_data_reg(creg,1);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
491 printf("\txori\t%s,%s,0x0000\n",drn,crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
492 printf("\tsltu\t%s,%s,1\n",crn,drn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
493 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
494 case PREINC:/* ++q */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
495 if (car(e2)==REGISTER) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
496 printf("\taddu \t%s,%s,%d\n",register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
497 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
498 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
499 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
500 printf("\taddu \t%s,%s,%d\n",crn,crn,caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
501 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
502 case POSTINC:/* p++ */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
503 if (car(e2)==REGISTER) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
504 printf("\taddu \t%s,%s,%d\n",register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
505 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
506 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
507 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
508 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
509 /* in case of register full we should copy crn to drn */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
510 xrn = emit_pop(0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
511 printf("\taddu \t%s,%s,%d\n",crn,xrn,caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
512 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
513 case CPOSTINC:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
514 /* char *p; *p++ */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
515 if (car(e2)==REGISTER) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
516 printf("\tmove\t%s,%s\n",crn,register_name(cadr(e2)));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
517 printf("\taddu\t%s,%s,%d\n",register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
518 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
519 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
520 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
521 emit_push(); /* in case of register full we should copy crn to drn */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
522 xrn = emit_pop(0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
523 printf("\tmovsbl (%s),%s\n",xrn,crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
524 printf("\tincl (%s)\n",xrn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
525 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
526 case CPREINC: /* char *p; *++p */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
527 if (car(e2)==REGISTER) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
528 printf("\taddu\t%s,%s,%d\n",register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
529 printf("\tmove\t%s,%s\n",crn,register_name(cadr(e2)));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
530 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
531 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
532 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
533 printf("\tincl (%s)\n",crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
534 printf("\tmovsbl (%s),%s\n",crn,crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
535 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
536 case CPOSTDEC:/* char *p; *p-- */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
537 if (car(e2)==REGISTER) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
538 printf("\tmove\t%s,%s\n",crn,register_name(cadr(e2)));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
539 printf("\tsubu\t%s,%s,1\n",register_name(cadr(e2)),register_name(cadr(e2)));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
540 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
541 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
542 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
543 printf("\tmovsbl (%s),%s\n",crn,crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
544 printf("\tdecl (%s)\n",crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
545 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
546 case CPREDEC:/* char *p; *--p */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
547 if (car(e2)==REGISTER) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
548 printf("\tdecl %s\n",register_name(cadr(e2)));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
549 printf("\tmove\t%s,%s\n",crn,register_name(cadr(e2)));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
550 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
551 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
552 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
553 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
554 xrn = emit_pop(0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
555 printf("\tdecl (%s)\n",xrn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
556 printf("\tmovsbl (%s),%s\n",xrn,crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
557 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
558 case MUL: case UMUL:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
559 case DIV: case UDIV:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
560 case MOD: case UMOD:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
561 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
562 case ADD: case SUB: case BAND: case EOR: case BOR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
563 machinop(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
564 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
565 case COND:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
566 e2=fwdlabel();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
567 b_expr(cadr(e1),0,e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
568 g_expr(caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
569 e4 = rname[creg];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
570 jmp(e3=fwdlabel());
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
571 fwddef(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
572 g_expr(cadddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
573 use_register(creg,e4,1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
574 fwddef(e3);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
575 return;
164
1c2a9232ea93 mc.h generation
kono
parents: 51
diff changeset
576 case STASS:
51
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
577 sassign(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
578 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
579 case ASS: case CASS:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
580 assign(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
581 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
582 case ASSOP: case CASSOP:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
583 assop(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
584 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
585 case COMMA:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
586 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
587 g_expr(caddr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
588 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
589 case RETURN:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
590 n = (NMTBL *)e2;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
591 if (retcont==0)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
592 retcont=fwdlabel();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
593 printf("\tla\t%s,$L%d\n",crn,retcont);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
594 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
595 case ENVIRONMENT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
596 printf("\tmove\t%s,$fp\n",crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
597 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
598 default:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
599 b_expr(e1,1,e2=fwdlabel()); /* including > < ... */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
600 /*printf("\txor \t%s,%s\n",crn,crn);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
601 jmp(e3=fwdlabel());
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
602 fwddef(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
603 printf("\tli \t%s,%d\n",crn,lvar(e2));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
604 fwddef(e3);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
605 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
606 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
607
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
608 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
609 bexpr(int e1, char cond, int l1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
610 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
611 gexpr_init();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
612 b_expr(e1,cond,l1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
613 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
614
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
615 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
616 b_expr(int e1, char cond, int l1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
617 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
618 int e2,l2;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
619 if (chk) return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
620 e2=cadr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
621 switch(car(e1)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
622 case LNOT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
623 b_expr(e2,!cond,l1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
624 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
625 case GT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
626 /*rexpr(e1,l1,cond?"bg":"ble");*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
627 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
628 case UGT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
629 /*rexpr(e1,l1,cond?"ba":"bbe");*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
630 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
631 case GE:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
632 /*rexpr(e1,l1,cond?"bge":"bl");*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
633 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
634 case UGE:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
635 /*rexpr(e1,l1,cond?"bae":"bb");*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
636 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
637 case LT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
638 /*rexpr(e1,l1,cond?"bl":"bge");*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
639 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
640 case ULT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
641 /*rexpr(e1,l1,cond?"bb":"bae");*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
642 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
643 case LE:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
644 /*rexpr(e1,l1,cond?"ble":"bg");*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
645 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
646 case ULE:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
647 /*rexpr(e1,l1,cond?"bbe":"ba");*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
648 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
649 case EQ:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
650 rexpr(e1,l1,cond?"beq":"bne");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
651 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
652 case NEQ:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
653 rexpr(e1,l1,cond?"bne":"beq");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
654 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
655 case LAND:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
656 b_expr(e2,0,cond?(l2=fwdlabel()):l1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
657 b_expr(caddr(e1),cond,l1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
658 if(cond) fwddef(l2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
659 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
660 case LOR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
661 b_expr(e2,1,cond?l1:(l2=fwdlabel()));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
662 b_expr(caddr(e1),cond,l1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
663 if(!cond) fwddef(l2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
664 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
665 case CRGVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
666 /*printf("\tcmpb $0,%s\n",caddr(e1));*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
667 jcond(l1,cond);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
668 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
669 case CRLVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
670 /*printf("\tcmpb $0,%d($fp)\n",lvar(e2));*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
671 jcond(l1,cond);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
672 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
673 case RGVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
674 /*printf("\tcmpl $0,%s\n",caddr(e1));*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
675 jcond(l1,cond);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
676 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
677 case RLVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
678 /*printf("\tlw \t%s,%d($fp)\n",crn,lvar(e2));*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
679 jcond(l1,cond);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
680 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
681 case REGISTER:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
682 /*printf("\tcmpl $0,%s\n",register_name(e2));*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
683 jcond(l1,cond);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
684 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
685 case CONST:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
686 if((cond&&e2)||(!cond&&!e2)) jmp(l1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
687 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
688 default:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
689 g_expr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
690 /*printf("\tcmpl $0,%s\n",crn);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
691 jcond(l1,cond);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
692 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
693 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
694 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
695
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
696 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
697 ascii(char *s)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
698 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
699 printf("\t.ascii \"");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
700 while(*s) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
701 if (*s=='\n')
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
702 printf("%cn",92);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
703 else if (*s<' ')
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
704 printf("%c%03o",92,*s);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
705 else if (*s==34)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
706 printf("%c%c",92,34);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
707 else
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
708 printf("%c",*s);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
709 s++;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
710 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
711 printf("%c\n",34);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
712 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
713
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
714 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
715 string(int e1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
716 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
717 char *s;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
718 int i,lb;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
719
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
720 if (0) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
721 s=(char *)cadr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
722 printf("\t.rdata\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
723 printf("\t.align\t2\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
724 lb=fwdlabel();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
725 printf("\tj\t$L%d\n",lb);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
726 i=backdef();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
727 ascii(s);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
728 printf("\t.align 2\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
729 fwddef(lb);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
730 printf("\tla\t%s,$L%d\n",crn,i);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
731 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
732 s=(char *)cadr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
733 printf("\t.rdata\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
734 printf("\t.align\t2\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
735 lb=fwdlabel();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
736 printf("$L%d:\n",lb);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
737 ascii(s);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
738 if (output_mode==TEXT_EMIT_MODE) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
739 printf("\t.text\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
740 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
741 text_mode();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
742 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
743 printf("\tla\t%s,$L%d\n",crn,lb);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
744 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
745 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
746
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
747 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
748 function(int e1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
749 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
750 int e2,e3,e4,e5,nargs;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
751 NMTBL *n;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
752
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
753 e2 = cadr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
754 nargs = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
755 for (e3 = caddr(e1); e3; e3 = cadr(e3)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
756 n=(NMTBL *)(e5=(cadr(e4 = car(e3))));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
757 switch(car(e4)){
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
758 case FNAME:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
759 printf("\tlw\t%s,0(%s)\n",crn,n->nm);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
760 break;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
761 case ADDRESS:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
762 g_expr(e5);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
763 break;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
764 default:g_expr(e4);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
765 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
766 ++nargs;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
767 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
768 if (car(e2) == FNAME) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
769 n=(NMTBL *)cadr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
770 use_register(creg,REG_04,0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
771 printf("\tjal\t%s\n",n->nm);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
772 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
773 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
774 use_register(creg,REG_04,0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
775 printf("\tjal\t*%s\n",crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
776 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
777 /*if (nargs) printf("\taddl $%d,%%esp\n",size_of_int*nargs);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
778 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
779
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
780 int
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
781 arg_size(int e3,int *nargs0)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
782 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
783 int i,nargs,offset_list,e,t;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
784
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
785 offset_list = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
786 /* we should use prototypes's type */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
787 for (i = nargs = 0; e3;e3 =cadr(e3)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
788 e = car(e3); t = caddr(e3);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
789 if (i < MAX_REGISTER_VAR && scalar(t)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
790 offset_list = list3(-(REG_05+i++),offset_list,e);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
791 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
792 offset_list =
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
793 list3(nargs,offset_list,e);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
794 nargs += (car(e3)==CHAR?size_of_int:size(t));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
795 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
796 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
797 *nargs0 = -nargs;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
798 return offset_list;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
799 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
800
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
801 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
802 jump(int e1, int env)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
803 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
804 int i,args,e2,e3,e4,e5,nargs,nargs0,regs;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
805 NMTBL *n,*code0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
806 int new_disp,scode,disp1;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
807 char *xrn;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
808
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
809 /* We need three passes. Compute Stack size, Compute Arg, Copy it. */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
810 /* count number of args */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
811 args = caddr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
812 args = reverse0(args);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
813 nargs = arg_size(args,&new_disp); /* compute in normal order */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
814 disp1 = (fnptr->sc==CODE)?0:-size_of_int;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
815 if (new_disp+disp1 < disp) { /* have to extend stack */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
816 if (fnptr->sc==CODE)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
817 printf("\tlw\t$sp,%d($fp)\n",new_disp-size_of_int);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
818 else
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
819 printf("\tlw\t$sp,%d($fp)\n",new_disp+disp_offset);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
820 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
821 /* compute jump address */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
822 e2 = cadr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
823 if (car(e2) == FNAME) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
824 code0=(NMTBL *)cadr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
825 if (code0->sc!=CODE) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
826 error(STERR); return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
827 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
828 } else { /* indirect */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
829 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
830 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
831 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
832 /* compute arguments in reverse order */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
833 regs = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
834 i=MAX_REGISTER_VAR;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
835 for (e3=nargs; e3;e3 =cadr(e3)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
836 n=(NMTBL *)(e5=(cadr(e4 = caddr(e3))));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
837 switch(car(e4)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
838 case FNAME:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
839 printf("\tlw\t%s,0(%s)\n",crn,n->nm);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
840 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
841 break;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
842 case ADDRESS:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
843 g_expr(e5);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
844 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
845 break;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
846 case RLVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
847 case CRLVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
848 if (env==0 && fnptr->sc==CODE) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
849 if (e5>=0 && e5==car(e3)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
850 /* The same positioned local variable. No need to copy */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
851 reg_stack[reg_sp++] = -2;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
852 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
853 break;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
854 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
855 g_expr(e4);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
856 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
857 break;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
858 case REGISTER:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
859 if (i>0 && rname[e5]==REG_05+ --i) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
860 /* The same register variable. No need to copy */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
861 reg_stack[reg_sp++] = e5;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
862 break;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
863 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
864 default:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
865 g_expr(e4);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
866 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
867 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
868 regs++;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
869 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
870 if (env) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
871 /* change the frame pointer */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
872 g_expr(env);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
873 printf("\tmove\t%s,$fp\n",crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
874 } else if (fnptr->sc==FUNCTION) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
875 printf("\tlw\t$fp,%d($fp)\n",disp_offset);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
876 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
877 /* force lvar offset mode to CODE */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
878 scode = fnptr->sc; fnptr->sc = CODE;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
879 /* copy arguments to destination environment if necessary */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
880 nargs = reverse0(nargs); /* pop in normal order */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
881 i=0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
882 for (e3=nargs; e3;e3 =cadr(e3)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
883 if ((e4=car(e3))<0) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
884 /* register case */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
885 if (reg_stack[--reg_sp]>=REG_05) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
886 /* the same registger */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
887 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
888 if(reg_stack[reg_sp]<0) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
889 /*printf("\tpopl %s\n",reg_name[rname[REG_05+i]]);*/ /* e4? */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
890 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
891 printf("\tmove\t%s,%s\n",
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
892 reg_name[rname[REG_05+i]],
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
893 reg_name[rname[reg_stack[reg_sp]]]); /* e4? */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
894 free_register(reg_stack[reg_sp]);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
895 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
896 i++;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
897 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
898 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
899 /* local variable case */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
900 if (reg_stack[reg_sp-1]== -2) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
901 /* same positioned variable */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
902 reg_sp--;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
903 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
904 xrn=emit_pop(0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
905 printf("\tlw\t%s,%d($fp)\n",xrn, lvar(e4));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
906 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
907 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
908 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
909 if (car(e2) != FNAME) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
910 xrn=emit_pop(0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
911 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
912 if (!env && new_disp+disp1>disp) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
913 /* shrink stack if necessary */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
914 printf("\tlw\t$sp,%d($fp)\n",new_disp-size_of_int);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
915 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
916 if (car(e2) == FNAME) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
917 printf("\tj\t%s\n",code0->nm);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
918 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
919 printf("\tj\t*%s\n",xrn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
920 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
921 fnptr->sc = scode;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
922 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
923
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
924
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
925 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
926 machinop(int e1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
927 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
928 int e2,e3,op;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
929
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
930 e2 = cadr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
931 op = car(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
932 e3 = caddr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
933 g_expr(e3);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
934 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
935 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
936 tosop(car(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
937 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
938 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
939
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
940
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
941 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
942 rindirect(int e1) /* *(p +5 ) */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
943
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
944 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
945 char *op;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
946 int e2,e3,byte;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
947
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
948 op = ((byte = (car(e1) == CRINDIRECT)) ? "lb" : "lw");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
949 e3 = cadr(e2 = cadr(e1));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
950 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
951 printf("\t%s \t%s,%d(%s)\n",op,crn,lvar(e3),crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
952 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
953
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
954 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
955 sassign(int e1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
956 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
957 int e2,e3,e4,sz;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
958 char *xrn;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
959
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
960 e2 = cadr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
961 e3 = cadr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
962 e4 = caddr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
963 sz = size(cadr(e2)); /* cld rep movsb */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
964 g_expr(e4);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
965 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
966 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
967 xrn = emit_pop(0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
968 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
969 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
970
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
971 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
972 assign(int e1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
973 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
974 char *op;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
975 int e2,e3,e4,byte;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
976 char *xrn;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
977
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
978 op = ((byte=(car(e1) == CASS))? "sb" : "sw");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
979 /* e2=e4 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
980 e2 = cadr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
981 e3 = cadr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
982 e4 = caddr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
983 switch(car(e2)) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
984 case GVAR: /* i=3 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
985 g_expr(e4);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
986 /*if (byte) use_data_reg(creg,1);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
987 printf("\t%s \t%s,%s\n",op,crn,caddr(e2));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
988 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
989 case LVAR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
990 g_expr(e4);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
991 /*if (byte) use_data_reg(creg,1);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
992 printf("\t%s \t%s,%d($fp)\n",op,crn,lvar(cadr(e2))*-1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
993 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
994 case REGISTER:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
995 g_expr(e4);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
996 if (creg!=cadr(e2))
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
997 printf("\t%s \t%s,%s\n",op,crn,register_name(cadr(e2)));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
998 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
999 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1000 g_expr(e4);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1001 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1002 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1003 xrn = emit_pop(0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1004 /*if (byte) use_data_reg(creg,1);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1005 printf("\t%s %s,(%s)\n",op,xrn,crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1006 printf("\tmove\t%s,%s\n",crn,xrn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1007 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1008 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1009
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1010 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1011 assop(int e1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1012 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1013 int e2,e3,byte,op,new_reg;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1014 char *xrn;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1015
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1016 /* e2 op= e3 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1017 byte = (car(e1) == CASSOP);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1018 e2 = cadr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1019 if (car(e2)==INDIRECT) e2=cadr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1020 e3 = caddr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1021 op = cadddr(e1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1022
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1023 g_expr(e3);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1024 emit_push();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1025 if (car(e2)==REGISTER) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1026 new_reg=creg;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1027 set_crn(cadr(e2));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1028 tosop(op);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1029 set_crn(new_reg);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1030 printf("\tmove\t%s,%s\n",crn,register_name(cadr(e2)));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1031 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1032 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1033 g_expr(e2);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1034 xrn = emit_pop(0); /* pop e3 value */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1035 /*printf("\tpushl %s # assop \n",crn);*/ /* push e2 address */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1036 ld_indexx(byte,0,crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1037 new_reg = get_register();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1038 /* push e3 value */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1039 if(new_reg<0) { /* もうレジスタがない */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1040 reg_stack[reg_sp++] = -1;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1041 /*printf("\tpushl %s\n",xrn);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1042 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1043 reg_stack[reg_sp++] = xreg; /* push するかわりにレジスタを使う */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1044 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1045 tosop(op);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1046 if(new_reg>=0) free_register(new_reg);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1047 /*printf("\tpopl %s # assop \n",drn);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1048 printf("\t%s\t%s,0(%s)\n",byte ? "lb" : "lw",crn,drn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1049 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1050
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1051 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1052
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1053
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1054 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1055 tosop(int op)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1056 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1057 int oreg;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1058 char *orn;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1059
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1060 oreg = pop_register();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1061 switch(op) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1062 case LSHIFT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1063 case ULSHIFT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1064 shift("sall",oreg);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1065 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1066 case RSHIFT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1067 shift("sarl",oreg);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1068 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1069 case URSHIFT:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1070 shift("shrl",oreg);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1071 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1072 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1073 if(oreg==-1) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1074 oreg = dreg;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1075 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1076 orn = reg_name[rname[oreg]];
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1077 switch(op) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1078 case ADD:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1079 printf("\taddu \t%s,%s,%s\n",crn,crn,orn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1080 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1081 case SUB:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1082 printf("\tsubu \t%s,%s,%s\n",crn,crn,orn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1083 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1084 case BAND:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1085 printf("\tand \t%s,%s,%s\n",crn,crn,orn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1086 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1087 case EOR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1088 printf("\txor \t%s,%s,%s\n",crn,crn,orn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1089 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1090 case BOR:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1091 printf("\tor \t%s,%s,%s\n",crn,crn,orn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1092 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1093 case MUL:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1094 case UMUL:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1095 printf("\t%s\t%s,%s\n","mult",crn,orn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1096 printf("\tmflo\t%s\n",crn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1097 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1098 case DIV:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1099 case UDIV:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1100 if (op==DIV)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1101 printf("\tdiv\t%s,%s,%s\n",crn,crn,orn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1102 else
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1103 printf("\txor\t%s,%s,%s\n\tdiv\t%s,%s,%s\n",crn,crn,orn,crn,crn,orn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1104 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1105 case MOD:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1106 case UMOD:
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1107 if (op==MOD)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1108 printf("\trem\t%s,%s,%s\n",crn,crn,orn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1109 else
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1110 printf("\txor\t%s,%s,%s\n\tdiv\t%s,%s,%s\n",crn,crn,orn,crn,crn,orn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1111 return;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1112 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1113 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1114
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1115 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1116 shift(char *op, int reg)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1117 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1118 if (reg>=0) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1119 use_register(lreg,REG_03,1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1120 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1121 use_register(dreg,REG_03,0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1122 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1123 /*printf("\t%s %%cl,%s\n",op,crn);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1124 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1125
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1126 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1127 ld_indexx(int byte, int n, char *xrn)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1128 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1129 char *op;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1130
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1131 op = byte ? "lb" : "lw";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1132 if (n)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1133 printf("\t%s\t%s,%d(%s)\n",op,crn,n,xrn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1134 else
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1135 printf("\t%s\t%s,0(%s)\n",op,crn,xrn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1136 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1137
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1138 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1139 st_indexx(int byte, int n, char *xrn)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1140 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1141 char *op;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1142
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1143 op = byte ? "sb" : "sw";
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1144 if (n)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1145 printf("\t%s\t%s,%d(%s)\n",op,crn,n,xrn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1146 else
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1147 printf("\t%s\t%s,0(%s)\n",op,crn,xrn);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1148 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1149
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1150 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1151 indexy(char *op, char *gvar)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1152 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1153 printf("\t%s %s,%s\n",op,crn,gvar);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1154 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1155
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1156 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1157 cmpdimm(int e, int csreg)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1158 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1159 /* used in dosiwtch() */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1160 use_register(creg,csreg,0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1161 /*printf("\tcmpl $%d,%s\n",e,crn);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1162 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1163
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1164 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1165 opening(char *filename)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1166 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1167 printf("\t.file \t1 \"%s\"\n",filename);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1168 printf(" # GNU C 2.7.2.2 [AL 1.1, MM 40] Sony PlayStation compiled by GNU C\n\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1169 printf(" # Cc1 defaults:\n\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1170 printf(" # Cc1 arguments (-G value = 8, Cpu = 3000, ISA = 1):\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1171 printf(" # -msoft-float -quiet -dumpbase -o\n\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1172 printf(" # gcc2_compiled.:\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1173 printf(" # __gnu_compiled_c:\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1174
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1175 printf("\t.text\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1176 emit_init();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1177 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1178
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1179 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1180 closing(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1181 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1182 global_table();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1183 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1184
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1185 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1186 jmp_label(int l)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1187 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1188 printf("\tjmp\t_%d\n",l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1189 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1190
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1191 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1192 jmp_eq_label(int l)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1193 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1194 printf("\tj\t_%d\n",l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1195 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1196
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1197 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1198 rexpr(int e1, int l1, char *s)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1199 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1200 g_expr(list3(SUB,cadr(e1),caddr(e1)));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1201 printf("\t%s\t%s,%s,$L%d\n",s,crn,crn,l1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1202 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1203
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1204 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1205 jcond(int l, char cond)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1206 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1207 printf("\t%s\t%s,%s,$L%d\n",cond?"bne":"beq",crn,crn,l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1208 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1209
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1210 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1211 jmp(int l)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1212 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1213 control=0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1214 printf("\tj\t$L%d\n",l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1215 /* align? */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1216 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1217
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1218 int
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1219 fwdlabel(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1220 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1221 return labelno++;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1222 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1223
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1224 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1225 fwddef(int l)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1226 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1227 control=1;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1228 printf("$L%d:\n",l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1229 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1230
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1231 int
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1232 backdef(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1233 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1234 control=1;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1235 printf("$L%d:\n",labelno);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1236 return labelno++;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1237 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1238
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1239 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1240 def_label(int cslabel, int dlabel)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1241 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1242 int fl;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1243
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1244 fl = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1245 if (control) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1246 jmp(fl=fwdlabel());
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1247 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1248 fwddef(cslabel);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1249 if (dlabel)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1250 jmp(dlabel);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1251 if (fl) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1252 fwddef(fl);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1253 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1254 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1255
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1256 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1257 gen_comment(char *s)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1258 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1259 printf("# %s",s);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1260 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1261
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1262 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1263 gen_source(char *s)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1264 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1265 printf("%s",s);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1266 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1267
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1268 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1269 code_enter(char *name)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1270 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1271 printf("\t.align 4\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1272 if (stmode!=STATIC)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1273 printf(".globl %s\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1274 printf("\t.type\t%s,@function\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1275 printf("%s:\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1276 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1277
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1278 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1279 code_enter1(int disp0,int args)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1280 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1281 if(disp0) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1282 printf("\tsubl $%d,%%esp\n",-disp0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1283 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1284 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1285
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1286 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1287 code_leave(char *name)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1288 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1289 local_table();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1290 printf("$L%d:\n",labelno);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1291 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1292 labelno++;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1293 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1294
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1295 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1296 enter(char *name, int disp)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1297 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1298 int a,b,i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1299 a = b = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1300
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1301 /*printf("\t.text\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1302 printf("\t.align \t2\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1303 if (stmode!=STATIC)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1304 printf("\t.globl \t%s\n",name);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1305 printf("%s:\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1306
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1307 printf("\t.frame \t$fp,%d,$31\n",-disp+save_reg*size_of_int);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1308
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1309
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1310 if(disp) a = 8;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1311
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1312 printf("\t.mask \t0x%d0000000,-8\n",a);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1313 printf("\t.fmask \t0x00000000,0\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1314
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1315 if(disp){
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1316 printf("\tsubu \t$sp,$sp,%d\n",-disp+save_reg*size_of_int);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1317 printf("\tsw\t$31,%d($sp)\n",-disp+4*save_reg1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1318 save_reg1--;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1319 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1320 for(i=save_reg1;i==0;i--) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1321 printf("\tsw\t$%d,%d($sp)\n",16+i,-disp+4*i);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1322 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1323
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1324 /*if(strcmp("main",name))
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1325 printf("\tjal \t%s_0\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1326 else
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1327 printf("\tjal \t__%s_0\n",name);*/
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1328
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1329 printf("\tjal \t%s_0\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1330
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1331 printf("\t.end \t%s\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1332 printf("\t.sdata\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1333 printf("\t.align 2\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1334
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1335 save_reg = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1336 save_reg1 = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1337 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1338
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1339 /* void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1340 enter_no(char *name, int disp)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1341 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1342
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1343 printf("\t.align \t2\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1344 if (stmode!=STATIC)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1345 printf("\t.globl \t%s\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1346
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1347 printf("\t.ent \t%s\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1348 printf("%s_0:\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1349 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1350
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1351 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1352 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1353 enter1(int disp)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1354 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1355 if(disp) printf("\tsubu \t$sp,$sp,%d\n",-disp+save_reg*size_of_int);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1356
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1357 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1358
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1359 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1360 leave(int control, char *name)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1361 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1362 int i;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1363
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1364 if (control)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1365 use_register(creg,REG_04,1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1366 if (retcont) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1367 if (control)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1368 jmp(retlabel);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1369 fwddef(retcont);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1370 use_register(creg,REG_04,0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1371 printf("\tmove\t%s,%s\n",crn,reg_name[REG_05]);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1372 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1373 fwddef(retlabel);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1374 use_register(creg,REG_04,0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1375 save_reg1 = save_reg;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1376 printf("\tmove\t$sp,$fp\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1377
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1378 printf("\tlw\t$31,%d($sp)\n",-disp+4*save_reg);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1379 save_reg--;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1380 for(i=save_reg;i==0;i--) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1381 printf("\tlw\t$%d,%d($sp)\n",16+i,-disp+4*i);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1382 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1383
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1384
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1385 if(disp) printf("\taddu \t$sp,$sp,%d\n",-disp+save_reg*size_of_int);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1386 printf("\tj\t$31\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1387
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1388 local_table();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1389 printf("$L%d:\n",labelno);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1390 labelno++;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1391 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1392
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1393
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1394 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1395 ret(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1396 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1397 use_register(creg,REG_04,1);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1398 jmp(retlabel);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1399 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1400
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1401 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1402 gen_gdecl(char *n, int gpc)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1403 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1404 /*
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1405 if (stmode!=STATIC)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1406 printf(".globl %s\n",n);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1407 */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1408 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1409
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1410 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1411 align(int t)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1412 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1413 if (t!=CHAR) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1414 if (data_alignment & 1)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1415 printf("\t.align 2\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1416 data_alignment = 0;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1417 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1418 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1419
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1420 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1421 emit_data(int e, int t, NMTBL *n)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1422 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1423 int l;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1424 char *name;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1425 name = n->nm;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1426 if(mode==GDECL) { /* global */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1427 if (n->dsp != -1) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1428 n->dsp = -1; /* initiallized flag */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1429 printf(".globl\t%s\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1430 data_mode(name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1431 align(t);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1432 printf("%s:\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1433 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1434 data_mode(0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1435 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1436 if(car(e)==CONST) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1437 if (t==CHAR) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1438 printf("\t.byte %d\n",cadr(e));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1439 if (data_alignment>0)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1440 data_alignment++;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1441 gpc += 1;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1442 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1443 printf("\t.long %d\n",cadr(e));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1444 gpc += size_of_int;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1445 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1446 } else if(t!=CHAR) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1447 gpc += size_of_int;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1448 if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1449 printf("\t.word %s\n",caddr(cadr(e)));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1450 } else if(car(e)==FNAME) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1451 printf("\t.word %s\n",((NMTBL *)cadr(e))->nm);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1452 } else if(car(e)==STRING) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1453 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1454 l = fwdlabel();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1455 printf("\t.word _%d\n",l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1456 printf("$L%d:\n",l);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1457 output_mode = RODATA_EMIT_MODE;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1458 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1459 ascii((char *)cadr(e));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1460 } else error(TYERR);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1461 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1462 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1463 /* if (n->sc!=LVAR) { error(TYERR); return; } */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1464 if(car(e)==CONST) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1465 printf("\tmove\t%s,%d\n",crn,cadr(e));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1466 printf("\t%s\t%s,%d($fp)\n",t==CHAR?"lb":"lw",crn,n->dsp);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1467 } else if(t!=CHAR) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1468 if(car(e)==ADDRESS&&car(cadr(e))==GVAR)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1469 printf("\tlw\t%s,0(%s)\n",crn,caddr(e));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1470 else if(car(e)==FNAME)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1471 printf("\tlw\t%s,0(%s)\n",crn,((NMTBL *)cadr(e))->nm);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1472 else if(car(e)==STRING) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1473 string(e);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1474 } else error(TYERR);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1475 printf("\tlw\t%s,%d($fp)\n",crn,n->dsp);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1476 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1477 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1478 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1479
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1480 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1481 emit_data_closing(NMTBL *n)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1482 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1483 int lb;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1484 if (mode=GDECL) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1485 data_mode(0);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1486 lb=fwdlabel();
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1487 printf("$L%d:\n",lb);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1488 printf("\t.size\t%s,_%d-%s\n",n->nm,lb,n->nm);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1489 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1490 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1491
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1492 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1493 global_table(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1494 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1495 NMTBL *n;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1496 for(n=ntable;n < &ntable[GSYMS];n++) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1497 if (n->sc == GVAR && n->dsp != -1) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1498 /* n->dsp = -1 means initialized global */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1499 printf("\n\t.comm \t%s,%d\n",n->nm,size(n->ty));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1500 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1501 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1502 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1503
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1504 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1505 local_table(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1506 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1507 NMTBL *n;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1508 /* static local variables */
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1509 for(n=ntable+GSYMS;n < &ntable[GSYMS+LSYMS];n++) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1510 if (n->sc == GVAR) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1511 printf(".lcomm %s,%d\n",n->nm,size(n->ty));
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1512 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1513 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1514 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1515
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1516 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1517 text_mode(void)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1518 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1519 if (output_mode!=TEXT_EMIT_MODE) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1520 printf(".text\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1521 printf("\t.align 2\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1522 output_mode = TEXT_EMIT_MODE;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1523 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1524 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1525
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1526 void
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1527 data_mode(char *name)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1528 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1529 if (output_mode!=DATA_EMIT_MODE) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1530 printf(".data\n");
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1531 output_mode = DATA_EMIT_MODE;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1532 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1533 if (name)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1534 printf("\t.type\t%s,@object\n",name);
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1535 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1536
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1537 int
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1538 lvar(int l)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1539 {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1540 if (l<0) {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1541 if (fnptr->sc==CODE)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1542 return l+code_disp_offset;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1543 else
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1544 return l+disp_offset;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1545 } else {
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1546 if (fnptr->sc==CODE)
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1547 return -l+code_arg_offset;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1548 else
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1549 return l+arg_offset;
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1550 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1551 }
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1552
c2ef3a2fbe88 *** empty log message ***
kono
parents:
diff changeset
1553 /* end */