Added simple expressions for the config file
git-svn-id: svn://svn.cc65.org/cc65/trunk@3556 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
340
src/ld65/cfgexpr.c
Normal file
340
src/ld65/cfgexpr.c
Normal file
@@ -0,0 +1,340 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* cfgexpr.c */
|
||||||
|
/* */
|
||||||
|
/* Simple expressions for use with in configuration file */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2005, Ullrich von Bassewitz */
|
||||||
|
/* R<>merstrasse 52 */
|
||||||
|
/* D-70794 Filderstadt */
|
||||||
|
/* EMail: uz@cc65.org */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* 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 "strbuf.h"
|
||||||
|
|
||||||
|
/* ld65 */
|
||||||
|
#include "cfgexpr.h"
|
||||||
|
#include "error.h"
|
||||||
|
#include "exports.h"
|
||||||
|
#include "scanner.h"
|
||||||
|
#include "spool.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Type of a CfgExpr */
|
||||||
|
enum {
|
||||||
|
ceEmpty,
|
||||||
|
ceInt,
|
||||||
|
ceString
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct CfgExpr CfgExpr;
|
||||||
|
struct CfgExpr {
|
||||||
|
unsigned Type; /* Type of the expression */
|
||||||
|
long IVal; /* Integer value if it's a string */
|
||||||
|
StrBuf SVal; /* String value if it's a string */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define CFGEXPR_INITIALIZER { ceEmpty, 0, STATIC_STRBUF_INITIALIZER }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Forwards */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void Expr (CfgExpr* E);
|
||||||
|
/* Full expression */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* struct CfgExpr */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void CE_Done (CfgExpr* E)
|
||||||
|
/* Cleanup a CfgExpr struct */
|
||||||
|
{
|
||||||
|
/* If the type is a string, we must delete the string buffer */
|
||||||
|
if (E->Type == ceString) {
|
||||||
|
DoneStrBuf (&E->SVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void CE_AssureInt (const CfgExpr* E)
|
||||||
|
/* Make sure, E contains an integer */
|
||||||
|
{
|
||||||
|
if (E->Type != ceInt) {
|
||||||
|
CfgError ("Integer type expected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void Factor (CfgExpr* E)
|
||||||
|
/* Read and return a factor in E */
|
||||||
|
{
|
||||||
|
Export* Sym;
|
||||||
|
|
||||||
|
|
||||||
|
switch (CfgTok) {
|
||||||
|
|
||||||
|
case CFGTOK_IDENT:
|
||||||
|
/* An identifier - search an export with the given name */
|
||||||
|
Sym = FindExport (GetStringId (CfgSVal));
|
||||||
|
if (Sym == 0) {
|
||||||
|
CfgError ("Unknown symbol in expression: `%s'", CfgSVal);
|
||||||
|
}
|
||||||
|
/* We can only handle constants */
|
||||||
|
if (!IsConstExport (Sym)) {
|
||||||
|
CfgError ("Value for symbol `%s' is not constant", CfgSVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use the symbol value */
|
||||||
|
E->IVal = GetExportVal (Sym);
|
||||||
|
E->Type = ceInt;
|
||||||
|
|
||||||
|
/* Skip the symbol name */
|
||||||
|
CfgNextTok ();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CFGTOK_INTCON:
|
||||||
|
/* An integer constant */
|
||||||
|
E->IVal = CfgIVal;
|
||||||
|
E->Type = ceInt;
|
||||||
|
CfgNextTok ();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CFGTOK_STRCON:
|
||||||
|
/* A string constant */
|
||||||
|
SB_CopyStr (&E->SVal, CfgSVal);
|
||||||
|
E->Type = ceString;
|
||||||
|
CfgNextTok ();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CFGTOK_PLUS:
|
||||||
|
/* Unary plus */
|
||||||
|
CfgNextTok ();
|
||||||
|
Factor (E);
|
||||||
|
CE_AssureInt (E);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CFGTOK_MINUS:
|
||||||
|
/* Unary minus */
|
||||||
|
CfgNextTok ();
|
||||||
|
Factor (E);
|
||||||
|
CE_AssureInt (E);
|
||||||
|
E->IVal = -E->IVal;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CFGTOK_LPAR:
|
||||||
|
/* Left parenthesis */
|
||||||
|
CfgNextTok ();
|
||||||
|
Expr (E);
|
||||||
|
CfgConsume (CFGTOK_RPAR, "')' expected");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
CfgError ("Invalid expression: %d", CfgTok);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void Term (CfgExpr* E)
|
||||||
|
/* Multiplicative operators: * and / */
|
||||||
|
{
|
||||||
|
/* Left operand */
|
||||||
|
Factor (E);
|
||||||
|
|
||||||
|
/* Handle multiplicative operators */
|
||||||
|
while (CfgTok == CFGTOK_MUL || CfgTok == CFGTOK_DIV) {
|
||||||
|
|
||||||
|
CfgExpr RightSide = CFGEXPR_INITIALIZER;
|
||||||
|
|
||||||
|
/* Remember the token */
|
||||||
|
cfgtok_t Tok = CfgTok;
|
||||||
|
|
||||||
|
/* Left side must be an int */
|
||||||
|
CE_AssureInt (E);
|
||||||
|
|
||||||
|
/* Get the right operand and make sure it's an int */
|
||||||
|
Factor (&RightSide);
|
||||||
|
CE_AssureInt (&RightSide);
|
||||||
|
|
||||||
|
/* Handle the operation */
|
||||||
|
switch (Tok) {
|
||||||
|
|
||||||
|
case CFGTOK_MUL:
|
||||||
|
E->IVal *= RightSide.IVal;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CFGTOK_DIV:
|
||||||
|
if (RightSide.IVal == 0) {
|
||||||
|
CfgError ("Division by zero");
|
||||||
|
}
|
||||||
|
E->IVal /= RightSide.IVal;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Internal ("Unhandled token in Term: %d", Tok);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cleanup RightSide (this is not really needed since it may not
|
||||||
|
* contain strings at this point, but call it anyway for clarity.
|
||||||
|
*/
|
||||||
|
CE_Done (&RightSide);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void SimpleExpr (CfgExpr* E)
|
||||||
|
/* Additive operators: + and - */
|
||||||
|
{
|
||||||
|
/* Left operand */
|
||||||
|
Term (E);
|
||||||
|
|
||||||
|
/* Handle additive operators */
|
||||||
|
while (CfgTok == CFGTOK_PLUS || CfgTok == CFGTOK_MINUS) {
|
||||||
|
|
||||||
|
CfgExpr RightSide = CFGEXPR_INITIALIZER;
|
||||||
|
|
||||||
|
/* Remember the token, then skip it */
|
||||||
|
cfgtok_t Tok = CfgTok;
|
||||||
|
CfgNextTok ();
|
||||||
|
|
||||||
|
/* Get the right operand */
|
||||||
|
Term (&RightSide);
|
||||||
|
|
||||||
|
/* Make sure, left and right side are of the same type */
|
||||||
|
if (E->Type != RightSide.Type) {
|
||||||
|
CfgError ("Incompatible types in expression");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Handle the operation */
|
||||||
|
switch (Tok) {
|
||||||
|
|
||||||
|
case CFGTOK_PLUS:
|
||||||
|
/* Plus is defined for strings and ints */
|
||||||
|
if (E->Type == ceInt) {
|
||||||
|
E->IVal += RightSide.IVal;
|
||||||
|
} else if (E->Type == ceString) {
|
||||||
|
SB_Append (&E->SVal, &RightSide.SVal);
|
||||||
|
} else {
|
||||||
|
Internal ("Unhandled type in '+' operator: %u", E->Type);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CFGTOK_MINUS:
|
||||||
|
/* Operands must be ints */
|
||||||
|
CE_AssureInt (E);
|
||||||
|
E->IVal -= RightSide.IVal;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Internal ("Unhandled token in SimpleExpr: %d", Tok);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cleanup RightSide */
|
||||||
|
CE_Done (&RightSide);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void Expr (CfgExpr* E)
|
||||||
|
/* Full expression */
|
||||||
|
{
|
||||||
|
SimpleExpr (E);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
long CfgIntExpr (void)
|
||||||
|
/* Read an expression, make sure it's an int, and return its value */
|
||||||
|
{
|
||||||
|
long Val;
|
||||||
|
|
||||||
|
CfgExpr E = CFGEXPR_INITIALIZER;
|
||||||
|
|
||||||
|
/* Parse the expression */
|
||||||
|
Expr (&E);
|
||||||
|
|
||||||
|
/* Make sure it's an integer */
|
||||||
|
CE_AssureInt (&E);
|
||||||
|
|
||||||
|
/* Get the value */
|
||||||
|
Val = E.IVal;
|
||||||
|
|
||||||
|
/* Cleaup E */
|
||||||
|
CE_Done (&E);
|
||||||
|
|
||||||
|
/* Return the value */
|
||||||
|
return Val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
long CfgCheckedIntExpr (long Min, long Max)
|
||||||
|
/* Read an expression, make sure it's an int and in range, then return its
|
||||||
|
* value.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* Get the value */
|
||||||
|
long Val = CfgIntExpr ();
|
||||||
|
|
||||||
|
/* Check the range */
|
||||||
|
if (Val < Min || Val > Max) {
|
||||||
|
CfgError ("Range error");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the value */
|
||||||
|
return Val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
61
src/ld65/cfgexpr.h
Normal file
61
src/ld65/cfgexpr.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* cfgexpr.h */
|
||||||
|
/* */
|
||||||
|
/* Simple expressions for use with in configuration file */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2005, Ullrich von Bassewitz */
|
||||||
|
/* R<>merstrasse 52 */
|
||||||
|
/* D-70794 Filderstadt */
|
||||||
|
/* EMail: uz@cc65.org */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* 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 CFGEXPR_H
|
||||||
|
#define CFGEXPR_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
long CfgIntExpr (void);
|
||||||
|
/* Read an expression, make sure it's an int, and return its value */
|
||||||
|
|
||||||
|
long CfgCheckedIntExpr (long Min, long Max);
|
||||||
|
/* Read an expression, make sure it's an int and in range, then return its
|
||||||
|
* value.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of cfgexpr.h */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -48,6 +48,7 @@
|
|||||||
/* ld65 */
|
/* ld65 */
|
||||||
#include "bin.h"
|
#include "bin.h"
|
||||||
#include "binfmt.h"
|
#include "binfmt.h"
|
||||||
|
#include "cfgexpr.h"
|
||||||
#include "condes.h"
|
#include "condes.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
@@ -444,14 +445,12 @@ static void ParseMemory (void)
|
|||||||
|
|
||||||
case CFGTOK_START:
|
case CFGTOK_START:
|
||||||
FlagAttr (&M->Attr, MA_START, "START");
|
FlagAttr (&M->Attr, MA_START, "START");
|
||||||
CfgAssureInt ();
|
M->Start = CfgIntExpr ();
|
||||||
M->Start = CfgIVal;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_SIZE:
|
case CFGTOK_SIZE:
|
||||||
FlagAttr (&M->Attr, MA_SIZE, "SIZE");
|
FlagAttr (&M->Attr, MA_SIZE, "SIZE");
|
||||||
CfgAssureInt ();
|
M->Size = CfgIntExpr ();
|
||||||
M->Size = CfgIVal;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_TYPE:
|
case CFGTOK_TYPE:
|
||||||
@@ -460,6 +459,7 @@ static void ParseMemory (void)
|
|||||||
if (CfgTok == CFGTOK_RO) {
|
if (CfgTok == CFGTOK_RO) {
|
||||||
M->Flags |= MF_RO;
|
M->Flags |= MF_RO;
|
||||||
}
|
}
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_FILE:
|
case CFGTOK_FILE:
|
||||||
@@ -467,6 +467,7 @@ static void ParseMemory (void)
|
|||||||
CfgAssureStr ();
|
CfgAssureStr ();
|
||||||
/* Get the file entry and insert the memory area */
|
/* Get the file entry and insert the memory area */
|
||||||
FileInsert (GetFile (GetStringId (CfgSVal)), M);
|
FileInsert (GetFile (GetStringId (CfgSVal)), M);
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_DEFINE:
|
case CFGTOK_DEFINE:
|
||||||
@@ -476,6 +477,7 @@ static void ParseMemory (void)
|
|||||||
if (CfgTok == CFGTOK_TRUE) {
|
if (CfgTok == CFGTOK_TRUE) {
|
||||||
M->Flags |= MF_DEFINE;
|
M->Flags |= MF_DEFINE;
|
||||||
}
|
}
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_FILL:
|
case CFGTOK_FILL:
|
||||||
@@ -485,13 +487,12 @@ static void ParseMemory (void)
|
|||||||
if (CfgTok == CFGTOK_TRUE) {
|
if (CfgTok == CFGTOK_TRUE) {
|
||||||
M->Flags |= MF_FILL;
|
M->Flags |= MF_FILL;
|
||||||
}
|
}
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_FILLVAL:
|
case CFGTOK_FILLVAL:
|
||||||
FlagAttr (&M->Attr, MA_FILLVAL, "FILLVAL");
|
FlagAttr (&M->Attr, MA_FILLVAL, "FILLVAL");
|
||||||
CfgAssureInt ();
|
M->FillVal = (unsigned char) CfgCheckedIntExpr (0, 0xFF);
|
||||||
CfgRangeCheck (0, 0xFF);
|
|
||||||
M->FillVal = (unsigned char) CfgIVal;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -499,8 +500,7 @@ static void ParseMemory (void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip the attribute value and an optional comma */
|
/* Skip an optional comma */
|
||||||
CfgNextTok ();
|
|
||||||
CfgOptionalComma ();
|
CfgOptionalComma ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,6 +641,7 @@ static void ParseSegments (void)
|
|||||||
};
|
};
|
||||||
|
|
||||||
unsigned Count;
|
unsigned Count;
|
||||||
|
long Val;
|
||||||
|
|
||||||
/* The MEMORY section must preceed the SEGMENTS section */
|
/* The MEMORY section must preceed the SEGMENTS section */
|
||||||
if ((SectionsEncountered & SE_MEMORY) == 0) {
|
if ((SectionsEncountered & SE_MEMORY) == 0) {
|
||||||
@@ -674,22 +675,20 @@ static void ParseSegments (void)
|
|||||||
switch (AttrTok) {
|
switch (AttrTok) {
|
||||||
|
|
||||||
case CFGTOK_ALIGN:
|
case CFGTOK_ALIGN:
|
||||||
CfgAssureInt ();
|
|
||||||
FlagAttr (&S->Attr, SA_ALIGN, "ALIGN");
|
FlagAttr (&S->Attr, SA_ALIGN, "ALIGN");
|
||||||
CfgRangeCheck (1, 0x10000);
|
Val = CfgCheckedIntExpr (1, 0x10000);
|
||||||
S->Align = BitFind (CfgIVal);
|
S->Align = BitFind (Val);
|
||||||
if ((0x01UL << S->Align) != CfgIVal) {
|
if ((0x01L << S->Align) != Val) {
|
||||||
CfgError ("Alignment must be a power of 2");
|
CfgError ("Alignment must be a power of 2");
|
||||||
}
|
}
|
||||||
S->Flags |= SF_ALIGN;
|
S->Flags |= SF_ALIGN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_ALIGN_LOAD:
|
case CFGTOK_ALIGN_LOAD:
|
||||||
CfgAssureInt ();
|
|
||||||
FlagAttr (&S->Attr, SA_ALIGN_LOAD, "ALIGN_LOAD");
|
FlagAttr (&S->Attr, SA_ALIGN_LOAD, "ALIGN_LOAD");
|
||||||
CfgRangeCheck (1, 0x10000);
|
Val = CfgCheckedIntExpr (1, 0x10000);
|
||||||
S->AlignLoad = BitFind (CfgIVal);
|
S->AlignLoad = BitFind (Val);
|
||||||
if ((0x01UL << S->AlignLoad) != CfgIVal) {
|
if ((0x01L << S->AlignLoad) != Val) {
|
||||||
CfgError ("Alignment must be a power of 2");
|
CfgError ("Alignment must be a power of 2");
|
||||||
}
|
}
|
||||||
S->Flags |= SF_ALIGN_LOAD;
|
S->Flags |= SF_ALIGN_LOAD;
|
||||||
@@ -702,18 +701,18 @@ static void ParseSegments (void)
|
|||||||
if (CfgTok == CFGTOK_TRUE) {
|
if (CfgTok == CFGTOK_TRUE) {
|
||||||
S->Flags |= SF_DEFINE;
|
S->Flags |= SF_DEFINE;
|
||||||
}
|
}
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_LOAD:
|
case CFGTOK_LOAD:
|
||||||
FlagAttr (&S->Attr, SA_LOAD, "LOAD");
|
FlagAttr (&S->Attr, SA_LOAD, "LOAD");
|
||||||
S->Load = CfgGetMemory (GetStringId (CfgSVal));
|
S->Load = CfgGetMemory (GetStringId (CfgSVal));
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_OFFSET:
|
case CFGTOK_OFFSET:
|
||||||
CfgAssureInt ();
|
|
||||||
FlagAttr (&S->Attr, SA_OFFSET, "OFFSET");
|
FlagAttr (&S->Attr, SA_OFFSET, "OFFSET");
|
||||||
CfgRangeCheck (1, 0x1000000);
|
S->Addr = CfgCheckedIntExpr (1, 0x1000000);
|
||||||
S->Addr = CfgIVal;
|
|
||||||
S->Flags |= SF_OFFSET;
|
S->Flags |= SF_OFFSET;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -723,18 +722,18 @@ static void ParseSegments (void)
|
|||||||
if (CfgTok == CFGTOK_TRUE) {
|
if (CfgTok == CFGTOK_TRUE) {
|
||||||
S->Flags |= SF_OPTIONAL;
|
S->Flags |= SF_OPTIONAL;
|
||||||
}
|
}
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_RUN:
|
case CFGTOK_RUN:
|
||||||
FlagAttr (&S->Attr, SA_RUN, "RUN");
|
FlagAttr (&S->Attr, SA_RUN, "RUN");
|
||||||
S->Run = CfgGetMemory (GetStringId (CfgSVal));
|
S->Run = CfgGetMemory (GetStringId (CfgSVal));
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_START:
|
case CFGTOK_START:
|
||||||
CfgAssureInt ();
|
|
||||||
FlagAttr (&S->Attr, SA_START, "START");
|
FlagAttr (&S->Attr, SA_START, "START");
|
||||||
CfgRangeCheck (1, 0x1000000);
|
S->Addr = CfgCheckedIntExpr (1, 0x1000000);
|
||||||
S->Addr = CfgIVal;
|
|
||||||
S->Flags |= SF_START;
|
S->Flags |= SF_START;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -748,6 +747,7 @@ static void ParseSegments (void)
|
|||||||
case CFGTOK_ZP: S->Flags |= (SF_BSS | SF_ZP); break;
|
case CFGTOK_ZP: S->Flags |= (SF_BSS | SF_ZP); break;
|
||||||
default: Internal ("Unexpected token: %d", CfgTok);
|
default: Internal ("Unexpected token: %d", CfgTok);
|
||||||
}
|
}
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -755,8 +755,7 @@ static void ParseSegments (void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip the attribute value and an optional comma */
|
/* Skip an optional comma */
|
||||||
CfgNextTok ();
|
|
||||||
CfgOptionalComma ();
|
CfgOptionalComma ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -921,6 +920,8 @@ static void ParseO65 (void)
|
|||||||
}
|
}
|
||||||
/* Insert the symbol into the table */
|
/* Insert the symbol into the table */
|
||||||
O65SetExport (O65FmtDesc, CfgSValId);
|
O65SetExport (O65FmtDesc, CfgSValId);
|
||||||
|
/* Eat the identifier token */
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_IMPORT:
|
case CFGTOK_IMPORT:
|
||||||
@@ -943,6 +944,8 @@ static void ParseO65 (void)
|
|||||||
}
|
}
|
||||||
/* Insert the symbol into the table */
|
/* Insert the symbol into the table */
|
||||||
O65SetImport (O65FmtDesc, CfgSValId);
|
O65SetImport (O65FmtDesc, CfgSValId);
|
||||||
|
/* Eat the identifier token */
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_TYPE:
|
case CFGTOK_TYPE:
|
||||||
@@ -963,6 +966,8 @@ static void ParseO65 (void)
|
|||||||
default:
|
default:
|
||||||
CfgError ("Unexpected type token");
|
CfgError ("Unexpected type token");
|
||||||
}
|
}
|
||||||
|
/* Eat the attribute token */
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_OS:
|
case CFGTOK_OS:
|
||||||
@@ -984,24 +989,21 @@ static void ParseO65 (void)
|
|||||||
default: CfgError ("Unexpected OS token");
|
default: CfgError ("Unexpected OS token");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_ID:
|
case CFGTOK_ID:
|
||||||
/* Cannot have this attribute twice */
|
/* Cannot have this attribute twice */
|
||||||
FlagAttr (&AttrFlags, atID, "ID");
|
FlagAttr (&AttrFlags, atID, "ID");
|
||||||
/* We're expecting a number in the 0..$FFFF range*/
|
/* We're expecting a number in the 0..$FFFF range*/
|
||||||
CfgAssureInt ();
|
ModuleId = (unsigned) CfgCheckedIntExpr (0, 0xFFFF);
|
||||||
CfgRangeCheck (0, 0xFFFF);
|
|
||||||
ModuleId = (unsigned) CfgIVal;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_VERSION:
|
case CFGTOK_VERSION:
|
||||||
/* Cannot have this attribute twice */
|
/* Cannot have this attribute twice */
|
||||||
FlagAttr (&AttrFlags, atVersion, "VERSION");
|
FlagAttr (&AttrFlags, atVersion, "VERSION");
|
||||||
/* We're expecting a number in byte range */
|
/* We're expecting a number in byte range */
|
||||||
CfgAssureInt ();
|
Version = (unsigned) CfgCheckedIntExpr (0, 0xFF);
|
||||||
CfgRangeCheck (0, 0xFF);
|
|
||||||
Version = (unsigned) CfgIVal;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1009,8 +1011,7 @@ static void ParseO65 (void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip the attribute value and an optional comma */
|
/* Skip an optional comma */
|
||||||
CfgNextTok ();
|
|
||||||
CfgOptionalComma ();
|
CfgOptionalComma ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1267,11 +1268,8 @@ static void ParseStartAddress (void)
|
|||||||
case CFGTOK_DEFAULT:
|
case CFGTOK_DEFAULT:
|
||||||
/* Don't allow this twice */
|
/* Don't allow this twice */
|
||||||
FlagAttr (&AttrFlags, atDefault, "DEFAULT");
|
FlagAttr (&AttrFlags, atDefault, "DEFAULT");
|
||||||
/* We expect a number */
|
/* We expect a numeric expression */
|
||||||
CfgAssureInt ();
|
DefStartAddr = CfgCheckedIntExpr (0, 0xFFFFFF);
|
||||||
CfgRangeCheck (0, 0xFFFFFF);
|
|
||||||
/* Remember the value for later */
|
|
||||||
DefStartAddr = CfgIVal;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1279,9 +1277,6 @@ static void ParseStartAddress (void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip the attribute value */
|
|
||||||
CfgNextTok ();
|
|
||||||
|
|
||||||
/* Semicolon ends the ConDes decl, otherwise accept an optional comma */
|
/* Semicolon ends the ConDes decl, otherwise accept an optional comma */
|
||||||
if (CfgTok == CFGTOK_SEMI) {
|
if (CfgTok == CFGTOK_SEMI) {
|
||||||
break;
|
break;
|
||||||
@@ -1376,10 +1371,10 @@ static void ParseSymbols (void)
|
|||||||
/* Allow an optional assignment */
|
/* Allow an optional assignment */
|
||||||
CfgOptionalAssign ();
|
CfgOptionalAssign ();
|
||||||
|
|
||||||
/* Make sure the next token is an integer, read and skip it */
|
/* Make sure the next token is an integer expression, read and
|
||||||
CfgAssureInt ();
|
* skip it.
|
||||||
Val = CfgIVal;
|
*/
|
||||||
CfgNextTok ();
|
Val = CfgIntExpr ();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -1403,8 +1398,10 @@ static void ParseSymbols (void)
|
|||||||
CfgSpecialToken (Attributes, ENTRY_COUNT (Attributes), "Attribute");
|
CfgSpecialToken (Attributes, ENTRY_COUNT (Attributes), "Attribute");
|
||||||
AttrTok = CfgTok;
|
AttrTok = CfgTok;
|
||||||
|
|
||||||
/* An optional assignment follows */
|
/* Skip the attribute name */
|
||||||
CfgNextTok ();
|
CfgNextTok ();
|
||||||
|
|
||||||
|
/* An optional assignment follows */
|
||||||
CfgOptionalAssign ();
|
CfgOptionalAssign ();
|
||||||
|
|
||||||
/* Check which attribute was given */
|
/* Check which attribute was given */
|
||||||
@@ -1413,10 +1410,8 @@ static void ParseSymbols (void)
|
|||||||
case CFGTOK_VALUE:
|
case CFGTOK_VALUE:
|
||||||
/* Don't allow this twice */
|
/* Don't allow this twice */
|
||||||
FlagAttr (&AttrFlags, atValue, "VALUE");
|
FlagAttr (&AttrFlags, atValue, "VALUE");
|
||||||
/* We expect a number */
|
/* We expect a numeric expression */
|
||||||
CfgAssureInt ();
|
Val = CfgIntExpr ();
|
||||||
/* Remember the value for later */
|
|
||||||
Val = CfgIVal;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_WEAK:
|
case CFGTOK_WEAK:
|
||||||
@@ -1424,6 +1419,7 @@ static void ParseSymbols (void)
|
|||||||
FlagAttr (&AttrFlags, atWeak, "WEAK");
|
FlagAttr (&AttrFlags, atWeak, "WEAK");
|
||||||
CfgBoolToken ();
|
CfgBoolToken ();
|
||||||
Weak = (CfgTok == CFGTOK_TRUE);
|
Weak = (CfgTok == CFGTOK_TRUE);
|
||||||
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1431,9 +1427,6 @@ static void ParseSymbols (void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip the attribute value */
|
|
||||||
CfgNextTok ();
|
|
||||||
|
|
||||||
/* Semicolon ends the decl, otherwise accept an optional comma */
|
/* Semicolon ends the decl, otherwise accept an optional comma */
|
||||||
if (CfgTok == CFGTOK_SEMI) {
|
if (CfgTok == CFGTOK_SEMI) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ CVT=cfg/cvt-cfg.pl
|
|||||||
OBJS = asserts.o \
|
OBJS = asserts.o \
|
||||||
bin.o \
|
bin.o \
|
||||||
binfmt.o \
|
binfmt.o \
|
||||||
|
cfgexpr.o \
|
||||||
condes.o \
|
condes.o \
|
||||||
config.o \
|
config.o \
|
||||||
dbgfile.o \
|
dbgfile.o \
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ endif
|
|||||||
OBJS = asserts.obj \
|
OBJS = asserts.obj \
|
||||||
bin.obj \
|
bin.obj \
|
||||||
binfmt.obj \
|
binfmt.obj \
|
||||||
|
cfgexpr.obj \
|
||||||
condes.obj \
|
condes.obj \
|
||||||
config.obj \
|
config.obj \
|
||||||
dbgfile.obj \
|
dbgfile.obj \
|
||||||
|
|||||||
@@ -225,6 +225,36 @@ Again:
|
|||||||
/* Other characters */
|
/* Other characters */
|
||||||
switch (C) {
|
switch (C) {
|
||||||
|
|
||||||
|
case '-':
|
||||||
|
NextChar ();
|
||||||
|
CfgTok = CFGTOK_MINUS;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '+':
|
||||||
|
NextChar ();
|
||||||
|
CfgTok = CFGTOK_PLUS;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '*':
|
||||||
|
NextChar ();
|
||||||
|
CfgTok = CFGTOK_MUL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '/':
|
||||||
|
NextChar ();
|
||||||
|
CfgTok = CFGTOK_DIV;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '(':
|
||||||
|
NextChar ();
|
||||||
|
CfgTok = CFGTOK_LPAR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ')':
|
||||||
|
NextChar ();
|
||||||
|
CfgTok = CFGTOK_RPAR;
|
||||||
|
break;
|
||||||
|
|
||||||
case '{':
|
case '{':
|
||||||
NextChar ();
|
NextChar ();
|
||||||
CfgTok = CFGTOK_LCURLY;
|
CfgTok = CFGTOK_LCURLY;
|
||||||
|
|||||||
@@ -47,9 +47,15 @@
|
|||||||
/* Config file tokens */
|
/* Config file tokens */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CFGTOK_NONE,
|
CFGTOK_NONE,
|
||||||
CFGTOK_INTCON,
|
CFGTOK_INTCON, /* Integer constant */
|
||||||
CFGTOK_STRCON,
|
CFGTOK_STRCON, /* String constant */
|
||||||
CFGTOK_IDENT,
|
CFGTOK_IDENT, /* Identifier */
|
||||||
|
CFGTOK_PLUS,
|
||||||
|
CFGTOK_MINUS,
|
||||||
|
CFGTOK_MUL,
|
||||||
|
CFGTOK_DIV,
|
||||||
|
CFGTOK_LPAR,
|
||||||
|
CFGTOK_RPAR,
|
||||||
CFGTOK_LCURLY,
|
CFGTOK_LCURLY,
|
||||||
CFGTOK_RCURLY,
|
CFGTOK_RCURLY,
|
||||||
CFGTOK_SEMI,
|
CFGTOK_SEMI,
|
||||||
|
|||||||
Reference in New Issue
Block a user