Renamed several expression ops and added others.

Placed the DumpExpr function into the common directory, since it is
used by the assembler and linker.


git-svn-id: svn://svn.cc65.org/cc65/trunk@225 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2000-07-29 15:53:33 +00:00
parent b40d409c4f
commit 0a57d32509
14 changed files with 285 additions and 331 deletions

View File

@@ -33,9 +33,11 @@
#include "../common/exprdefs.h"
#include "../common/xmalloc.h"
/* common */
#include "exprdefs.h"
#include "xmalloc.h"
/* ca65 */
#include "error.h"
#include "global.h"
#include "instr.h"
@@ -113,145 +115,6 @@ static void FreeExprNode (ExprNode* E)
/*****************************************************************************/
/* Dump an expression tree on stdout for debugging */
/*****************************************************************************/
static void InternalDumpExpr (ExprNode* Expr)
/* Dump an expression in UPN */
{
if (Expr == 0) {
return;
}
InternalDumpExpr (Expr->Left);
InternalDumpExpr (Expr->Right);
switch (Expr->Op) {
case EXPR_LITERAL:
case EXPR_ULABEL:
printf (" $%04lX", Expr->V.Val & 0xFFFF);
break;
case EXPR_SYMBOL:
printf (" %s", GetSymName (Expr->V.Sym));
break;
case EXPR_SEGMENT:
printf (" SEG");
break;
case EXPR_PLUS:
printf (" +");
break;
case EXPR_MINUS:
printf (" -");
break;
case EXPR_MUL:
printf (" *");
break;
case EXPR_DIV:
printf (" /");
break;
case EXPR_MOD:
printf (" %%");
break;
case EXPR_OR:
printf (" OR");
break;
case EXPR_XOR:
printf (" XOR");
break;
case EXPR_AND:
printf (" AND");
break;
case EXPR_SHL:
printf (" SHL");
break;
case EXPR_SHR:
printf (" SHR");
break;
case EXPR_EQ:
printf (" =");
break;
case EXPR_NE:
printf ("<>");
break;
case EXPR_LT:
printf (" <");
break;
case EXPR_GT:
printf (" >");
break;
case EXPR_UNARY_MINUS:
printf (" NEG");
break;
case EXPR_NOT:
printf (" ~");
break;
case EXPR_LOBYTE:
printf (" LO");
break;
case EXPR_HIBYTE:
printf (" HI");
break;
case EXPR_SWAP:
printf (" SWAP");
break;
case EXPR_BAND:
printf (" BOOL_AND");
break;
case EXPR_BOR:
printf (" BOOL_OR");
break;
case EXPR_BXOR:
printf (" BOOL_XOR");
break;
case EXPR_BNOT:
printf (" BOOL_NOT");
break;
default:
Internal ("Unknown Op type: %u", Expr->Op);
}
}
void DumpExpr (ExprNode* Expr)
/* Dump an expression tree to stdout */
{
InternalDumpExpr (Expr);
printf ("\n");
}
/*****************************************************************************/
/* Code */
/*****************************************************************************/
@@ -682,14 +545,14 @@ static ExprNode* Factor (void)
NextTok ();
N = NewExprNode ();
N->Left = Factor ();
N->Op = EXPR_LOBYTE;
N->Op = EXPR_BYTE0;
break;
case TOK_GT:
NextTok ();
N = NewExprNode ();
N->Left = Factor ();
N->Op = EXPR_HIBYTE;
N->Op = EXPR_BYTE1;
break;
case TOK_LPAREN:
@@ -1273,7 +1136,8 @@ int IsByteExpr (ExprNode* Root)
SimplifyExpr (Root);
}
return IsByteRange (GetExprVal (Root));
} else if (Root->Op == EXPR_LOBYTE || Root->Op == EXPR_HIBYTE) {
} else if (Root->Op == EXPR_BYTE0 || Root->Op == EXPR_BYTE1 ||
Root->Op == EXPR_BYTE2 || Root->Op == EXPR_BYTE3) {
/* Symbol forced to have byte range */
IsByte = 1;
} else {
@@ -1370,12 +1234,18 @@ long GetExprVal (ExprNode* Expr)
case EXPR_NOT:
return ~GetExprVal (Expr->Left);
case EXPR_LOBYTE:
case EXPR_BYTE0:
return GetExprVal (Expr->Left) & 0xFF;
case EXPR_HIBYTE:
case EXPR_BYTE1:
return (GetExprVal (Expr->Left) >> 8) & 0xFF;
case EXPR_BYTE2:
return (GetExprVal (Expr->Left) >> 16) & 0xFF;
case EXPR_BYTE3:
return (GetExprVal (Expr->Left) >> 24) & 0xFF;
case EXPR_SWAP:
Left = GetExprVal (Expr->Left);
return ((Left >> 8) & 0x00FF) | ((Left << 8) & 0xFF00);

View File

@@ -38,7 +38,8 @@
#include "../common/exprdefs.h"
/* common */
#include "exprdefs.h"
@@ -99,9 +100,6 @@ int IsByteRange (long Val);
int IsWordRange (long Val);
/* Return true if this is a word value */
void DumpExpr (ExprNode* Expr);
/* Dump an expression tree to stdout */
ExprNode* FinalizeExpr (ExprNode* Expr);
/* Resolve any symbols by cloning the symbol expression tree instead of the
* symbol reference, then try to simplify the expression as much as possible.

View File

@@ -37,9 +37,11 @@
#include <errno.h>
#include <ctype.h>
#include "../common/segdefs.h"
#include "../common/xmalloc.h"
/* common */
#include "segdefs.h"
#include "xmalloc.h"
/* cc65 */
#include "error.h"
#include "fragment.h"
#include "global.h"
@@ -160,7 +162,7 @@ static Segment* NewSegment (const char* Name, unsigned SegType)
return S;
}
void UseCodeSeg (void)
/* Use the code segment */
@@ -629,10 +631,6 @@ static Fragment* NewFragment (unsigned char Type, unsigned short Len)
if (LineCur) {
if (LineCur->FragList == 0) {
LineCur->FragList = F;
/* First fragment - set the PC
LineCur->PC = GetPC ();
LineCur->Reloc = RelocMode;
*/
} else {
LineCur->FragLast->LineList = F;
}

View File

@@ -1131,6 +1131,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoFarAddr },
{ ccNone, DoFeature },
{ ccNone, DoFileOpt },
{ ccNone, DoUnexpected }, /* .FORCEWORD */
{ ccNone, DoGlobal },
{ ccNone, DoGlobalZP },
{ ccNone, DoI16 },

View File

@@ -122,7 +122,7 @@ struct DotKeyword {
} DotKeywords [] = {
{ "A16", TOK_A16 },
{ "A8", TOK_A8 },
{ "ADDR", TOK_ADDR },
{ "ADDR", TOK_ADDR },
{ "ALIGN", TOK_ALIGN },
{ "AND", TOK_BAND },
{ "ASCIIZ", TOK_ASCIIZ },
@@ -164,6 +164,7 @@ struct DotKeyword {
{ "FEATURE", TOK_FEATURE },
{ "FILEOPT", TOK_FILEOPT },
{ "FOPT", TOK_FILEOPT },
{ "FORCEWORD", TOK_FORCEWORD },
{ "GLOBAL", TOK_GLOBAL },
{ "GLOBALZP", TOK_GLOBALZP },
{ "I16", TOK_I16 },
@@ -500,7 +501,7 @@ static void NextChar (void)
/* End of file. Add an empty line to the listing. This is a
* small hack needed to keep the PC output in sync.
*/
NewListingLine ("", IFile->Pos.Name, ICount);
NewListingLine ("", IFile->Pos.Name, ICount);
C = EOF;
return;
}
@@ -731,7 +732,7 @@ Again:
IVal = 0;
while (IsDigit (C)) {
if (IVal > (0xFFFFFFFF / 10)) {
Error (ERR_NUM_OVERFLOW);
Error (ERR_NUM_OVERFLOW);
IVal = 0;
}
IVal = (IVal * 10) + DigitVal (C);

View File

@@ -143,6 +143,7 @@ enum Token {
TOK_FARADDR,
TOK_FEATURE,
TOK_FILEOPT,
TOK_FORCEWORD,
TOK_GLOBAL,
TOK_GLOBALZP,
TOK_I16,