/* common */
#include "check.h"
-#include "print.h"
+#include "debugflag.h"
#include "shift.h"
#include "xmalloc.h"
{
ED->Flags = ED_OK;
ED->AddrSize = ADDR_SIZE_DEFAULT;
- ED->Val = 0;
+ ED->Val = 0;
ED->SymCount = 0;
ED->SymLimit = 0;
ED->SymRef = 0;
static int ED_IsValid (const ExprDesc* D)
/* Return true if the expression is valid, that is, neither the ERROR nor the
- * TOO_COMPLEX flags are set.
- */
+** TOO_COMPLEX flags are set.
+*/
{
return ((D->Flags & (ED_ERROR | ED_TOO_COMPLEX)) == 0);
}
{
if (ED->AddrSize == ADDR_SIZE_DEFAULT) {
/* If ED is valid, ADDR_SIZE_DEFAULT gets always overridden, otherwise
- * it takes precedence over anything else.
- */
+ ** it takes precedence over anything else.
+ */
if (ED_IsValid (ED)) {
ED->AddrSize = Right->AddrSize;
}
} else if (Right->AddrSize == ADDR_SIZE_DEFAULT) {
/* If Right is valid, ADDR_SIZE_DEFAULT gets always overridden,
- * otherwise it takes precedence over anything else.
- */
+ ** otherwise it takes precedence over anything else.
+ */
if (!ED_IsValid (Right)) {
ED->AddrSize = Right->AddrSize;
}
} else {
/* Neither ED nor Right has a default address size, use the larger of
- * the two.
- */
+ ** the two.
+ */
if (Right->AddrSize > ED->AddrSize) {
ED->AddrSize = Right->AddrSize;
}
static ED_SymRef* ED_FindSymRef (ExprDesc* ED, SymEntry* Sym)
/* Find a symbol reference and return it. Return NULL if the reference does
- * not exist.
- */
+** not exist.
+*/
{
unsigned I;
ED_SymRef* SymRef;
static ED_SecRef* ED_FindSecRef (ExprDesc* ED, unsigned Sec)
/* Find a section reference and return it. Return NULL if the reference does
- * not exist.
- */
+** not exist.
+*/
{
unsigned I;
ED_SecRef* SecRef;
static ED_SymRef* ED_AllocSymRef (ExprDesc* ED, SymEntry* Sym)
/* Allocate a new symbol reference and return it. The count of the new
- * reference will be set to zero, and the reference itself to Sym.
- */
+** reference will be set to zero, and the reference itself to Sym.
+*/
{
ED_SymRef* SymRef;
static ED_SecRef* ED_AllocSecRef (ExprDesc* ED, unsigned Sec)
/* Allocate a new section reference and return it. The count of the new
- * reference will be set to zero, and the reference itself to Sec.
- */
+** reference will be set to zero, and the reference itself to Sec.
+*/
{
ED_SecRef* SecRef;
static ED_SymRef* ED_GetSymRef (ExprDesc* ED, SymEntry* Sym)
/* Get a symbol reference and return it. If the symbol reference does not
- * exist, a new one is created and returned.
- */
+** exist, a new one is created and returned.
+*/
{
ED_SymRef* SymRef = ED_FindSymRef (ED, Sym);
if (SymRef == 0) {
static ED_SecRef* ED_GetSecRef (ExprDesc* ED, unsigned Sec)
/* Get a section reference and return it. If the section reference does not
- * exist, a new one is created and returned.
- */
+** exist, a new one is created and returned.
+*/
{
ED_SecRef* SecRef = ED_FindSecRef (ED, Sec);
if (SecRef == 0) {
static void ED_Move (ExprDesc* From, ExprDesc* To)
/* Move the data from one ExprDesc to another. Old data is freed, and From
- * is prepared to that ED_Done may be called safely.
- */
+** is prepared to that ED_Done may be called safely.
+*/
{
/* Delete old data */
ED_Done (To);
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
static void StudyBinaryExpr (ExprNode* Expr, ExprDesc* D)
/* Study a binary expression subtree. This is a helper function for StudyExpr
- * used for operations that succeed when both operands are known and constant.
- * It evaluates the two subtrees and checks if they are constant. If they
- * aren't constant, it will set the TOO_COMPLEX flag, and merge references.
- * Otherwise the first value is returned in D->Val, the second one in D->Right,
- * so the actual operation can be done by the caller.
- */
+** used for operations that succeed when both operands are known and constant.
+** It evaluates the two subtrees and checks if they are constant. If they
+** aren't constant, it will set the TOO_COMPLEX flag, and merge references.
+** Otherwise the first value is returned in D->Val, the second one in D->Right,
+** so the actual operation can be done by the caller.
+*/
{
ExprDesc Right;
SymEntry* Sym = Expr->V.Sym;
/* If the symbol is defined somewhere, it has an expression associated.
- * In this case, just study the expression associated with the symbol,
- * but mark the symbol so if we encounter it twice, we know that we have
- * a circular reference.
- */
+ ** In this case, just study the expression associated with the symbol,
+ ** but mark the symbol so if we encounter it twice, we know that we have
+ ** a circular reference.
+ */
if (SymHasExpr (Sym)) {
if (SymHasUserMark (Sym)) {
LIError (&Sym->DefLines,
- "Circular reference in definition of symbol `%m%p'",
+ "Circular reference in definition of symbol '%m%p'",
GetSymName (Sym));
ED_SetError (D);
} else {
SymUnmarkUser (Sym);
/* If requested and if the expression is valid, dump it */
- if (Verbosity > 0 && !ED_HasError (D)) {
+ if (Debug > 0 && !ED_HasError (D)) {
DumpExpr (Expr, SymResolve);
}
/* If the symbol has an explicit address size, use it. This may
- * lead to range errors later (maybe even in the linker stage), if
- * the user lied about the address size, but for now we trust him.
- */
+ ** lead to range errors later (maybe even in the linker stage), if
+ ** the user lied about the address size, but for now we trust him.
+ */
AddrSize = GetSymAddrSize (Sym);
if (AddrSize != ADDR_SIZE_DEFAULT) {
D->AddrSize = AddrSize;
} else if (SymIsImport (Sym)) {
/* The symbol is an import. Track the symbols used and update the
- * address size.
- */
+ ** address size.
+ */
ED_SymRef* SymRef = ED_GetSymRef (D, Sym);
++SymRef->Count;
ED_UpdateAddrSize (D, GetSymAddrSize (Sym));
SymTable* Parent;
/* The symbol is undefined. Track symbol usage but set the "too
- * complex" flag, since we cannot evaluate the final result.
- */
+ ** complex" flag, since we cannot evaluate the final result.
+ */
ED_SymRef* SymRef = ED_GetSymRef (D, Sym);
++SymRef->Count;
ED_Invalidate (D);
/* Since the symbol may be a forward, and we may need a statement
- * about the address size, check higher lexical levels for a symbol
- * with the same name and use its address size if we find such a
- * symbol which is defined.
- */
+ ** about the address size, check higher lexical levels for a symbol
+ ** with the same name and use its address size if we find such a
+ ** symbol which is defined.
+ */
AddrSize = GetSymAddrSize (Sym);
Parent = GetSymParentScope (Sym);
if (AddrSize == ADDR_SIZE_DEFAULT && Parent != 0) {
/* Study an unnamed label expression node */
{
/* If we can resolve the label, study the expression associated with it,
- * otherwise mark the expression as too complex to evaluate.
- */
+ ** otherwise mark the expression as too complex to evaluate.
+ */
if (ULabCanResolve ()) {
/* We can resolve the label */
StudyExprInternal (ULabResolve (Expr->V.IVal), D);
StudyExprInternal (Expr->Right, &Right);
/* We can handle the operation if at least one of both operands is const
- * and the other one is valid.
- */
+ ** and the other one is valid.
+ */
if (ED_IsConst (D) && ED_IsValid (&Right)) {
/* Multiplicate both, result goes into Right */
/* Study this expression node */
switch (Expr->Op) {
- case EXPR_LITERAL:
+ case EXPR_LITERAL:
StudyLiteral (Expr, D);
- break;
+ break;
- case EXPR_SYMBOL:
+ case EXPR_SYMBOL:
StudySymbol (Expr, D);
break;
- case EXPR_SECTION:
+ case EXPR_SECTION:
StudySection (Expr, D);
- break;
+ break;
- case EXPR_ULABEL:
+ case EXPR_ULABEL:
StudyULabel (Expr, D);
break;
- case EXPR_PLUS:
+ case EXPR_PLUS:
StudyPlus (Expr, D);
- break;
+ break;
- case EXPR_MINUS:
- StudyMinus (Expr, D);
- break;
+ case EXPR_MINUS:
+ StudyMinus (Expr, D);
+ break;
case EXPR_MUL:
StudyMul (Expr, D);
break;
default:
- Internal ("Unknown Op type: %u", Expr->Op);
- break;
+ Internal ("Unknown Op type: %u", Expr->Op);
+ break;
}
}
}
/* If we don't have an address size, assign one if the expression is a
- * constant.
- */
+ ** constant.
+ */
if (D->AddrSize == ADDR_SIZE_DEFAULT && ED_IsConst (D)) {
D->AddrSize = GetConstAddrSize (D->Val);
}
/* If the expression is valid, throw away the address size and recalculate
- * it using the data we have. This is more exact than the on-the-fly
- * calculation done when evaluating the tree, because symbols may have
- * been removed from the expression, and the final numeric value is now
- * known.
- */
+ ** it using the data we have. This is more exact than the on-the-fly
+ ** calculation done when evaluating the tree, because symbols may have
+ ** been removed from the expression, and the final numeric value is now
+ ** known.
+ */
if (ED_IsValid (D)) {
unsigned char AddrSize;
/* If there are symbols or sections, use the largest one. If the
- * expression resolves to a const, use the address size of the value.
- */
+ ** expression resolves to a const, use the address size of the value.
+ */
if (D->SymCount > 0 || D->SecCount > 0) {
D->AddrSize = ADDR_SIZE_DEFAULT;
printf ("%u sections:\n", D->SecCount);
#endif
}
-
-
-