1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-09 06:29:38 +00:00

Add #pragma charmap()

Cosmetical changes.


git-svn-id: svn://svn.cc65.org/cc65/trunk@1162 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-02-18 08:40:11 +00:00
parent f0dae93d42
commit 3b5808788b
6 changed files with 84 additions and 23 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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 */

View File

@ -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 <stdlib.h>
#include <string.h>
/* 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;

View File

@ -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;

View File

@ -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) {