if (Tok != TOK_LPAREN) {
Error (ERR_LPAREN_EXPECTED);
SkipUntilSep ();
- return LiteralExpr (0);
+ return GenLiteralExpr (0);
}
NextTok ();
ConsumeRParen ();
/* Return an expression node with the boolean code */
- return LiteralExpr (Result);
+ return GenLiteralExpr (Result);
}
switch (Tok) {
case TOK_INTCON:
- N = LiteralExpr (IVal);
+ N = GenLiteralExpr (IVal);
NextTok ();
break;
case TOK_CHARCON:
- N = LiteralExpr (TgtTranslateChar (IVal));
+ N = GenLiteralExpr (TgtTranslateChar (IVal));
NextTok ();
break;
NextTok ();
if (Tok != TOK_IDENT) {
Error (ERR_IDENT_EXPECTED);
- N = LiteralExpr (0); /* Dummy */
+ N = GenLiteralExpr (0); /* Dummy */
} else {
S = SymRef (SVal, SCOPE_GLOBAL);
if (SymIsConst (S)) {
/* Use the literal value instead */
- N = LiteralExpr (GetSymVal (S));
+ N = GenLiteralExpr (GetSymVal (S));
} else {
/* Create symbol node */
N = NewExprNode ();
S = SymRef (SVal, SCOPE_LOCAL);
if (SymIsConst (S)) {
/* Use the literal value instead */
- N = LiteralExpr (GetSymVal (S));
+ N = GenLiteralExpr (GetSymVal (S));
} else {
/* Create symbol node */
N = NewExprNode ();
case TOK_STAR:
case TOK_PC:
NextTok ();
- N = CurrentPC ();
+ N = GenCurrentPC ();
break;
case TOK_LT:
break;
case TOK_CPU:
- N = LiteralExpr (GetCPU());
+ N = GenLiteralExpr (GetCPU());
NextTok ();
break;
break;
case TOK_TIME:
- N = LiteralExpr (time (0));
+ N = GenLiteralExpr (time (0));
NextTok ();
break;
default:
if (LooseCharTerm && Tok == TOK_STRCON && strlen(SVal) == 1) {
/* A character constant */
- N = LiteralExpr (TgtTranslateChar (SVal[0]));
+ N = GenLiteralExpr (TgtTranslateChar (SVal[0]));
} else {
- N = LiteralExpr (0); /* Dummy */
+ N = GenLiteralExpr (0); /* Dummy */
Error (ERR_SYNTAX);
}
NextTok ();
-ExprNode* LiteralExpr (long Val)
+ExprNode* GenLiteralExpr (long Val)
/* Return an expression tree that encodes the given literal value */
{
ExprNode* Expr = NewExprNode ();
-ExprNode* CurrentPC (void)
+ExprNode* GenCurrentPC (void)
/* Return the current program counter as expression */
{
ExprNode* Left;
Root = NewExprNode ();
Root->Left = Left;
- Root->Right = LiteralExpr (GetPC ());
+ Root->Right = GenLiteralExpr (GetPC ());
Root->Op = EXPR_PLUS;
} else {
- /* Absolute mode, just return PC value */
- Root = LiteralExpr (GetPC ());
+ /* Absolute mode, just return PC value */
+ Root = GenLiteralExpr (GetPC ());
}
return Root;
-ExprNode* SwapExpr (ExprNode* Expr)
+ExprNode* GenSwapExpr (ExprNode* Expr)
/* Return an extended expression with lo and hi bytes swapped */
{
ExprNode* N = NewExprNode ();
-ExprNode* BranchExpr (unsigned Offs)
+ExprNode* GenBranchExpr (unsigned Offs)
/* Return an expression that encodes the difference between current PC plus
* offset and the target expression (that is, Expression() - (*+Offs) ).
*/
N = NewExprNode ();
N->Left = Left;
- N->Right = LiteralExpr (GetPC () + Offs);
+ N->Right = GenLiteralExpr (GetPC () + Offs);
N->Op = EXPR_PLUS;
} else {
- N = LiteralExpr (GetPC () + Offs);
+ N = GenLiteralExpr (GetPC () + Offs);
}
/* Create the root node */
-ExprNode* ULabelExpr (unsigned Num)
+ExprNode* GenULabelExpr (unsigned Num)
/* Return an expression for an unnamed label with the given index */
{
/* Get an expression node */
-ExprNode* ForceByteExpr (ExprNode* Expr)
+ExprNode* GenByteExpr (ExprNode* Expr)
/* Force the given expression into a byte and return the result */
{
/* Use the low byte operator to force the expression into byte size */
-ExprNode* ForceWordExpr (ExprNode* Expr)
+ExprNode* GenWordExpr (ExprNode* Expr)
/* Force the given expression into a word and return the result. */
{
/* AND the expression by $FFFF to force it into word size */
ExprNode* Root = NewExprNode ();
Root->Left = Expr;
Root->Op = EXPR_AND;
- Root->Right = LiteralExpr (0xFFFF);
+ Root->Right = GenLiteralExpr (0xFFFF);
/* Return the result */
return Root;
-ExprNode* CompareExpr (ExprNode* Expr, long Val)
-/* Generate an expression that compares Expr and Val for equality */
+ExprNode* GenNE (ExprNode* Expr, long Val)
+/* Generate an expression that compares Expr and Val for inequality */
{
/* Generate a compare node */
ExprNode* Root = NewExprNode ();
Root->Left = Expr;
- Root->Op = EXPR_EQ;
- Root->Right = LiteralExpr (Val);
+ Root->Op = EXPR_NE;
+ Root->Right = GenLiteralExpr (Val);
/* Return the result */
return Root;
DumpExpr (Expr);
}
PError (GetSymPos (Sym), ERR_CIRCULAR_REFERENCE);
- return LiteralExpr (0); /* Return a dummy value */
+ return GenLiteralExpr (0); /* Return a dummy value */
}
SymMarkUser (Sym);
Expr = RemoveSyms (GetSymExpr (Sym), 1);
return Expr;
} else if (SymIsConst (Expr->V.Sym)) {
/* The symbol is a constant */
- return LiteralExpr (GetSymVal (Expr->V.Sym));
+ return GenLiteralExpr (GetSymVal (Expr->V.Sym));
}
break;
Expr = ConstExtract (Expr, &Val, 1);
if (Expr == 0) {
/* Reduced to a literal value */
- Expr = LiteralExpr (Val);
+ Expr = GenLiteralExpr (Val);
} else if (Val) {
/* Extracted a value */
N = NewExprNode ();
N->Op = EXPR_PLUS;
N->Left = Expr;
- N->Right = LiteralExpr (Val);
+ N->Right = GenLiteralExpr (Val);
Expr = N;
}
return Expr;
void FreeExpr (ExprNode* Root);
/* Free the expression tree, Root is pointing to. */
-ExprNode* LiteralExpr (long Val);
+ExprNode* GenLiteralExpr (long Val);
/* Return an expression tree that encodes the given literal value */
-ExprNode* CurrentPC (void);
+ExprNode* GenCurrentPC (void);
/* Return the current program counter as expression */
-ExprNode* SwapExpr (ExprNode* Expr);
+ExprNode* GenSwapExpr (ExprNode* Expr);
/* Return an extended expression with lo and hi bytes swapped */
-ExprNode* BranchExpr (unsigned Offs);
+ExprNode* GenBranchExpr (unsigned Offs);
/* Return an expression that encodes the difference between current PC plus
* offset and the target expression (that is, Expression() - (*+Offs) ).
*/
-ExprNode* ULabelExpr (unsigned Num);
+ExprNode* GenULabelExpr (unsigned Num);
/* Return an expression for an unnamed label with the given index */
-ExprNode* ForceByteExpr (ExprNode* Expr);
+ExprNode* GenByteExpr (ExprNode* Expr);
/* Force the given expression into a byte and return the result */
-ExprNode* ForceWordExpr (ExprNode* Expr);
+ExprNode* GenWordExpr (ExprNode* Expr);
/* Force the given expression into a word and return the result. */
-ExprNode* CompareExpr (ExprNode* Expr, long Val);
-/* Generate an expression that compares Expr and Val for equality */
+ExprNode* GenNE (ExprNode* Expr, long Val);
+/* Generate an expression that compares Expr and Val for inequality */
int IsConstExpr (ExprNode* Root);
/* Return true if the given expression is a constant expression, that is, one
* mode, force this address into 16 bit range to allow
* addressing inside a 64K segment.
*/
- Emit2 (A->Opcode, ForceWordExpr (A->Expr));
+ Emit2 (A->Opcode, GenWordExpr (A->Expr));
} else {
Emit2 (A->Opcode, A->Expr);
}
static void PutPCRel8 (const InsDesc* Ins)
/* Handle branches with a 8 bit distance */
{
- EmitPCRel (Ins->BaseCode, BranchExpr (2), 1);
+ EmitPCRel (Ins->BaseCode, GenBranchExpr (2), 1);
}
static void PutPCRel16 (const InsDesc* Ins)
/* Handle branches with an 16 bit distance and PER */
{
- EmitPCRel (Ins->BaseCode, BranchExpr (3), 2);
+ EmitPCRel (Ins->BaseCode, GenBranchExpr (3), 2);
}
* a page cross. Be sure to use a copy of the expression otherwise
* things will go weird later.
*/
- ExprNode* E = CompareExpr (ForceByteExpr (CloneExpr (A.Expr)), 0xFF);
+ ExprNode* E = GenNE (GenByteExpr (CloneExpr (A.Expr)), 0xFF);
/* Generate the message */
unsigned Msg = GetStringId ("\"jmp (abs)\" across page border");
}
/* Define the symbol */
- SymDef (SymName, LiteralExpr (Val), 0, 0);
+ SymDef (SymName, GenLiteralExpr (Val), 0, 0);
}
Done = 1;
} else {
/* Define a label */
- SymDef (Ident, CurrentPC(), IsZPSeg(), 1);
+ SymDef (Ident, GenCurrentPC(), IsZPSeg(), 1);
/* Skip the colon. If NoColonLabels is enabled, allow labels
* without a colon if there is no whitespace before the
* identifier.
#include <ctype.h>
#include <errno.h>
-/* common */
+/* common */
#include "assertdefs.h"
#include "bitops.h"
#include "cddefs.h"
{
while (1) {
if (GetCPU() == CPU_65816) {
- EmitWord (ForceWordExpr (Expression ()));
+ EmitWord (GenWordExpr (Expression ()));
} else {
/* Do a range check */
EmitWord (Expression ());
/* Output double bytes */
{
while (1) {
- EmitWord (SwapExpr (Expression ()));
+ EmitWord (GenSwapExpr (Expression ()));
if (Tok != TOK_COMMA) {
break;
} else {
{
if (Tok == TOK_IDENT) {
/* The new scope has a name */
- SymDef (SVal, CurrentPC (), IsZPSeg (), 1);
+ SymDef (SVal, GenCurrentPC (), IsZPSeg (), 1);
NextTok ();
}
SymEnterLevel ();
/* */
/* */
/* */
-/* (C) 2000 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 2000-2003 Ullrich von Bassewitz */
+/* Römerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* Label does not exist */
Error (ERR_UNDEFINED_LABEL);
/* We must return something valid */
- return CurrentPC();
+ return GenCurrentPC();
} else {
/* Return a copy of the label value */
return CloneExpr (L->Val);
}
/* Return an unnamed label expression */
- return ULabelExpr (LabelNum);
+ return GenULabelExpr (LabelNum);
}
}
/* Create a new label if needed, or use an existing one */
if (ULabLastDef == 0 || ULabLastDef->Next == 0) {
/* The last label is also the last defined label, we need a new one */
- ULabLastDef = NewULabel (CurrentPC ());
+ ULabLastDef = NewULabel (GenCurrentPC ());
} else {
/* We do already have the label, but it's undefined until now */
ULabLastDef = ULabLastDef->Next;
- ULabLastDef->Val = CurrentPC ();
+ ULabLastDef->Val = GenCurrentPC ();
ULabLastDef->Pos = CurPos;
}
++ULabDefCount;
/* If the label is open (not defined), return some valid value */
if (L->Val == 0) {
- return LiteralExpr (0);
+ return GenLiteralExpr (0);
} else {
return CloneExpr (L->Val);
}