From: cuz Date: Mon, 18 Feb 2002 08:40:11 +0000 (+0000) Subject: Add #pragma charmap() X-Git-Tag: V2.12.0~2451 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3b5808788bed043ae26f562649363668085272e0;p=cc65 Add #pragma charmap() Cosmetical changes. git-svn-id: svn://svn.cc65.org/cc65/trunk@1162 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 9aabf0eab..0b516c956 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2001 Ullrich von Bassewitz */ +/* (C) 1998-2002 Ullrich von Bassewitz */ /* Wacholderweg 14 */ /* D-70597 Stuttgart */ /* EMail: uz@musoftware.de */ @@ -230,7 +230,7 @@ static void ParseEnumDecl (void) if (CurTok.Tok == TOK_ASSIGN) { ExprDesc lval; NextToken (); - constexpr (&lval); + ConstExpr (&lval); EnumVal = lval.ConstVal; } @@ -858,7 +858,7 @@ static void Decl (Declaration* D, unsigned Mode) /* Read the size if it is given */ if (CurTok.Tok != TOK_RBRACK) { ExprDesc lval; - constexpr (&lval); + ConstExpr (&lval); Size = lval.ConstVal; } ConsumeRBrack (); @@ -960,7 +960,7 @@ static void ParseVoidInit (void) /* Allow an arbitrary list of values */ ConsumeLCurly (); do { - constexpr (&lval); + ConstExpr (&lval); switch (lval.Type[0]) { case T_SCHAR: @@ -1069,7 +1069,7 @@ void ParseInit (type* T) case T_SCHAR: case T_UCHAR: - constexpr (&lval); + ConstExpr (&lval); if ((lval.Flags & E_MCTYPE) == E_TCONST) { /* Make it byte sized */ lval.ConstVal &= 0xFF; @@ -1083,7 +1083,7 @@ void ParseInit (type* T) 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; @@ -1094,7 +1094,7 @@ void ParseInit (type* T) case T_LONG: case T_ULONG: - constexpr (&lval); + ConstExpr (&lval); if ((lval.Flags & E_MCTYPE) == E_TCONST) { /* Make it long sized */ lval.ConstVal &= 0xFFFFFFFF; diff --git a/src/cc65/expr.c b/src/cc65/expr.c index a814b402f..e272bba98 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -3215,14 +3215,29 @@ void expression (ExprDesc* lval) -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); } } @@ -3235,7 +3250,7 @@ void intexpr (ExprDesc* lval) 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); } } diff --git a/src/cc65/expr.h b/src/cc65/expr.h index 1a6d18a8f..fabd91b40 100644 --- a/src/cc65/expr.h +++ b/src/cc65/expr.h @@ -92,9 +92,12 @@ int evalexpr (unsigned flags, int (*f) (ExprDesc*), ExprDesc* lval); * 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 */ diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c index ce1a8a4ba..125bc22b6 100644 --- a/src/cc65/pragma.c +++ b/src/cc65/pragma.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2001 Ullrich von Bassewitz */ +/* (C) 1998-2002 Ullrich von Bassewitz */ /* Wacholderweg 14 */ /* D-70597 Stuttgart */ /* EMail: uz@cc65.org */ @@ -36,6 +36,9 @@ #include #include +/* common */ +#include "tgttrans.h" + /* cc65 */ #include "codegen.h" #include "error.h" @@ -58,6 +61,7 @@ /* Tokens for the #pragmas */ typedef enum { PR_BSSSEG, + PR_CHARMAP, PR_CHECKSTACK, PR_CODESEG, PR_DATASEG, @@ -72,9 +76,10 @@ typedef enum { /* 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 }, @@ -170,15 +175,49 @@ static void SegNamePragma (segment_t Seg) +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); } @@ -221,6 +260,10 @@ void DoPragma (void) SegNamePragma (SEG_BSS); break; + case PR_CHARMAP: + CharMapPragma (); + break; + case PR_CHECKSTACK: FlagPragma (&CheckStack); break; diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index 8a826e0bb..f1135acb2 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -147,7 +147,7 @@ static void keepch (char c) { *mptr++ = c; } - + static void keepstr (const char* S) @@ -758,7 +758,7 @@ static int DoIf (int Skip) NextToken (); /* Call the expression parser */ - constexpr (&lval); + ConstExpr (&lval); /* End preprocessing mode */ Preprocessing = 0; diff --git a/src/cc65/swstmt.c b/src/cc65/swstmt.c index c1317449f..fc4d40a63 100644 --- a/src/cc65/swstmt.c +++ b/src/cc65/swstmt.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2001 Ullrich von Bassewitz */ +/* (C) 1998-2002 Ullrich von Bassewitz */ /* Wacholderweg 14 */ /* D-70597 Stuttgart */ /* EMail: uz@cc65.org */ @@ -121,7 +121,7 @@ void SwitchStatement (void) NextToken (); /* Read the selector expression */ - constexpr (&CaseExpr); + ConstExpr (&CaseExpr); if (!IsClassInt (CaseExpr.Type)) { Error ("Switch quantity not an integer"); } @@ -142,14 +142,14 @@ void SwitchStatement (void) 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) {