/*****************************************************************************/
/* */
-/* codegen.h */
+/* codegen.h */
/* */
-/* 6502 code generator */
+/* 6502 code generator */
/* */
/* */
/* */
-/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2013, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
/* Code generator flags.
- * Note: The type flags are designed so that a smaller type may override a
- * larger one by or'ing it into the existing one.
- */
-#define CF_NONE 0x0000 /* No special flags */
-
-#define CF_TYPE 0x0007 /* Mask for operand type */
-#define CF_CHAR 0x0003 /* Operation on characters */
-#define CF_INT 0x0001 /* Operation on ints */
-#define CF_PTR CF_INT /* Alias for readability */
-#define CF_LONG 0x0000 /* Operation on longs */
+** Note: The type flags are designed so that a smaller type may override a
+** larger one by or'ing it into the existing one.
+** Note^2: The actual type including the sign flag is in the lower bits, so
+** we can mask the information and use them as a table index.
+*/
+#define CF_NONE 0x0000 /* No special flags */
+
+/* Values for the actual type */
+#define CF_CHAR 0x0003 /* Operation on characters */
+#define CF_INT 0x0001 /* Operation on ints */
+#define CF_PTR CF_INT /* Alias for readability */
+#define CF_LONG 0x0000 /* Operation on longs */
#define CF_FLOAT 0x0004 /* Operation on a float */
-#define CF_NOKEEP 0x0008 /* Value may get destroyed when storing */
+/* Signedness */
+#define CF_UNSIGNED 0x0008 /* Value is unsigned */
-#define CF_UNSIGNED 0x0010 /* Value is unsigned */
-#define CF_CONST 0x0020 /* Constant value available */
-#define CF_CONSTADDR 0x0040 /* Constant address value available */
-#define CF_TEST 0x0080 /* Test value */
-#define CF_FIXARGC 0x0100 /* Function has fixed arg count */
-#define CF_FORCECHAR 0x0200 /* Handle chars as chars, not ints */
-#define CF_REG 0x0800 /* Value is in primary register */
+/* Masks for retrieving type information */
+#define CF_TYPEMASK 0x0007 /* Type information */
+#define CF_STYPEMASK 0x000F /* Includes signedness */
-/* Type of static address */
-#define CF_ADDRMASK 0xF000 /* Type of address */
-#define CF_STATIC 0x0000 /* Static local */
-#define CF_EXTERNAL 0x1000 /* Static external */
-#define CF_ABSOLUTE 0x2000 /* Numeric absolute address */
-#define CF_LOCAL 0x4000 /* Auto variable */
-#define CF_REGVAR 0x8000 /* Register variable */
+#define CF_NOKEEP 0x0010 /* Value may get destroyed when storing */
+#define CF_CONST 0x0020 /* Constant value available */
+#define CF_CONSTADDR 0x0040 /* Constant address value available */
+#define CF_TEST 0x0080 /* Test value */
+#define CF_FIXARGC 0x0100 /* Function has fixed arg count */
+#define CF_FORCECHAR 0x0200 /* Handle chars as chars, not ints */
+#define CF_REG 0x0800 /* Value is in primary register */
+/* Type of static address */
+#define CF_ADDRMASK 0xF000 /* Type of address */
+#define CF_STATIC 0x0000 /* Static local */
+#define CF_EXTERNAL 0x1000 /* Static external */
+#define CF_ABSOLUTE 0x2000 /* Numeric absolute address */
+#define CF_LOCAL 0x4000 /* Auto variable */
+#define CF_REGVAR 0x8000 /* Register variable */
-/* Compiler relative stackpointer */
-extern int oursp;
/* Forward */
struct StrBuf;
/*****************************************************************************/
-/* Files, pre- and postamble */
+/* Files, pre- and postamble */
/*****************************************************************************/
/*****************************************************************************/
-/* Segment support */
+/* Segment support */
/*****************************************************************************/
void g_usebss (void);
/* Switch to the bss segment */
-void g_segname (segment_t Seg, const char* Name);
-/* Set the name of a segment */
+void g_segname (segment_t Seg);
+/* Emit the name of a segment if necessary */
/*****************************************************************************/
-/* Functions handling local labels */
+/* Functions handling local labels */
/*****************************************************************************/
void g_defdatalabel (unsigned label);
/* Define a local data label */
+void g_aliasdatalabel (unsigned label, unsigned baselabel, long offs);
+/* Define label as a local alias for baselabel+offs */
+
/*****************************************************************************/
-/* Functions handling global labels */
+/* Functions handling global labels */
/*****************************************************************************/
void g_defimport (const char* Name, int ZP);
/* Import the given label */
+void g_importstartup (void);
+/* Forced import of the startup segment */
+
void g_importmainargs (void);
/* Forced import of a special symbol that handles arguments to main */
/*****************************************************************************/
-/* stack */
+/* stack */
/*****************************************************************************/
/*****************************************************************************/
-/* type conversion and similiar stuff */
+/* type conversion and similiar stuff */
/*****************************************************************************/
unsigned g_typeadjust (unsigned lhs, unsigned rhs);
/* Adjust the integer operands before doing a binary operation. lhs is a flags
- * value, that corresponds to the value on TOS, rhs corresponds to the value
- * in (e)ax. The return value is the the flags value for the resulting type.
- */
+** value, that corresponds to the value on TOS, rhs corresponds to the value
+** in (e)ax. The return value is the the flags value for the resulting type.
+*/
unsigned g_typecast (unsigned lhs, unsigned rhs);
/* Cast the value in the primary register to the operand size that is flagged
- * by the lhs value. Return the result value.
- */
+** by the lhs value. Return the result value.
+*/
void g_scale (unsigned flags, long val);
/* Scale the value in the primary register by the given value. If val is positive,
- * scale up, is val is negative, scale down. This function is used to scale
- * the operands or results of pointer arithmetic by the size of the type, the
- * pointer points to.
- */
+** scale up, is val is negative, scale down. This function is used to scale
+** the operands or results of pointer arithmetic by the size of the type, the
+** pointer points to.
+*/
/*****************************************************************************/
-/* Function entry and exit */
+/* Function entry and exit */
/*****************************************************************************/
/*****************************************************************************/
-/* Register variables */
+/* Register variables */
/*****************************************************************************/
/*****************************************************************************/
-/* Fetching memory cells */
+/* Fetching memory cells */
/*****************************************************************************/
void g_getind (unsigned Flags, unsigned Offs);
/* Fetch the specified object type indirect through the primary register
- * into the primary register
- */
+** into the primary register
+*/
void g_leasp (int Offs);
/* Fetch the address of the specified symbol into the primary register */
void g_leavariadic (int Offs);
/* Fetch the address of a parameter in a variadic function into the primary
- * register
- */
+** register
+*/
/*****************************************************************************/
-/* Store into memory */
+/* Store into memory */
/*****************************************************************************/
void g_putind (unsigned flags, unsigned offs);
/* Store the specified object type in the primary register at the address
- * on the top of the stack
- */
+** on the top of the stack
+*/
/*****************************************************************************/
-/* Adds and subs of variables fix a fixed address */
+/* Adds and subs of variables fix a fixed address */
/*****************************************************************************/
/*****************************************************************************/
-/* Special op= functions */
+/* Special op= functions */
/*****************************************************************************/
void g_addeqstatic (unsigned flags, unsigned long label, long offs,
- unsigned long val);
+ unsigned long val);
/* Emit += for a static variable */
void g_addeqlocal (unsigned flags, int offs, unsigned long val);
/* Emit += for the location with address in ax */
void g_subeqstatic (unsigned flags, unsigned long label, long offs,
- unsigned long val);
+ unsigned long val);
/* Emit -= for a static variable */
void g_subeqlocal (unsigned flags, int offs, unsigned long val);
/*****************************************************************************/
-/* Add a variable address to the value in ax */
+/* Add a variable address to the value in ax */
/*****************************************************************************/
/*****************************************************************************/
-/* */
+/* */
/*****************************************************************************/
void g_cmp (unsigned flags, unsigned long val);
/* Immidiate compare. The primary register will not be changed, Z flag
- * will be set.
- */
+** will be set.
+*/
void g_test (unsigned flags);
/* Test the value in the primary and set the condition codes */
void g_swap (unsigned flags);
/* Swap the primary register and the top of the stack. flags give the type
- * of *both* values (must have same size).
- */
+** of *both* values (must have same size).
+*/
void g_call (unsigned Flags, const char* Label, unsigned ArgSize);
/* Call the specified subroutine name */
void g_falsejump (unsigned flags, unsigned label);
/* Jump to label if zero flag set */
+void g_drop (unsigned Space);
+/* Drop space allocated on the stack */
+
void g_space (int space);
/* Create or drop space on the stack */
/*****************************************************************************/
-/* Switch statement */
+/* Switch statement */
/*****************************************************************************/
/*****************************************************************************/
-/* User supplied assembler code */
+/* User supplied assembler code */
/*****************************************************************************/
-/*****************************************************************************/
-/* Inlined known functions */
-/*****************************************************************************/
-
-
-
-void g_strlen (unsigned flags, unsigned long val, long offs);
-/* Inline the strlen() function */
-
-
-
/* End of codegen.h */
-#endif
-
+#endif