mirror of
https://github.com/cc65/cc65.git
synced 2024-12-25 02:29:52 +00:00
Start adding (limited) support for symbols.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4804 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
7e72e7d46b
commit
03d3868d45
@ -1302,8 +1302,8 @@ static void ParseFile (InputData* D)
|
||||
}
|
||||
|
||||
/* Something we know? */
|
||||
if (D->Tok != TOK_ID && D->Tok != TOK_NAME &&
|
||||
D->Tok != TOK_SIZE && D->Tok != TOK_MTIME) {
|
||||
if (D->Tok != TOK_ID && D->Tok != TOK_MTIME &&
|
||||
D->Tok != TOK_NAME && D->Tok != TOK_SIZE) {
|
||||
/* Done */
|
||||
break;
|
||||
}
|
||||
@ -1327,6 +1327,15 @@ static void ParseFile (InputData* D)
|
||||
NextToken (D);
|
||||
break;
|
||||
|
||||
case TOK_MTIME:
|
||||
if (!IntConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
}
|
||||
MTime = D->IVal;
|
||||
NextToken (D);
|
||||
InfoBits |= ibMTime;
|
||||
break;
|
||||
|
||||
case TOK_NAME:
|
||||
if (!StrConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
@ -1346,15 +1355,6 @@ static void ParseFile (InputData* D)
|
||||
InfoBits |= ibSize;
|
||||
break;
|
||||
|
||||
case TOK_MTIME:
|
||||
if (!IntConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
}
|
||||
MTime = D->IVal;
|
||||
NextToken (D);
|
||||
InfoBits |= ibMTime;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* NOTREACHED */
|
||||
UnexpectedToken (D);
|
||||
@ -1427,8 +1427,8 @@ static void ParseLine (InputData* D)
|
||||
}
|
||||
|
||||
/* Something we know? */
|
||||
if (D->Tok != TOK_FILE && D->Tok != TOK_SEGMENT &&
|
||||
D->Tok != TOK_LINE && D->Tok != TOK_RANGE) {
|
||||
if (D->Tok != TOK_FILE && D->Tok != TOK_LINE &&
|
||||
D->Tok != TOK_RANGE && D->Tok != TOK_SEGMENT) {
|
||||
/* Done */
|
||||
break;
|
||||
}
|
||||
@ -1452,15 +1452,6 @@ static void ParseLine (InputData* D)
|
||||
NextToken (D);
|
||||
break;
|
||||
|
||||
case TOK_SEGMENT:
|
||||
if (!IntConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
}
|
||||
Segment = D->IVal;
|
||||
InfoBits |= ibSegment;
|
||||
NextToken (D);
|
||||
break;
|
||||
|
||||
case TOK_LINE:
|
||||
if (!IntConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
@ -1487,6 +1478,15 @@ static void ParseLine (InputData* D)
|
||||
InfoBits |= ibRange;
|
||||
break;
|
||||
|
||||
case TOK_SEGMENT:
|
||||
if (!IntConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
}
|
||||
Segment = D->IVal;
|
||||
InfoBits |= ibSegment;
|
||||
NextToken (D);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* NOTREACHED */
|
||||
UnexpectedToken (D);
|
||||
@ -1581,6 +1581,11 @@ static void ParseSegment (InputData* D)
|
||||
/* Check what the token was */
|
||||
switch (Tok) {
|
||||
|
||||
case TOK_ADDRSIZE:
|
||||
NextToken (D);
|
||||
InfoBits |= ibAddrSize;
|
||||
break;
|
||||
|
||||
case TOK_ID:
|
||||
if (!IntConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
@ -1619,15 +1624,6 @@ static void ParseSegment (InputData* D)
|
||||
InfoBits |= ibOutputOffs;
|
||||
break;
|
||||
|
||||
case TOK_START:
|
||||
if (!IntConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
}
|
||||
Start = (cc65_addr) D->IVal;
|
||||
NextToken (D);
|
||||
InfoBits |= ibStart;
|
||||
break;
|
||||
|
||||
case TOK_SIZE:
|
||||
if (!IntConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
@ -1637,9 +1633,13 @@ static void ParseSegment (InputData* D)
|
||||
InfoBits |= ibSize;
|
||||
break;
|
||||
|
||||
case TOK_ADDRSIZE:
|
||||
case TOK_START:
|
||||
if (!IntConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
}
|
||||
Start = (cc65_addr) D->IVal;
|
||||
NextToken (D);
|
||||
InfoBits |= ibAddrSize;
|
||||
InfoBits |= ibStart;
|
||||
break;
|
||||
|
||||
case TOK_TYPE:
|
||||
@ -1701,11 +1701,128 @@ ErrorExit:
|
||||
static void ParseSym (InputData* D)
|
||||
/* Parse a SYM line */
|
||||
{
|
||||
cc65_symbol_type Type;
|
||||
long Value;
|
||||
StrBuf SymName = STRBUF_INITIALIZER;
|
||||
enum {
|
||||
ibNone = 0x00,
|
||||
ibSymName = 0x01,
|
||||
ibValue = 0x02,
|
||||
ibAddrSize = 0x04,
|
||||
ibType = 0x08,
|
||||
ibRequired = ibSymName | ibValue | ibAddrSize | ibType,
|
||||
} InfoBits = ibNone;
|
||||
|
||||
/* Skip the SYM token */
|
||||
NextToken (D);
|
||||
|
||||
/* ### */
|
||||
SkipLine (D);
|
||||
/* More stuff follows */
|
||||
while (1) {
|
||||
|
||||
Token Tok;
|
||||
|
||||
/* Check for an unknown keyword */
|
||||
if (D->Tok == TOK_IDENT) {
|
||||
UnknownKeyword (D);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Something we know? */
|
||||
if (D->Tok != TOK_ADDRSIZE && D->Tok != TOK_NAME &&
|
||||
D->Tok != TOK_TYPE && D->Tok != TOK_VALUE) {
|
||||
/* Done */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Remember the token, skip it, check for equal */
|
||||
Tok = D->Tok;
|
||||
NextToken (D);
|
||||
if (!ConsumeEqual (D)) {
|
||||
goto ErrorExit;
|
||||
}
|
||||
|
||||
/* Check what the token was */
|
||||
switch (Tok) {
|
||||
|
||||
case TOK_ADDRSIZE:
|
||||
NextToken (D);
|
||||
InfoBits |= ibAddrSize;
|
||||
break;
|
||||
|
||||
case TOK_NAME:
|
||||
if (!StrConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
}
|
||||
SB_Copy (&SymName, &D->SVal);
|
||||
SB_Terminate (&SymName);
|
||||
InfoBits |= ibSymName;
|
||||
NextToken (D);
|
||||
break;
|
||||
|
||||
case TOK_TYPE:
|
||||
switch (D->Tok) {
|
||||
case TOK_EQUATE:
|
||||
Type = CC65_SYM_EQUATE;
|
||||
break;
|
||||
case TOK_LABEL:
|
||||
Type = CC65_SYM_LABEL;
|
||||
break;
|
||||
default:
|
||||
ParseError (D, CC65_ERROR,
|
||||
"Unknown value for attribute \"type\"");
|
||||
SkipLine (D);
|
||||
goto ErrorExit;
|
||||
}
|
||||
NextToken (D);
|
||||
InfoBits |= ibType;
|
||||
break;
|
||||
|
||||
case TOK_VALUE:
|
||||
if (!IntConstFollows (D)) {
|
||||
goto ErrorExit;
|
||||
}
|
||||
Value = D->IVal;
|
||||
InfoBits |= ibValue;
|
||||
NextToken (D);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* NOTREACHED */
|
||||
UnexpectedToken (D);
|
||||
goto ErrorExit;
|
||||
|
||||
}
|
||||
|
||||
/* Comma or done */
|
||||
if (D->Tok != TOK_COMMA) {
|
||||
break;
|
||||
}
|
||||
NextToken (D);
|
||||
}
|
||||
|
||||
/* Check for end of line */
|
||||
if (D->Tok != TOK_EOL && D->Tok != TOK_EOF) {
|
||||
UnexpectedToken (D);
|
||||
SkipLine (D);
|
||||
goto ErrorExit;
|
||||
}
|
||||
|
||||
/* Check for required and/or matched information */
|
||||
if ((InfoBits & ibRequired) != ibRequired) {
|
||||
ParseError (D, CC65_ERROR, "Required attributes missing");
|
||||
goto ErrorExit;
|
||||
}
|
||||
|
||||
/* Create the symbol info and remember it */
|
||||
#if 0
|
||||
S = NewSegInfo (&SegName, Id, Start, Size, &OutputName, OutputOffs);
|
||||
CollAppend (&D->Info->SegInfoByName, S);
|
||||
#endif
|
||||
|
||||
ErrorExit:
|
||||
/* Entry point in case of errors */
|
||||
SB_Done (&SymName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,14 +91,14 @@ typedef void (*cc65_errorfunc) (const struct cc65_parseerror*);
|
||||
*/
|
||||
typedef struct cc65_linedata cc65_linedata;
|
||||
struct cc65_linedata {
|
||||
const char* source_name; /* Name of the file */
|
||||
unsigned long source_size; /* Size of file */
|
||||
unsigned long source_mtime; /* Modification time */
|
||||
cc65_line source_line; /* Line number */
|
||||
cc65_addr line_start; /* Start address for this line */
|
||||
cc65_addr line_end; /* End address for this line */
|
||||
const char* output_name; /* Output file */
|
||||
unsigned long output_offs; /* Offset in output file */
|
||||
const char* source_name; /* Name of the file */
|
||||
unsigned long source_size; /* Size of file */
|
||||
unsigned long source_mtime; /* Modification time */
|
||||
cc65_line source_line; /* Line number */
|
||||
cc65_addr line_start; /* Start address for this line */
|
||||
cc65_addr line_end; /* End address for this line */
|
||||
const char* output_name; /* Output file */
|
||||
unsigned long output_offs; /* Offset in output file */
|
||||
};
|
||||
|
||||
typedef struct cc65_lineinfo cc65_lineinfo;
|
||||
@ -110,9 +110,9 @@ struct cc65_lineinfo {
|
||||
/* Source file information */
|
||||
typedef struct cc65_sourcedata cc65_sourcedata;
|
||||
struct cc65_sourcedata {
|
||||
const char* source_name; /* Name of the file */
|
||||
unsigned long source_size; /* Size of file */
|
||||
unsigned long source_mtime; /* Modification time */
|
||||
const char* source_name; /* Name of the file */
|
||||
unsigned long source_size; /* Size of file */
|
||||
unsigned long source_mtime; /* Modification time */
|
||||
};
|
||||
|
||||
typedef struct cc65_sourceinfo cc65_sourceinfo;
|
||||
@ -130,11 +130,11 @@ struct cc65_sourceinfo {
|
||||
*/
|
||||
typedef struct cc65_segmentdata cc65_segmentdata;
|
||||
struct cc65_segmentdata {
|
||||
const char* segment_name; /* Name of the segment */
|
||||
cc65_addr segment_start; /* Start address of segment */
|
||||
cc65_addr segment_size; /* Size of segment */
|
||||
const char* output_name; /* Output file this seg was written to */
|
||||
unsigned long output_offs; /* Offset of this seg in output file */
|
||||
const char* segment_name; /* Name of the segment */
|
||||
cc65_addr segment_start; /* Start address of segment */
|
||||
cc65_addr segment_size; /* Size of segment */
|
||||
const char* output_name; /* Output file this seg was written to */
|
||||
unsigned long output_offs; /* Offset of this seg in output file */
|
||||
};
|
||||
|
||||
typedef struct cc65_segmentinfo cc65_segmentinfo;
|
||||
@ -143,6 +143,25 @@ struct cc65_segmentinfo {
|
||||
cc65_segmentdata data[1]; /* Data sets, number is dynamic */
|
||||
};
|
||||
|
||||
/* Symbol information */
|
||||
typedef enum {
|
||||
CC65_SYM_EQUATE,
|
||||
CC65_SYM_LABEL /* Some sort of address */
|
||||
} cc65_symbol_type;
|
||||
|
||||
typedef struct cc65_symboldata cc65_symboldata;
|
||||
struct cc65_symboldata {
|
||||
const char* symbol_name; /* Name of symbol */
|
||||
cc65_symbol_type symbol_type; /* Type of symbol */
|
||||
long symbol_value; /* Value of symbol */
|
||||
};
|
||||
|
||||
typedef struct cc65_symbolinfo cc65_symbolinfo;
|
||||
struct cc65_symbolinfo {
|
||||
unsigned count; /* Number of data sets that follow */
|
||||
cc65_symboldata data[1]; /* Data sets, number is dynamic */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user