4 * Ullrich von Bassewitz, 04.06.1998
14 /*****************************************************************************/
16 /*****************************************************************************/
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.
24 #define CF_NONE 0x0000 /* No special flags */
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 */
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 */
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 */
51 /* Compiler relative stackpointer */
56 /*****************************************************************************/
57 /* Pre- and postamble */
58 /*****************************************************************************/
62 void g_preamble (void);
63 /* Generate the assembler code preamble */
65 void g_postamble (void);
66 /* Generate assembler code postamble */
70 /*****************************************************************************/
72 /*****************************************************************************/
76 void g_usecode (void);
77 /* Switch to the code segment */
79 void g_userodata (void);
80 /* Switch to the read only data segment */
82 void g_usedata (void);
83 /* Switch to the data segment */
86 /* Switch to the bss segment */
88 void g_codename (const char* Name);
89 /* Set the name of the CODE segment */
91 void g_rodataname (const char* Name);
92 /* Set the name of the RODATA segment */
94 void g_dataname (const char* Name);
95 /* Set the name of the DATA segment */
97 void g_bssname (const char* Name);
98 /* Set the name of the BSS segment */
102 /*****************************************************************************/
103 /* Functions handling local labels */
104 /*****************************************************************************/
108 void g_defloclabel (unsigned label);
109 /* Define a local label */
113 /*****************************************************************************/
114 /* Functions handling global labels */
115 /*****************************************************************************/
119 void g_defgloblabel (const char* Name);
120 /* Define a global label with the given name */
122 void g_defexport (const char* Name, int ZP);
123 /* Export the given label */
125 void g_defimport (const char* Name, int ZP);
126 /* Import the given label */
130 /*****************************************************************************/
132 /*****************************************************************************/
136 int pop (unsigned flags);
137 /* Pop an argument of the given size */
139 int push (unsigned flags);
140 /* Push an argument of the given size */
142 unsigned sizeofarg (unsigned flags);
143 /* Return the size of a function argument type that is encoded in flags */
147 /*****************************************************************************/
148 /* type conversion and similiar stuff */
149 /*****************************************************************************/
153 void g_toslong (unsigned flags);
154 /* Make sure, the value on TOS is a long. Convert if necessary */
156 void g_tosint (unsigned flags);
157 /* Make sure, the value on TOS is an int. Convert if necessary */
159 void g_reglong (unsigned flags);
160 /* Make sure, the value in the primary register a long. Convert if necessary */
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.
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.
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
182 /*****************************************************************************/
183 /* Function entry and exit */
184 /*****************************************************************************/
188 void g_enter (unsigned flags, const char* Name, unsigned argsize);
189 /* Function prologue */
191 void g_leave (int flags, int val);
192 /* Function epilogue */
196 /*****************************************************************************/
197 /* Register variables */
198 /*****************************************************************************/
202 void g_save_regvars (int RegOffs, unsigned Bytes);
203 /* Save register variables */
205 void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes);
206 /* Restore register variables */
210 /*****************************************************************************/
211 /* Fetching memory cells */
212 /*****************************************************************************/
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);
224 /*****************************************************************************/
225 /* Store into memory */
226 /*****************************************************************************/
230 void g_putstatic (unsigned flags, unsigned long label, unsigned offs);
231 /* Store the primary register into the specified static memory cell */
233 void g_putlocal (unsigned flags, int offs);
234 /* Put data into local object. */
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
243 /*****************************************************************************/
244 /* Adds and subs of variables fix a fixed address */
245 /*****************************************************************************/
249 void g_addlocal (unsigned flags, int offs);
250 /* Add a local variable to ax */
252 void g_addstatic (unsigned flags, unsigned long label, unsigned offs);
253 /* Add a static variable to ax */
257 /*****************************************************************************/
258 /* Compares of ax with a variable with fixed address */
259 /*****************************************************************************/
263 void g_cmplocal (unsigned flags, int offs);
264 /* Compare a local variable to ax */
266 void g_cmpstatic (unsigned flags, unsigned label, unsigned offs);
267 /* Compare a static variable to ax */
271 /*****************************************************************************/
272 /* Special op= functions */
273 /*****************************************************************************/
277 void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs,
279 /* Emit += for a static variable */
281 void g_addeqlocal (unsigned flags, int offs, unsigned long val);
282 /* Emit += for a local variable */
284 void g_addeqind (unsigned flags, unsigned offs, unsigned long val);
285 /* Emit += for the location with address in ax */
287 void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs,
289 /* Emit -= for a static variable */
291 void g_subeqlocal (unsigned flags, int offs, unsigned long val);
292 /* Emit -= for a local variable */
294 void g_subeqind (unsigned flags, unsigned offs, unsigned long val);
295 /* Emit -= for the location with address in ax */
299 /*****************************************************************************/
300 /* Add a variable address to the value in ax */
301 /*****************************************************************************/
305 void g_addaddr_local (unsigned flags, int offs);
306 /* Add the address of a local variable to ax */
308 void g_addaddr_static (unsigned flags, unsigned long label, unsigned offs);
309 /* Add the address of a static variable to ax */
313 /*****************************************************************************/
315 /*****************************************************************************/
319 void g_save (unsigned flags);
320 void g_restore (unsigned flags);
322 void g_cmp (unsigned flags, unsigned long val);
323 /* Immidiate compare. The primary register will not be changed, Z flag
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);
335 void g_case (unsigned flags, unsigned label, unsigned long val);
336 /* Create table code for one case selector */
338 void g_truejump (unsigned flags, unsigned label);
339 /* Jump to label if zero flag clear */
341 void g_falsejump (unsigned flags, unsigned label);
342 /* Jump to label if zero flag set */
344 void g_space (int space);
345 /* Create or drop space on the stack */
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);
371 void g_res (unsigned n);
373 void g_defdata (unsigned flags, unsigned long val, unsigned offs);
374 /* Define data with the size given in flags */
376 void g_defbytes (const unsigned char *bytes, unsigned count);
377 void g_zerobytes (unsigned n);
381 /*****************************************************************************/
382 /* Inlined known functions */
383 /*****************************************************************************/
387 void g_strlen (unsigned flags, unsigned long val, unsigned offs);
388 /* Inline the strlen() function */
392 /* End of codegen.h */