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 / app.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  26KB  |  1,110 lines

  1. /* This is the Assembler Pre-Processor
  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. /* Modified by Allen Wirfs-Brock, Instantiations Inc 2/90 */
  22. /* App, the assembler pre-processor.  This pre-processor strips out excess
  23.    spaces, turns single-quoted characters into a decimal constant, and turns
  24.    # <number> <filename> <garbage> into a .line <number>\n.file <filename>
  25.    pair.  This needs better error-handling.  */
  26.  
  27. #include <stdio.h>
  28. #include "as.h"            /* For BAD_CASE() only */
  29.  
  30. #if (__STDC__ != 1)
  31. #ifndef const
  32. #define const  /* empty */
  33. #endif
  34. #endif
  35.  
  36. /* Whether we are scrubbing in m68k MRI mode.  This is different from
  37.    flag_m68k_mri, because the two flags will be affected by the .mri
  38.    pseudo-op at different times.  */
  39. static int scrub_m68k_mri;
  40.  
  41. /* The pseudo-op which switches in and out of MRI mode.  See the
  42.    comment in do_scrub_chars.  */
  43. static const char mri_pseudo[] = ".mri 0";
  44.  
  45. static char lex[256];
  46. static const char symbol_chars[] =
  47. "$._ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  48.  
  49. #define LEX_IS_SYMBOL_COMPONENT        1
  50. #define LEX_IS_WHITESPACE        2
  51. #define LEX_IS_LINE_SEPARATOR        3
  52. #define LEX_IS_COMMENT_START        4
  53. #define LEX_IS_LINE_COMMENT_START    5
  54. #define    LEX_IS_TWOCHAR_COMMENT_1ST    6
  55. #define    LEX_IS_TWOCHAR_COMMENT_2ND    7
  56. #define    LEX_IS_STRINGQUOTE        8
  57. #define    LEX_IS_COLON            9
  58. #define    LEX_IS_NEWLINE            10
  59. #define    LEX_IS_ONECHAR_QUOTE        11
  60. #define IS_SYMBOL_COMPONENT(c)        (lex[c] == LEX_IS_SYMBOL_COMPONENT)
  61. #define IS_WHITESPACE(c)        (lex[c] == LEX_IS_WHITESPACE)
  62. #define IS_LINE_SEPARATOR(c)        (lex[c] == LEX_IS_LINE_SEPARATOR)
  63. #define IS_COMMENT(c)            (lex[c] == LEX_IS_COMMENT_START)
  64. #define IS_LINE_COMMENT(c)        (lex[c] == LEX_IS_LINE_COMMENT_START)
  65. #define    IS_NEWLINE(c)            (lex[c] == LEX_IS_NEWLINE)
  66.  
  67. static int process_escape PARAMS ((int));
  68.  
  69. /* FIXME-soon: The entire lexer/parser thingy should be
  70.    built statically at compile time rather than dynamically
  71.    each and every time the assembler is run.  xoxorich. */
  72.  
  73. void 
  74. do_scrub_begin (m68k_mri)
  75.      int m68k_mri;
  76. {
  77.   const char *p;
  78.  
  79.   scrub_m68k_mri = m68k_mri;
  80.  
  81.   lex[' '] = LEX_IS_WHITESPACE;
  82.   lex['\t'] = LEX_IS_WHITESPACE;
  83.   lex['\n'] = LEX_IS_NEWLINE;
  84.   lex[';'] = LEX_IS_LINE_SEPARATOR;
  85.   lex[':'] = LEX_IS_COLON;
  86.  
  87.   if (! m68k_mri)
  88.     {
  89.       lex['"'] = LEX_IS_STRINGQUOTE;
  90.  
  91. #ifndef TC_HPPA
  92.       lex['\''] = LEX_IS_ONECHAR_QUOTE;
  93. #endif
  94.  
  95. #ifdef SINGLE_QUOTE_STRINGS
  96.       lex['\''] = LEX_IS_STRINGQUOTE;
  97. #endif
  98.     }
  99.  
  100.   /* Note: if any other character can be LEX_IS_STRINGQUOTE, the loop
  101.      in state 5 of do_scrub_chars must be changed.  */
  102.  
  103.   /* Note that these override the previous defaults, e.g. if ';' is a
  104.      comment char, then it isn't a line separator.  */
  105.   for (p = symbol_chars; *p; ++p)
  106.     {
  107.       lex[(unsigned char) *p] = LEX_IS_SYMBOL_COMPONENT;
  108.     }                /* declare symbol characters */
  109.  
  110.   /* The m68k backend wants to be able to change comment_chars.  */
  111. #ifndef tc_comment_chars
  112. #define tc_comment_chars comment_chars
  113. #endif
  114.   for (p = tc_comment_chars; *p; p++)
  115.     {
  116.       lex[(unsigned char) *p] = LEX_IS_COMMENT_START;
  117.     }                /* declare comment chars */
  118.  
  119.   for (p = line_comment_chars; *p; p++)
  120.     {
  121.       lex[(unsigned char) *p] = LEX_IS_LINE_COMMENT_START;
  122.     }                /* declare line comment chars */
  123.  
  124.   for (p = line_separator_chars; *p; p++)
  125.     {
  126.       lex[(unsigned char) *p] = LEX_IS_LINE_SEPARATOR;
  127.     }                /* declare line separators */
  128.  
  129.   /* Only allow slash-star comments if slash is not in use */
  130.   if (lex['/'] == 0)
  131.     {
  132.       lex['/'] = LEX_IS_TWOCHAR_COMMENT_1ST;
  133.     }
  134.   /* FIXME-soon.  This is a bad hack but otherwise, we can't do
  135.      c-style comments when '/' is a line comment char. xoxorich. */
  136.   if (lex['*'] == 0)
  137.     {
  138.       lex['*'] = LEX_IS_TWOCHAR_COMMENT_2ND;
  139.     }
  140.  
  141.   if (m68k_mri)
  142.     {
  143.       lex['\''] = LEX_IS_STRINGQUOTE;
  144.       lex[';'] = LEX_IS_COMMENT_START;
  145.       lex['*'] = LEX_IS_LINE_COMMENT_START;
  146.       /* The MRI documentation says '!' is LEX_IS_COMMENT_START, but
  147.          then it can't be used in an expression.  */
  148.       lex['!'] = LEX_IS_LINE_COMMENT_START;
  149.     }
  150. }                /* do_scrub_begin() */
  151.  
  152. /* Saved state of the scrubber */
  153. static int state;
  154. static int old_state;
  155. static char *out_string;
  156. static char out_buf[20];
  157. static int add_newlines;
  158. static char *saved_input;
  159. static int saved_input_len;
  160. static const char *mri_state;
  161. static char mri_last_ch;
  162.  
  163. /* Data structure for saving the state of app across #include's.  Note that
  164.    app is called asynchronously to the parsing of the .include's, so our
  165.    state at the time .include is interpreted is completely unrelated.
  166.    That's why we have to save it all.  */
  167.  
  168. struct app_save
  169.   {
  170.     int state;
  171.     int old_state;
  172.     char *out_string;
  173.     char out_buf[sizeof (out_buf)];
  174.     int add_newlines;
  175.     char *saved_input;
  176.     int saved_input_len;
  177.     int scrub_m68k_mri;
  178.     const char *mri_state;
  179.     char mri_last_ch;
  180.   };
  181.  
  182. char *
  183. app_push ()
  184. {
  185.   register struct app_save *saved;
  186.  
  187.   saved = (struct app_save *) xmalloc (sizeof (*saved));
  188.   saved->state = state;
  189.   saved->old_state = old_state;
  190.   saved->out_string = out_string;
  191.   memcpy (saved->out_buf, out_buf, sizeof (out_buf));
  192.   saved->add_newlines = add_newlines;
  193.   saved->saved_input = saved_input;
  194.   saved->saved_input_len = saved_input_len;
  195.   saved->scrub_m68k_mri = scrub_m68k_mri;
  196.   saved->mri_state = mri_state;
  197.   saved->mri_last_ch = mri_last_ch;
  198.  
  199.   /* do_scrub_begin() is not useful, just wastes time. */
  200.  
  201.   state = 0;
  202.   saved_input = NULL;
  203.  
  204.   return (char *) saved;
  205. }
  206.  
  207. void 
  208. app_pop (arg)
  209.      char *arg;
  210. {
  211.   register struct app_save *saved = (struct app_save *) arg;
  212.  
  213.   /* There is no do_scrub_end (). */
  214.   state = saved->state;
  215.   old_state = saved->old_state;
  216.   out_string = saved->out_string;
  217.   memcpy (out_buf, saved->out_buf, sizeof (out_buf));
  218.   add_newlines = saved->add_newlines;
  219.   saved_input = saved->saved_input;
  220.   saved_input_len = saved->saved_input_len;
  221.   scrub_m68k_mri = saved->scrub_m68k_mri;
  222.   mri_state = saved->mri_state;
  223.   mri_last_ch = saved->mri_last_ch;
  224.  
  225.   free (arg);
  226. }                /* app_pop() */
  227.  
  228. /* @@ This assumes that \n &c are the same on host and target.  This is not
  229.    necessarily true.  */
  230. static int 
  231. process_escape (ch)
  232.      int ch;
  233. {
  234.   switch (ch)
  235.     {
  236.     case 'b':
  237.       return '\b';
  238.     case 'f':
  239.       return '\f';
  240.     case 'n':
  241.       return '\n';
  242.     case 'r':
  243.       return '\r';
  244.     case 't':
  245.       return '\t';
  246.     case '\'':
  247.       return '\'';
  248.     case '"':
  249.       return '\"';
  250.     default:
  251.       return ch;
  252.     }
  253. }
  254.  
  255. /* This function is called to process input characters.  The GET
  256.    parameter is used to retrieve more input characters.  GET should
  257.    set its parameter to point to a buffer, and return the length of
  258.    the buffer; it should return 0 at end of file.  The scrubbed output
  259.    characters are put into the buffer starting at TOSTART; the TOSTART
  260.    buffer is TOLEN bytes in length.  The function returns the number
  261.    of scrubbed characters put into TOSTART.  This will be TOLEN unless
  262.    end of file was seen.  This function is arranged as a state
  263.    machine, and saves its state so that it may return at any point.
  264.    This is the way the old code used to work.  */
  265.  
  266. int
  267. do_scrub_chars (get, tostart, tolen)
  268.      int (*get) PARAMS ((char **));
  269.      char *tostart;
  270.      int tolen;
  271. {
  272.   char *to = tostart;
  273.   char *toend = tostart + tolen;
  274.   char *from;
  275.   char *fromend;
  276.   int fromlen;
  277.   register int ch, ch2 = 0;
  278.  
  279.   /*State 0: beginning of normal line
  280.       1: After first whitespace on line (flush more white)
  281.       2: After first non-white (opcode) on line (keep 1white)
  282.       3: after second white on line (into operands) (flush white)
  283.       4: after putting out a .line, put out digits
  284.       5: parsing a string, then go to old-state
  285.       6: putting out \ escape in a "d string.
  286.       7: After putting out a .appfile, put out string.
  287.       8: After putting out a .appfile string, flush until newline.
  288.       9: After seeing symbol char in state 3 (keep 1white after symchar)
  289.      10: After seeing whitespace in state 9 (keep white before symchar)
  290.      11: After seeing a symbol character in state 0 (eg a label definition)
  291.      -1: output string in out_string and go to the state in old_state
  292.      -2: flush text until a '*' '/' is seen, then go to state old_state
  293.       */
  294.  
  295.   /* I added states 9 and 10 because the MIPS ECOFF assembler uses
  296.      constructs like ``.loc 1 20''.  This was turning into ``.loc
  297.      120''.  States 9 and 10 ensure that a space is never dropped in
  298.      between characters which could appear in a identifier.  Ian
  299.      Taylor, ian@cygnus.com.
  300.  
  301.      I added state 11 so that something like "Lfoo add %r25,%r26,%r27" works
  302.      correctly on the PA (and any other target where colons are optional).
  303.      Jeff Law, law@cs.utah.edu.  */
  304.  
  305.   /* This macro gets the next input character.  */
  306.  
  307. #define GET()                \
  308.   (from < fromend            \
  309.    ? *from++                \
  310.    : ((saved_input != NULL        \
  311.        ? (free (saved_input),        \
  312.       saved_input = NULL,        \
  313.       0)                \
  314.        : 0),                \
  315.       fromlen = (*get) (&from),        \
  316.       fromend = from + fromlen,        \
  317.       (fromlen == 0            \
  318.        ? EOF                \
  319.        : *from++)))
  320.  
  321.   /* This macro pushes a character back on the input stream.  */
  322.  
  323. #define UNGET(uch) (*--from = (uch))
  324.  
  325.   /* This macro puts a character into the output buffer.  If this
  326.      character fills the output buffer, this macro jumps to the label
  327.      TOFULL.  We use this rather ugly approach because we need to
  328.      handle two different termination conditions: EOF on the input
  329.      stream, and a full output buffer.  It would be simpler if we
  330.      always read in the entire input stream before processing it, but
  331.      I don't want to make such a significant change to the assembler's
  332.      memory usage.  */
  333.  
  334. #define PUT(pch)            \
  335.   do                    \
  336.     {                    \
  337.       *to++ = (pch);            \
  338.       if (to >= toend)            \
  339.         goto tofull;            \
  340.     }                    \
  341.   while (0)
  342.  
  343.   if (saved_input != NULL)
  344.     {
  345.       from = saved_input;
  346.       fromend = from + saved_input_len;
  347.     }
  348.   else
  349.     {
  350.       fromlen = (*get) (&from);
  351.       if (fromlen == 0)
  352.     return 0;
  353.       fromend = from + fromlen;
  354.     }
  355.  
  356.   while (1)
  357.     {
  358.       /* The cases in this switch end with continue, in order to
  359.          branch back to the top of this while loop and generate the
  360.          next output character in the appropriate state.  */
  361.       switch (state)
  362.     {
  363.     case -1:
  364.       ch = *out_string++;
  365.       if (*out_string == '\0')
  366.         {
  367.           state = old_state;
  368.           old_state = 3;
  369.         }
  370.       PUT (ch);
  371.       continue;
  372.  
  373.     case -2:
  374.       for (;;)
  375.         {
  376.           do
  377.         {
  378.           ch = GET ();
  379.  
  380.           if (ch == EOF)
  381.             {
  382.               as_warn ("end of file in comment");
  383.               goto fromeof;
  384.             }
  385.  
  386.           if (ch == '\n')
  387.             PUT ('\n');
  388.         }
  389.           while (ch != '*');
  390.  
  391.           while ((ch = GET ()) == '*')
  392.         ;
  393.  
  394.           if (ch == EOF)
  395.         {
  396.           as_warn ("end of file in comment");
  397.           goto fromeof;
  398.         }
  399.  
  400.           if (ch == '/')
  401.         break;
  402.  
  403.           UNGET (ch);
  404.         }
  405.  
  406.       state = old_state;
  407.       PUT (' ');
  408.       continue;
  409.  
  410.     case 4:
  411.       ch = GET ();
  412.       if (ch == EOF)
  413.         goto fromeof;
  414.       else if (ch >= '0' && ch <= '9')
  415.         PUT (ch);
  416.       else
  417.         {
  418.           while (ch != EOF && IS_WHITESPACE (ch))
  419.         ch = GET ();
  420.           if (ch == '"')
  421.         {
  422.           UNGET (ch);
  423.           if (scrub_m68k_mri)
  424.             out_string = "\n\tappfile ";
  425.           else
  426.             out_string = "\n\t.appfile ";
  427.           old_state = 7;
  428.           state = -1;
  429.           PUT (*out_string++);
  430.         }
  431.           else
  432.         {
  433.           while (ch != EOF && ch != '\n')
  434.             ch = GET ();
  435.           state = 0;
  436.           PUT (ch);
  437.         }
  438.         }
  439.       continue;
  440.  
  441.     case 5:
  442.       /* We are going to copy everything up to a quote character,
  443.              with special handling for a backslash.  We try to
  444.              optimize the copying in the simple case without using the
  445.              GET and PUT macros.  */
  446.       {
  447.         char *s;
  448.         int len;
  449.  
  450.         for (s = from; s < fromend; s++)
  451.           {
  452.         ch = *s;
  453.         /* This condition must be changed if the type of any
  454.                    other character can be LEX_IS_STRINGQUOTE.  */
  455.         if (ch == '\\'
  456.             || ch == '"'
  457.             || ch == '\''
  458.             || ch == '\n')
  459.           break;
  460.           }
  461.         len = s - from;
  462.         if (len > toend - to)
  463.           len = toend - to;
  464.         if (len > 0)
  465.           {
  466.         memcpy (to, from, len);
  467.         to += len;
  468.         from += len;
  469.           }
  470.       }
  471.  
  472.       ch = GET ();
  473.       if (ch == EOF)
  474.         {
  475.           as_warn ("end of file in string: inserted '\"'");
  476.           state = old_state;
  477.           UNGET ('\n');
  478.           PUT ('"');
  479.         }
  480.       else if (lex[ch] == LEX_IS_STRINGQUOTE)
  481.         {
  482.           state = old_state;
  483.           PUT (ch);
  484.         }
  485. #ifndef NO_STRING_ESCAPES
  486.       else if (ch == '\\')
  487.         {
  488.           state = 6;
  489.           PUT (ch);
  490.         }
  491. #endif
  492.       else if (scrub_m68k_mri && ch == '\n')
  493.         {
  494.           /* Just quietly terminate the string.  This permits lines like
  495.            bne    label    loop if we haven't reach end yet
  496.          */
  497.           state = old_state;
  498.           UNGET (ch);
  499.           PUT ('\'');
  500.         }
  501.       else
  502.         {
  503.           PUT (ch);
  504.         }
  505.       continue;
  506.  
  507.     case 6:
  508.       state = 5;
  509.       ch = GET ();
  510.       switch (ch)
  511.         {
  512.           /* Handle strings broken across lines, by turning '\n' into
  513.          '\\' and 'n'.  */
  514.         case '\n':
  515.           UNGET ('n');
  516.           add_newlines++;
  517.           PUT ('\\');
  518.           continue;
  519.  
  520.         case '"':
  521.         case '\\':
  522.         case 'b':
  523.         case 'f':
  524.         case 'n':
  525.         case 'r':
  526.         case 't':
  527.         case 'v':
  528.         case 'x':
  529.         case 'X':
  530.         case '0':
  531.         case '1':
  532.         case '2':
  533.         case '3':
  534.         case '4':
  535.         case '5':
  536.         case '6':
  537.         case '7':
  538.           break;
  539. #if defined(IGNORE_NONSTANDARD_ESCAPES) | defined(ONLY_STANDARD_ESCAPES)
  540.         default:
  541.           as_warn ("Unknown escape '\\%c' in string: Ignored", ch);
  542.           break;
  543. #else  /* ONLY_STANDARD_ESCAPES */
  544.         default:
  545.           /* Accept \x as x for any x */
  546.           break;
  547. #endif /* ONLY_STANDARD_ESCAPES */
  548.  
  549.         case EOF:
  550.           as_warn ("End of file in string: '\"' inserted");
  551.           PUT ('"');
  552.           continue;
  553.         }
  554.       PUT (ch);
  555.       continue;
  556.  
  557.     case 7:
  558.       ch = GET ();
  559.       state = 5;
  560.       old_state = 8;
  561.       if (ch == EOF)
  562.         goto fromeof;
  563.       PUT (ch);
  564.       continue;
  565.  
  566.     case 8:
  567.       do
  568.         ch = GET ();
  569.       while (ch != '\n' && ch != EOF);
  570.       if (ch == EOF)
  571.         goto fromeof;
  572.       state = 0;
  573.       PUT (ch);
  574.       continue;
  575.     }
  576.  
  577.       /* OK, we are somewhere in states 0 through 4 or 9 through 11 */
  578.  
  579.       /* flushchar: */
  580.       ch = GET ();
  581.  
  582.     recycle:
  583.  
  584. #ifdef TC_M68K
  585.       /* We want to have pseudo-ops which control whether we are in
  586.          MRI mode or not.  Unfortunately, since m68k MRI mode affects
  587.          the scrubber, that means that we need a special purpose
  588.          recognizer here.  */
  589.       if (mri_state == NULL)
  590.     {
  591.       if ((state == 0 || state == 1)
  592.           && ch == mri_pseudo[0])
  593.         mri_state = mri_pseudo + 1;
  594.     }
  595.       else
  596.     {
  597.       /* We advance to the next state if we find the right
  598.          character, or if we need a space character and we get any
  599.          whitespace character, or if we need a '0' and we get a
  600.          '1' (this is so that we only need one state to handle
  601.          ``.mri 0'' and ``.mri 1'').  */
  602.       if (ch != '\0'
  603.           && (*mri_state == ch
  604.           || (*mri_state == ' '
  605.               && lex[ch] == LEX_IS_WHITESPACE)
  606.           || (*mri_state == '0'
  607.               && ch == '1')))
  608.         {
  609.           mri_last_ch = ch;
  610.           ++mri_state;
  611.         }
  612.       else if (*mri_state != '\0'
  613.            || (lex[ch] != LEX_IS_WHITESPACE
  614.                && lex[ch] != LEX_IS_NEWLINE))
  615.         {
  616.           /* We did not get the expected character, or we didn't
  617.          get a valid terminating character after seeing the
  618.          entire pseudo-op, so we must go back to the
  619.          beginning.  */
  620.           mri_state = NULL;
  621.         }
  622.       else
  623.         {
  624.           /* We've read the entire pseudo-op.  mips_last_ch is
  625.                  either '0' or '1' indicating whether to enter or
  626.                  leave MRI mode.  */
  627.           do_scrub_begin (mri_last_ch == '1');
  628.  
  629.           /* We continue handling the character as usual.  The
  630.                  main gas reader must also handle the .mri pseudo-op
  631.                  to control expression parsing and the like.  */
  632.         }
  633.     }
  634. #endif
  635.  
  636.       if (ch == EOF)
  637.     {
  638.       if (state != 0)
  639.         {
  640.           as_warn ("end of file not at end of a line; newline inserted");
  641.           state = 0;
  642.           PUT ('\n');
  643.         }
  644.       goto fromeof;
  645.     }
  646.  
  647.       switch (lex[ch])
  648.     {
  649.     case LEX_IS_WHITESPACE:
  650.       do
  651.         {
  652.           ch = GET ();
  653.         }
  654.       while (ch != EOF && IS_WHITESPACE (ch));
  655.       if (ch == EOF)
  656.         goto fromeof;
  657.  
  658.       if (state == 0)
  659.         {
  660.           /* Preserve a single whitespace character at the
  661.          beginning of a line.  */
  662.           state = 1;
  663.           UNGET (ch);
  664.           PUT (' ');
  665.           break;
  666.         }
  667.  
  668.       if (IS_COMMENT (ch)
  669.           || ch == '/'
  670.           || IS_LINE_SEPARATOR (ch))
  671.         {
  672.           if (scrub_m68k_mri)
  673.         {
  674.           /* In MRI mode, we keep these spaces.  */
  675.           UNGET (ch);
  676.           PUT (' ');
  677.           break;
  678.         }
  679.           goto recycle;
  680.         }
  681.  
  682.       /* If we're in state 2 or 11, we've seen a non-white
  683.          character followed by whitespace.  If the next character
  684.          is ':', this is whitespace after a label name which we
  685.          normally must ignore.  In MRI mode, though, spaces are
  686.          not permitted between the label and the colon.  */
  687.       if ((state == 2 || state == 11)
  688.           && lex[ch] == LEX_IS_COLON
  689.           && ! scrub_m68k_mri)
  690.         {
  691.           state = 1;
  692.           PUT (ch);
  693.           break;
  694.         }
  695.  
  696.       switch (state)
  697.         {
  698.         case 0:
  699.           state++;
  700.           goto recycle;    /* Punted leading sp */
  701.         case 1:
  702.           /* We can arrive here if we leave a leading whitespace
  703.          character at the beginning of a line.  */
  704.           goto recycle;
  705.         case 2:
  706.           state = 3;
  707.           if (to + 1 < toend)
  708.         {
  709.           /* Optimize common case by skipping UNGET/GET.  */
  710.           PUT (' ');    /* Sp after opco */
  711.           goto recycle;
  712.         }
  713.           UNGET (ch);
  714.           PUT (' ');
  715.           break;
  716.         case 3:
  717.           if (scrub_m68k_mri)
  718.         {
  719.           /* In MRI mode, we keep these spaces.  */
  720.           UNGET (ch);
  721.           PUT (' ');
  722.           break;
  723.         }
  724.           goto recycle;    /* Sp in operands */
  725.         case 9:
  726.         case 10:
  727.           if (scrub_m68k_mri)
  728.         {
  729.           /* In MRI mode, we keep these spaces.  */
  730.           state = 3;
  731.           UNGET (ch);
  732.           PUT (' ');
  733.           break;
  734.         }
  735.           state = 10;    /* Sp after symbol char */
  736.           goto recycle;
  737.         case 11:
  738.           if (flag_m68k_mri
  739. #ifdef LABELS_WITHOUT_COLONS
  740.           || 1
  741. #endif
  742.           )
  743.         state = 1;
  744.           else
  745.         {
  746.           /* We know that ch is not ':', since we tested that
  747.                      case above.  Therefore this is not a label, so it
  748.                      must be the opcode, and we've just seen the
  749.                      whitespace after it.  */
  750.           state = 3;
  751.         }
  752.           UNGET (ch);
  753.           PUT (' ');    /* Sp after label definition.  */
  754.           break;
  755.         default:
  756.           BAD_CASE (state);
  757.         }
  758.       break;
  759.  
  760.     case LEX_IS_TWOCHAR_COMMENT_1ST:
  761.       ch2 = GET ();
  762.       if (ch2 != EOF && lex[ch2] == LEX_IS_TWOCHAR_COMMENT_2ND)
  763.         {
  764.           for (;;)
  765.         {
  766.           do
  767.             {
  768.               ch2 = GET ();
  769.               if (ch2 != EOF && IS_NEWLINE (ch2))
  770.             add_newlines++;
  771.             }
  772.           while (ch2 != EOF &&
  773.              (lex[ch2] != LEX_IS_TWOCHAR_COMMENT_2ND));
  774.  
  775.           while (ch2 != EOF &&
  776.              (lex[ch2] == LEX_IS_TWOCHAR_COMMENT_2ND))
  777.             {
  778.               ch2 = GET ();
  779.             }
  780.  
  781.           if (ch2 == EOF
  782.               || lex[ch2] == LEX_IS_TWOCHAR_COMMENT_1ST)
  783.             break;
  784.           UNGET (ch2);
  785.         }
  786.           if (ch2 == EOF)
  787.         as_warn ("end of file in multiline comment");
  788.  
  789.           ch = ' ';
  790.           goto recycle;
  791.         }
  792.       else
  793.         {
  794.           if (ch2 != EOF)
  795.         UNGET (ch2);
  796.           if (state == 9 || state == 10)
  797.         state = 3;
  798.           PUT (ch);
  799.         }
  800.       break;
  801.  
  802.     case LEX_IS_STRINGQUOTE:
  803.       if (state == 10)
  804.         {
  805.           /* Preserve the whitespace in foo "bar" */
  806.           UNGET (ch);
  807.           state = 3;
  808.           PUT (' ');
  809.  
  810.           /* PUT didn't jump out.  We could just break, but we
  811.                  know what will happen, so optimize a bit.  */
  812.           ch = GET ();
  813.           old_state = 3;
  814.         }
  815.       else if (state == 9)
  816.         old_state = 3;
  817.       else
  818.         old_state = state;
  819.       state = 5;
  820.       PUT (ch);
  821.       break;
  822.  
  823. #ifndef IEEE_STYLE
  824.     case LEX_IS_ONECHAR_QUOTE:
  825.       if (state == 10)
  826.         {
  827.           /* Preserve the whitespace in foo 'b' */
  828.           UNGET (ch);
  829.           state = 3;
  830.           PUT (' ');
  831.           break;
  832.         }
  833.       ch = GET ();
  834.       if (ch == EOF)
  835.         {
  836.           as_warn ("end of file after a one-character quote; \\0 inserted");
  837.           ch = 0;
  838.         }
  839.       if (ch == '\\')
  840.         {
  841.           ch = GET ();
  842.           if (ch == EOF)
  843.         {
  844.           as_warn ("end of file in escape character");
  845.           ch = '\\';
  846.         }
  847.           else
  848.         ch = process_escape (ch);
  849.         }
  850.       sprintf (out_buf, "%d", (int) (unsigned char) ch);
  851.  
  852.       /* None of these 'x constants for us.  We want 'x'.  */
  853.       if ((ch = GET ()) != '\'')
  854.         {
  855. #ifdef REQUIRE_CHAR_CLOSE_QUOTE
  856.           as_warn ("Missing close quote: (assumed)");
  857. #else
  858.           if (ch != EOF)
  859.         UNGET (ch);
  860. #endif
  861.         }
  862.       if (strlen (out_buf) == 1)
  863.         {
  864.           PUT (out_buf[0]);
  865.           break;
  866.         }
  867.       if (state == 9)
  868.         old_state = 3;
  869.       else
  870.         old_state = state;
  871.       state = -1;
  872.       out_string = out_buf;
  873.       PUT (*out_string++);
  874.       break;
  875. #endif
  876.  
  877.     case LEX_IS_COLON:
  878.       if (state == 9 || state == 10)
  879.         state = 3;
  880.       else if (state != 3)
  881.         state = 1;
  882.       PUT (ch);
  883.       break;
  884.  
  885.     case LEX_IS_NEWLINE:
  886.       /* Roll out a bunch of newlines from inside comments, etc.  */
  887.       if (add_newlines)
  888.         {
  889.           --add_newlines;
  890.           UNGET (ch);
  891.         }
  892.       /* fall thru into... */
  893.  
  894.     case LEX_IS_LINE_SEPARATOR:
  895.       state = 0;
  896.       PUT (ch);
  897.       break;
  898.  
  899.     case LEX_IS_LINE_COMMENT_START:
  900.       /* FIXME-someday: The two character comment stuff was badly
  901.          thought out.  On i386, we want '/' as line comment start
  902.          AND we want C style comments.  hence this hack.  The
  903.          whole lexical process should be reworked.  xoxorich.  */
  904.       if (ch == '/')
  905.         {
  906.           ch2 = GET ();
  907.           if (ch2 == '*')
  908.         {
  909.           state = -2;
  910.           break;
  911.         }
  912.           else
  913.         {
  914.           UNGET (ch2);
  915.         }
  916.         } /* bad hack */
  917.  
  918.       if (state == 0 || state == 1)    /* Only comment at start of line.  */
  919.         {
  920.           int startch;
  921.  
  922.           startch = ch;
  923.  
  924.           do
  925.         {
  926.           ch = GET ();
  927.         }
  928.           while (ch != EOF && IS_WHITESPACE (ch));
  929.           if (ch == EOF)
  930.         {
  931.           as_warn ("end of file in comment; newline inserted");
  932.           PUT ('\n');
  933.           break;
  934.         }
  935.           if (ch < '0' || ch > '9' || state != 0 || startch != '#')
  936.         {
  937.           /* Not a CPP line.  */
  938.           while (ch != EOF && !IS_NEWLINE (ch))
  939.             ch = GET ();
  940.           if (ch == EOF)
  941.             as_warn ("EOF in Comment: Newline inserted");
  942.           state = 0;
  943.           PUT ('\n');
  944.           break;
  945.         }
  946.           /* Loks like `# 123 "filename"' from cpp.  */
  947.           UNGET (ch);
  948.           old_state = 4;
  949.           state = -1;
  950.           if (scrub_m68k_mri)
  951.         out_string = "\tappline ";
  952.           else
  953.         out_string = "\t.appline ";
  954.           PUT (*out_string++);
  955.           break;
  956.         }
  957.  
  958.       /* We have a line comment character which is not at the
  959.          start of a line.  If this is also a normal comment
  960.          character, fall through.  Otherwise treat it as a default
  961.          character.  */
  962.       if (strchr (tc_comment_chars, ch) == NULL
  963.           && (! scrub_m68k_mri
  964.           || (ch != '!' && ch != '*')))
  965.         goto de_fault;
  966.       if (scrub_m68k_mri
  967.           && (ch == '!' || ch == '*' || ch == '#')
  968.           && state != 1
  969.           && state != 10)
  970.         goto de_fault;
  971.       /* Fall through.  */
  972.     case LEX_IS_COMMENT_START:
  973.       do
  974.         {
  975.           ch = GET ();
  976.         }
  977.       while (ch != EOF && !IS_NEWLINE (ch));
  978.       if (ch == EOF)
  979.         as_warn ("end of file in comment; newline inserted");
  980.       state = 0;
  981.       PUT ('\n');
  982.       break;
  983.  
  984.     case LEX_IS_SYMBOL_COMPONENT:
  985.       if (state == 10)
  986.         {
  987.           /* This is a symbol character following another symbol
  988.          character, with whitespace in between.  We skipped
  989.          the whitespace earlier, so output it now.  */
  990.           UNGET (ch);
  991.           state = 3;
  992.           PUT (' ');
  993.           break;
  994.         }
  995.  
  996.       if (state == 3)
  997.         state = 9;
  998.  
  999.       /* This is a common case.  Quickly copy CH and all the
  1000.              following symbol component or normal characters.  */
  1001.       if (to + 1 < toend && mri_state == NULL)
  1002.         {
  1003.           char *s;
  1004.           int len;
  1005.  
  1006.           for (s = from; s < fromend; s++)
  1007.         {
  1008.           int type;
  1009.  
  1010.           ch2 = *s;
  1011.           type = lex[ch2];
  1012.           if (type != 0
  1013.               && type != LEX_IS_SYMBOL_COMPONENT)
  1014.             break;
  1015.         }
  1016.           if (s > from)
  1017.         {
  1018.           /* Handle the last character normally, for
  1019.                      simplicity.  */
  1020.           --s;
  1021.         }
  1022.           len = s - from;
  1023.           if (len > (toend - to) - 1)
  1024.         len = (toend - to) - 1;
  1025.           if (len > 0)
  1026.         {
  1027.           PUT (ch);
  1028.           if (len > 8)
  1029.             {
  1030.               memcpy (to, from, len);
  1031.               to += len;
  1032.               from += len;
  1033.             }
  1034.           else
  1035.             {
  1036.               switch (len)
  1037.             {
  1038.             case 8: *to++ = *from++;
  1039.             case 7: *to++ = *from++;
  1040.             case 6: *to++ = *from++;
  1041.             case 5: *to++ = *from++;
  1042.             case 4: *to++ = *from++;
  1043.             case 3: *to++ = *from++;
  1044.             case 2: *to++ = *from++;
  1045.             case 1: *to++ = *from++;
  1046.             }
  1047.             } 
  1048.           ch = GET ();
  1049.         }
  1050.         }
  1051.  
  1052.       /* Fall through.  */
  1053.     default:
  1054.     de_fault:
  1055.       /* Some relatively `normal' character.  */
  1056.       if (state == 0)
  1057.         {
  1058.           state = 11;    /* Now seeing label definition */
  1059.         }
  1060.       else if (state == 1)
  1061.         {
  1062.           state = 2;    /* Ditto */
  1063.         }
  1064.       else if (state == 9)
  1065.         {
  1066.           if (lex[ch] != LEX_IS_SYMBOL_COMPONENT)
  1067.         state = 3;
  1068.         }
  1069.       else if (state == 10)
  1070.         {
  1071.           state = 3;
  1072.         }
  1073.       PUT (ch);
  1074.       break;
  1075.     }
  1076.     }
  1077.  
  1078.   /*NOTREACHED*/
  1079.  
  1080.  fromeof:
  1081.   /* We have reached the end of the input.  */
  1082.   return to - tostart;
  1083.  
  1084.  tofull:
  1085.   /* The output buffer is full.  Save any input we have not yet
  1086.      processed.  */
  1087.   if (fromend > from)
  1088.     {
  1089.       char *save;
  1090.  
  1091.       save = (char *) xmalloc (fromend - from);
  1092.       memcpy (save, from, fromend - from);
  1093.       if (saved_input != NULL)
  1094.     free (saved_input);
  1095.       saved_input = save;
  1096.       saved_input_len = fromend - from;
  1097.     }
  1098.   else
  1099.     {
  1100.       if (saved_input != NULL)
  1101.     {
  1102.       free (saved_input);
  1103.       saved_input = NULL;
  1104.     }
  1105.     }
  1106.   return to - tostart;
  1107. }
  1108.  
  1109. /* end of app.c */
  1110.