2000-07-29 15:53:33 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* 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 */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-11 13:58:00 +00:00
|
|
|
static void InternalDumpExpr (const ExprNode* Expr, const ExprNode* (*ResolveSym) (const struct SymEntry*))
|
2000-07-29 15:53:33 +00:00
|
|
|
/* Dump an expression in RPN to stdout */
|
|
|
|
{
|
|
|
|
if (Expr == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2003-11-11 13:58:00 +00:00
|
|
|
InternalDumpExpr (Expr->Left, ResolveSym);
|
|
|
|
InternalDumpExpr (Expr->Right, ResolveSym);
|
2000-07-29 15:53:33 +00:00
|
|
|
|
|
|
|
switch (Expr->Op) {
|
|
|
|
|
|
|
|
case EXPR_LITERAL:
|
|
|
|
case EXPR_ULABEL:
|
|
|
|
printf (" $%04lX", Expr->V.Val & 0xFFFF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXPR_SYMBOL:
|
2003-11-11 13:58:00 +00:00
|
|
|
if (ResolveSym && (Expr = ResolveSym (Expr->V.Sym)) != 0) {
|
|
|
|
printf (" SYM (");
|
|
|
|
InternalDumpExpr (Expr, ResolveSym);
|
|
|
|
printf (") ");
|
|
|
|
} else {
|
|
|
|
printf ("SYM ");
|
|
|
|
}
|
2000-07-29 15:53:33 +00:00
|
|
|
break;
|
|
|
|
|
2003-11-10 13:51:49 +00:00
|
|
|
case EXPR_SECTION:
|
|
|
|
printf (" SEC");
|
|
|
|
break;
|
|
|
|
|
2000-07-29 15:53:33 +00:00
|
|
|
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;
|
|
|
|
|
2003-11-10 13:58:30 +00:00
|
|
|
case EXPR_LE:
|
|
|
|
printf (" <=");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXPR_GE:
|
|
|
|
printf (" >=");
|
|
|
|
break;
|
|
|
|
|
2003-11-10 22:18:49 +00:00
|
|
|
case EXPR_BOOLAND:
|
2003-11-10 13:58:30 +00:00
|
|
|
printf (" BOOL_AND");
|
|
|
|
break;
|
|
|
|
|
2003-11-10 22:18:49 +00:00
|
|
|
case EXPR_BOOLOR:
|
2003-11-10 13:58:30 +00:00
|
|
|
printf (" BOOL_OR");
|
|
|
|
break;
|
|
|
|
|
2003-11-10 22:18:49 +00:00
|
|
|
case EXPR_BOOLXOR:
|
2003-11-10 13:58:30 +00:00
|
|
|
printf (" BOOL_XOR");
|
|
|
|
break;
|
|
|
|
|
2000-07-29 15:53:33 +00:00
|
|
|
case EXPR_UNARY_MINUS:
|
|
|
|
printf (" NEG");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXPR_NOT:
|
|
|
|
printf (" ~");
|
|
|
|
break;
|
|
|
|
|
2003-11-10 13:58:30 +00:00
|
|
|
case EXPR_SWAP:
|
|
|
|
printf (" SWAP");
|
|
|
|
break;
|
|
|
|
|
2003-11-10 22:18:49 +00:00
|
|
|
case EXPR_BOOLNOT:
|
2003-11-10 13:58:30 +00:00
|
|
|
printf (" BOOL_NOT");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXPR_FORCEWORD:
|
|
|
|
printf (" FORCE_WORD");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXPR_FORCEFAR:
|
|
|
|
printf (" FORCE_FAR");
|
|
|
|
break;
|
|
|
|
|
2000-07-29 15:53:33 +00:00
|
|
|
case EXPR_BYTE0:
|
|
|
|
printf (" BYTE0");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXPR_BYTE1:
|
|
|
|
printf (" BYTE1");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXPR_BYTE2:
|
|
|
|
printf (" BYTE2");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXPR_BYTE3:
|
|
|
|
printf (" BYTE3");
|
|
|
|
break;
|
|
|
|
|
2003-11-10 13:58:30 +00:00
|
|
|
case EXPR_WORD0:
|
|
|
|
printf (" WORD0");
|
2000-07-29 15:53:33 +00:00
|
|
|
break;
|
|
|
|
|
2003-11-10 13:58:30 +00:00
|
|
|
case EXPR_WORD1:
|
|
|
|
printf (" WORD1");
|
2000-07-29 15:53:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
AbEnd ("Unknown Op type: %u", Expr->Op);
|
2003-11-10 22:18:49 +00:00
|
|
|
|
2000-07-29 15:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-11 13:58:00 +00:00
|
|
|
void DumpExpr (const ExprNode* Expr, const ExprNode* (*ResolveSym) (const struct SymEntry*))
|
2000-07-29 15:53:33 +00:00
|
|
|
/* Dump an expression tree to stdout */
|
|
|
|
{
|
2003-11-11 13:58:00 +00:00
|
|
|
InternalDumpExpr (Expr, ResolveSym);
|
2000-07-29 15:53:33 +00:00
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|