Back to index

cell-binutils  2.17cvs20070401
expr.h
Go to the documentation of this file.
00001 /* expr.h -> header file for expr.c
00002    Copyright 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
00003    2002, 2003 Free Software Foundation, Inc.
00004 
00005    This file is part of GAS, the GNU Assembler.
00006 
00007    GAS is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    GAS is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with GAS; see the file COPYING.  If not, write to the Free
00019    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00020    02110-1301, USA.  */
00021 
00022 /*
00023  * By popular demand, we define a struct to represent an expression.
00024  * This will no doubt mutate as expressions become baroque.
00025  *
00026  * Currently, we support expressions like "foo OP bar + 42".  In other
00027  * words we permit a (possibly undefined) symbol, a (possibly
00028  * undefined) symbol and the operation used to combine the symbols,
00029  * and an (absolute) augend.  RMS says this is so we can have 1-pass
00030  * assembly for any compiler emissions, and a 'case' statement might
00031  * emit 'undefined1 - undefined2'.
00032  *
00033  * The type of an expression used to be stored as a segment.  That got
00034  * confusing because it overloaded the concept of a segment.  I added
00035  * an operator field, instead.
00036  */
00037 
00038 /* This is the type of an expression.  The operator types are also
00039    used while parsing an expression.
00040 
00041    NOTE: This enumeration must match the op_rank array in expr.c.  */
00042 
00043 typedef enum {
00044   /* An illegal expression.  */
00045   O_illegal,
00046   /* A nonexistent expression.  */
00047   O_absent,
00048   /* X_add_number (a constant expression).  */
00049   O_constant,
00050   /* X_add_symbol + X_add_number.  */
00051   O_symbol,
00052   /* X_add_symbol + X_add_number - the base address of the image.  */
00053   O_symbol_rva,
00054   /* A register (X_add_number is register number).  */
00055   O_register,
00056   /* A big value.  If X_add_number is negative or 0, the value is in
00057      generic_floating_point_number.  Otherwise the value is in
00058      generic_bignum, and X_add_number is the number of LITTLENUMs in
00059      the value.  */
00060   O_big,
00061   /* (- X_add_symbol) + X_add_number.  */
00062   O_uminus,
00063   /* (~ X_add_symbol) + X_add_number.  */
00064   O_bit_not,
00065   /* (! X_add_symbol) + X_add_number.  */
00066   O_logical_not,
00067   /* (X_add_symbol * X_op_symbol) + X_add_number.  */
00068   O_multiply,
00069   /* (X_add_symbol / X_op_symbol) + X_add_number.  */
00070   O_divide,
00071   /* (X_add_symbol % X_op_symbol) + X_add_number.  */
00072   O_modulus,
00073   /* (X_add_symbol << X_op_symbol) + X_add_number.  */
00074   O_left_shift,
00075   /* (X_add_symbol >> X_op_symbol) + X_add_number.  */
00076   O_right_shift,
00077   /* (X_add_symbol | X_op_symbol) + X_add_number.  */
00078   O_bit_inclusive_or,
00079   /* (X_add_symbol |~ X_op_symbol) + X_add_number.  */
00080   O_bit_or_not,
00081   /* (X_add_symbol ^ X_op_symbol) + X_add_number.  */
00082   O_bit_exclusive_or,
00083   /* (X_add_symbol & X_op_symbol) + X_add_number.  */
00084   O_bit_and,
00085   /* (X_add_symbol + X_op_symbol) + X_add_number.  */
00086   O_add,
00087   /* (X_add_symbol - X_op_symbol) + X_add_number.  */
00088   O_subtract,
00089   /* (X_add_symbol == X_op_symbol) + X_add_number.  */
00090   O_eq,
00091   /* (X_add_symbol != X_op_symbol) + X_add_number.  */
00092   O_ne,
00093   /* (X_add_symbol < X_op_symbol) + X_add_number.  */
00094   O_lt,
00095   /* (X_add_symbol <= X_op_symbol) + X_add_number.  */
00096   O_le,
00097   /* (X_add_symbol >= X_op_symbol) + X_add_number.  */
00098   O_ge,
00099   /* (X_add_symbol > X_op_symbol) + X_add_number.  */
00100   O_gt,
00101   /* (X_add_symbol && X_op_symbol) + X_add_number.  */
00102   O_logical_and,
00103   /* (X_add_symbol || X_op_symbol) + X_add_number.  */
00104   O_logical_or,
00105   /* X_op_symbol [ X_add_symbol ] */
00106   O_index,
00107   /* machine dependent operators */
00108   O_md1,  O_md2,  O_md3,  O_md4,  O_md5,  O_md6,  O_md7,  O_md8,
00109   O_md9,  O_md10, O_md11, O_md12, O_md13, O_md14, O_md15, O_md16,
00110   O_md17, O_md18, O_md19, O_md20, O_md21, O_md22, O_md23, O_md24,
00111   O_md25, O_md26, O_md27, O_md28, O_md29, O_md30, O_md31, O_md32,
00112   /* this must be the largest value */
00113   O_max
00114 } operatorT;
00115 
00116 typedef struct expressionS {
00117   /* The main symbol.  */
00118   symbolS *X_add_symbol;
00119   /* The second symbol, if needed.  */
00120   symbolS *X_op_symbol;
00121   /* A number to add.  */
00122   offsetT X_add_number;
00123 
00124   /* The type of the expression.  We can't assume that an arbitrary
00125      compiler can handle a bitfield of enum type.  FIXME: We could
00126      check this using autoconf.  */
00127 #ifdef __GNUC__
00128   operatorT X_op : 8;
00129 #else
00130   unsigned char X_op;
00131 #endif
00132 
00133   /* Non-zero if X_add_number should be regarded as unsigned.  This is
00134      only valid for O_constant expressions.  It is only used when an
00135      O_constant must be extended into a bignum (i.e., it is not used
00136      when performing arithmetic on these values).
00137      FIXME: This field is not set very reliably.  */
00138   unsigned int X_unsigned : 1;
00139 
00140   /* 7 additional bits can be defined if needed.  */
00141 
00142   /* Machine dependent field */
00143   unsigned short X_md;
00144 } expressionS;
00145 
00146 enum expr_mode
00147 {
00148   expr_evaluate,
00149   expr_normal,
00150   expr_defer
00151 };
00152 
00153 /* "result" should be type (expressionS *).  */
00154 #define expression(result) expr (0, result, expr_normal)
00155 #define expression_and_evaluate(result) expr (0, result, expr_evaluate)
00156 #define deferred_expression(result) expr (0, result, expr_defer)
00157 
00158 /* If an expression is O_big, look here for its value. These common
00159    data may be clobbered whenever expr() is called.  */
00160 /* Flonums returned here.  Big enough to hold most precise flonum.  */
00161 extern FLONUM_TYPE generic_floating_point_number;
00162 /* Bignums returned here.  */
00163 extern LITTLENUM_TYPE generic_bignum[];
00164 /* Number of littlenums in above.  */
00165 #define SIZE_OF_LARGE_NUMBER (20)
00166 
00167 typedef char operator_rankT;
00168 
00169 extern char get_symbol_end (void);
00170 extern void expr_begin (void);
00171 extern void expr_set_precedence (void);
00172 extern segT expr (int, expressionS *, enum expr_mode);
00173 extern unsigned int get_single_number (void);
00174 extern symbolS *make_expr_symbol (expressionS * expressionP);
00175 extern int expr_symbol_where (symbolS *, char **, unsigned int *);
00176 
00177 extern symbolS *expr_build_uconstant (offsetT);
00178 extern symbolS *expr_build_dot (void);
00179 
00180 int resolve_expression (expressionS *);