1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-11 11:30:13 +00:00

Removed underlines from structure names.

Moved the fragment type into its own module.


git-svn-id: svn://svn.cc65.org/cc65/trunk@430 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2000-11-02 22:11:25 +00:00
parent d341e0ad76
commit 18840117ec
13 changed files with 276 additions and 150 deletions

View File

@ -36,9 +36,11 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "../common/xmalloc.h"
/* common */
#include "xmalloc.h"
/* ld65 */
#include "global.h"
#include "error.h"
#include "fileio.h"
@ -91,7 +93,7 @@ void FreeBinDesc (BinDesc* D)
/* Free a binary format descriptor */
{
xfree (D);
}
}
@ -206,7 +208,7 @@ static int BinUnresolved (const char* Name, void* D)
void BinWriteTarget (BinDesc* D, struct File_* F)
void BinWriteTarget (BinDesc* D, struct File* F)
/* Write a binary output file */
{
Memory* M;

View File

@ -49,52 +49,52 @@
/* File list entry */
typedef struct File_ File;
struct File_ {
typedef struct File File;
struct File {
File* Next; /* Pointer to next entry in list */
unsigned Flags;
unsigned Format; /* Output format */
struct Memory_* MemList; /* List of memory areas in this file */
struct Memory_* MemLast; /* Last memory area in this file */
char Name [1]; /* Name of file */
struct Memory* MemList; /* List of memory areas in this file */
struct Memory* MemLast; /* Last memory area in this file */
char Name [1]; /* Name of file */
};
/* Segment list node. Needed because there are two lists (RUN & LOAD) */
typedef struct MemListNode_ MemListNode;
struct MemListNode_ {
MemListNode* Next; /* Next entry */
struct SegDesc_* Seg; /* Segment */
typedef struct MemListNode MemListNode;
struct MemListNode {
MemListNode* Next; /* Next entry */
struct SegDesc* Seg; /* Segment */
};
/* Memory list entry */
typedef struct Memory_ Memory;
struct Memory_ {
Memory* Next; /* Pointer to next entry in list */
typedef struct Memory Memory;
struct Memory {
Memory* Next; /* Pointer to next entry in list */
Memory* FNext; /* Next in file list */
unsigned Attr; /* Which values are valid? */
unsigned Flags; /* Set of bitmapped flags */
unsigned Flags; /* Set of bitmapped flags */
unsigned long Start; /* Start address */
unsigned long Size; /* Length of memory section */
unsigned long FillLevel; /* Actual fill level of segment */
unsigned char FillVal; /* Value used to fill rest of seg */
MemListNode* SegList; /* List of segments for this section */
MemListNode* SegLast; /* Last segment in this section */
File* F; /* File that contains the entry */
char Name [1]; /* Name of the memory section */
File* F; /* File that contains the entry */
char Name [1]; /* Name of the memory section */
};
/* Segment descriptor entry */
typedef struct SegDesc_ SegDesc;
struct SegDesc_ {
SegDesc* Next; /* Pointer to next entry in list */
Segment* Seg; /* Pointer to segment structure */
unsigned Attr; /* Attributes for segment */
unsigned Flags; /* Set of bitmapped flags */
Memory* Load; /* Load memory section */
Memory* Run; /* Run memory section */
typedef struct SegDesc SegDesc;
struct SegDesc {
SegDesc* Next; /* Pointer to next entry in list */
Segment* Seg; /* Pointer to segment structure */
unsigned Attr; /* Attributes for segment */
unsigned Flags; /* Set of bitmapped flags */
Memory* Load; /* Load memory section */
Memory* Run; /* Run memory section */
unsigned long Addr; /* Start address or offset into segment */
unsigned char Align; /* Alignment if given */
char Name [1]; /* Copy of name */
unsigned char Align; /* Alignment if given */
char Name [1]; /* Copy of name */
};
/* Segment list */
@ -107,17 +107,17 @@ extern unsigned SegDescCount; /* Number of entries in list */
#define MF_RO 0x0004 /* Read only memory area */
/* Segment flags */
#define SF_RO 0x0001 /* Read only segment */
#define SF_BSS 0x0002 /* Segment is BSS style segment */
#define SF_ZP 0x0004 /* Zeropage segment (o65 only) */
#define SF_WPROT 0x0008 /* Write protected segment */
#define SF_RO 0x0001 /* Read only segment */
#define SF_BSS 0x0002 /* Segment is BSS style segment */
#define SF_ZP 0x0004 /* Zeropage segment (o65 only) */
#define SF_WPROT 0x0008 /* Write protected segment */
#define SF_DEFINE 0x0010 /* Define start and size */
#define SF_ALIGN 0x0020 /* Align the segment */
#define SF_OFFSET 0x0040 /* Segment has offset in memory */
#define SF_START 0x0080 /* Segment has fixed start address */
#define SF_ALIGN 0x0020 /* Align the segment */
#define SF_OFFSET 0x0040 /* Segment has offset in memory */
#define SF_START 0x0080 /* Segment has fixed start address */
#define SF_LOAD_AND_RUN 0x1000 /* LOAD and RUN given */
#define SF_RUN_DEF 0x2000 /* RUN symbols already defined */
#define SF_LOAD_DEF 0x4000 /* LOAD symbols already defined */
#define SF_LOAD_DEF 0x4000 /* LOAD symbols already defined */
@ -145,3 +145,4 @@ void CfgWriteTarget (void);

View File

@ -43,7 +43,7 @@
/* common */
#include "exprdefs.h"
#include "filepos.h"
/* ld65 */
#include "objdata.h"
@ -56,8 +56,8 @@
/* Debug symbol structure */
typedef struct DbgSym_ DbgSym;
struct DbgSym_ {
typedef struct DbgSym DbgSym;
struct DbgSym {
DbgSym* Next; /* Pool linear list link */
unsigned Flags; /* Generic flags */
ObjData* Obj; /* Object file that exports the name */
@ -92,4 +92,5 @@ void PrintDbgSymLabels (ObjData* O, FILE* F);

View File

@ -2,7 +2,7 @@
/* */
/* exports.c */
/* */
/* Exports handing for the ld65 linker */
/* Exports handling for the ld65 linker */
/* */
/* */
/* */

View File

@ -43,7 +43,7 @@
/* common */
#include "exprdefs.h"
#include "filepos.h"
/* ld65 */
#include "objdata.h"
#include "config.h"
@ -57,29 +57,29 @@
/* Import symbol structure */
typedef struct Import_ Import;
struct Import_ {
Import* Next; /* Single linked list */
ObjData* Obj; /* Object file that imports the name */
FilePos Pos; /* File position of reference */
typedef struct Import Import;
struct Import {
Import* Next; /* Single linked list */
ObjData* Obj; /* Object file that imports the name */
FilePos Pos; /* File position of reference */
union {
struct Export_* Exp; /* Matching export for this import */
const char* Name; /* Name if not in table */
struct Export* Exp; /* Matching export for this import */
const char* Name; /* Name if not in table */
} V;
unsigned char Type; /* Type of import */
unsigned char Type; /* Type of import */
};
/* Export symbol structure */
typedef struct Export_ Export;
struct Export_ {
typedef struct Export Export;
struct Export {
Export* Next; /* Hash table link */
unsigned Flags; /* Generic flags */
ObjData* Obj; /* Object file that exports the name */
unsigned ImpCount; /* How many imports for this symbol? */
Import* ImpList; /* List of imports for this symbol */
FilePos Pos; /* File position of definition */
unsigned Flags; /* Generic flags */
ObjData* Obj; /* Object file that exports the name */
unsigned ImpCount; /* How many imports for this symbol? */
Import* ImpList; /* List of imports for this symbol */
FilePos Pos; /* File position of definition */
ExprNode* Expr; /* Expression (0 if not def'd) */
unsigned char Type; /* Type of export */
char* Name; /* Name - dynamically allocated */
@ -157,7 +157,7 @@ void CircularRefError (const Export* E);
/* Print an error about a circular reference using to define the given export */
/* End of exports.h */
#endif

View File

@ -38,8 +38,10 @@
#include "../common/exprdefs.h"
/* common */
#include "exprdefs.h"
/* ld65 */
#include "objdata.h"
#include "exports.h"
#include "config.h"

79
src/ld65/fragment.c Normal file
View File

@ -0,0 +1,79 @@
/*****************************************************************************/
/* */
/* fragment.c */
/* */
/* Code/data fragment routines */
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
/* common */
#include "xmalloc.h"
/* ld65 */
#include "segments.h"
#include "fragment.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
Fragment* NewFragment (unsigned char Type, unsigned long Size, Section* S)
/* Create a new fragment and insert it into the section S */
{
/* Allocate memory */
Fragment* F = xmalloc (sizeof (Fragment) - 1 + Size); /* Portable? */
/* Initialize the data */
F->Next = 0;
F->Obj = 0;
F->Size = Size;
F->Expr = 0;
F->Type = Type;
/* Insert the code fragment into the segment */
if (S->FragRoot == 0) {
/* First fragment */
S->FragRoot = F;
} else {
S->FragLast->Next = F;
}
S->FragLast = F;
S->Size += Size;
/* Return the new fragment */
return F;
}

83
src/ld65/fragment.h Normal file
View File

@ -0,0 +1,83 @@
/*****************************************************************************/
/* */
/* fragment.h */
/* */
/* Code/data fragment routines */
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
#ifndef FRAGMENT_H
#define FRAGMENT_H
/* common */
#include "filepos.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Fragment structure */
typedef struct Fragment Fragment;
struct Fragment {
Fragment* Next; /* Next fragment in list */
struct ObjData* Obj; /* Source of fragment */
unsigned long Size; /* Size of data/expression */
struct ExprNode* Expr; /* Expression if FRAG_EXPR */
FilePos Pos; /* File position in source */
unsigned char Type; /* Type of fragment */
unsigned char LitBuf [1]; /* Dynamically alloc'ed literal buffer */
};
/*****************************************************************************/
/* Code */
/*****************************************************************************/
Fragment* NewFragment (unsigned char Type, unsigned long Size, struct Section* S);
/* Create a new fragment and insert it into the section S */
/* End of fragment.h */
#endif

View File

@ -26,6 +26,7 @@ OBJS = bin.o \
expr.o \
extsyms.o \
fileio.o \
fragment.o \
global.o \
library.o \
main.o \

View File

@ -76,6 +76,7 @@ OBJS = bin.obj \
expr.obj \
extsyms.obj \
fileio.obj \
fragment.obj \
global.obj \
library.obj \
main.obj \

View File

@ -56,24 +56,24 @@
/* Internal structure holding object file data */
typedef struct ObjData_ ObjData;
struct ObjData_ {
typedef struct ObjData ObjData;
struct ObjData {
ObjData* Next; /* Linked list of all objects */
char* Name; /* Module name */
char* LibName; /* Name of library */
ObjHeader Header; /* Header of file */
ObjHeader Header; /* Header of file */
unsigned long Start; /* Start offset of data in library */
unsigned Flags;
unsigned FileCount; /* Input file count */
char** Files; /* List of input files */
unsigned SectionCount; /* Count of sections in this object */
struct Section_** Sections; /* List of all sections */
unsigned ExportCount; /* Count of exports */
struct Export_** Exports; /* List of all exports */
unsigned ImportCount; /* Count of imports */
struct Import_** Imports; /* List of all imports */
unsigned DbgSymCount; /* Count of debug symbols */
struct DbgSym_** DbgSyms; /* List of debug symbols */
unsigned FileCount; /* Input file count */
char** Files; /* List of input files */
unsigned SectionCount; /* Count of sections in this object */
struct Section** Sections; /* List of all sections */
unsigned ExportCount; /* Count of exports */
struct Export** Exports; /* List of all exports */
unsigned ImportCount; /* Count of imports */
struct Import** Imports; /* List of all imports */
unsigned DbgSymCount; /* Count of debug symbols */
struct DbgSym** DbgSyms; /* List of debug symbols */
};
@ -105,4 +105,4 @@ void FreeObjData (ObjData* O);

View File

@ -48,6 +48,7 @@
#include "error.h"
#include "expr.h"
#include "fileio.h"
#include "fragment.h"
#include "global.h"
#include "segments.h"
@ -59,20 +60,6 @@
/* Fragment structure */
typedef struct Fragment_ Fragment;
struct Fragment_ {
Fragment* Next; /* Next fragment in list */
ObjData* Obj; /* Source of fragment */
unsigned long Size; /* Size of data/expression */
ExprNode* Expr; /* Expression if FRAG_EXPR */
FilePos Pos; /* File position in source */
unsigned char Type; /* Type of fragment */
unsigned char LitBuf [1]; /* Dynamically alloc'ed literal buffer */
};
/* Hash table */
#define HASHTAB_SIZE 253
static Segment* HashTab [HASHTAB_SIZE];
@ -88,35 +75,6 @@ static Segment* SegRoot = 0; /* List of all segments */
static Fragment* NewFragment (unsigned char Type, unsigned long Size, Section* S)
/* Create a new fragment and insert it into the segment S */
{
/* Allocate memory */
Fragment* F = xmalloc (sizeof (Fragment) - 1 + Size); /* Portable? */
/* Initialize the data */
F->Next = 0;
F->Obj = 0;
F->Size = Size;
F->Expr = 0;
F->Type = Type;
/* Insert the code fragment into the segment */
if (S->FragRoot == 0) {
/* First fragment */
S->FragRoot = F;
} else {
S->FragLast->Next = F;
}
S->FragLast = F;
S->Size += Size;
/* Return the new fragment */
return F;
}
static Segment* NewSegment (const char* Name, unsigned char Type)
/* Create a new segment and initialize it */
{
@ -413,7 +371,7 @@ void SegDump (void)
while (Count--) {
if (I > 75) {
printf ("\n ");
I = 3;
I = 3;
}
printf (" %02X", *Data++);
I += 3;
@ -435,7 +393,7 @@ void SegDump (void)
case FRAG_FILL:
printf (" Empty space (%lu bytes)\n", F->Size);
break;
break;
default:
Internal ("Invalid fragment type: %02X", F->Type);

View File

@ -40,9 +40,8 @@
#include <stdio.h>
#include "../common/exprdefs.h"
#include "objdata.h"
/* common */
#include "exprdefs.h"
@ -52,34 +51,32 @@
/* Forward for the section structure (a section is a part of a segment) */
typedef struct Section_ Section;
/* Segment structure */
typedef struct Segment_ Segment;
struct Segment_ {
Segment* Next; /* Hash list */
Segment* List; /* List of all segments */
Section* SecRoot; /* Section list */
Section* SecLast; /* Pointer to last section */
unsigned long PC; /* PC were this segment is located */
unsigned long Size; /* Size of data so far */
ObjData* AlignObj; /* Module that requested the alignment */
unsigned char Align; /* Alignment needed */
unsigned char FillVal; /* Value to use for fill bytes */
unsigned char Type; /* Type of segment */
char Dumped; /* Did we dump this segment? */
typedef struct Segment Segment;
struct Segment {
Segment* Next; /* Hash list */
Segment* List; /* List of all segments */
struct Section* SecRoot; /* Section list */
struct Section* SecLast; /* Pointer to last section */
unsigned long PC; /* PC were this segment is located */
unsigned long Size; /* Size of data so far */
struct ObjData* AlignObj; /* Module that requested the alignment */
unsigned char Align; /* Alignment needed */
unsigned char FillVal; /* Value to use for fill bytes */
unsigned char Type; /* Type of segment */
char Dumped; /* Did we dump this segment? */
char Name [1]; /* Name, dynamically allocated */
};
/* Section structure (a section is a part of a segment) */
struct Section_ {
Section* Next; /* List of sections in a segment */
Segment* Seg; /* Segment that contains the section */
struct Fragment_* FragRoot; /* Fragment list */
struct Fragment_* FragLast; /* Pointer to last fragment */
typedef struct Section Section;
struct Section {
Section* Next; /* List of sections in a segment */
Segment* Seg; /* Segment that contains the section */
struct Fragment* FragRoot; /* Fragment list */
struct Fragment* FragLast; /* Pointer to last fragment */
unsigned long Offs; /* Offset into the segment */
unsigned long Size; /* Size of the section */
unsigned char Align; /* Alignment */
@ -97,10 +94,10 @@ struct Section_ {
#define SEG_EXPR_TOO_COMPLEX 2 /* Expression too complex */
typedef unsigned (*SegWriteFunc) (ExprNode* E, /* The expression to write */
int Signed, /* Signed expression? */
unsigned Size, /* Size (=range) */
unsigned long Offs, /* File offset */
void* Data); /* Callers data */
int Signed, /* Signed expression? */
unsigned Size, /* Size (=range) */
unsigned long Offs, /* File offset */
void* Data); /* Callers data */
@ -110,7 +107,7 @@ typedef unsigned (*SegWriteFunc) (ExprNode* E, /* The expression to write
Section* ReadSection (FILE* F, ObjData* O);
Section* ReadSection (FILE* F, struct ObjData* O);
/* Read a section from a file */
Segment* SegFind (const char* Name);
@ -150,3 +147,4 @@ void CheckSegments (void);