-#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"
-/*****************************************************************************/
-/* 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 */
/*****************************************************************************/
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:
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 {
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);
-#include "../common/exprdefs.h"
+/* common */
+#include "exprdefs.h"
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.
#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"
return S;
}
-
+
void UseCodeSeg (void)
/* Use the code segment */
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;
}
{ ccNone, DoFarAddr },
{ ccNone, DoFeature },
{ ccNone, DoFileOpt },
+ { ccNone, DoUnexpected }, /* .FORCEWORD */
{ ccNone, DoGlobal },
{ ccNone, DoGlobalZP },
{ ccNone, DoI16 },
} DotKeywords [] = {
{ "A16", TOK_A16 },
{ "A8", TOK_A8 },
- { "ADDR", TOK_ADDR },
+ { "ADDR", TOK_ADDR },
{ "ALIGN", TOK_ALIGN },
{ "AND", TOK_BAND },
{ "ASCIIZ", TOK_ASCIIZ },
{ "FEATURE", TOK_FEATURE },
{ "FILEOPT", TOK_FILEOPT },
{ "FOPT", TOK_FILEOPT },
+ { "FORCEWORD", TOK_FORCEWORD },
{ "GLOBAL", TOK_GLOBAL },
{ "GLOBALZP", TOK_GLOBALZP },
{ "I16", TOK_I16 },
/* 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;
}
IVal = 0;
while (IsDigit (C)) {
if (IVal > (0xFFFFFFFF / 10)) {
- Error (ERR_NUM_OVERFLOW);
+ Error (ERR_NUM_OVERFLOW);
IVal = 0;
}
IVal = (IVal * 10) + DigitVal (C);
TOK_FARADDR,
TOK_FEATURE,
TOK_FILEOPT,
+ TOK_FORCEWORD,
TOK_GLOBAL,
TOK_GLOBALZP,
TOK_I16,
-#include <ctype.h>
+#include <string.h>
+#include <ctype.h>
-/* common */
+/* common */
#include "xmalloc.h"
/* cc65 */
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
/* 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;
}
--- /dev/null
+/*****************************************************************************/
+/* */
+/* 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");
+}
+
+
+
/* */
/* */
/* */
-/* (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 */
/* 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)
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;
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+void DumpExpr (const ExprNode* Expr);
+/* Dump an expression tree to stdout */
+
+
+
/* End of exprdefs.h */
#endif
OBJS = abend.o \
bitops.o \
cmdline.o \
+ exprdefs.o \
fname.o \
hashstr.o \
xmalloc.o \
OBJS = abend.obj \
bitops.obj \
cmdline.obj \
+ exprdefs.obj \
fname.obj \
hashstr.obj \
wildargv.obj \
/* 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
/* common */
#include "exprdefs.h"
#include "xmalloc.h"
-
+
/* ld65 */
#include "global.h"
#include "error.h"
-/*****************************************************************************/
-/* 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 */
/*****************************************************************************/
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);
/* */
/* */
/* */
-/* (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 */
#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"
* 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);
/* 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;
}
/* 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) {
default:
Internal ("O65WriteExpr: Invalid expression size: %u", Size);
- RelocType = 0; /* Avoid gcc warnings */
+ RelocType = 0; /* Avoid gcc warnings */
}
}