1
0
mirror of https://github.com/cc65/cc65.git synced 2025-03-18 16:30:38 +00:00

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,

View File

@ -33,9 +33,10 @@
#include <ctype.h>
#include <string.h>
#include <ctype.h>
/* common */
/* common */
#include "xmalloc.h"
/* cc65 */
@ -45,7 +46,7 @@
/*****************************************************************************/
/* Data */
/* Data */
/*****************************************************************************/
@ -89,7 +90,7 @@ int ValidSegName (const char* Name)
/* Return true if the given segment name is valid, return false otherwise */
{
/* Must start with '_' or a letter */
if (*Name != '_' && !isalpha(*Name)) {
if ((*Name != '_' && !isalpha(*Name)) || strlen(Name) > 80) {
return 0;
}

189
src/common/exprdefs.c Normal file
View File

@ -0,0 +1,189 @@
/*****************************************************************************/
/* */
/* exprdefs.c */
/* */
/* Expression tree definitions */
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
#include <stdio.h>
#include "abend.h"
#include "exprdefs.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
static void InternalDumpExpr (const ExprNode* Expr)
/* Dump an expression in RPN to stdout */
{
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 (" 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 (" MOD");
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_BYTE0:
printf (" BYTE0");
break;
case EXPR_BYTE1:
printf (" BYTE1");
break;
case EXPR_BYTE2:
printf (" BYTE2");
break;
case EXPR_BYTE3:
printf (" BYTE3");
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:
AbEnd ("Unknown Op type: %u", Expr->Op);
}
}
void DumpExpr (const ExprNode* Expr)
/* Dump an expression tree to stdout */
{
InternalDumpExpr (Expr);
printf ("\n");
}

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -84,10 +84,17 @@
/* Unary operations, right hand side is empty */
#define EXPR_UNARY_MINUS (EXPR_UNARYNODE | 0x01)
#define EXPR_NOT (EXPR_UNARYNODE | 0x02)
#define EXPR_LOBYTE (EXPR_UNARYNODE | 0x03)
#define EXPR_HIBYTE (EXPR_UNARYNODE | 0x04)
#define EXPR_SWAP (EXPR_UNARYNODE | 0x05)
#define EXPR_BNOT (EXPR_UNARYNODE | 0x06)
#define EXPR_SWAP (EXPR_UNARYNODE | 0x03)
#define EXPR_BNOT (EXPR_UNARYNODE | 0x04)
#define EXPR_FORCEWORD (EXPR_UNARYNODE | 0x05)
#define EXPR_FORCEFAR (EXPR_UNARYNODE | 0x06)
#define EXPR_BYTE0 (EXPR_UNARYNODE | 0x08)
#define EXPR_BYTE1 (EXPR_UNARYNODE | 0x09)
#define EXPR_BYTE2 (EXPR_UNARYNODE | 0x0A)
#define EXPR_BYTE3 (EXPR_UNARYNODE | 0x0B)
#define EXPR_WORD0 (EXPR_UNARYNODE | 0x0C)
#define EXPR_WORD1 (EXPR_UNARYNODE | 0x0D)
@ -101,7 +108,7 @@ struct ExprNode_ {
union {
long Val; /* If this is a value */
struct SymEntry_* Sym; /* If this is a symbol */
unsigned SegNum; /* If this is a segment */
unsigned SegNum; /* If this is a segment */
unsigned ImpNum; /* If this is an import */
struct Memory_* MemArea; /* If this is a memory area */
} V;
@ -116,6 +123,17 @@ struct ExprNode_ {
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void DumpExpr (const ExprNode* Expr);
/* Dump an expression tree to stdout */
/* End of exprdefs.h */
#endif

View File

@ -12,6 +12,7 @@ LIB = common.a
OBJS = abend.o \
bitops.o \
cmdline.o \
exprdefs.o \
fname.o \
hashstr.o \
xmalloc.o \

View File

@ -68,6 +68,7 @@ CCCFG = -bt=$(TARGET) -d1 -onatx -zp4 -5 -zq -w2
OBJS = abend.obj \
bitops.obj \
cmdline.obj \
exprdefs.obj \
fname.obj \
hashstr.obj \
wildargv.obj \

View File

@ -46,7 +46,7 @@
/* Defines for magic and version */
#define OBJ_MAGIC 0x616E7A55
#define OBJ_VERSION 0x0005
#define OBJ_VERSION 0x0006
/* Size of an object file header */
#define OBJ_HDR_SIZE 56

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