]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/expr.h
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gas / expr.h
CommitLineData
252b5132 1/* expr.h -> header file for expr.c
fd67aa11 2 Copyright (C) 1987-2024 Free Software Foundation, Inc.
252b5132
RH
3
4 This file is part of GAS, the GNU Assembler.
5
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
ec2655a6 8 the Free Software Foundation; either version 3, or (at your option)
252b5132
RH
9 any later version.
10
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
4b4da160
NC
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
252b5132 20
145667f8
MH
21/* By popular demand, we define a struct to represent an expression.
22 This will no doubt mutate as expressions become baroque.
23
24 Currently, we support expressions like "foo OP bar + 42". In other
25 words we permit a (possibly undefined) symbol, a (possibly
26 undefined) symbol and the operation used to combine the symbols,
27 and an (absolute) augend. RMS says this is so we can have 1-pass
28 assembly for any compiler emissions, and a 'case' statement might
29 emit 'undefined1 - undefined2'.
30
31 The type of an expression used to be stored as a segment. That got
32 confusing because it overloaded the concept of a segment. I added
33 an operator field, instead. */
252b5132
RH
34
35/* This is the type of an expression. The operator types are also
36 used while parsing an expression.
37
38 NOTE: This enumeration must match the op_rank array in expr.c. */
39
145667f8
MH
40typedef enum
41{
252b5132
RH
42 /* An illegal expression. */
43 O_illegal,
44 /* A nonexistent expression. */
45 O_absent,
46 /* X_add_number (a constant expression). */
47 O_constant,
48 /* X_add_symbol + X_add_number. */
49 O_symbol,
50 /* X_add_symbol + X_add_number - the base address of the image. */
51 O_symbol_rva,
145667f8
MH
52 /* The section index of X_add_symbol. */
53 O_secidx,
252b5132
RH
54 /* A register (X_add_number is register number). */
55 O_register,
56 /* A big value. If X_add_number is negative or 0, the value is in
57 generic_floating_point_number. Otherwise the value is in
58 generic_bignum, and X_add_number is the number of LITTLENUMs in
59 the value. */
60 O_big,
61 /* (- X_add_symbol) + X_add_number. */
62 O_uminus,
63 /* (~ X_add_symbol) + X_add_number. */
64 O_bit_not,
65 /* (! X_add_symbol) + X_add_number. */
66 O_logical_not,
67 /* (X_add_symbol * X_op_symbol) + X_add_number. */
68 O_multiply,
69 /* (X_add_symbol / X_op_symbol) + X_add_number. */
70 O_divide,
7f31df7c 71 /* (X_add_symbol % X_op_symbol) + X_add_number. */
252b5132 72 O_modulus,
7f31df7c 73 /* (X_add_symbol << X_op_symbol) + X_add_number. */
252b5132 74 O_left_shift,
7f31df7c 75 /* (X_add_symbol >> X_op_symbol) + X_add_number. */
252b5132 76 O_right_shift,
7f31df7c 77 /* (X_add_symbol | X_op_symbol) + X_add_number. */
252b5132 78 O_bit_inclusive_or,
7f31df7c 79 /* (X_add_symbol |~ X_op_symbol) + X_add_number. */
252b5132 80 O_bit_or_not,
7f31df7c 81 /* (X_add_symbol ^ X_op_symbol) + X_add_number. */
252b5132 82 O_bit_exclusive_or,
7f31df7c 83 /* (X_add_symbol & X_op_symbol) + X_add_number. */
252b5132 84 O_bit_and,
7f31df7c 85 /* (X_add_symbol + X_op_symbol) + X_add_number. */
252b5132 86 O_add,
7f31df7c 87 /* (X_add_symbol - X_op_symbol) + X_add_number. */
252b5132
RH
88 O_subtract,
89 /* (X_add_symbol == X_op_symbol) + X_add_number. */
90 O_eq,
91 /* (X_add_symbol != X_op_symbol) + X_add_number. */
92 O_ne,
93 /* (X_add_symbol < X_op_symbol) + X_add_number. */
94 O_lt,
95 /* (X_add_symbol <= X_op_symbol) + X_add_number. */
96 O_le,
97 /* (X_add_symbol >= X_op_symbol) + X_add_number. */
98 O_ge,
99 /* (X_add_symbol > X_op_symbol) + X_add_number. */
100 O_gt,
101 /* (X_add_symbol && X_op_symbol) + X_add_number. */
102 O_logical_and,
103 /* (X_add_symbol || X_op_symbol) + X_add_number. */
104 O_logical_or,
b585bc2c
RH
105 /* X_op_symbol [ X_add_symbol ] */
106 O_index,
dd33dc0f
MM
107 /* machine dependent operators */
108 O_md1, O_md2, O_md3, O_md4, O_md5, O_md6, O_md7, O_md8,
109 O_md9, O_md10, O_md11, O_md12, O_md13, O_md14, O_md15, O_md16,
3765b1be
RH
110 O_md17, O_md18, O_md19, O_md20, O_md21, O_md22, O_md23, O_md24,
111 O_md25, O_md26, O_md27, O_md28, O_md29, O_md30, O_md31, O_md32,
252b5132
RH
112 /* this must be the largest value */
113 O_max
114} operatorT;
115
145667f8
MH
116typedef struct expressionS
117{
252b5132 118 /* The main symbol. */
49309057 119 symbolS *X_add_symbol;
252b5132 120 /* The second symbol, if needed. */
49309057 121 symbolS *X_op_symbol;
252b5132
RH
122 /* A number to add. */
123 offsetT X_add_number;
446a06c9 124
bf29b231
RH
125 /* The type of the expression. We can't assume that an arbitrary
126 compiler can handle a bitfield of enum type. FIXME: We could
127 check this using autoconf. */
128#ifdef __GNUC__
446a06c9 129 operatorT X_op : 8;
bf29b231 130#else
446a06c9 131 unsigned char X_op;
bf29b231 132#endif
446a06c9 133
252b5132
RH
134 /* Non-zero if X_add_number should be regarded as unsigned. This is
135 only valid for O_constant expressions. It is only used when an
136 O_constant must be extended into a bignum (i.e., it is not used
137 when performing arithmetic on these values).
138 FIXME: This field is not set very reliably. */
139 unsigned int X_unsigned : 1;
956a6ba3
JB
140 /* This is used to implement "word size + 1 bit" arithmetic, so that e.g.
141 expressions used with .sleb128 directives can use the full range available
142 for an unsigned word, but can also properly represent all values of a
143 signed word. */
144 unsigned int X_extrabit : 1;
446a06c9
MM
145
146 /* 7 additional bits can be defined if needed. */
147
148 /* Machine dependent field */
149 unsigned short X_md;
252b5132
RH
150} expressionS;
151
9497f5ac
NC
152enum expr_mode
153{
154 expr_evaluate,
155 expr_normal,
156 expr_defer
157};
158
a01b9fa4 159/* "result" should be type (expressionS *). */
9497f5ac
NC
160#define expression(result) expr (0, result, expr_normal)
161#define expression_and_evaluate(result) expr (0, result, expr_evaluate)
162#define deferred_expression(result) expr (0, result, expr_defer)
252b5132
RH
163
164/* If an expression is O_big, look here for its value. These common
a01b9fa4
KH
165 data may be clobbered whenever expr() is called. */
166/* Flonums returned here. Big enough to hold most precise flonum. */
252b5132 167extern FLONUM_TYPE generic_floating_point_number;
a01b9fa4 168/* Bignums returned here. */
252b5132 169extern LITTLENUM_TYPE generic_bignum[];
a01b9fa4 170/* Number of littlenums in above. */
252b5132
RH
171#define SIZE_OF_LARGE_NUMBER (20)
172
173typedef char operator_rankT;
174
d02603dc
NC
175extern char get_symbol_name (char **);
176extern char restore_line_pointer (char);
dd625418 177extern void expr_begin (void);
6eb099ae 178extern void expr_end (void);
dd625418 179extern void expr_set_precedence (void);
fcaed75e 180extern void expr_set_rank (operatorT, operator_rankT);
4455e9ad
JB
181extern void add_to_result (expressionS *, offsetT, int);
182extern void subtract_from_result (expressionS *, offsetT, int);
9497f5ac 183extern segT expr (int, expressionS *, enum expr_mode);
dd625418 184extern unsigned int get_single_number (void);
529b6c24 185extern symbolS *make_expr_symbol (const expressionS * expressionP);
3b4dbbbf 186extern int expr_symbol_where (symbolS *, const char **, unsigned int *);
b7adb16d 187extern void current_location (expressionS *);
dd625418 188extern symbolS *expr_build_uconstant (offsetT);
dd625418 189extern symbolS *expr_build_dot (void);
32d71569
AM
190extern uint32_t generic_bignum_to_int32 (void);
191extern uint64_t generic_bignum_to_int64 (void);
145667f8 192extern int resolve_expression (expressionS *);
d50c498a 193extern void resolve_register (expressionS *);
e2d15955 194
5b7c81bd 195extern bool literal_prefix_dollar_hex;