]> git.sur5r.net Git - cc65/blobdiff - src/cc65/codegen.h
Merge pull request #564 from bauen1/none-library
[cc65] / src / cc65 / codegen.h
index 58e0217ef1f56b4f4024123155a7f753f9aff5d0..4ad3756187fe9fe2ab9d16470f0375a0f35ac355 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                codegen.h                                 */
+/*                                 codegen.h                                 */
 /*                                                                           */
-/*                           6502 code generator                            */
+/*                            6502 code generator                            */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2004 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 StackPtr;
 
 /* Forward */
 struct StrBuf;
@@ -94,7 +98,7 @@ struct StrBuf;
 
 
 /*****************************************************************************/
-/*                        Files, pre- and postamble                         */
+/*                         Files, pre- and postamble                         */
 /*****************************************************************************/
 
 
@@ -108,7 +112,7 @@ void g_fileinfo (const char* Name, unsigned long Size, unsigned long MTime);
 
 
 /*****************************************************************************/
-/*                             Segment support                              */
+/*                              Segment support                              */
 /*****************************************************************************/
 
 
@@ -128,7 +132,7 @@ void g_segname (segment_t Seg);
 
 
 /*****************************************************************************/
-/*                     Functions handling local labels                      */
+/*                      Functions handling local labels                      */
 /*****************************************************************************/
 
 
@@ -139,10 +143,13 @@ void g_defcodelabel (unsigned label);
 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                      */
 /*****************************************************************************/
 
 
@@ -156,13 +163,16 @@ void g_defexport (const char* Name, int ZP);
 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                                   */
 /*****************************************************************************/
 
 
@@ -179,7 +189,7 @@ unsigned sizeofarg (unsigned flags);
 
 
 /*****************************************************************************/
-/*                   type conversion and similiar stuff                     */
+/*                    type conversion and similiar stuff                     */
 /*****************************************************************************/
 
 
@@ -198,26 +208,26 @@ void g_reglong (unsigned Flags);
 
 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                          */
 /*****************************************************************************/
 
 
@@ -231,7 +241,7 @@ void g_leave (void);
 
 
 /*****************************************************************************/
-/*                           Register variables                             */
+/*                            Register variables                             */
 /*****************************************************************************/
 
 
@@ -248,7 +258,7 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes);
 
 
 /*****************************************************************************/
-/*                          Fetching memory cells                           */
+/*                           Fetching memory cells                           */
 /*****************************************************************************/
 
 
@@ -264,21 +274,21 @@ void g_getlocal (unsigned Flags, int Offs);
 
 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                             */
 /*****************************************************************************/
 
 
@@ -291,13 +301,13 @@ void g_putlocal (unsigned Flags, int Offs, long Val);
 
 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               */
 /*****************************************************************************/
 
 
@@ -311,13 +321,13 @@ void g_addstatic (unsigned flags, unsigned long label, long offs);
 
 
 /*****************************************************************************/
-/*                          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);
@@ -327,7 +337,7 @@ void g_addeqind (unsigned flags, unsigned 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);
@@ -339,7 +349,7 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val);
 
 
 /*****************************************************************************/
-/*                        Add a variable address to the value in ax                 */
+/*                 Add a variable address to the value in ax                 */
 /*****************************************************************************/
 
 
@@ -353,7 +363,7 @@ void g_addaddr_static (unsigned flags, unsigned long label, long offs);
 
 
 /*****************************************************************************/
-/*                                                                          */
+/*                                                                           */
 /*****************************************************************************/
 
 
@@ -366,8 +376,8 @@ void g_restore (unsigned flags);
 
 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 */
@@ -377,8 +387,8 @@ void g_push (unsigned flags, unsigned long val);
 
 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 */
@@ -395,6 +405,9 @@ void g_truejump (unsigned flags, unsigned label);
 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 */
 
@@ -451,7 +464,7 @@ void g_initstatic (unsigned InitLabel, unsigned VarLabel, unsigned Size);
 
 
 /*****************************************************************************/
-/*                                    Switch statement                              */
+/*                             Switch statement                              */
 /*****************************************************************************/
 
 
@@ -462,7 +475,7 @@ void g_switch (Collection* Nodes, unsigned DefaultLabel, unsigned Depth);
 
 
 /*****************************************************************************/
-/*                      User supplied assembler code                        */
+/*                       User supplied assembler code                        */
 /*****************************************************************************/
 
 
@@ -473,6 +486,5 @@ void g_asmcode (struct StrBuf* B);
 
 
 /* End of codegen.h */
-#endif
-
 
+#endif