]> git.sur5r.net Git - cc65/blob - src/cc65/codegen.h
6321e60179e145c45088262bf5563a699d1f294b
[cc65] / src / cc65 / codegen.h
1 /*
2  * codegen.h
3  *
4  * Ullrich von Bassewitz, 04.06.1998
5  */
6
7
8
9 #ifndef CODEGEN_H
10 #define CODEGEN_H
11
12
13
14 /*****************************************************************************/
15 /*                                   data                                    */
16 /*****************************************************************************/
17
18
19
20 /* Code generator flags.
21  * Note: The type flags are designed so that a smaller type may override a
22  * larger one by or'ing it into the existing one.
23  */
24 #define CF_NONE         0x0000  /* No special flags */
25
26 #define CF_TYPE         0x000F  /* Mask for operand type */
27 #define CF_CHAR         0x0003  /* Operation on characters */
28 #define CF_INT          0x0001  /* Operation on ints */
29 #define CF_PTR          CF_INT  /* Alias for readability */
30 #define CF_LONG         0x0000  /* Operation on longs */
31
32 #define CF_UNSIGNED     0x0010  /* Value is unsigned */
33 #define CF_CONST        0x0020  /* Constant value available */
34 #define CF_CONSTADDR    0x0040  /* Constant address value available */
35 #define CF_TEST         0x0080  /* Test value */
36 #define CF_FIXARGC      0x0100  /* Function has fixed arg count */
37 #define CF_FORCECHAR    0x0200  /* Handle chars as chars, not ints */
38 #define CF_SHORT        0x0400  /* Use short addressing */
39 #define CF_REG          0x0800  /* Value is in primary register */
40
41 /* Type of static address */
42 #define CF_ADDRMASK     0xF000  /* Type of address */
43 #define CF_STATIC       0x0000  /* Static local */
44 #define CF_EXTERNAL     0x1000  /* Static external */
45 #define CF_ABSOLUTE     0x2000  /* Numeric absolute address */
46 #define CF_LOCAL        0x4000  /* Auto variable */
47 #define CF_REGVAR       0x8000  /* Register variable */
48
49
50
51 /* Compiler relative stackpointer */
52 extern int oursp;
53
54
55
56 /*****************************************************************************/
57 /*                            Pre- and postamble                             */
58 /*****************************************************************************/
59
60
61
62 void g_preamble (void);
63 /* Generate the assembler code preamble */
64
65 void g_postamble (void);
66 /* Generate assembler code postamble */
67
68
69
70 /*****************************************************************************/
71 /*                              Segment support                              */
72 /*****************************************************************************/
73
74
75
76 void g_usecode (void);
77 /* Switch to the code segment */
78
79 void g_userodata (void);
80 /* Switch to the read only data segment */
81
82 void g_usedata (void);
83 /* Switch to the data segment */
84
85 void g_usebss (void);
86 /* Switch to the bss segment */
87
88 void g_codename (const char* Name);
89 /* Set the name of the CODE segment */
90
91 void g_rodataname (const char* Name);
92 /* Set the name of the RODATA segment */
93
94 void g_dataname (const char* Name);
95 /* Set the name of the DATA segment */
96
97 void g_bssname (const char* Name);
98 /* Set the name of the BSS segment */
99
100
101
102 /*****************************************************************************/
103 /*                      Functions handling local labels                      */
104 /*****************************************************************************/
105
106
107
108 void g_defloclabel (unsigned label);
109 /* Define a local label */
110
111
112
113 /*****************************************************************************/
114 /*                     Functions handling global labels                      */
115 /*****************************************************************************/
116
117
118
119 void g_defgloblabel (const char* Name);
120 /* Define a global label with the given name */
121
122 void g_defexport (const char* Name, int ZP);
123 /* Export the given label */
124
125 void g_defimport (const char* Name, int ZP);
126 /* Import the given label */
127
128
129
130 /*****************************************************************************/
131 /*                                   stack                                   */
132 /*****************************************************************************/
133
134
135
136 int pop (unsigned flags);
137 /* Pop an argument of the given size */
138
139 int push (unsigned flags);
140 /* Push an argument of the given size */
141
142 unsigned sizeofarg (unsigned flags);
143 /* Return the size of a function argument type that is encoded in flags */
144
145
146
147 /*****************************************************************************/
148 /*                    type conversion and similiar stuff                     */
149 /*****************************************************************************/
150
151
152
153 void g_toslong (unsigned flags);
154 /* Make sure, the value on TOS is a long. Convert if necessary */
155
156 void g_tosint (unsigned flags);
157 /* Make sure, the value on TOS is an int. Convert if necessary */
158
159 void g_reglong (unsigned flags);
160 /* Make sure, the value in the primary register a long. Convert if necessary */
161
162 unsigned g_typeadjust (unsigned lhs, unsigned rhs);
163 /* Adjust the integer operands before doing a binary operation. lhs is a flags
164  * value, that corresponds to the value on TOS, rhs corresponds to the value
165  *  in (e)ax. The return value is the the flags value for the resulting type.
166  */
167
168 unsigned g_typecast (unsigned lhs, unsigned rhs);
169 /* Cast the value in the primary register to the operand size that is flagged
170  * by the lhs value. Return the result value.
171  */
172
173 void g_scale (unsigned flags, long val);
174 /* Scale the value in the primary register by the given value. If val is positive,
175  * scale up, is val is negative, scale down. This function is used to scale
176  * the operands or results of pointer arithmetic by the size of the type, the
177  * pointer points to.
178  */
179
180
181
182 /*****************************************************************************/
183 /*                          Function entry and exit                          */
184 /*****************************************************************************/
185
186
187
188 void g_enter (unsigned flags, unsigned argsize);
189 /* Function prologue */
190
191 void g_leave (int flags, int val);
192 /* Function epilogue */
193
194
195
196 /*****************************************************************************/
197 /*                            Register variables                             */
198 /*****************************************************************************/
199
200
201
202 void g_save_regvars (int RegOffs, unsigned Bytes);
203 /* Save register variables */
204
205 void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes);
206 /* Restore register variables */
207
208
209
210 /*****************************************************************************/
211 /*                           Fetching memory cells                           */
212 /*****************************************************************************/
213
214
215
216 void g_getimmed (unsigned flags, unsigned long val, unsigned offs);
217 void g_getstatic (unsigned flags, unsigned long label, unsigned offs);
218 void g_getlocal (unsigned flags, int offs);
219 void g_getind (unsigned flags, unsigned offs);
220 void g_leasp (int offs);
221
222
223
224 /*****************************************************************************/
225 /*                             Store into memory                             */
226 /*****************************************************************************/
227
228
229
230 void g_putstatic (unsigned flags, unsigned long label, unsigned offs);
231 /* Store the primary register into the specified static memory cell */
232
233 void g_putlocal (unsigned flags, int offs);
234 /* Put data into local object. */
235
236 void g_putind (unsigned flags, unsigned offs);
237 /* Store the specified object type in the primary register at the address
238  * on the top of the stack
239  */
240
241
242
243 /*****************************************************************************/
244 /*              Adds and subs of variables fix a fixed address               */
245 /*****************************************************************************/
246
247
248
249 void g_addlocal (unsigned flags, int offs);
250 /* Add a local variable to ax */
251
252 void g_addstatic (unsigned flags, unsigned long label, unsigned offs);
253 /* Add a static variable to ax */
254
255
256
257 /*****************************************************************************/
258 /*             Compares of ax with a variable with fixed address             */
259 /*****************************************************************************/
260
261
262
263 void g_cmplocal (unsigned flags, int offs);
264 /* Compare a local variable to ax */
265
266 void g_cmpstatic (unsigned flags, unsigned label, unsigned offs);
267 /* Compare a static variable to ax */
268
269
270
271 /*****************************************************************************/
272 /*                           Special op= functions                           */
273 /*****************************************************************************/
274
275
276
277 void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs,
278                     unsigned long val);
279 /* Emit += for a static variable */
280
281 void g_addeqlocal (unsigned flags, int offs, unsigned long val);
282 /* Emit += for a local variable */
283
284 void g_addeqind (unsigned flags, unsigned offs, unsigned long val);
285 /* Emit += for the location with address in ax */
286
287 void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs,
288                     unsigned long val);
289 /* Emit -= for a static variable */
290
291 void g_subeqlocal (unsigned flags, int offs, unsigned long val);
292 /* Emit -= for a local variable */
293
294 void g_subeqind (unsigned flags, unsigned offs, unsigned long val);
295 /* Emit -= for the location with address in ax */
296
297
298
299 /*****************************************************************************/
300 /*                 Add a variable address to the value in ax                 */
301 /*****************************************************************************/
302
303
304
305 void g_addaddr_local (unsigned flags, int offs);
306 /* Add the address of a local variable to ax */
307
308 void g_addaddr_static (unsigned flags, unsigned long label, unsigned offs);
309 /* Add the address of a static variable to ax */
310
311
312
313 /*****************************************************************************/
314 /*                                                                           */
315 /*****************************************************************************/
316
317
318
319 void g_save (unsigned flags);
320 void g_restore (unsigned flags);
321
322 void g_cmp (unsigned flags, unsigned long val);
323 /* Immidiate compare. The primary register will not be changed, Z flag
324  * will be set.
325  */
326
327 void g_test (unsigned flags);
328 void g_push (unsigned flags, unsigned long val);
329 void g_swap (unsigned flags);
330 void g_call (unsigned flags, char *lbl, unsigned argsize);
331 void g_callind (unsigned flags, unsigned argsize);
332 void g_jump (unsigned label);
333 void g_switch (unsigned flags);
334
335 void g_case (unsigned flags, unsigned label, unsigned long val);
336 /* Create table code for one case selector */
337
338 void g_truejump (unsigned flags, unsigned label);
339 /* Jump to label if zero flag clear */
340
341 void g_falsejump (unsigned flags, unsigned label);
342 /* Jump to label if zero flag set */
343
344 void g_space (int space);
345 /* Create or drop space on the stack */
346
347 void g_add (unsigned flags, unsigned long val);
348 void g_sub (unsigned flags, unsigned long val);
349 void g_rsub (unsigned flags, unsigned long val);
350 void g_mul (unsigned flags, unsigned long val);
351 void g_div (unsigned flags, unsigned long val);
352 void g_mod (unsigned flags, unsigned long val);
353 void g_or (unsigned flags, unsigned long val);
354 void g_xor (unsigned flags, unsigned long val);
355 void g_and (unsigned flags, unsigned long val);
356 void g_asr (unsigned flags, unsigned long val);
357 void g_asl (unsigned flags, unsigned long val);
358 void g_neg (unsigned flags);
359 void g_bneg (unsigned flags);
360 void g_com (unsigned flags);
361 void g_inc (unsigned flags, unsigned long n);
362 void g_dec (unsigned flags, unsigned long n);
363 void g_eq (unsigned flags, unsigned long val);
364 void g_ne (unsigned flags, unsigned long val);
365 void g_lt (unsigned flags, unsigned long val);
366 void g_le (unsigned flags, unsigned long val);
367 void g_gt (unsigned flags, unsigned long val);
368 void g_ge (unsigned flags, unsigned long val);
369 void g_makebool (unsigned flags);
370 void outdat (int n);
371 void g_res (unsigned n);
372
373 void g_defdata (unsigned flags, unsigned long val, unsigned offs);
374 /* Define data with the size given in flags */
375
376 void g_defbytes (const unsigned char *bytes, unsigned count);
377 void g_zerobytes (unsigned n);
378
379
380
381 /*****************************************************************************/
382 /*                          Inlined known functions                          */
383 /*****************************************************************************/
384
385
386
387 void g_strlen (unsigned flags, unsigned long val, unsigned offs);
388 /* Inline the strlen() function */
389
390
391
392 /* End of codegen.h */
393 #endif
394
395