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

@@ -36,7 +36,7 @@
/* common */
#include "exprdefs.h"
#include "xmalloc.h"
/* ld65 */
#include "global.h"
#include "error.h"
@@ -77,144 +77,6 @@ static void FreeExprNode (ExprNode* E)
/*****************************************************************************/
/* Dump an expression tree on stdout for debugging */
/*****************************************************************************/
static void InternalDumpExpr (const ExprNode* Expr)
/* Dump an expression in UPN */
{
if (Expr == 0) {
return;
}
InternalDumpExpr (Expr->Left);
InternalDumpExpr (Expr->Right);
switch (Expr->Op) {
case EXPR_LITERAL:
printf (" $%04lX", Expr->V.Val & 0xFFFF);
break;
case EXPR_SYMBOL:
printf (" 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 (const ExprNode* Expr)
/* Dump an expression tree to stdout */
{
InternalDumpExpr (Expr);
printf ("\n");
}
/*****************************************************************************/
/* Code */
/*****************************************************************************/
@@ -451,12 +313,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

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1999 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1999-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -38,9 +38,11 @@
#include <errno.h>
#include <time.h>
#include "../common/version.h"
#include "../common/xmalloc.h"
/* common */
#include "version.h"
#include "xmalloc.h"
/* ld65 */
#include "error.h"
#include "exports.h"
#include "expr.h"
@@ -448,7 +450,7 @@ static unsigned O65WriteExpr (ExprNode* E, int Signed, unsigned Size,
* Calculate the number of bytes between this entry and the last one, and
* setup all necessary intermediate bytes in the relocation table.
*/
Offs += D->SegSize; /* Calulate full offset */
Offs += D->SegSize; /* Calulate full offset */
Diff = ((long) Offs) - D->LastOffs;
while (Diff > 0xFE) {
O65RelocPutByte (D->CurReloc, 0xFF);
@@ -461,7 +463,9 @@ static unsigned O65WriteExpr (ExprNode* E, int Signed, unsigned Size,
/* Determine the expression to relocate */
Expr = E;
if (E->Op == EXPR_LOBYTE || E->Op == EXPR_HIBYTE) {
if (E->Op == EXPR_BYTE0 || E->Op == EXPR_BYTE1 ||
E->Op == EXPR_BYTE2 || E->Op == EXPR_BYTE3 ||
E->Op == EXPR_WORD0 || E->Op == EXPR_WORD1) {
/* Use the real expression */
Expr = E->Left;
}
@@ -491,19 +495,22 @@ static unsigned O65WriteExpr (ExprNode* E, int Signed, unsigned Size,
/* Write out the offset that goes into the segment. */
BinVal = ED.Val;
if (E->Op == EXPR_LOBYTE) {
BinVal &= 0x00FF;
} else if (E->Op == EXPR_HIBYTE) {
BinVal = (BinVal >> 8) & 0x00FF;
switch (E->Op) {
case EXPR_BYTE0: BinVal &= 0xFF; break;
case EXPR_BYTE1: BinVal = (BinVal >> 8) & 0xFF; break;
case EXPR_BYTE2: BinVal = (BinVal >> 16) & 0xFF; break;
case EXPR_BYTE3: BinVal = (BinVal >> 24) & 0xFF; break;
case EXPR_WORD0: BinVal &= 0xFFFF; break;
case EXPR_WORD1: BinVal = (BinVal >> 16) & 0xFFFF; break;
}
WriteVal (D->F, BinVal, Size);
/* Determine the actual type of relocation entry needed from the
* information gathered about the expression.
*/
if (E->Op == EXPR_LOBYTE) {
if (E->Op == EXPR_BYTE0) {
RelocType = O65RELOC_LOW;
} else if (E->Op == EXPR_HIBYTE) {
} else if (E->Op == EXPR_BYTE1) {
RelocType = O65RELOC_HIGH;
} else {
switch (Size) {
@@ -526,7 +533,7 @@ static unsigned O65WriteExpr (ExprNode* E, int Signed, unsigned Size,
default:
Internal ("O65WriteExpr: Invalid expression size: %u", Size);
RelocType = 0; /* Avoid gcc warnings */
RelocType = 0; /* Avoid gcc warnings */
}
}