From 01d2b809a1411da08b1642f8a0ccf7aee9898a72 Mon Sep 17 00:00:00 2001 From: acqn Date: Sat, 21 Oct 2023 23:41:36 +0800 Subject: [PATCH] Renamed struct Segments to SegContext as well as some related functions. --- src/cc65/asmlabel.c | 4 ++-- src/cc65/asmlabel.h | 4 ++-- src/cc65/function.c | 4 ++-- src/cc65/segments.c | 48 +++++++++++++++++++++++++-------------------- src/cc65/segments.h | 24 +++++++++++------------ src/cc65/symentry.h | 4 ++-- 6 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/cc65/asmlabel.c b/src/cc65/asmlabel.c index 7d5db75e6..a07607048 100644 --- a/src/cc65/asmlabel.c +++ b/src/cc65/asmlabel.c @@ -52,7 +52,7 @@ -static struct Segments* CurrentFunctionSegment; +static struct SegContext* CurrentFunctionSegment; @@ -62,7 +62,7 @@ static struct Segments* CurrentFunctionSegment; -void UseLabelPoolFromSegments (struct Segments* Seg) +void UseLabelPoolFromSegments (struct SegContext* Seg) /* Use the info in segments for generating new label numbers */ { CurrentFunctionSegment = Seg; diff --git a/src/cc65/asmlabel.h b/src/cc65/asmlabel.h index dbfe2f443..7e8039cc4 100644 --- a/src/cc65/asmlabel.h +++ b/src/cc65/asmlabel.h @@ -44,7 +44,7 @@ -struct Segments; +struct SegContext; @@ -54,7 +54,7 @@ struct Segments; -void UseLabelPoolFromSegments (struct Segments* Seg); +void UseLabelPoolFromSegments (struct SegContext* Seg); /* Use the info in segments for generating new label numbers */ unsigned GetLocalLabel (void); diff --git a/src/cc65/function.c b/src/cc65/function.c index 38a8f45aa..1fee9b342 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -547,7 +547,7 @@ void NewFunc (SymEntry* Func, FuncDesc* D) } /* Allocate code and data segments for this function */ - Func->V.F.Seg = PushSegments (Func); + Func->V.F.Seg = PushSegContext (Func); /* Use the info in the segments for generating new local labels */ UseLabelPoolFromSegments (Func->V.F.Seg); @@ -696,7 +696,7 @@ void NewFunc (SymEntry* Func, FuncDesc* D) } /* Switch back to the old segments */ - PopSegments (); + PopSegContext (); /* Reset the current function pointer */ FreeFunction (CurrentFunc); diff --git a/src/cc65/segments.c b/src/cc65/segments.c index 8283b9da5..764ae29ea 100644 --- a/src/cc65/segments.c +++ b/src/cc65/segments.c @@ -69,11 +69,11 @@ typedef struct { } SegAddrSize_t; -/* Pointer to the current segment list. Output goes here. */ -Segments* CS = 0; +/* Pointer to the current segment context. Output goes here. */ +SegContext* CS = 0; -/* Pointer to the global segment list */ -Segments* GS = 0; +/* Pointer to the global segment context */ +SegContext* GS = 0; /* Actual names for the segments */ static StrStack SegmentNames[SEG_COUNT]; @@ -86,12 +86,12 @@ static Collection SegmentAddrSizes; ** maximum stack depth is 2, so there is not really a need for a better ** implementation. */ -static Collection SegmentStack = STATIC_COLLECTION_INITIALIZER; +static Collection SegContextStack = STATIC_COLLECTION_INITIALIZER; /*****************************************************************************/ -/* Code */ +/* Segment name and address size */ /*****************************************************************************/ @@ -226,11 +226,17 @@ const char* GetSegName (segment_t Seg) -static Segments* NewSegments (SymEntry* Func) -/* Initialize a Segments structure (set all fields to NULL) */ +/*****************************************************************************/ +/* Segment context */ +/*****************************************************************************/ + + + +static SegContext* NewSegContext (SymEntry* Func) +/* Initialize a SegContext structure (set all fields to NULL) */ { /* Allocate memory */ - Segments* S = xmalloc (sizeof (Segments)); + SegContext* S = xmalloc (sizeof (SegContext)); /* Initialize the fields */ S->Text = NewTextSeg (Func); @@ -248,14 +254,14 @@ static Segments* NewSegments (SymEntry* Func) -Segments* PushSegments (SymEntry* Func) -/* Make the new segment list current but remember the old one */ +SegContext* PushSegContext (SymEntry* Func) +/* Make the new segment context current but remember the old one */ { /* Push the current pointer onto the stack */ - CollAppend (&SegmentStack, CS); + CollAppend (&SegContextStack, CS); - /* Create a new Segments structure */ - CS = NewSegments (Func); + /* Create a new SegContext structure */ + CS = NewSegContext (Func); /* Return the new struct */ return CS; @@ -263,14 +269,14 @@ Segments* PushSegments (SymEntry* Func) -void PopSegments (void) -/* Pop the old segment list (make it current) */ +void PopSegContext (void) +/* Pop the old segment context (make it current) */ { /* Must have something on the stack */ - PRECONDITION (CollCount (&SegmentStack) > 0); + PRECONDITION (CollCount (&SegContextStack) > 0); /* Pop the last segment and set it as current */ - CS = CollPop (&SegmentStack); + CS = CollPop (&SegContextStack); } @@ -278,13 +284,13 @@ void PopSegments (void) void CreateGlobalSegments (void) /* Create the global segments and remember them in GS */ { - GS = PushSegments (0); + GS = PushSegContext (0); } void UseDataSeg (segment_t DSeg) -/* For the current segment list, use the data segment DSeg */ +/* For the current segment context, use the data segment DSeg */ { /* Check the input */ PRECONDITION (CS && DSeg != SEG_CODE); @@ -372,7 +378,7 @@ void RemoveGlobalCode (void) -void OutputSegments (const Segments* S) +void OutputSegments (const SegContext* S) /* Output the given segments to the output file */ { /* Output the function prologue if the segments came from a function */ diff --git a/src/cc65/segments.h b/src/cc65/segments.h index 91d702df6..d7c9e3c11 100644 --- a/src/cc65/segments.h +++ b/src/cc65/segments.h @@ -78,8 +78,8 @@ typedef enum segment_t { } segment_t; /* A list of all segments used when generating code */ -typedef struct Segments Segments; -struct Segments { +typedef struct SegContext SegContext; +struct SegContext { struct TextSeg* Text; /* Text segment */ struct CodeSeg* Code; /* Code segment */ struct DataSeg* Data; /* Data segment */ @@ -90,11 +90,11 @@ struct Segments { unsigned NextDataLabel; /* Number to generate unique data labels */ }; -/* Pointer to the current segment list. Output goes here. */ -extern Segments* CS; +/* Pointer to the current segment context. Output goes here. */ +extern SegContext* CS; -/* Pointer to the global segment list */ -extern Segments* GS; +/* Pointer to the global segment context */ +extern SegContext* GS; @@ -132,17 +132,17 @@ void PopSegName (segment_t Seg); const char* GetSegName (segment_t Seg); /* Get the name of the given segment */ -Segments* PushSegments (struct SymEntry* Func); -/* Make the new segment list current but remember the old one */ +SegContext* PushSegContext (struct SymEntry* Func); +/* Make the new segment context current but remember the old one */ -void PopSegments (void); -/* Pop the old segment list (make it current) */ +void PopSegContext (void); +/* Pop the old segment context (make it current) */ void CreateGlobalSegments (void); /* Create the global segments and remember them in GS */ void UseDataSeg (segment_t DSeg); -/* For the current segment list, use the data segment DSeg */ +/* For the current segment context, use the data segment DSeg */ struct DataSeg* GetDataSeg (void); /* Return the current data segment */ @@ -165,7 +165,7 @@ int HaveGlobalCode (void); void RemoveGlobalCode (void); /* Remove all code from the global code segment. Used for error recovery. */ -void OutputSegments (const Segments* S); +void OutputSegments (const SegContext* S); /* Output the given segments to the output file */ diff --git a/src/cc65/symentry.h b/src/cc65/symentry.h index 5ebd30a75..76a4272ae 100644 --- a/src/cc65/symentry.h +++ b/src/cc65/symentry.h @@ -56,7 +56,7 @@ -struct Segments; +struct SegContext; struct LiteralPool; struct CodeEntry; @@ -156,7 +156,7 @@ struct SymEntry { /* Data for functions */ struct { - struct Segments* Seg; /* Segments for this function */ + struct SegContext* Seg; /* SegContext for this function */ struct LiteralPool* LitPool; /* Literal pool for this function */ } F;