]> git.sur5r.net Git - cc65/blobdiff - src/ca65/segment.h
More lineinfo usage.
[cc65] / src / ca65 / segment.h
index 1d6ce796e4ee02d7f5611f1710bfb90e95258282..e1e9027831d1cf6b81d0ac18b25ca3fb817a008f 100644 (file)
@@ -6,8 +6,8 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2003 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
+/* (C) 1998-2007 Ullrich von Bassewitz                                       */
+/*               Roemerstrasse 52                                            */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
@@ -40,6 +40,7 @@
 
 /* common */
 #include "fragdefs.h"
+#include "inline.h"
 #include "segdefs.h"
 
 /* ca65 */
 
 
 /*****************************************************************************/
-/*                                  Data                                    */
+/*                                  Data                                    */
 /*****************************************************************************/
 
 
 
-/* Are we in absolute mode or in relocatable mode? */
-extern int     RelocMode;
+/* Segment definition */
+typedef struct Segment Segment;
+struct Segment {
+    Segment*               List;               /* List of all segments */
+    Fragment*              Root;               /* Root of fragment list */
+    Fragment*              Last;               /* Pointer to last fragment */
+    unsigned long   FragCount;          /* Number of fragments */
+    unsigned        Num;                       /* Segment number */
+    unsigned        Align;                     /* Segment alignment */
+    int             RelocMode;          /* Relocatable mode if OrgPerSeg */
+    unsigned long   PC;                 /* PC if in relocatable mode */
+    unsigned long   AbsPC;              /* PC if in local absolute mode */
+                                        /* (OrgPerSeg is true) */
+    SegDef*         Def;                /* Segment definition (name and type) */
+};
 
 /* Definitions for predefined segments */
 extern SegDef NullSegDef;
@@ -64,6 +78,12 @@ extern SegDef BssSegDef;
 extern SegDef RODataSegDef;
 extern SegDef CodeSegDef;
 
+/* List of all segments */
+extern Segment* SegmentList;
+
+/* Currently active segment */
+extern Segment* ActiveSeg;
+
 
 
 /*****************************************************************************/
@@ -78,11 +98,35 @@ Fragment* GenFragment (unsigned char Type, unsigned short Len);
 void UseSeg (const SegDef* D);
 /* Use the given segment */
 
-const SegDef* GetCurrentSeg (void);
+#if defined(HAVE_INLINE)
+INLINE const SegDef* GetCurrentSegDef (void)
 /* Get a pointer to the segment defininition of the current segment */
+{
+    return ActiveSeg->Def;
+}
+#else
+#  define GetCurrentSegDef()    (ActiveSeg->Def)
+#endif
 
-unsigned GetSegNum (void);
+#if defined(HAVE_INLINE)
+INLINE unsigned GetCurrentSegNum (void)
 /* Get the number of the current segment */
+{
+    return ActiveSeg->Num;
+}
+#else
+#  define GetCurrentSegNum()    (ActiveSeg->Num)
+#endif
+
+#if defined(HAVE_INLINE)
+INLINE unsigned char GetCurrentSegAddrSize (void)
+/* Get the address size of the current segment */
+{
+    return ActiveSeg->Def->AddrSize;
+}
+#else
+#  define GetCurrentSegAddrSize()    (ActiveSeg->Def->AddrSize)
+#endif
 
 void SegAlign (unsigned Power, int Val);
 /* Align the PC segment to 2^Power. If Val is -1, emit fill fragments (the
@@ -90,20 +134,24 @@ void SegAlign (unsigned Power, int Val);
  * given value.
  */
 
-int IsZPSeg (void);
-/* Return true if the current segment is a zeropage segment */
-
-int IsFarSeg (void);
-/* Return true if the current segment is a far segment */
-
-unsigned GetSegType (unsigned SegNum);
-/* Return the type of the segment with the given number */
+unsigned char GetSegAddrSize (unsigned SegNum);
+/* Return the address size of the segment with the given number */
 
 unsigned long GetPC (void);
 /* Get the program counter of the current segment */
 
-void SetAbsPC (unsigned long AbsPC);
-/* Set the program counter in absolute mode */
+int GetRelocMode (void);
+/* Return true if we're currently in relocatable mode */
+
+void EnterAbsoluteMode (unsigned long AbsPC);
+/* Enter absolute (non relocatable mode). Depending on the OrgPerSeg flag,
+ * this will either switch the mode globally or for the current segment.
+ */
+
+void EnterRelocMode (void);
+/* Enter relocatable mode. Depending on the OrgPerSeg flag, this will either
+ * switch the mode globally or for the current segment.
+ */
 
 void SegCheck (void);
 /* Check the segments for range and other errors */
@@ -111,6 +159,9 @@ void SegCheck (void);
 void SegDump (void);
 /* Dump the contents of all segments */
 
+void InitSegments (void);
+/* Initialize segments */
+
 void WriteSegments (void);
 /* Write the segment data to the object file */