Renamed struct Segments to SegContext as well as some related functions.

This commit is contained in:
acqn 2023-10-21 23:41:36 +08:00
parent bb1b5c363e
commit 01d2b809a1
6 changed files with 47 additions and 41 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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 */

View File

@ -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 */

View File

@ -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;