Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* as.c - GAS main program. |
c7a89bde ILT |
2 | Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 1996 |
3 | Free Software Foundation, Inc. | |
6efd877d | 4 | |
a39116f1 | 5 | This file is part of GAS, the GNU Assembler. |
6efd877d | 6 | |
a39116f1 RP |
7 | GAS is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
6efd877d | 11 | |
a39116f1 RP |
12 | GAS is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
6efd877d | 16 | |
a39116f1 RP |
17 | You should have received a copy of the GNU General Public License |
18 | along with GAS; see the file COPYING. If not, write to | |
7e047ac2 | 19 | the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
fecd2382 RP |
20 | |
21 | /* | |
22 | * Main program for AS; a 32-bit assembler of GNU. | |
23 | * Understands command arguments. | |
24 | * Has a few routines that don't fit in other modules because they | |
25 | * are shared. | |
26 | * | |
27 | * | |
28 | * bugs | |
29 | * | |
30 | * : initialisers | |
31 | * Since no-one else says they will support them in future: I | |
32 | * don't support them now. | |
33 | * | |
34 | */ | |
35 | ||
ebd6f117 DM |
36 | #include "ansidecl.h" |
37 | #include "libiberty.h" | |
38 | ||
fecd2382 RP |
39 | #define COMMON |
40 | ||
41 | #include "as.h" | |
5d9f0ecf | 42 | #include "subsegs.h" |
6aba9d29 | 43 | #include "output-file.h" |
7e047ac2 ILT |
44 | #include "sb.h" |
45 | #include "macro.h" | |
d3038350 | 46 | |
f5200318 | 47 | static void perform_an_assembly_pass PARAMS ((int argc, char **argv)); |
7e047ac2 | 48 | static int macro_expr PARAMS ((const char *, int, sb *, int *)); |
fecd2382 | 49 | |
6efd877d | 50 | int listing; /* true if a listing is wanted */ |
5d9f0ecf | 51 | |
85a961c6 ILT |
52 | static char *listing_filename = NULL; /* Name of listing file. */ |
53 | ||
7e047ac2 ILT |
54 | /* Maximum level of macro nesting. */ |
55 | ||
56 | int max_macro_nest = 100; | |
57 | ||
6efd877d | 58 | char *myname; /* argv[0] */ |
67f3dd71 | 59 | #ifdef BFD_ASSEMBLER |
6aba9d29 | 60 | segT reg_section, expr_section; |
67f3dd71 KR |
61 | segT text_section, data_section, bss_section; |
62 | #endif | |
ca7bd557 | 63 | |
c7a89bde ILT |
64 | int chunksize = 5000; |
65 | ||
66 | /* To monitor memory allocation more effectively, make this non-zero. | |
67 | Then the chunk sizes for gas and bfd will be reduced. */ | |
68 | int debug_memory = 0; | |
69 | ||
fecd2382 | 70 | \f |
f5200318 KR |
71 | void |
72 | print_version_id () | |
73 | { | |
74 | static int printed; | |
75 | if (printed) | |
76 | return; | |
77 | printed = 1; | |
78 | ||
79 | fprintf (stderr, "GNU assembler version %s (%s)", GAS_VERSION, TARGET_ALIAS); | |
80 | #ifdef BFD_ASSEMBLER | |
81 | fprintf (stderr, ", using BFD version %s", BFD_VERSION); | |
82 | #endif | |
83 | fprintf (stderr, "\n"); | |
84 | } | |
85 | ||
ebd6f117 DM |
86 | void |
87 | show_usage (stream) | |
88 | FILE *stream; | |
fecd2382 | 89 | { |
ebd6f117 DM |
90 | fprintf (stream, "Usage: %s [option...] [asmfile...]\n", myname); |
91 | ||
92 | fprintf (stream, "\ | |
93 | Options:\n\ | |
94 | -a[sub-option...] turn on listings\n\ | |
95 | Sub-options [default hls]:\n\ | |
96 | d omit debugging directives\n\ | |
97 | h include high-level source\n\ | |
98 | l include assembly\n\ | |
99 | n omit forms processing\n\ | |
85a961c6 ILT |
100 | s include symbols\n\ |
101 | =file set listing file name (must be last sub-option)\n"); | |
a2a1a548 | 102 | fprintf (stream, "\ |
baed44cd | 103 | -D produce assembler debugging messages\n\ |
c7a89bde | 104 | --defsym SYM=VAL define symbol SYM to given value\n\ |
ebd6f117 DM |
105 | -f skip whitespace and comment preprocessing\n\ |
106 | --help show this message and exit\n\ | |
107 | -I DIR add DIR to search list for .include directives\n\ | |
108 | -J don't warn about signed overflow\n\ | |
109 | -K warn when differences altered for long displacements\n\ | |
110 | -L keep local symbols (starting with `L')\n"); | |
111 | fprintf (stream, "\ | |
7e047ac2 | 112 | -M,--mri assemble in MRI compatibility mode\n\ |
baed44cd | 113 | -nocpp ignored\n\ |
f3d817d8 | 114 | -o OBJFILE name the object-file output OBJFILE (default a.out)\n\ |
ebd6f117 | 115 | -R fold data section into text section\n\ |
c7a89bde | 116 | --statistics print various measured statistics from execution\n\ |
ebd6f117 DM |
117 | --version print assembler version number and exit\n\ |
118 | -W suppress warnings\n\ | |
119 | -w ignored\n\ | |
baed44cd | 120 | -X ignored\n\ |
ebd6f117 DM |
121 | -Z generate object file even after errors\n"); |
122 | ||
f3d817d8 | 123 | md_show_usage (stream); |
ebd6f117 DM |
124 | } |
125 | ||
4761bb02 KR |
126 | #ifdef USE_EMULATIONS |
127 | #define EMULATION_ENVIRON "AS_EMULATION" | |
128 | ||
129 | extern struct emulation mipsbelf, mipslelf, mipself; | |
130 | extern struct emulation mipsbecoff, mipslecoff, mipsecoff; | |
131 | ||
4761bb02 KR |
132 | static struct emulation *const emulations[] = { EMULATIONS }; |
133 | static const int n_emulations = sizeof (emulations) / sizeof (emulations[0]); | |
134 | ||
135 | static void | |
136 | select_emulation_mode (argc, argv) | |
137 | int argc; | |
138 | char **argv; | |
139 | { | |
140 | int i; | |
141 | char *p, *em = 0; | |
142 | ||
143 | for (i = 1; i < argc; i++) | |
144 | if (!strncmp ("--em", argv[i], 4)) | |
145 | break; | |
146 | ||
147 | if (i == argc) | |
148 | goto do_default; | |
149 | ||
150 | p = strchr (argv[i], '='); | |
151 | if (p) | |
152 | p++; | |
153 | else | |
154 | p = argv[i+1]; | |
155 | ||
156 | if (!p || !*p) | |
157 | as_fatal ("missing emulation mode name"); | |
158 | em = p; | |
159 | ||
160 | do_default: | |
161 | if (em == 0) | |
162 | em = getenv (EMULATION_ENVIRON); | |
163 | if (em == 0) | |
164 | em = DEFAULT_EMULATION; | |
165 | ||
166 | if (em) | |
167 | { | |
168 | for (i = 0; i < n_emulations; i++) | |
169 | if (!strcmp (emulations[i]->name, em)) | |
170 | break; | |
171 | if (i == n_emulations) | |
172 | as_fatal ("unrecognized emulation name `%s'", em); | |
173 | this_emulation = emulations[i]; | |
174 | } | |
175 | else | |
176 | this_emulation = emulations[0]; | |
177 | ||
178 | this_emulation->init (); | |
179 | } | |
180 | ||
181 | const char * | |
182 | default_emul_bfd_name () | |
183 | { | |
184 | abort (); | |
8095b665 | 185 | return NULL; |
4761bb02 KR |
186 | } |
187 | ||
188 | void | |
189 | common_emul_init () | |
190 | { | |
191 | this_format = this_emulation->format; | |
192 | ||
193 | if (this_emulation->leading_underscore == 2) | |
194 | this_emulation->leading_underscore = this_format->dfl_leading_underscore; | |
195 | ||
196 | if (this_emulation->default_endian != 2) | |
197 | target_big_endian = this_emulation->default_endian; | |
198 | ||
199 | if (this_emulation->fake_label_name == 0) | |
200 | { | |
201 | if (this_emulation->leading_underscore) | |
202 | this_emulation->fake_label_name = "L0\001"; | |
203 | else | |
204 | /* What other parameters should we test? */ | |
205 | this_emulation->fake_label_name = ".L0\001"; | |
206 | } | |
207 | } | |
208 | #endif | |
209 | ||
ebd6f117 | 210 | /* |
ebd6f117 DM |
211 | * Since it is easy to do here we interpret the special arg "-" |
212 | * to mean "use stdin" and we set that argv[] pointing to "". | |
213 | * After we have munged argv[], the only things left are source file | |
214 | * name(s) and ""(s) denoting stdin. These file names are used | |
215 | * (perhaps more than once) later. | |
f3d817d8 | 216 | * |
ebd6f117 DM |
217 | * check for new machine-dep cmdline options in |
218 | * md_parse_option definitions in config/tc-*.c | |
219 | */ | |
220 | ||
221 | void | |
f3d817d8 DM |
222 | parse_args (pargc, pargv) |
223 | int *pargc; | |
224 | char ***pargv; | |
ebd6f117 | 225 | { |
f3d817d8 DM |
226 | int old_argc, new_argc; |
227 | char **old_argv, **new_argv; | |
228 | ||
229 | /* Starting the short option string with '-' is for programs that | |
230 | expect options and other ARGV-elements in any order and that care about | |
231 | the ordering of the two. We describe each non-option ARGV-element | |
232 | as if it were the argument of an option with character code 1. */ | |
233 | ||
234 | char *shortopts; | |
235 | extern CONST char *md_shortopts; | |
a7aa7a2b ILT |
236 | static const char std_shortopts[] = |
237 | { | |
238 | '-', 'J', | |
239 | #ifndef WORKING_DOT_WORD | |
240 | /* -K is not meaningful if .word is not being hacked. */ | |
241 | 'K', | |
a2a1a548 | 242 | #endif |
7e047ac2 | 243 | 'L', 'M', 'R', 'W', 'Z', 'f', 'a', ':', ':', 'D', 'I', ':', 'o', ':', |
a7aa7a2b ILT |
244 | #ifndef VMS |
245 | /* -v takes an argument on VMS, so we don't make it a generic | |
246 | option. */ | |
247 | 'v', | |
248 | #endif | |
249 | 'w', 'X', | |
250 | '\0' | |
251 | }; | |
f3d817d8 DM |
252 | struct option *longopts; |
253 | extern struct option md_longopts[]; | |
254 | extern size_t md_longopts_size; | |
460531da | 255 | static const struct option std_longopts[] = { |
f3d817d8 DM |
256 | #define OPTION_HELP (OPTION_STD_BASE) |
257 | {"help", no_argument, NULL, OPTION_HELP}, | |
7e047ac2 | 258 | {"mri", no_argument, NULL, 'M'}, |
f3d817d8 DM |
259 | #define OPTION_NOCPP (OPTION_STD_BASE + 1) |
260 | {"nocpp", no_argument, NULL, OPTION_NOCPP}, | |
261 | #define OPTION_STATISTICS (OPTION_STD_BASE + 2) | |
262 | {"statistics", no_argument, NULL, OPTION_STATISTICS}, | |
263 | #define OPTION_VERSION (OPTION_STD_BASE + 3) | |
264 | {"version", no_argument, NULL, OPTION_VERSION}, | |
460531da KR |
265 | #define OPTION_DUMPCONFIG (OPTION_STD_BASE + 4) |
266 | {"dump-config", no_argument, NULL, OPTION_DUMPCONFIG}, | |
fb870b50 MT |
267 | #define OPTION_VERBOSE (OPTION_STD_BASE + 5) |
268 | {"verbose", no_argument, NULL, OPTION_VERBOSE}, | |
4761bb02 KR |
269 | #define OPTION_EMULATION (OPTION_STD_BASE + 6) |
270 | {"emulation", required_argument, NULL, OPTION_EMULATION}, | |
c7a89bde ILT |
271 | #define OPTION_DEFSYM (OPTION_STD_BASE + 7) |
272 | {"defsym", required_argument, NULL, OPTION_DEFSYM} | |
f3d817d8 DM |
273 | }; |
274 | ||
275 | /* Construct the option lists from the standard list and the | |
276 | target dependent list. */ | |
277 | shortopts = concat (std_shortopts, md_shortopts, (char *) NULL); | |
a2a1a548 | 278 | longopts = (struct option *) xmalloc (sizeof (std_longopts) + md_longopts_size); |
f3d817d8 DM |
279 | memcpy (longopts, std_longopts, sizeof (std_longopts)); |
280 | memcpy ((char *) longopts + sizeof (std_longopts), | |
281 | md_longopts, md_longopts_size); | |
282 | ||
283 | /* Make a local copy of the old argv. */ | |
284 | old_argc = *pargc; | |
285 | old_argv = *pargv; | |
286 | ||
287 | /* Initialize a new argv that contains no options. */ | |
288 | new_argv = (char **) xmalloc (sizeof (char *) * (old_argc + 1)); | |
289 | new_argv[0] = old_argv[0]; | |
290 | new_argc = 1; | |
291 | new_argv[new_argc] = NULL; | |
292 | ||
293 | while (1) | |
6efd877d | 294 | { |
f3d817d8 DM |
295 | /* getopt_long_only is like getopt_long, but '-' as well as '--' can |
296 | indicate a long option. */ | |
297 | int longind; | |
298 | int optc = getopt_long_only (old_argc, old_argv, shortopts, longopts, | |
299 | &longind); | |
ebd6f117 | 300 | |
f3d817d8 DM |
301 | if (optc == -1) |
302 | break; | |
6efd877d | 303 | |
f3d817d8 DM |
304 | switch (optc) |
305 | { | |
306 | default: | |
307 | /* md_parse_option should return 1 if it recognizes optc, | |
308 | 0 if not. */ | |
fb870b50 MT |
309 | if (md_parse_option (optc, optarg) != 0) |
310 | break; | |
311 | /* `-v' isn't included in the general short_opts list, so check for | |
312 | it explicity here before deciding we've gotten a bad argument. */ | |
313 | if (optc == 'v') | |
314 | { | |
315 | #ifdef VMS | |
316 | /* Telling getopt to treat -v's value as optional can result | |
317 | in it picking up a following filename argument here. The | |
318 | VMS code in md_parse_option can return 0 in that case, | |
319 | but it has no way of pushing the filename argument back. */ | |
320 | if (optarg && *optarg) | |
321 | new_argv[new_argc++] = optarg, new_argv[new_argc] = NULL; | |
322 | else | |
323 | #else | |
324 | case 'v': | |
325 | #endif | |
326 | case OPTION_VERBOSE: | |
327 | print_version_id (); | |
328 | break; | |
329 | } | |
330 | /*FALLTHRU*/ | |
f3d817d8 DM |
331 | |
332 | case '?': | |
333 | exit (EXIT_FAILURE); | |
334 | ||
335 | case 1: /* File name. */ | |
336 | if (!strcmp (optarg, "-")) | |
337 | optarg = ""; | |
338 | new_argv[new_argc++] = optarg; | |
339 | new_argv[new_argc] = NULL; | |
340 | break; | |
341 | ||
342 | case OPTION_HELP: | |
343 | show_usage (stdout); | |
460531da | 344 | exit (EXIT_SUCCESS); |
f3d817d8 DM |
345 | |
346 | case OPTION_NOCPP: | |
347 | break; | |
348 | ||
349 | case OPTION_STATISTICS: | |
460531da | 350 | flag_print_statistics = 1; |
f3d817d8 DM |
351 | break; |
352 | ||
353 | case OPTION_VERSION: | |
354 | print_version_id (); | |
460531da KR |
355 | exit (EXIT_SUCCESS); |
356 | ||
4761bb02 | 357 | case OPTION_EMULATION: |
e63c594d | 358 | #ifdef USE_EMULATIONS |
4761bb02 KR |
359 | if (strcmp (optarg, this_emulation->name)) |
360 | as_fatal ("multiple emulation names specified"); | |
e63c594d FF |
361 | #else |
362 | as_fatal ("emulations not handled in this configuration"); | |
363 | #endif | |
4761bb02 KR |
364 | break; |
365 | ||
460531da KR |
366 | case OPTION_DUMPCONFIG: |
367 | fprintf (stderr, "alias = %s\n", TARGET_ALIAS); | |
368 | fprintf (stderr, "canonical = %s\n", TARGET_CANONICAL); | |
369 | fprintf (stderr, "cpu-type = %s\n", TARGET_CPU); | |
370 | #ifdef TARGET_OBJ_FORMAT | |
371 | fprintf (stderr, "format = %s\n", TARGET_OBJ_FORMAT); | |
372 | #endif | |
373 | #ifdef TARGET_FORMAT | |
374 | fprintf (stderr, "bfd-target = %s\n", TARGET_FORMAT); | |
375 | #endif | |
376 | exit (EXIT_SUCCESS); | |
f3d817d8 | 377 | |
c7a89bde ILT |
378 | case OPTION_DEFSYM: |
379 | { | |
380 | char *s; | |
381 | long i; | |
382 | symbolS *sym; | |
383 | ||
384 | for (s = optarg; *s != '\0' && *s != '='; s++) | |
385 | ; | |
386 | if (*s == '\0') | |
387 | as_fatal ("bad defsym; format is --defsym name=value"); | |
388 | *s++ = '\0'; | |
389 | i = strtol (s, (char **) NULL, 0); | |
390 | sym = symbol_new (optarg, absolute_section, (valueT) i, | |
391 | &zero_address_frag); | |
392 | symbol_table_insert (sym); | |
393 | } | |
394 | break; | |
395 | ||
f3d817d8 | 396 | case 'J': |
def66e24 DM |
397 | flag_signed_overflow_ok = 1; |
398 | break; | |
399 | ||
a7aa7a2b | 400 | #ifndef WORKING_DOT_WORD |
f3d817d8 | 401 | case 'K': |
def66e24 DM |
402 | flag_warn_displacement = 1; |
403 | break; | |
a7aa7a2b | 404 | #endif |
def66e24 | 405 | |
f3d817d8 | 406 | case 'L': |
def66e24 DM |
407 | flag_keep_locals = 1; |
408 | break; | |
409 | ||
7e047ac2 ILT |
410 | case 'M': |
411 | flag_mri = 1; | |
c7a89bde ILT |
412 | #ifdef TC_M68K |
413 | flag_m68k_mri = 1; | |
414 | #endif | |
7e047ac2 ILT |
415 | break; |
416 | ||
f3d817d8 | 417 | case 'R': |
def66e24 DM |
418 | flag_readonly_data_in_text = 1; |
419 | break; | |
420 | ||
f3d817d8 | 421 | case 'W': |
def66e24 DM |
422 | flag_no_warnings = 1; |
423 | break; | |
424 | ||
f3d817d8 | 425 | case 'Z': |
def66e24 | 426 | flag_always_generate_output = 1; |
f3d817d8 DM |
427 | break; |
428 | ||
429 | case 'a': | |
430 | if (optarg) | |
6efd877d | 431 | { |
f3d817d8 | 432 | while (*optarg) |
d3038350 | 433 | { |
f3d817d8 DM |
434 | switch (*optarg) |
435 | { | |
436 | case 'd': | |
437 | listing |= LISTING_NODEBUG; | |
438 | break; | |
439 | case 'h': | |
440 | listing |= LISTING_HLL; | |
441 | break; | |
442 | case 'l': | |
443 | listing |= LISTING_LISTING; | |
444 | break; | |
445 | case 'n': | |
446 | listing |= LISTING_NOFORM; | |
447 | break; | |
448 | case 's': | |
449 | listing |= LISTING_SYMBOLS; | |
450 | break; | |
85a961c6 | 451 | case '=': |
c7a89bde | 452 | listing_filename = xstrdup (optarg + 1); |
85a961c6 ILT |
453 | optarg += strlen (listing_filename); |
454 | break; | |
f3d817d8 | 455 | default: |
460531da | 456 | as_fatal ("invalid listing option `%c'", *optarg); |
f3d817d8 DM |
457 | break; |
458 | } | |
459 | optarg++; | |
d3038350 | 460 | } |
6efd877d | 461 | } |
f3d817d8 DM |
462 | if (!listing) |
463 | listing = LISTING_DEFAULT; | |
464 | break; | |
465 | ||
466 | case 'D': | |
467 | /* DEBUG is implemented: it debugs different */ | |
baed44cd | 468 | /* things from other people's assemblers. */ |
def66e24 DM |
469 | flag_debug = 1; |
470 | break; | |
471 | ||
472 | case 'f': | |
473 | flag_no_comments = 1; | |
f3d817d8 DM |
474 | break; |
475 | ||
476 | case 'I': | |
477 | { /* Include file directory */ | |
c7a89bde | 478 | char *temp = xstrdup (optarg); |
f3d817d8 DM |
479 | add_include_dir (temp); |
480 | break; | |
481 | } | |
482 | ||
483 | case 'o': | |
c7a89bde | 484 | out_file_name = xstrdup (optarg); |
f3d817d8 DM |
485 | break; |
486 | ||
f3d817d8 DM |
487 | case 'w': |
488 | break; | |
489 | ||
490 | case 'X': | |
491 | /* -X means treat warnings as errors */ | |
492 | break; | |
6efd877d | 493 | } |
6efd877d | 494 | } |
f3d817d8 DM |
495 | |
496 | free (shortopts); | |
497 | free (longopts); | |
498 | ||
499 | *pargc = new_argc; | |
500 | *pargv = new_argv; | |
ebd6f117 DM |
501 | } |
502 | ||
c7a89bde ILT |
503 | static void dump_statistics (); |
504 | static long start_time; | |
505 | ||
ebd6f117 DM |
506 | int |
507 | main (argc, argv) | |
508 | int argc; | |
509 | char **argv; | |
510 | { | |
c7a89bde ILT |
511 | int macro_alternate; |
512 | int macro_strip_at; | |
ebd6f117 | 513 | int keep_it; |
c7a89bde ILT |
514 | |
515 | start_time = get_run_time (); | |
516 | ||
517 | if (debug_memory) | |
518 | { | |
519 | #ifdef BFD_ASSEMBLER | |
520 | extern long _bfd_chunksize; | |
521 | _bfd_chunksize = 64; | |
522 | #endif | |
523 | chunksize = 64; | |
524 | } | |
ebd6f117 | 525 | |
a2a1a548 ILT |
526 | #ifdef HOST_SPECIAL_INIT |
527 | HOST_SPECIAL_INIT (argc, argv); | |
528 | #endif | |
460531da | 529 | |
ebd6f117 | 530 | myname = argv[0]; |
d2a0c9f9 KR |
531 | xmalloc_set_program_name (myname); |
532 | ||
87e48495 KR |
533 | START_PROGRESS (myname, 0); |
534 | ||
ebd6f117 DM |
535 | #ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME |
536 | #define OBJ_DEFAULT_OUTPUT_FILE_NAME "a.out" | |
537 | #endif | |
d2a0c9f9 | 538 | |
ebd6f117 DM |
539 | out_file_name = OBJ_DEFAULT_OUTPUT_FILE_NAME; |
540 | ||
4761bb02 | 541 | hex_init (); |
ebd6f117 DM |
542 | #ifdef BFD_ASSEMBLER |
543 | bfd_init (); | |
8095b665 | 544 | bfd_set_error_program_name (myname); |
ebd6f117 DM |
545 | #endif |
546 | ||
4761bb02 KR |
547 | #ifdef USE_EMULATIONS |
548 | select_emulation_mode (argc, argv); | |
549 | #endif | |
550 | ||
87e48495 | 551 | PROGRESS (1); |
ebd6f117 | 552 | symbol_begin (); |
87e48495 | 553 | frag_init (); |
ebd6f117 | 554 | subsegs_begin (); |
f3d817d8 | 555 | parse_args (&argc, &argv); |
c7a89bde | 556 | read_begin (); |
7e047ac2 ILT |
557 | input_scrub_begin (); |
558 | expr_begin (); | |
c7a89bde ILT |
559 | |
560 | if (flag_print_statistics) | |
561 | xatexit (dump_statistics); | |
562 | ||
563 | macro_alternate = 0; | |
564 | macro_strip_at = 0; | |
565 | #ifdef TC_I960 | |
566 | macro_strip_at = flag_mri; | |
567 | #endif | |
568 | #ifdef TC_A29K | |
569 | /* For compatibility with the AMD 29K family macro assembler | |
570 | specification. */ | |
571 | macro_alternate = 1; | |
572 | macro_strip_at = 1; | |
573 | #endif | |
574 | ||
575 | macro_init (macro_alternate, flag_mri, macro_strip_at, macro_expr); | |
67f3dd71 | 576 | |
87e48495 KR |
577 | PROGRESS (1); |
578 | ||
67f3dd71 KR |
579 | #ifdef BFD_ASSEMBLER |
580 | output_file_create (out_file_name); | |
581 | assert (stdoutput != 0); | |
fecd2382 | 582 | #endif |
67f3dd71 | 583 | |
ebd6f117 DM |
584 | #ifdef tc_init_after_args |
585 | tc_init_after_args (); | |
586 | #endif | |
587 | ||
87e48495 KR |
588 | PROGRESS (1); |
589 | ||
6efd877d | 590 | perform_an_assembly_pass (argc, argv); /* Assemble it. */ |
c7a89bde ILT |
591 | |
592 | #ifdef md_end | |
593 | md_end (); | |
fb870b50 | 594 | #endif |
8b13fa4e | 595 | |
6efd877d | 596 | if (seen_at_least_1_file () |
def66e24 | 597 | && !((had_warnings () && flag_always_generate_output) |
6efd877d | 598 | || had_errors () > 0)) |
398527f2 | 599 | keep_it = 1; |
f5200318 | 600 | else |
398527f2 KR |
601 | keep_it = 0; |
602 | ||
603 | if (keep_it) | |
604 | write_object_file (); | |
605 | ||
606 | #ifndef NO_LISTING | |
85a961c6 | 607 | listing_print (listing_filename); |
f5200318 | 608 | #endif |
6efd877d | 609 | |
ebd6f117 | 610 | #ifndef OBJ_VMS /* does its own file handling */ |
398527f2 KR |
611 | #ifndef BFD_ASSEMBLER |
612 | if (keep_it) | |
613 | #endif | |
614 | output_file_close (out_file_name); | |
ebd6f117 | 615 | #endif |
398527f2 KR |
616 | |
617 | if (!keep_it) | |
618 | unlink (out_file_name); | |
619 | ||
6efd877d | 620 | input_scrub_end (); |
6efd877d | 621 | |
87e48495 KR |
622 | END_PROGRESS (myname); |
623 | ||
c7a89bde ILT |
624 | /* Use xexit instead of return, because under VMS environments they |
625 | may not place the same interpretation on the value given. */ | |
626 | if ((had_warnings () && flag_always_generate_output) | |
627 | || had_errors () > 0) | |
628 | xexit (EXIT_FAILURE); | |
629 | xexit (EXIT_SUCCESS); | |
630 | } | |
631 | ||
632 | static void | |
633 | dump_statistics () | |
634 | { | |
635 | extern char **environ; | |
e63c594d | 636 | #ifdef HAVE_SBRK |
c7a89bde | 637 | char *lim = (char *) sbrk (0); |
e63c594d | 638 | #endif |
c7a89bde | 639 | long run_time = get_run_time () - start_time; |
ca7bd557 | 640 | |
c7a89bde ILT |
641 | fprintf (stderr, "%s: total time in assembly: %ld.%06ld\n", |
642 | myname, run_time / 1000000, run_time % 1000000); | |
e63c594d | 643 | #ifdef HAVE_SBRK |
c7a89bde ILT |
644 | fprintf (stderr, "%s: data size %ld\n", |
645 | myname, (long) (lim - (char *) &environ)); | |
e63c594d | 646 | #endif |
ca7bd557 | 647 | |
c7a89bde ILT |
648 | subsegs_print_statistics (stderr); |
649 | write_print_statistics (stderr); | |
650 | symbol_print_statistics (stderr); | |
651 | read_print_statistics (stderr); | |
652 | ||
653 | #ifdef tc_print_statistics | |
654 | tc_print_statistics (stderr); | |
655 | #endif | |
656 | #ifdef obj_print_statistics | |
657 | obj_print_statistics (stderr); | |
658 | #endif | |
d3038350 | 659 | } |
fecd2382 | 660 | \f |
6efd877d | 661 | |
fecd2382 RP |
662 | /* perform_an_assembly_pass() |
663 | * | |
664 | * Here to attempt 1 pass over each input file. | |
665 | * We scan argv[*] looking for filenames or exactly "" which is | |
666 | * shorthand for stdin. Any argv that is NULL is not a file-name. | |
667 | * We set need_pass_2 TRUE if, after this, we still have unresolved | |
668 | * expressions of the form (unknown value)+-(unknown value). | |
669 | * | |
670 | * Note the un*x semantics: there is only 1 logical input file, but it | |
671 | * may be a catenation of many 'physical' input files. | |
672 | */ | |
6efd877d KR |
673 | static void |
674 | perform_an_assembly_pass (argc, argv) | |
675 | int argc; | |
676 | char **argv; | |
fecd2382 | 677 | { |
6efd877d | 678 | int saw_a_file = 0; |
67f3dd71 KR |
679 | #ifdef BFD_ASSEMBLER |
680 | flagword applicable; | |
681 | #endif | |
682 | ||
6efd877d KR |
683 | need_pass_2 = 0; |
684 | ||
67f3dd71 | 685 | #ifndef BFD_ASSEMBLER |
5d9f0ecf | 686 | #ifdef MANY_SEGMENTS |
f5200318 KR |
687 | { |
688 | unsigned int i; | |
689 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
6efd877d | 690 | segment_info[i].fix_root = 0; |
f5200318 | 691 | } |
6efd877d | 692 | /* Create the three fixed ones */ |
6aba9d29 JL |
693 | { |
694 | segT seg; | |
695 | ||
ebd6f117 DM |
696 | #ifdef TE_APOLLO |
697 | seg = subseg_new (".wtext", 0); | |
698 | #else | |
6aba9d29 | 699 | seg = subseg_new (".text", 0); |
ebd6f117 | 700 | #endif |
6aba9d29 JL |
701 | assert (seg == SEG_E0); |
702 | seg = subseg_new (".data", 0); | |
703 | assert (seg == SEG_E1); | |
704 | seg = subseg_new (".bss", 0); | |
705 | assert (seg == SEG_E2); | |
ebd6f117 DM |
706 | #ifdef TE_APOLLO |
707 | create_target_segments (); | |
708 | #endif | |
6aba9d29 JL |
709 | } |
710 | ||
e6498b10 | 711 | #else /* not MANY_SEGMENTS */ |
6efd877d KR |
712 | text_fix_root = NULL; |
713 | data_fix_root = NULL; | |
714 | bss_fix_root = NULL; | |
e6498b10 | 715 | #endif /* not MANY_SEGMENTS */ |
67f3dd71 KR |
716 | #else /* BFD_ASSEMBLER */ |
717 | /* Create the standard sections, and those the assembler uses | |
718 | internally. */ | |
719 | text_section = subseg_new (".text", 0); | |
67f3dd71 | 720 | data_section = subseg_new (".data", 0); |
67f3dd71 | 721 | bss_section = subseg_new (".bss", 0); |
67f3dd71 KR |
722 | /* @@ FIXME -- we're setting the RELOC flag so that sections are assumed |
723 | to have relocs, otherwise we don't find out in time. */ | |
724 | applicable = bfd_applicable_section_flags (stdoutput); | |
725 | bfd_set_section_flags (stdoutput, text_section, | |
726 | applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
727 | | SEC_CODE | SEC_READONLY)); | |
728 | /* @@ FIXME -- SEC_CODE seems to mean code only, rather than code possibly.*/ | |
729 | bfd_set_section_flags (stdoutput, data_section, | |
730 | applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)); | |
731 | bfd_set_section_flags (stdoutput, bss_section, applicable & SEC_ALLOC); | |
8b13fa4e | 732 | seg_info (bss_section)->bss = 1; |
67f3dd71 KR |
733 | subseg_new (BFD_ABS_SECTION_NAME, 0); |
734 | subseg_new (BFD_UND_SECTION_NAME, 0); | |
67f3dd71 | 735 | reg_section = subseg_new ("*GAS `reg' section*", 0); |
6aba9d29 | 736 | expr_section = subseg_new ("*GAS `expr' section*", 0); |
67f3dd71 | 737 | |
67f3dd71 | 738 | #endif /* BFD_ASSEMBLER */ |
e6498b10 | 739 | |
6aba9d29 JL |
740 | subseg_set (text_section, 0); |
741 | ||
f5200318 KR |
742 | /* This may add symbol table entries, which requires having an open BFD, |
743 | and sections already created, in BFD_ASSEMBLER mode. */ | |
744 | md_begin (); | |
745 | ||
6efd877d KR |
746 | argv++; /* skip argv[0] */ |
747 | argc--; /* skip argv[0] */ | |
748 | while (argc--) | |
749 | { | |
750 | if (*argv) | |
751 | { /* Is it a file-name argument? */ | |
87e48495 | 752 | PROGRESS (1); |
6efd877d KR |
753 | saw_a_file++; |
754 | /* argv->"" if stdin desired, else->filename */ | |
755 | read_a_source_file (*argv); | |
a39116f1 | 756 | } |
6efd877d KR |
757 | argv++; /* completed that argv */ |
758 | } | |
759 | if (!saw_a_file) | |
760 | read_a_source_file (""); | |
761 | } /* perform_an_assembly_pass() */ | |
fecd2382 | 762 | |
7e047ac2 ILT |
763 | /* The interface between the macro code and gas expression handling. */ |
764 | ||
765 | static int | |
766 | macro_expr (emsg, idx, in, val) | |
767 | const char *emsg; | |
768 | int idx; | |
769 | sb *in; | |
770 | int *val; | |
771 | { | |
772 | char *hold; | |
773 | expressionS ex; | |
774 | ||
775 | sb_terminate (in); | |
776 | ||
777 | hold = input_line_pointer; | |
778 | input_line_pointer = in->ptr + idx; | |
779 | expression (&ex); | |
780 | idx = input_line_pointer - in->ptr; | |
781 | input_line_pointer = hold; | |
782 | ||
783 | if (ex.X_op != O_constant) | |
784 | as_bad ("%s", emsg); | |
785 | ||
786 | *val = (int) ex.X_add_number; | |
787 | ||
788 | return idx; | |
789 | } | |
790 | ||
a39116f1 | 791 | /* end of as.c */ |