home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / gas / as.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  20KB  |  821 lines

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