Changes to let cons handle bignums like general expressions.
[binutils-gdb.git] / gas / as.h
1 /* as.h - global header file
2 Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
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
8 the Free Software Foundation; either version 2, or (at your option)
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
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #define GAS 1
21 /*
22 * I think this stuff is largely out of date. xoxorich.
23 *
24 * CAPITALISED names are #defined.
25 * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
26 * "lowercaseT" is a typedef of "lowercase" objects.
27 * "lowercaseP" is type "pointer to object of type 'lowercase'".
28 * "lowercaseS" is typedef struct ... lowercaseS.
29 *
30 * #define DEBUG to enable all the "know" assertion tests.
31 * #define SUSPECT when debugging hash code.
32 * #define COMMON as "extern" for all modules except one, where you #define
33 * COMMON as "".
34 * If TEST is #defined, then we are testing a module: #define COMMON as "".
35 */
36
37 /* These #defines are for parameters of entire assembler. */
38
39 #define DEBUG /* temporary */
40 /* These #includes are for type definitions etc. */
41
42 #include <stdio.h>
43 #ifdef DEBUG
44 #undef NDEBUG
45 #endif
46 #include <assert.h>
47
48 #include <ansidecl.h>
49 #ifdef BFD_ASSEMBLER
50 #include <bfd.h>
51 #endif
52 #include "host.h"
53 #include "flonum.h"
54
55 /* Make Saber happier on obstack.h. */
56 #ifdef SABER
57 #undef __PTR_TO_INT
58 #define __PTR_TO_INT(P) ((int)(P))
59 #undef __INT_TO_PTR
60 #define __INT_TO_PTR(P) ((char *)(P))
61 #endif
62
63 #ifndef __LINE__
64 #define __LINE__ "unknown"
65 #endif /* __LINE__ */
66
67 #ifndef __FILE__
68 #define __FILE__ "unknown"
69 #endif /* __FILE__ */
70
71 #ifndef __STDC__
72 #ifndef const
73 #define const
74 #endif
75 #ifndef volatile
76 #define volatile
77 #endif
78 #endif /* ! __STDC__ */
79
80 #define obstack_chunk_alloc xmalloc
81 #define obstack_chunk_free xfree
82
83 #define xfree free
84
85 #define BAD_CASE(val) \
86 { \
87 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
88 (long) val, __LINE__, __FILE__); \
89 }
90 \f
91
92 /* These are assembler-wide concepts */
93
94 #ifdef BFD_ASSEMBLER
95 extern bfd *stdoutput;
96 typedef bfd_vma addressT;
97 typedef bfd_signed_vma offsetT;
98 #else
99 typedef unsigned long addressT;
100 typedef long offsetT;
101 #endif
102
103 /* Type of symbol value, etc. For use in prototypes. */
104 typedef addressT valueT;
105
106 #ifndef COMMON
107 #ifdef TEST
108 #define COMMON /* declare our COMMONs storage here. */
109 #else
110 #define COMMON extern /* our commons live elswhere */
111 #endif
112 #endif
113 /* COMMON now defined */
114
115 #ifdef DEBUG
116 #ifndef know
117 #define know(p) assert(p) /* Verify our assumptions! */
118 #endif /* not yet defined */
119 #else
120 #define know(p) /* know() checks are no-op.ed */
121 #endif
122
123 #if defined (BROKEN_ASSERT) && !defined (NDEBUG)
124 /* Used on machines where the "assert" macro is buggy. (For example, on the
125 RS/6000, Reiser-cpp substitution is done to put the condition into a
126 string, so if the condition contains a string, parse errors result.) If
127 the condition fails, just drop core file. */
128 #undef assert
129 #define assert(p) ((p) ? 0 : (abort (), 0))
130 #endif
131 \f
132 /* input_scrub.c */
133
134 /*
135 * Supplies sanitised buffers to read.c.
136 * Also understands printing line-number part of error messages.
137 */
138 \f
139
140 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
141
142 #ifndef BFD_ASSEMBLER
143
144 #ifdef MANY_SEGMENTS
145 #include "bfd.h"
146 #define N_SEGMENTS 10
147 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
148 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
149 #define SEG_TEXT SEG_E0
150 #define SEG_DATA SEG_E1
151 #define SEG_BSS SEG_E2
152 #else
153 #define N_SEGMENTS 3
154 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
155 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
156 #endif
157
158 typedef enum _segT
159 {
160 SEG_ABSOLUTE = 0,
161 SEG_LIST,
162 SEG_UNKNOWN,
163 SEG_GOOF, /* Only happens if AS has a logic error. */
164 /* Invented so we don't crash printing */
165 /* error message involving weird segment. */
166 SEG_EXPR, /* Intermediate expression values. */
167 SEG_DEBUG, /* Debug segment */
168 SEG_NTV, /* Transfert vector preload segment */
169 SEG_PTV, /* Transfert vector postload segment */
170 SEG_REGISTER /* Mythical: a register-valued expression */
171 } segT;
172
173 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
174 #else
175 typedef asection *segT;
176 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
177 && (SEG) != undefined_section \
178 && (SEG) != reg_section \
179 && (SEG) != expr_section)
180 #endif
181 typedef int subsegT;
182
183 /* What subseg we are accreting now? */
184 COMMON subsegT now_subseg;
185
186 /* Segment our instructions emit to. */
187 COMMON segT now_seg;
188
189 #ifdef BFD_ASSEMBLER
190 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
191 #else
192 extern char *const seg_name[];
193 #define segment_name(SEG) seg_name[(int) (SEG)]
194 #endif
195
196 #ifndef BFD_ASSEMBLER
197 extern int section_alignment[];
198 #endif
199
200 #ifdef BFD_ASSEMBLER
201 extern segT reg_section, expr_section;
202 /* Shouldn't these be eliminated someday? */
203 extern segT text_section, data_section, bss_section;
204 #define absolute_section (&bfd_abs_section)
205 #define undefined_section (&bfd_und_section)
206 #else
207 #define reg_section SEG_REGISTER
208 #define expr_section SEG_EXPR
209 #define text_section SEG_TEXT
210 #define data_section SEG_DATA
211 #define bss_section SEG_BSS
212 #define absolute_section SEG_ABSOLUTE
213 #define undefined_section SEG_UNKNOWN
214 #endif
215
216 /* relax() */
217
218 typedef enum _relax_state
219 {
220 /* Variable chars to be repeated fr_offset times.
221 Fr_symbol unused. Used with fr_offset == 0 for a
222 constant length frag. */
223 rs_fill = 1,
224
225 /* Align: Fr_offset: power of 2. 1 variable char: fill character. */
226 rs_align,
227
228 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
229 character. */
230 rs_org,
231
232 rs_machine_dependent
233
234 #ifndef WORKING_DOT_WORD
235 /* JF: gunpoint */
236 , rs_broken_word
237 #endif
238 } relax_stateT;
239
240 /* typedef unsigned char relax_substateT; */
241 /* JF this is more likely to leave the end of a struct frag on an align
242 boundry. Be very careful with this. */
243 typedef unsigned long relax_substateT;
244
245 /* Enough bits for address, but still an integer type.
246 Could be a problem, cross-assembling for 64-bit machines. */
247 typedef addressT relax_addressT;
248 \f
249
250 /* frags.c */
251
252 /*
253 * A code fragment (frag) is some known number of chars, followed by some
254 * unknown number of chars. Typically the unknown number of chars is an
255 * instruction address whose size is yet unknown. We always know the greatest
256 * possible size the unknown number of chars may become, and reserve that
257 * much room at the end of the frag.
258 * Once created, frags do not change address during assembly.
259 * We chain the frags in (a) forward-linked list(s). The object-file address
260 * of the 1st char of a frag is generally not known until after relax().
261 * Many things at assembly time describe an address by {object-file-address
262 * of a particular frag}+offset.
263
264 BUG: it may be smarter to have a single pointer off to various different
265 notes for different frag kinds. See how code pans
266 */
267 struct frag
268 {
269 /* Object file address. */
270 addressT fr_address;
271 /* Chain forward; ascending address order. Rooted in frch_root. */
272 struct frag *fr_next;
273
274 /* (Fixed) number of chars we know we have. May be 0. */
275 offsetT fr_fix;
276 /* (Variable) number of chars after above. May be 0. */
277 offsetT fr_var;
278 /* For variable-length tail. */
279 struct symbol *fr_symbol;
280 /* For variable-length tail. */
281 offsetT fr_offset;
282 /* Points to opcode low addr byte, for relaxation. */
283 char *fr_opcode;
284
285 #ifndef NO_LISTING
286 struct list_info_struct *line;
287 #endif
288
289 /* What state is my tail in? */
290 relax_stateT fr_type;
291 relax_substateT fr_subtype;
292
293 /* These are needed only on the NS32K machines */
294 char fr_pcrel_adjust;
295 char fr_bsr;
296
297 /* Chars begin here.
298 One day we will compile fr_literal[0]. */
299 char fr_literal[1];
300 };
301
302 #define SIZEOF_STRUCT_FRAG \
303 ((int)zero_address_frag.fr_literal-(int)&zero_address_frag)
304 /* We want to say fr_literal[0] above. */
305
306 typedef struct frag fragS;
307
308 /* Current frag we are building. This frag is incomplete. It is, however,
309 included in frchain_now. The fr_fix field is bogus; instead, use:
310 obstack_next_free(&frags)-frag_now->fr_literal. */
311 COMMON fragS *frag_now;
312 #define frag_now_fix() ((char*)obstack_next_free (&frags) - frag_now->fr_literal)
313
314 /* For foreign-segment symbol fixups. */
315 COMMON fragS zero_address_frag;
316 /* For local common (N_BSS segment) fixups. */
317 COMMON fragS bss_address_frag;
318
319 /* main program "as.c" (command arguments etc) */
320
321 /* ['x'] TRUE if "-x" seen. */
322 COMMON char flagseen[128];
323 COMMON unsigned char flag_readonly_data_in_text;
324 COMMON unsigned char flag_suppress_warnings;
325 COMMON unsigned char flag_always_generate_output;
326
327 /* name of emitted object file */
328 COMMON char *out_file_name;
329
330 /* TRUE if we need a second pass. */
331 COMMON int need_pass_2;
332
333 /* TRUE if we should do no relaxing, and
334 leave lots of padding. */
335 COMMON int linkrelax;
336
337 struct _pseudo_type
338 {
339 /* assembler mnemonic, lower case, no '.' */
340 char *poc_name;
341 /* Do the work */
342 void (*poc_handler) PARAMS ((int));
343 /* Value to pass to handler */
344 int poc_val;
345 };
346
347 typedef struct _pseudo_type pseudo_typeS;
348
349 #ifdef BFD_ASSEMBLER_xxx
350 struct lineno_struct
351 {
352 alent line;
353 fragS *frag;
354 struct lineno_struct *next;
355 };
356 typedef struct lineno_struct lineno;
357 #endif
358
359 #if defined (__STDC__) && !defined(NO_STDARG)
360
361 #if __GNUC__ >= 2
362 /* for use with -Wformat */
363 #define PRINTF_LIKE(FCN) void FCN (const char *Format, ...) \
364 __attribute__ ((format (printf, 1, 2)))
365 #else /* ANSI C with stdarg, but not GNU C */
366 #define PRINTF_LIKE(FCN) void FCN (const char *Format, ...)
367 #endif
368 #else /* not ANSI C, or not stdarg */
369 #define PRINTF_LIKE(FCN) void FCN ()
370 #endif
371
372 PRINTF_LIKE (as_bad);
373 PRINTF_LIKE (as_fatal);
374 PRINTF_LIKE (as_tsktsk);
375 PRINTF_LIKE (as_warn);
376 void fprint_value PARAMS ((FILE *file, addressT value));
377 void sprint_value PARAMS ((char *buf, addressT value));
378
379 int had_errors PARAMS ((void));
380 int had_warnings PARAMS ((void));
381
382 void print_version_id PARAMS ((void));
383 char *app_push PARAMS ((void));
384 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
385 char *input_scrub_include_file PARAMS ((char *filename, char *position));
386 char *input_scrub_new_file PARAMS ((char *filename));
387 char *input_scrub_next_buffer PARAMS ((char **bufp));
388 #if 0 /* incompatible with solaris 2 native cc */
389 char *strstr PARAMS ((const char *s, const char *wanted));
390 #endif
391 char *xmalloc PARAMS ((unsigned long size));
392 char *xrealloc PARAMS ((char *ptr, unsigned long n));
393 int do_scrub_next_char PARAMS ((int (*get) (void), void (*unget) (int)));
394 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
395 long exponent_bits));
396 int had_err PARAMS ((void));
397 int ignore_input PARAMS ((void));
398 int scrub_from_file PARAMS ((void));
399 int scrub_from_string PARAMS ((void));
400 int seen_at_least_1_file PARAMS ((void));
401 void app_pop PARAMS ((char *arg));
402 void as_howmuch PARAMS ((FILE * stream));
403 void as_perror PARAMS ((char *gripe, char *filename));
404 void as_where PARAMS ((void));
405 void bump_line_counters PARAMS ((void));
406 void do_scrub_begin PARAMS ((void));
407 void input_scrub_begin PARAMS ((void));
408 void input_scrub_close PARAMS ((void));
409 void input_scrub_end PARAMS ((void));
410 void int_to_gen PARAMS ((long x));
411 void new_logical_line PARAMS ((char *fname, int line_number));
412 void scrub_to_file PARAMS ((int ch));
413 void scrub_to_string PARAMS ((int ch));
414 void subsegs_begin PARAMS ((void));
415 void subseg_change PARAMS ((segT seg, int subseg));
416 segT subseg_new PARAMS ((const char *name, subsegT subseg));
417 void subseg_set PARAMS ((segT seg, subsegT subseg));
418
419 /* this one starts the chain of target dependant headers */
420 #include "targ-env.h"
421
422 #include "expr.h"
423 #include "struc-symbol.h"
424 #include "write.h"
425 #include "frags.h"
426 #include "hash.h"
427 #include "read.h"
428 #include "symbols.h"
429
430 #include "tc.h"
431 #include "obj.h"
432
433 #include "listing.h"
434
435 #ifdef BFD_ASSEMBLER
436 /* Someday perhaps this will be selectable at run-time. */
437 #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
438 #define OUTPUT_FLAVOR bfd_target_aout_flavour
439 #endif
440 #ifdef OBJ_COFF
441 #define OUTPUT_FLAVOR bfd_target_coff_flavour
442 #endif
443 #ifdef OBJ_ECOFF
444 #define OUTPUT_FLAVOR bfd_target_ecoff_flavour
445 #endif
446 #ifdef OBJ_ELF
447 #define OUTPUT_FLAVOR bfd_target_elf_flavour
448 #endif
449 #endif /* BFD_ASSEMBLER */
450
451 /* end of as.h */