/* */
/* */
/* */
-/* (C) 1998-2001 Ullrich von Bassewitz */
+/* (C) 1998-2002 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
if (CurTok.Tok == TOK_ASSIGN) {
ExprDesc lval;
NextToken ();
- constexpr (&lval);
+ ConstExpr (&lval);
EnumVal = lval.ConstVal;
}
/* Read the size if it is given */
if (CurTok.Tok != TOK_RBRACK) {
ExprDesc lval;
- constexpr (&lval);
+ ConstExpr (&lval);
Size = lval.ConstVal;
}
ConsumeRBrack ();
/* Allow an arbitrary list of values */
ConsumeLCurly ();
do {
- constexpr (&lval);
+ ConstExpr (&lval);
switch (lval.Type[0]) {
case T_SCHAR:
case T_SCHAR:
case T_UCHAR:
- constexpr (&lval);
+ ConstExpr (&lval);
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
/* Make it byte sized */
lval.ConstVal &= 0xFF;
case T_INT:
case T_UINT:
case T_PTR:
- constexpr (&lval);
+ ConstExpr (&lval);
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
/* Make it word sized */
lval.ConstVal &= 0xFFFF;
case T_LONG:
case T_ULONG:
- constexpr (&lval);
+ ConstExpr (&lval);
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
/* Make it long sized */
lval.ConstVal &= 0xFFFFFFFF;
-void constexpr (ExprDesc* lval)
+void ConstExpr (ExprDesc* lval)
/* Get a constant value */
{
memset (lval, 0, sizeof (*lval));
if (expr (hie1, lval) != 0 || (lval->Flags & E_MCONST) == 0) {
Error ("Constant expression expected");
/* To avoid any compiler errors, make the expression a valid const */
- MakeConstIntExpr (lval, 1);
+ MakeConstIntExpr (lval, 1);
+ }
+}
+
+
+
+void ConstIntExpr (ExprDesc* Val)
+/* Get a constant int value */
+{
+ memset (Val, 0, sizeof (*Val));
+ if (expr (hie1, Val) != 0 ||
+ (Val->Flags & E_MCONST) == 0 ||
+ !IsClassInt (Val->Type)) {
+ Error ("Constant integer expression expected");
+ /* To avoid any compiler errors, make the expression a valid const */
+ MakeConstIntExpr (Val, 1);
}
}
if (!IsClassInt (lval->Type)) {
Error ("Integer expression expected");
/* To avoid any compiler errors, make the expression a valid int */
- MakeConstIntExpr (lval, 1);
+ MakeConstIntExpr (lval, 1);
}
}
* primary register and 1 is returned.
*/
-void constexpr (ExprDesc* lval);
+void ConstExpr (ExprDesc* lval);
/* Get a constant value */
+void ConstIntExpr (ExprDesc* Val);
+/* Get a constant int value */
+
void intexpr (ExprDesc* lval);
/* Get an integer expression */
/* */
/* */
/* */
-/* (C) 1998-2001 Ullrich von Bassewitz */
+/* (C) 1998-2002 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@cc65.org */
#include <stdlib.h>
#include <string.h>
+/* common */
+#include "tgttrans.h"
+
/* cc65 */
#include "codegen.h"
#include "error.h"
/* Tokens for the #pragmas */
typedef enum {
PR_BSSSEG,
+ PR_CHARMAP,
PR_CHECKSTACK,
PR_CODESEG,
PR_DATASEG,
/* Pragma table */
static const struct Pragma {
const char* Key; /* Keyword */
- pragma_t Tok; /* Token */
+ pragma_t Tok; /* Token */
} Pragmas[] = {
{ "bssseg", PR_BSSSEG },
+ { "charmap", PR_CHARMAP },
{ "checkstack", PR_CHECKSTACK },
{ "codeseg", PR_CODESEG },
{ "dataseg", PR_DATASEG },
+static void CharMapPragma (void)
+/* Change the character map */
+{
+ unsigned Index, C;
+
+ ExprDesc Val;
+
+ /* Read the character index */
+ ConstIntExpr (&Val);
+ if (Val.ConstVal < 1 || Val.ConstVal > 255) {
+ Error ("Character index out of range");
+ Index = 'A';
+ } else {
+ Index = Val.ConstVal;
+ }
+
+ /* Comma follows */
+ ConsumeComma ();
+
+ /* Read the character code */
+ ConstIntExpr (&Val);
+ if (Val.ConstVal < 1 || Val.ConstVal > 255) {
+ Error ("Character code out of range");
+ C = 'A';
+ } else {
+ C = Val.ConstVal;
+ }
+
+ /* Remap the character */
+ TgtTranslateSet (Index, C);
+}
+
+
+
static void FlagPragma (unsigned char* Flag)
/* Handle a pragma that expects a boolean paramater */
{
- /* Read a constant expression */
- ExprDesc val;
- constexpr (&val);
+ /* Read a constant integer expression */
+ ExprDesc Val;
+ ConstIntExpr (&Val);
/* Store the value into the flag parameter */
- *Flag = (val.ConstVal != 0);
+ *Flag = (Val.ConstVal != 0);
}
SegNamePragma (SEG_BSS);
break;
+ case PR_CHARMAP:
+ CharMapPragma ();
+ break;
+
case PR_CHECKSTACK:
FlagPragma (&CheckStack);
break;
{
*mptr++ = c;
}
-
+
static void keepstr (const char* S)
NextToken ();
/* Call the expression parser */
- constexpr (&lval);
+ ConstExpr (&lval);
/* End preprocessing mode */
Preprocessing = 0;
/* */
/* */
/* */
-/* (C) 1998-2001 Ullrich von Bassewitz */
+/* (C) 1998-2002 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@cc65.org */
NextToken ();
/* Read the selector expression */
- constexpr (&CaseExpr);
+ ConstExpr (&CaseExpr);
if (!IsClassInt (CaseExpr.Type)) {
Error ("Switch quantity not an integer");
}
Error ("Range error");
}
break;
-
+
case T_SHORT:
case T_INT:
if (Val < -32768 || Val > 32767) {
Error ("Range error");
}
break;
-
+
case T_USHORT:
case T_UINT:
if (Val < 0 || Val > 65535) {