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:
@@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2001 Ullrich von Bassewitz */
|
/* (C) 1998-2002 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@musoftware.de */
|
/* EMail: uz@musoftware.de */
|
||||||
@@ -230,7 +230,7 @@ static void ParseEnumDecl (void)
|
|||||||
if (CurTok.Tok == TOK_ASSIGN) {
|
if (CurTok.Tok == TOK_ASSIGN) {
|
||||||
ExprDesc lval;
|
ExprDesc lval;
|
||||||
NextToken ();
|
NextToken ();
|
||||||
constexpr (&lval);
|
ConstExpr (&lval);
|
||||||
EnumVal = lval.ConstVal;
|
EnumVal = lval.ConstVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -858,7 +858,7 @@ static void Decl (Declaration* D, unsigned Mode)
|
|||||||
/* Read the size if it is given */
|
/* Read the size if it is given */
|
||||||
if (CurTok.Tok != TOK_RBRACK) {
|
if (CurTok.Tok != TOK_RBRACK) {
|
||||||
ExprDesc lval;
|
ExprDesc lval;
|
||||||
constexpr (&lval);
|
ConstExpr (&lval);
|
||||||
Size = lval.ConstVal;
|
Size = lval.ConstVal;
|
||||||
}
|
}
|
||||||
ConsumeRBrack ();
|
ConsumeRBrack ();
|
||||||
@@ -960,7 +960,7 @@ static void ParseVoidInit (void)
|
|||||||
/* Allow an arbitrary list of values */
|
/* Allow an arbitrary list of values */
|
||||||
ConsumeLCurly ();
|
ConsumeLCurly ();
|
||||||
do {
|
do {
|
||||||
constexpr (&lval);
|
ConstExpr (&lval);
|
||||||
switch (lval.Type[0]) {
|
switch (lval.Type[0]) {
|
||||||
|
|
||||||
case T_SCHAR:
|
case T_SCHAR:
|
||||||
@@ -1069,7 +1069,7 @@ void ParseInit (type* T)
|
|||||||
|
|
||||||
case T_SCHAR:
|
case T_SCHAR:
|
||||||
case T_UCHAR:
|
case T_UCHAR:
|
||||||
constexpr (&lval);
|
ConstExpr (&lval);
|
||||||
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
|
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
|
||||||
/* Make it byte sized */
|
/* Make it byte sized */
|
||||||
lval.ConstVal &= 0xFF;
|
lval.ConstVal &= 0xFF;
|
||||||
@@ -1083,7 +1083,7 @@ void ParseInit (type* T)
|
|||||||
case T_INT:
|
case T_INT:
|
||||||
case T_UINT:
|
case T_UINT:
|
||||||
case T_PTR:
|
case T_PTR:
|
||||||
constexpr (&lval);
|
ConstExpr (&lval);
|
||||||
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
|
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
|
||||||
/* Make it word sized */
|
/* Make it word sized */
|
||||||
lval.ConstVal &= 0xFFFF;
|
lval.ConstVal &= 0xFFFF;
|
||||||
@@ -1094,7 +1094,7 @@ void ParseInit (type* T)
|
|||||||
|
|
||||||
case T_LONG:
|
case T_LONG:
|
||||||
case T_ULONG:
|
case T_ULONG:
|
||||||
constexpr (&lval);
|
ConstExpr (&lval);
|
||||||
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
|
if ((lval.Flags & E_MCTYPE) == E_TCONST) {
|
||||||
/* Make it long sized */
|
/* Make it long sized */
|
||||||
lval.ConstVal &= 0xFFFFFFFF;
|
lval.ConstVal &= 0xFFFFFFFF;
|
||||||
|
|||||||
@@ -3215,14 +3215,29 @@ void expression (ExprDesc* lval)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void constexpr (ExprDesc* lval)
|
void ConstExpr (ExprDesc* lval)
|
||||||
/* Get a constant value */
|
/* Get a constant value */
|
||||||
{
|
{
|
||||||
memset (lval, 0, sizeof (*lval));
|
memset (lval, 0, sizeof (*lval));
|
||||||
if (expr (hie1, lval) != 0 || (lval->Flags & E_MCONST) == 0) {
|
if (expr (hie1, lval) != 0 || (lval->Flags & E_MCONST) == 0) {
|
||||||
Error ("Constant expression expected");
|
Error ("Constant expression expected");
|
||||||
/* To avoid any compiler errors, make the expression a valid const */
|
/* 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)) {
|
if (!IsClassInt (lval->Type)) {
|
||||||
Error ("Integer expression expected");
|
Error ("Integer expression expected");
|
||||||
/* To avoid any compiler errors, make the expression a valid int */
|
/* To avoid any compiler errors, make the expression a valid int */
|
||||||
MakeConstIntExpr (lval, 1);
|
MakeConstIntExpr (lval, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,9 +92,12 @@ int evalexpr (unsigned flags, int (*f) (ExprDesc*), ExprDesc* lval);
|
|||||||
* primary register and 1 is returned.
|
* primary register and 1 is returned.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void constexpr (ExprDesc* lval);
|
void ConstExpr (ExprDesc* lval);
|
||||||
/* Get a constant value */
|
/* Get a constant value */
|
||||||
|
|
||||||
|
void ConstIntExpr (ExprDesc* Val);
|
||||||
|
/* Get a constant int value */
|
||||||
|
|
||||||
void intexpr (ExprDesc* lval);
|
void intexpr (ExprDesc* lval);
|
||||||
/* Get an integer expression */
|
/* Get an integer expression */
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2001 Ullrich von Bassewitz */
|
/* (C) 1998-2002 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@@ -36,6 +36,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "tgttrans.h"
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "codegen.h"
|
#include "codegen.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
@@ -58,6 +61,7 @@
|
|||||||
/* Tokens for the #pragmas */
|
/* Tokens for the #pragmas */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PR_BSSSEG,
|
PR_BSSSEG,
|
||||||
|
PR_CHARMAP,
|
||||||
PR_CHECKSTACK,
|
PR_CHECKSTACK,
|
||||||
PR_CODESEG,
|
PR_CODESEG,
|
||||||
PR_DATASEG,
|
PR_DATASEG,
|
||||||
@@ -72,9 +76,10 @@ typedef enum {
|
|||||||
/* Pragma table */
|
/* Pragma table */
|
||||||
static const struct Pragma {
|
static const struct Pragma {
|
||||||
const char* Key; /* Keyword */
|
const char* Key; /* Keyword */
|
||||||
pragma_t Tok; /* Token */
|
pragma_t Tok; /* Token */
|
||||||
} Pragmas[] = {
|
} Pragmas[] = {
|
||||||
{ "bssseg", PR_BSSSEG },
|
{ "bssseg", PR_BSSSEG },
|
||||||
|
{ "charmap", PR_CHARMAP },
|
||||||
{ "checkstack", PR_CHECKSTACK },
|
{ "checkstack", PR_CHECKSTACK },
|
||||||
{ "codeseg", PR_CODESEG },
|
{ "codeseg", PR_CODESEG },
|
||||||
{ "dataseg", PR_DATASEG },
|
{ "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)
|
static void FlagPragma (unsigned char* Flag)
|
||||||
/* Handle a pragma that expects a boolean paramater */
|
/* Handle a pragma that expects a boolean paramater */
|
||||||
{
|
{
|
||||||
/* Read a constant expression */
|
/* Read a constant integer expression */
|
||||||
ExprDesc val;
|
ExprDesc Val;
|
||||||
constexpr (&val);
|
ConstIntExpr (&Val);
|
||||||
|
|
||||||
/* Store the value into the flag parameter */
|
/* 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);
|
SegNamePragma (SEG_BSS);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PR_CHARMAP:
|
||||||
|
CharMapPragma ();
|
||||||
|
break;
|
||||||
|
|
||||||
case PR_CHECKSTACK:
|
case PR_CHECKSTACK:
|
||||||
FlagPragma (&CheckStack);
|
FlagPragma (&CheckStack);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -758,7 +758,7 @@ static int DoIf (int Skip)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Call the expression parser */
|
/* Call the expression parser */
|
||||||
constexpr (&lval);
|
ConstExpr (&lval);
|
||||||
|
|
||||||
/* End preprocessing mode */
|
/* End preprocessing mode */
|
||||||
Preprocessing = 0;
|
Preprocessing = 0;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2001 Ullrich von Bassewitz */
|
/* (C) 1998-2002 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@@ -121,7 +121,7 @@ void SwitchStatement (void)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Read the selector expression */
|
/* Read the selector expression */
|
||||||
constexpr (&CaseExpr);
|
ConstExpr (&CaseExpr);
|
||||||
if (!IsClassInt (CaseExpr.Type)) {
|
if (!IsClassInt (CaseExpr.Type)) {
|
||||||
Error ("Switch quantity not an integer");
|
Error ("Switch quantity not an integer");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user