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