From cf885e7a705dd8a3c8f5f2fbadd312f2f2d79a2f Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Sun, 22 Nov 2009 19:11:09 +0100 Subject: [PATCH] move operator-to-string conversion to unit.c So it can be used elsewhere (e.g. by an object file dumper). --- unit.c | 34 ++++++++++++++++++++++++++++++++++ unit.h | 3 ++- xlnk.c | 38 ++------------------------------------ 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/unit.c b/unit.c index 2776369..6e44442 100644 --- a/unit.c +++ b/unit.c @@ -430,3 +430,37 @@ void xasm_unit_finalize(xasm_unit *u) finalize_segment(&u->dataseg); finalize_segment(&u->codeseg); } + +/** + * Gets string representation of an operator (OP_*, see objdef.h). + * @param op Operator + * @return String representation of operator + */ +const char *xasm_operator_to_string(int op) +{ + switch (op) { + case XASM_OP_PLUS: return "+"; + case XASM_OP_MINUS: return "-"; + case XASM_OP_MUL: return "*"; + case XASM_OP_DIV: return "/"; + case XASM_OP_MOD: return "%"; + case XASM_OP_SHL: return "<<"; + case XASM_OP_SHR: return ">>"; + case XASM_OP_AND: return "&"; + case XASM_OP_OR: return "|"; + case XASM_OP_XOR: return "^"; + case XASM_OP_EQ: return "=="; + case XASM_OP_NE: return "!="; + case XASM_OP_LT: return "<"; + case XASM_OP_GT: return ">"; + case XASM_OP_LE: return "<="; + case XASM_OP_GE: return ">="; + case XASM_OP_NOT: return "!"; + case XASM_OP_NEG: return "~"; + case XASM_OP_LO: return "<"; + case XASM_OP_HI: return ">"; + case XASM_OP_UMINUS: return "-"; + case XASM_OP_BANK: return "^"; + } + return ""; +} diff --git a/unit.h b/unit.h index 331f29a..60590e8 100644 --- a/unit.h +++ b/unit.h @@ -63,7 +63,7 @@ typedef struct tag_xasm_constant xasm_constant; */ struct tag_xasm_external { - unsigned char unit; + unsigned char unit; /* Unit to import from (0=any unit) (currently not used) */ char *name; struct tag_xasm_unit *from; /* Unit exported from */ }; @@ -149,5 +149,6 @@ typedef struct tag_xasm_unit xasm_unit; int xasm_unit_read(char *, xasm_unit *); void xasm_unit_finalize(xasm_unit *); +const char *xasm_operator_to_string(int op); #endif /* !UNIT_H */ diff --git a/xlnk.c b/xlnk.c index b719c76..5059741 100644 --- a/xlnk.c +++ b/xlnk.c @@ -703,40 +703,6 @@ static void finalize_constant(xasm_constant *c) } /** - * Gets string representation of an operator (OP_*, see objdef.h). - * @param op Operator - * @return String representation of operator - */ -static const char *operator_to_string(int op) -{ - switch (op) { - case XASM_OP_PLUS: return "+"; - case XASM_OP_MINUS: return "-"; - case XASM_OP_MUL: return "*"; - case XASM_OP_DIV: return "/"; - case XASM_OP_MOD: return "%"; - case XASM_OP_SHL: return "<<"; - case XASM_OP_SHR: return ">>"; - case XASM_OP_AND: return "&"; - case XASM_OP_OR: return "|"; - case XASM_OP_XOR: return "^"; - case XASM_OP_EQ: return "=="; - case XASM_OP_NE: return "!="; - case XASM_OP_LT: return "<"; - case XASM_OP_GT: return ">"; - case XASM_OP_LE: return "<="; - case XASM_OP_GE: return ">="; - case XASM_OP_NOT: return "!"; - case XASM_OP_NEG: return "~"; - case XASM_OP_LO: return "<"; - case XASM_OP_HI: return ">"; - case XASM_OP_UMINUS: return "-"; - case XASM_OP_BANK: return "^"; - } - return ""; -} - -/** * Evaluates an expression recursively. * The result will either be a integer or string literal, indicating successful * evaluation; or an invalid type indicating that a symbol could not be translated @@ -833,7 +799,7 @@ static void eval_recursive(xunit *u, xasm_expression *e, xasm_constant *result) } else { result->type = -1; - err("incompatible operands to `%s' in expression", operator_to_string(e->op_expr.operator) ); + err("incompatible operands to `%s' in expression", xasm_operator_to_string(e->op_expr.operator) ); } /* Discard the operands */ finalize_constant(&lhs_result); @@ -866,7 +832,7 @@ static void eval_recursive(xunit *u, xasm_expression *e, xasm_constant *result) } else { /* Error, invalid operand */ - err("incompatible operand to `%s' in expression", operator_to_string(e->op_expr.operator) ); + err("incompatible operand to `%s' in expression", xasm_operator_to_string(e->op_expr.operator) ); result->type = -1; } /* Discard the operand */ -- 2.11.4.GIT