app.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. /* This is the Assembler Pre-Processor
  2. Copyright (C) 1987-2022 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  11. License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to the Free
  14. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. /* Modified by Allen Wirfs-Brock, Instantiations Inc 2/90. */
  17. /* App, the assembler pre-processor. This pre-processor strips out
  18. excess spaces, turns single-quoted characters into a decimal
  19. constant, and turns the # in # <number> <filename> <garbage> into a
  20. .linefile. This needs better error-handling. */
  21. #include "as.h"
  22. #if (__STDC__ != 1)
  23. #ifndef const
  24. #define const /* empty */
  25. #endif
  26. #endif
  27. #ifdef H_TICK_HEX
  28. int enable_h_tick_hex = 0;
  29. #endif
  30. #ifdef TC_M68K
  31. /* Whether we are scrubbing in m68k MRI mode. This is different from
  32. flag_m68k_mri, because the two flags will be affected by the .mri
  33. pseudo-op at different times. */
  34. static int scrub_m68k_mri;
  35. /* The pseudo-op which switches in and out of MRI mode. See the
  36. comment in do_scrub_chars. */
  37. static const char mri_pseudo[] = ".mri 0";
  38. #else
  39. #define scrub_m68k_mri 0
  40. #endif
  41. #if defined TC_ARM && defined OBJ_ELF
  42. /* The pseudo-op for which we need to special-case `@' characters.
  43. See the comment in do_scrub_chars. */
  44. static const char symver_pseudo[] = ".symver";
  45. static const char * symver_state;
  46. #endif
  47. static char last_char;
  48. static char lex[256];
  49. static const char symbol_chars[] =
  50. "$._ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  51. #define LEX_IS_SYMBOL_COMPONENT 1
  52. #define LEX_IS_WHITESPACE 2
  53. #define LEX_IS_LINE_SEPARATOR 3
  54. #define LEX_IS_COMMENT_START 4
  55. #define LEX_IS_LINE_COMMENT_START 5
  56. #define LEX_IS_TWOCHAR_COMMENT_1ST 6
  57. #define LEX_IS_STRINGQUOTE 8
  58. #define LEX_IS_COLON 9
  59. #define LEX_IS_NEWLINE 10
  60. #define LEX_IS_ONECHAR_QUOTE 11
  61. #ifdef TC_V850
  62. #define LEX_IS_DOUBLEDASH_1ST 12
  63. #endif
  64. #ifdef TC_M32R
  65. #define DOUBLEBAR_PARALLEL
  66. #endif
  67. #ifdef DOUBLEBAR_PARALLEL
  68. #define LEX_IS_DOUBLEBAR_1ST 13
  69. #endif
  70. #define LEX_IS_PARALLEL_SEPARATOR 14
  71. #ifdef H_TICK_HEX
  72. #define LEX_IS_H 15
  73. #endif
  74. #define IS_SYMBOL_COMPONENT(c) (lex[c] == LEX_IS_SYMBOL_COMPONENT)
  75. #define IS_WHITESPACE(c) (lex[c] == LEX_IS_WHITESPACE)
  76. #define IS_LINE_SEPARATOR(c) (lex[c] == LEX_IS_LINE_SEPARATOR)
  77. #define IS_PARALLEL_SEPARATOR(c) (lex[c] == LEX_IS_PARALLEL_SEPARATOR)
  78. #define IS_COMMENT(c) (lex[c] == LEX_IS_COMMENT_START)
  79. #define IS_LINE_COMMENT(c) (lex[c] == LEX_IS_LINE_COMMENT_START)
  80. #define IS_NEWLINE(c) (lex[c] == LEX_IS_NEWLINE)
  81. static int process_escape (int);
  82. /* FIXME-soon: The entire lexer/parser thingy should be
  83. built statically at compile time rather than dynamically
  84. each and every time the assembler is run. xoxorich. */
  85. void
  86. do_scrub_begin (int m68k_mri ATTRIBUTE_UNUSED)
  87. {
  88. const char *p;
  89. int c;
  90. lex[' '] = LEX_IS_WHITESPACE;
  91. lex['\t'] = LEX_IS_WHITESPACE;
  92. lex['\r'] = LEX_IS_WHITESPACE;
  93. lex['\n'] = LEX_IS_NEWLINE;
  94. lex[':'] = LEX_IS_COLON;
  95. #ifdef TC_M68K
  96. scrub_m68k_mri = m68k_mri;
  97. if (! m68k_mri)
  98. #endif
  99. {
  100. lex['"'] = LEX_IS_STRINGQUOTE;
  101. #if ! defined (TC_HPPA)
  102. lex['\''] = LEX_IS_ONECHAR_QUOTE;
  103. #endif
  104. #ifdef SINGLE_QUOTE_STRINGS
  105. lex['\''] = LEX_IS_STRINGQUOTE;
  106. #endif
  107. }
  108. /* Note: if any other character can be LEX_IS_STRINGQUOTE, the loop
  109. in state 5 of do_scrub_chars must be changed. */
  110. /* Note that these override the previous defaults, e.g. if ';' is a
  111. comment char, then it isn't a line separator. */
  112. for (p = symbol_chars; *p; ++p)
  113. lex[(unsigned char) *p] = LEX_IS_SYMBOL_COMPONENT;
  114. for (c = 128; c < 256; ++c)
  115. lex[c] = LEX_IS_SYMBOL_COMPONENT;
  116. #ifdef tc_symbol_chars
  117. /* This macro permits the processor to specify all characters which
  118. may appears in an operand. This will prevent the scrubber from
  119. discarding meaningful whitespace in certain cases. The i386
  120. backend uses this to support prefixes, which can confuse the
  121. scrubber as to whether it is parsing operands or opcodes. */
  122. for (p = tc_symbol_chars; *p; ++p)
  123. lex[(unsigned char) *p] = LEX_IS_SYMBOL_COMPONENT;
  124. #endif
  125. /* The m68k backend wants to be able to change comment_chars. */
  126. #ifndef tc_comment_chars
  127. #define tc_comment_chars comment_chars
  128. #endif
  129. for (p = tc_comment_chars; *p; p++)
  130. lex[(unsigned char) *p] = LEX_IS_COMMENT_START;
  131. for (p = line_comment_chars; *p; p++)
  132. lex[(unsigned char) *p] = LEX_IS_LINE_COMMENT_START;
  133. #ifndef tc_line_separator_chars
  134. #define tc_line_separator_chars line_separator_chars
  135. #endif
  136. for (p = tc_line_separator_chars; *p; p++)
  137. lex[(unsigned char) *p] = LEX_IS_LINE_SEPARATOR;
  138. #ifdef tc_parallel_separator_chars
  139. /* This macro permits the processor to specify all characters which
  140. separate parallel insns on the same line. */
  141. for (p = tc_parallel_separator_chars; *p; p++)
  142. lex[(unsigned char) *p] = LEX_IS_PARALLEL_SEPARATOR;
  143. #endif
  144. /* Only allow slash-star comments if slash is not in use.
  145. FIXME: This isn't right. We should always permit them. */
  146. if (lex['/'] == 0)
  147. lex['/'] = LEX_IS_TWOCHAR_COMMENT_1ST;
  148. #ifdef TC_M68K
  149. if (m68k_mri)
  150. {
  151. lex['\''] = LEX_IS_STRINGQUOTE;
  152. lex[';'] = LEX_IS_COMMENT_START;
  153. lex['*'] = LEX_IS_LINE_COMMENT_START;
  154. /* The MRI documentation says '!' is LEX_IS_COMMENT_START, but
  155. then it can't be used in an expression. */
  156. lex['!'] = LEX_IS_LINE_COMMENT_START;
  157. }
  158. #endif
  159. #ifdef TC_V850
  160. lex['-'] = LEX_IS_DOUBLEDASH_1ST;
  161. #endif
  162. #ifdef DOUBLEBAR_PARALLEL
  163. lex['|'] = LEX_IS_DOUBLEBAR_1ST;
  164. #endif
  165. #ifdef TC_D30V
  166. /* Must do this is we want VLIW instruction with "->" or "<-". */
  167. lex['-'] = LEX_IS_SYMBOL_COMPONENT;
  168. #endif
  169. #ifdef H_TICK_HEX
  170. if (enable_h_tick_hex)
  171. {
  172. lex['h'] = LEX_IS_H;
  173. lex['H'] = LEX_IS_H;
  174. }
  175. #endif
  176. }
  177. /* Saved state of the scrubber. */
  178. static int state;
  179. static int old_state;
  180. static const char *out_string;
  181. static char out_buf[20];
  182. static int add_newlines;
  183. static char *saved_input;
  184. static size_t saved_input_len;
  185. static char input_buffer[32 * 1024];
  186. static const char *mri_state;
  187. static char mri_last_ch;
  188. /* Data structure for saving the state of app across #include's. Note that
  189. app is called asynchronously to the parsing of the .include's, so our
  190. state at the time .include is interpreted is completely unrelated.
  191. That's why we have to save it all. */
  192. struct app_save
  193. {
  194. int state;
  195. int old_state;
  196. const char * out_string;
  197. char out_buf[sizeof (out_buf)];
  198. int add_newlines;
  199. char * saved_input;
  200. size_t saved_input_len;
  201. #ifdef TC_M68K
  202. int scrub_m68k_mri;
  203. #endif
  204. const char * mri_state;
  205. char mri_last_ch;
  206. #if defined TC_ARM && defined OBJ_ELF
  207. const char * symver_state;
  208. #endif
  209. char last_char;
  210. };
  211. char *
  212. app_push (void)
  213. {
  214. struct app_save *saved;
  215. saved = XNEW (struct app_save);
  216. saved->state = state;
  217. saved->old_state = old_state;
  218. saved->out_string = out_string;
  219. memcpy (saved->out_buf, out_buf, sizeof (out_buf));
  220. saved->add_newlines = add_newlines;
  221. if (saved_input == NULL)
  222. saved->saved_input = NULL;
  223. else
  224. {
  225. saved->saved_input = XNEWVEC (char, saved_input_len);
  226. memcpy (saved->saved_input, saved_input, saved_input_len);
  227. saved->saved_input_len = saved_input_len;
  228. }
  229. #ifdef TC_M68K
  230. saved->scrub_m68k_mri = scrub_m68k_mri;
  231. #endif
  232. saved->mri_state = mri_state;
  233. saved->mri_last_ch = mri_last_ch;
  234. #if defined TC_ARM && defined OBJ_ELF
  235. saved->symver_state = symver_state;
  236. #endif
  237. saved->last_char = last_char;
  238. /* do_scrub_begin() is not useful, just wastes time. */
  239. state = 0;
  240. saved_input = NULL;
  241. add_newlines = 0;
  242. return (char *) saved;
  243. }
  244. void
  245. app_pop (char *arg)
  246. {
  247. struct app_save *saved = (struct app_save *) arg;
  248. /* There is no do_scrub_end (). */
  249. state = saved->state;
  250. old_state = saved->old_state;
  251. out_string = saved->out_string;
  252. memcpy (out_buf, saved->out_buf, sizeof (out_buf));
  253. add_newlines = saved->add_newlines;
  254. if (saved->saved_input == NULL)
  255. saved_input = NULL;
  256. else
  257. {
  258. gas_assert (saved->saved_input_len <= sizeof (input_buffer));
  259. memcpy (input_buffer, saved->saved_input, saved->saved_input_len);
  260. saved_input = input_buffer;
  261. saved_input_len = saved->saved_input_len;
  262. free (saved->saved_input);
  263. }
  264. #ifdef TC_M68K
  265. scrub_m68k_mri = saved->scrub_m68k_mri;
  266. #endif
  267. mri_state = saved->mri_state;
  268. mri_last_ch = saved->mri_last_ch;
  269. #if defined TC_ARM && defined OBJ_ELF
  270. symver_state = saved->symver_state;
  271. #endif
  272. last_char = saved->last_char;
  273. free (arg);
  274. }
  275. /* @@ This assumes that \n &c are the same on host and target. This is not
  276. necessarily true. */
  277. static int
  278. process_escape (int ch)
  279. {
  280. switch (ch)
  281. {
  282. case 'b':
  283. return '\b';
  284. case 'f':
  285. return '\f';
  286. case 'n':
  287. return '\n';
  288. case 'r':
  289. return '\r';
  290. case 't':
  291. return '\t';
  292. case '\'':
  293. return '\'';
  294. case '"':
  295. return '\"';
  296. default:
  297. return ch;
  298. }
  299. }
  300. #define MULTIBYTE_WARN_COUNT_LIMIT 10
  301. static unsigned int multibyte_warn_count = 0;
  302. bool
  303. scan_for_multibyte_characters (const unsigned char * start,
  304. const unsigned char * end,
  305. bool warn)
  306. {
  307. if (end <= start)
  308. return false;
  309. if (warn && multibyte_warn_count > MULTIBYTE_WARN_COUNT_LIMIT)
  310. return false;
  311. bool found = false;
  312. while (start < end)
  313. {
  314. unsigned char c;
  315. if ((c = * start++) <= 0x7f)
  316. continue;
  317. if (!warn)
  318. return true;
  319. found = true;
  320. const char * filename;
  321. unsigned int lineno;
  322. filename = as_where (& lineno);
  323. if (filename == NULL)
  324. as_warn (_("multibyte character (%#x) encountered in input"), c);
  325. else if (lineno == 0)
  326. as_warn (_("multibyte character (%#x) encountered in %s"), c, filename);
  327. else
  328. as_warn (_("multibyte character (%#x) encountered in %s at or near line %u"), c, filename, lineno);
  329. if (++ multibyte_warn_count == MULTIBYTE_WARN_COUNT_LIMIT)
  330. {
  331. as_warn (_("further multibyte character warnings suppressed"));
  332. break;
  333. }
  334. }
  335. return found;
  336. }
  337. /* This function is called to process input characters. The GET
  338. parameter is used to retrieve more input characters. GET should
  339. set its parameter to point to a buffer, and return the length of
  340. the buffer; it should return 0 at end of file. The scrubbed output
  341. characters are put into the buffer starting at TOSTART; the TOSTART
  342. buffer is TOLEN bytes in length. The function returns the number
  343. of scrubbed characters put into TOSTART. This will be TOLEN unless
  344. end of file was seen. This function is arranged as a state
  345. machine, and saves its state so that it may return at any point.
  346. This is the way the old code used to work. */
  347. size_t
  348. do_scrub_chars (size_t (*get) (char *, size_t), char *tostart, size_t tolen)
  349. {
  350. char *to = tostart;
  351. char *toend = tostart + tolen;
  352. char *from;
  353. char *fromend;
  354. size_t fromlen;
  355. int ch, ch2 = 0;
  356. /* Character that started the string we're working on. */
  357. static char quotechar;
  358. /*State 0: beginning of normal line
  359. 1: After first whitespace on line (flush more white)
  360. 2: After first non-white (opcode) on line (keep 1white)
  361. 3: after second white on line (into operands) (flush white)
  362. 4: after putting out a .linefile, put out digits
  363. 5: parsing a string, then go to old-state
  364. 6: putting out \ escape in a "d string.
  365. 7: no longer used
  366. 8: no longer used
  367. 9: After seeing symbol char in state 3 (keep 1white after symchar)
  368. 10: After seeing whitespace in state 9 (keep white before symchar)
  369. 11: After seeing a symbol character in state 0 (eg a label definition)
  370. -1: output string in out_string and go to the state in old_state
  371. -2: flush text until a '*' '/' is seen, then go to state old_state
  372. #ifdef TC_V850
  373. 12: After seeing a dash, looking for a second dash as a start
  374. of comment.
  375. #endif
  376. #ifdef DOUBLEBAR_PARALLEL
  377. 13: After seeing a vertical bar, looking for a second
  378. vertical bar as a parallel expression separator.
  379. #endif
  380. #ifdef TC_PREDICATE_START_CHAR
  381. 14: After seeing a predicate start character at state 0, looking
  382. for a predicate end character as predicate.
  383. 15: After seeing a predicate start character at state 1, looking
  384. for a predicate end character as predicate.
  385. #endif
  386. #ifdef TC_Z80
  387. 16: After seeing an 'a' or an 'A' at the start of a symbol
  388. 17: After seeing an 'f' or an 'F' in state 16
  389. #endif
  390. */
  391. /* I added states 9 and 10 because the MIPS ECOFF assembler uses
  392. constructs like ``.loc 1 20''. This was turning into ``.loc
  393. 120''. States 9 and 10 ensure that a space is never dropped in
  394. between characters which could appear in an identifier. Ian
  395. Taylor, ian@cygnus.com.
  396. I added state 11 so that something like "Lfoo add %r25,%r26,%r27" works
  397. correctly on the PA (and any other target where colons are optional).
  398. Jeff Law, law@cs.utah.edu.
  399. I added state 13 so that something like "cmp r1, r2 || trap #1" does not
  400. get squashed into "cmp r1,r2||trap#1", with the all important space
  401. between the 'trap' and the '#1' being eliminated. nickc@cygnus.com */
  402. /* This macro gets the next input character. */
  403. #define GET() \
  404. (from < fromend \
  405. ? * (unsigned char *) (from++) \
  406. : (saved_input = NULL, \
  407. fromlen = (*get) (input_buffer, sizeof input_buffer), \
  408. from = input_buffer, \
  409. fromend = from + fromlen, \
  410. (fromlen == 0 \
  411. ? EOF \
  412. : * (unsigned char *) (from++))))
  413. /* This macro pushes a character back on the input stream. */
  414. #define UNGET(uch) (*--from = (uch))
  415. /* This macro puts a character into the output buffer. If this
  416. character fills the output buffer, this macro jumps to the label
  417. TOFULL. We use this rather ugly approach because we need to
  418. handle two different termination conditions: EOF on the input
  419. stream, and a full output buffer. It would be simpler if we
  420. always read in the entire input stream before processing it, but
  421. I don't want to make such a significant change to the assembler's
  422. memory usage. */
  423. #define PUT(pch) \
  424. do \
  425. { \
  426. *to++ = (pch); \
  427. if (to >= toend) \
  428. goto tofull; \
  429. } \
  430. while (0)
  431. if (saved_input != NULL)
  432. {
  433. from = saved_input;
  434. fromend = from + saved_input_len;
  435. }
  436. else
  437. {
  438. fromlen = (*get) (input_buffer, sizeof input_buffer);
  439. if (fromlen == 0)
  440. return 0;
  441. from = input_buffer;
  442. fromend = from + fromlen;
  443. if (multibyte_handling == multibyte_warn)
  444. (void) scan_for_multibyte_characters ((const unsigned char *) from,
  445. (const unsigned char* ) fromend,
  446. true /* Generate warnings. */);
  447. }
  448. while (1)
  449. {
  450. /* The cases in this switch end with continue, in order to
  451. branch back to the top of this while loop and generate the
  452. next output character in the appropriate state. */
  453. switch (state)
  454. {
  455. case -1:
  456. ch = *out_string++;
  457. if (*out_string == '\0')
  458. {
  459. state = old_state;
  460. old_state = 3;
  461. }
  462. PUT (ch);
  463. continue;
  464. case -2:
  465. for (;;)
  466. {
  467. do
  468. {
  469. ch = GET ();
  470. if (ch == EOF)
  471. {
  472. as_warn (_("end of file in comment"));
  473. goto fromeof;
  474. }
  475. if (ch == '\n')
  476. PUT ('\n');
  477. }
  478. while (ch != '*');
  479. while ((ch = GET ()) == '*')
  480. ;
  481. if (ch == EOF)
  482. {
  483. as_warn (_("end of file in comment"));
  484. goto fromeof;
  485. }
  486. if (ch == '/')
  487. break;
  488. UNGET (ch);
  489. }
  490. state = old_state;
  491. UNGET (' ');
  492. continue;
  493. case 4:
  494. ch = GET ();
  495. if (ch == EOF)
  496. goto fromeof;
  497. else if (ch >= '0' && ch <= '9')
  498. PUT (ch);
  499. else
  500. {
  501. while (ch != EOF && IS_WHITESPACE (ch))
  502. ch = GET ();
  503. if (ch == '"')
  504. {
  505. quotechar = ch;
  506. state = 5;
  507. old_state = 3;
  508. PUT (ch);
  509. }
  510. else
  511. {
  512. while (ch != EOF && ch != '\n')
  513. ch = GET ();
  514. state = 0;
  515. PUT (ch);
  516. }
  517. }
  518. continue;
  519. case 5:
  520. /* We are going to copy everything up to a quote character,
  521. with special handling for a backslash. We try to
  522. optimize the copying in the simple case without using the
  523. GET and PUT macros. */
  524. {
  525. char *s;
  526. ptrdiff_t len;
  527. for (s = from; s < fromend; s++)
  528. {
  529. ch = *s;
  530. if (ch == '\\'
  531. || ch == quotechar
  532. || ch == '\n')
  533. break;
  534. }
  535. len = s - from;
  536. if (len > toend - to)
  537. len = toend - to;
  538. if (len > 0)
  539. {
  540. memcpy (to, from, len);
  541. to += len;
  542. from += len;
  543. if (to >= toend)
  544. goto tofull;
  545. }
  546. }
  547. ch = GET ();
  548. if (ch == EOF)
  549. {
  550. /* This buffer is here specifically so
  551. that the UNGET below will work. */
  552. static char one_char_buf[1];
  553. as_warn (_("end of file in string; '%c' inserted"), quotechar);
  554. state = old_state;
  555. from = fromend = one_char_buf + 1;
  556. fromlen = 1;
  557. UNGET ('\n');
  558. PUT (quotechar);
  559. }
  560. else if (ch == quotechar)
  561. {
  562. state = old_state;
  563. PUT (ch);
  564. }
  565. else if (TC_STRING_ESCAPES && ch == '\\')
  566. {
  567. state = 6;
  568. PUT (ch);
  569. }
  570. else if (scrub_m68k_mri && ch == '\n')
  571. {
  572. /* Just quietly terminate the string. This permits lines like
  573. bne label loop if we haven't reach end yet. */
  574. state = old_state;
  575. UNGET (ch);
  576. PUT ('\'');
  577. }
  578. else
  579. {
  580. PUT (ch);
  581. }
  582. continue;
  583. case 6:
  584. state = 5;
  585. ch = GET ();
  586. switch (ch)
  587. {
  588. /* Handle strings broken across lines, by turning '\n' into
  589. '\\' and 'n'. */
  590. case '\n':
  591. UNGET ('n');
  592. add_newlines++;
  593. PUT ('\\');
  594. continue;
  595. case EOF:
  596. as_warn (_("end of file in string; '%c' inserted"), quotechar);
  597. PUT (quotechar);
  598. continue;
  599. case '"':
  600. case '\\':
  601. case 'b':
  602. case 'f':
  603. case 'n':
  604. case 'r':
  605. case 't':
  606. case 'v':
  607. case 'x':
  608. case 'X':
  609. case '0':
  610. case '1':
  611. case '2':
  612. case '3':
  613. case '4':
  614. case '5':
  615. case '6':
  616. case '7':
  617. break;
  618. default:
  619. #ifdef ONLY_STANDARD_ESCAPES
  620. as_warn (_("unknown escape '\\%c' in string; ignored"), ch);
  621. #endif
  622. break;
  623. }
  624. PUT (ch);
  625. continue;
  626. #ifdef DOUBLEBAR_PARALLEL
  627. case 13:
  628. ch = GET ();
  629. if (ch != '|')
  630. abort ();
  631. /* Reset back to state 1 and pretend that we are parsing a
  632. line from just after the first white space. */
  633. state = 1;
  634. PUT ('|');
  635. #ifdef TC_TIC6X
  636. /* "||^" is used for SPMASKed instructions. */
  637. ch = GET ();
  638. if (ch == EOF)
  639. goto fromeof;
  640. else if (ch == '^')
  641. PUT ('^');
  642. else
  643. UNGET (ch);
  644. #endif
  645. continue;
  646. #endif
  647. #ifdef TC_Z80
  648. case 16:
  649. /* We have seen an 'a' at the start of a symbol, look for an 'f'. */
  650. ch = GET ();
  651. if (ch == 'f' || ch == 'F')
  652. {
  653. state = 17;
  654. PUT (ch);
  655. }
  656. else
  657. {
  658. if (ch != EOF)
  659. UNGET (ch);
  660. state = 9;
  661. break;
  662. }
  663. /* Fall through. */
  664. case 17:
  665. /* We have seen "af" at the start of a symbol,
  666. a ' here is a part of that symbol. */
  667. ch = GET ();
  668. state = 9;
  669. if (ch == '\'')
  670. /* Change to avoid warning about unclosed string. */
  671. PUT ('`');
  672. else if (ch != EOF)
  673. UNGET (ch);
  674. break;
  675. #endif
  676. }
  677. /* OK, we are somewhere in states 0 through 4 or 9 through 11. */
  678. /* flushchar: */
  679. ch = GET ();
  680. #ifdef TC_PREDICATE_START_CHAR
  681. if (ch == TC_PREDICATE_START_CHAR && (state == 0 || state == 1))
  682. {
  683. state += 14;
  684. PUT (ch);
  685. continue;
  686. }
  687. else if (state == 14 || state == 15)
  688. {
  689. if (ch == TC_PREDICATE_END_CHAR)
  690. {
  691. state -= 14;
  692. PUT (ch);
  693. ch = GET ();
  694. }
  695. else
  696. {
  697. PUT (ch);
  698. continue;
  699. }
  700. }
  701. #endif
  702. recycle:
  703. #if defined TC_ARM && defined OBJ_ELF
  704. /* We need to watch out for .symver directives. See the comment later
  705. in this function. */
  706. if (symver_state == NULL)
  707. {
  708. if ((state == 0 || state == 1) && ch == symver_pseudo[0])
  709. symver_state = symver_pseudo + 1;
  710. }
  711. else
  712. {
  713. /* We advance to the next state if we find the right
  714. character. */
  715. if (ch != '\0' && (*symver_state == ch))
  716. ++symver_state;
  717. else if (*symver_state != '\0')
  718. /* We did not get the expected character, or we didn't
  719. get a valid terminating character after seeing the
  720. entire pseudo-op, so we must go back to the beginning. */
  721. symver_state = NULL;
  722. else
  723. {
  724. /* We've read the entire pseudo-op. If this is the end
  725. of the line, go back to the beginning. */
  726. if (IS_NEWLINE (ch))
  727. symver_state = NULL;
  728. }
  729. }
  730. #endif /* TC_ARM && OBJ_ELF */
  731. #ifdef TC_M68K
  732. /* We want to have pseudo-ops which control whether we are in
  733. MRI mode or not. Unfortunately, since m68k MRI mode affects
  734. the scrubber, that means that we need a special purpose
  735. recognizer here. */
  736. if (mri_state == NULL)
  737. {
  738. if ((state == 0 || state == 1)
  739. && ch == mri_pseudo[0])
  740. mri_state = mri_pseudo + 1;
  741. }
  742. else
  743. {
  744. /* We advance to the next state if we find the right
  745. character, or if we need a space character and we get any
  746. whitespace character, or if we need a '0' and we get a
  747. '1' (this is so that we only need one state to handle
  748. ``.mri 0'' and ``.mri 1''). */
  749. if (ch != '\0'
  750. && (*mri_state == ch
  751. || (*mri_state == ' '
  752. && lex[ch] == LEX_IS_WHITESPACE)
  753. || (*mri_state == '0'
  754. && ch == '1')))
  755. {
  756. mri_last_ch = ch;
  757. ++mri_state;
  758. }
  759. else if (*mri_state != '\0'
  760. || (lex[ch] != LEX_IS_WHITESPACE
  761. && lex[ch] != LEX_IS_NEWLINE))
  762. {
  763. /* We did not get the expected character, or we didn't
  764. get a valid terminating character after seeing the
  765. entire pseudo-op, so we must go back to the
  766. beginning. */
  767. mri_state = NULL;
  768. }
  769. else
  770. {
  771. /* We've read the entire pseudo-op. mips_last_ch is
  772. either '0' or '1' indicating whether to enter or
  773. leave MRI mode. */
  774. do_scrub_begin (mri_last_ch == '1');
  775. mri_state = NULL;
  776. /* We continue handling the character as usual. The
  777. main gas reader must also handle the .mri pseudo-op
  778. to control expression parsing and the like. */
  779. }
  780. }
  781. #endif
  782. if (ch == EOF)
  783. {
  784. if (state != 0)
  785. {
  786. as_warn (_("end of file not at end of a line; newline inserted"));
  787. state = 0;
  788. PUT ('\n');
  789. }
  790. goto fromeof;
  791. }
  792. switch (lex[ch])
  793. {
  794. case LEX_IS_WHITESPACE:
  795. do
  796. {
  797. ch = GET ();
  798. }
  799. while (ch != EOF && IS_WHITESPACE (ch));
  800. if (ch == EOF)
  801. goto fromeof;
  802. if (state == 0)
  803. {
  804. /* Preserve a single whitespace character at the
  805. beginning of a line. */
  806. state = 1;
  807. UNGET (ch);
  808. PUT (' ');
  809. break;
  810. }
  811. #ifdef KEEP_WHITE_AROUND_COLON
  812. if (lex[ch] == LEX_IS_COLON)
  813. {
  814. /* Only keep this white if there's no white *after* the
  815. colon. */
  816. ch2 = GET ();
  817. if (ch2 != EOF)
  818. UNGET (ch2);
  819. if (!IS_WHITESPACE (ch2))
  820. {
  821. state = 9;
  822. UNGET (ch);
  823. PUT (' ');
  824. break;
  825. }
  826. }
  827. #endif
  828. if (IS_COMMENT (ch)
  829. || IS_LINE_SEPARATOR (ch)
  830. || IS_PARALLEL_SEPARATOR (ch))
  831. {
  832. if (scrub_m68k_mri)
  833. {
  834. /* In MRI mode, we keep these spaces. */
  835. UNGET (ch);
  836. PUT (' ');
  837. break;
  838. }
  839. goto recycle;
  840. }
  841. /* If we're in state 2 or 11, we've seen a non-white
  842. character followed by whitespace. If the next character
  843. is ':', this is whitespace after a label name which we
  844. normally must ignore. In MRI mode, though, spaces are
  845. not permitted between the label and the colon. */
  846. if ((state == 2 || state == 11)
  847. && lex[ch] == LEX_IS_COLON
  848. && ! scrub_m68k_mri)
  849. {
  850. state = 1;
  851. PUT (ch);
  852. break;
  853. }
  854. switch (state)
  855. {
  856. case 1:
  857. /* We can arrive here if we leave a leading whitespace
  858. character at the beginning of a line. */
  859. goto recycle;
  860. case 2:
  861. state = 3;
  862. if (to + 1 < toend)
  863. {
  864. /* Optimize common case by skipping UNGET/GET. */
  865. PUT (' '); /* Sp after opco */
  866. goto recycle;
  867. }
  868. UNGET (ch);
  869. PUT (' ');
  870. break;
  871. case 3:
  872. #ifndef TC_KEEP_OPERAND_SPACES
  873. /* For TI C6X, we keep these spaces as they may separate
  874. functional unit specifiers from operands. */
  875. if (scrub_m68k_mri)
  876. #endif
  877. {
  878. /* In MRI mode, we keep these spaces. */
  879. UNGET (ch);
  880. PUT (' ');
  881. break;
  882. }
  883. goto recycle; /* Sp in operands */
  884. case 9:
  885. case 10:
  886. #ifndef TC_KEEP_OPERAND_SPACES
  887. if (scrub_m68k_mri)
  888. #endif
  889. {
  890. /* In MRI mode, we keep these spaces. */
  891. state = 3;
  892. UNGET (ch);
  893. PUT (' ');
  894. break;
  895. }
  896. state = 10; /* Sp after symbol char */
  897. goto recycle;
  898. case 11:
  899. if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
  900. state = 1;
  901. else
  902. {
  903. /* We know that ch is not ':', since we tested that
  904. case above. Therefore this is not a label, so it
  905. must be the opcode, and we've just seen the
  906. whitespace after it. */
  907. state = 3;
  908. }
  909. UNGET (ch);
  910. PUT (' '); /* Sp after label definition. */
  911. break;
  912. default:
  913. BAD_CASE (state);
  914. }
  915. break;
  916. case LEX_IS_TWOCHAR_COMMENT_1ST:
  917. ch2 = GET ();
  918. if (ch2 == '*')
  919. {
  920. for (;;)
  921. {
  922. do
  923. {
  924. ch2 = GET ();
  925. if (ch2 != EOF && IS_NEWLINE (ch2))
  926. add_newlines++;
  927. }
  928. while (ch2 != EOF && ch2 != '*');
  929. while (ch2 == '*')
  930. ch2 = GET ();
  931. if (ch2 == EOF || ch2 == '/')
  932. break;
  933. /* This UNGET will ensure that we count newlines
  934. correctly. */
  935. UNGET (ch2);
  936. }
  937. if (ch2 == EOF)
  938. as_warn (_("end of file in multiline comment"));
  939. ch = ' ';
  940. goto recycle;
  941. }
  942. #ifdef DOUBLESLASH_LINE_COMMENTS
  943. else if (ch2 == '/')
  944. {
  945. do
  946. {
  947. ch = GET ();
  948. }
  949. while (ch != EOF && !IS_NEWLINE (ch));
  950. if (ch == EOF)
  951. as_warn ("end of file in comment; newline inserted");
  952. state = 0;
  953. PUT ('\n');
  954. break;
  955. }
  956. #endif
  957. else
  958. {
  959. if (ch2 != EOF)
  960. UNGET (ch2);
  961. if (state == 9 || state == 10)
  962. state = 3;
  963. PUT (ch);
  964. }
  965. break;
  966. case LEX_IS_STRINGQUOTE:
  967. quotechar = ch;
  968. if (state == 10)
  969. {
  970. /* Preserve the whitespace in foo "bar". */
  971. UNGET (ch);
  972. state = 3;
  973. PUT (' ');
  974. /* PUT didn't jump out. We could just break, but we
  975. know what will happen, so optimize a bit. */
  976. ch = GET ();
  977. old_state = 9;
  978. }
  979. else if (state == 3)
  980. old_state = 9;
  981. else
  982. old_state = state;
  983. state = 5;
  984. PUT (ch);
  985. break;
  986. case LEX_IS_ONECHAR_QUOTE:
  987. #ifdef H_TICK_HEX
  988. if (state == 9 && enable_h_tick_hex)
  989. {
  990. char c;
  991. c = GET ();
  992. as_warn ("'%c found after symbol", c);
  993. UNGET (c);
  994. }
  995. #endif
  996. if (state == 10)
  997. {
  998. /* Preserve the whitespace in foo 'b'. */
  999. UNGET (ch);
  1000. state = 3;
  1001. PUT (' ');
  1002. break;
  1003. }
  1004. ch = GET ();
  1005. if (ch == EOF)
  1006. {
  1007. as_warn (_("end of file after a one-character quote; \\0 inserted"));
  1008. ch = 0;
  1009. }
  1010. if (ch == '\\')
  1011. {
  1012. ch = GET ();
  1013. if (ch == EOF)
  1014. {
  1015. as_warn (_("end of file in escape character"));
  1016. ch = '\\';
  1017. }
  1018. else
  1019. ch = process_escape (ch);
  1020. }
  1021. sprintf (out_buf, "%d", (int) (unsigned char) ch);
  1022. /* None of these 'x constants for us. We want 'x'. */
  1023. if ((ch = GET ()) != '\'')
  1024. {
  1025. #ifdef REQUIRE_CHAR_CLOSE_QUOTE
  1026. as_warn (_("missing close quote; (assumed)"));
  1027. #else
  1028. if (ch != EOF)
  1029. UNGET (ch);
  1030. #endif
  1031. }
  1032. if (strlen (out_buf) == 1)
  1033. {
  1034. PUT (out_buf[0]);
  1035. break;
  1036. }
  1037. if (state == 9)
  1038. old_state = 3;
  1039. else
  1040. old_state = state;
  1041. state = -1;
  1042. out_string = out_buf;
  1043. PUT (*out_string++);
  1044. break;
  1045. case LEX_IS_COLON:
  1046. #ifdef KEEP_WHITE_AROUND_COLON
  1047. state = 9;
  1048. #else
  1049. if (state == 9 || state == 10)
  1050. state = 3;
  1051. else if (state != 3)
  1052. state = 1;
  1053. #endif
  1054. PUT (ch);
  1055. break;
  1056. case LEX_IS_NEWLINE:
  1057. /* Roll out a bunch of newlines from inside comments, etc. */
  1058. if (add_newlines)
  1059. {
  1060. --add_newlines;
  1061. UNGET (ch);
  1062. }
  1063. /* Fall through. */
  1064. case LEX_IS_LINE_SEPARATOR:
  1065. state = 0;
  1066. PUT (ch);
  1067. break;
  1068. case LEX_IS_PARALLEL_SEPARATOR:
  1069. state = 1;
  1070. PUT (ch);
  1071. break;
  1072. #ifdef TC_V850
  1073. case LEX_IS_DOUBLEDASH_1ST:
  1074. ch2 = GET ();
  1075. if (ch2 != '-')
  1076. {
  1077. if (ch2 != EOF)
  1078. UNGET (ch2);
  1079. goto de_fault;
  1080. }
  1081. /* Read and skip to end of line. */
  1082. do
  1083. {
  1084. ch = GET ();
  1085. }
  1086. while (ch != EOF && ch != '\n');
  1087. if (ch == EOF)
  1088. as_warn (_("end of file in comment; newline inserted"));
  1089. state = 0;
  1090. PUT ('\n');
  1091. break;
  1092. #endif
  1093. #ifdef DOUBLEBAR_PARALLEL
  1094. case LEX_IS_DOUBLEBAR_1ST:
  1095. ch2 = GET ();
  1096. if (ch2 != EOF)
  1097. UNGET (ch2);
  1098. if (ch2 != '|')
  1099. goto de_fault;
  1100. /* Handle '||' in two states as invoking PUT twice might
  1101. result in the first one jumping out of this loop. We'd
  1102. then lose track of the state and one '|' char. */
  1103. state = 13;
  1104. PUT ('|');
  1105. break;
  1106. #endif
  1107. case LEX_IS_LINE_COMMENT_START:
  1108. /* FIXME-someday: The two character comment stuff was badly
  1109. thought out. On i386, we want '/' as line comment start
  1110. AND we want C style comments. hence this hack. The
  1111. whole lexical process should be reworked. xoxorich. */
  1112. if (ch == '/')
  1113. {
  1114. ch2 = GET ();
  1115. if (ch2 == '*')
  1116. {
  1117. old_state = 3;
  1118. state = -2;
  1119. break;
  1120. }
  1121. else if (ch2 != EOF)
  1122. {
  1123. UNGET (ch2);
  1124. }
  1125. }
  1126. if (state == 0 || state == 1) /* Only comment at start of line. */
  1127. {
  1128. int startch;
  1129. startch = ch;
  1130. do
  1131. {
  1132. ch = GET ();
  1133. }
  1134. while (ch != EOF && IS_WHITESPACE (ch));
  1135. if (ch == EOF)
  1136. {
  1137. as_warn (_("end of file in comment; newline inserted"));
  1138. PUT ('\n');
  1139. break;
  1140. }
  1141. if (ch < '0' || ch > '9' || state != 0 || startch != '#')
  1142. {
  1143. /* Not a cpp line. */
  1144. while (ch != EOF && !IS_NEWLINE (ch))
  1145. ch = GET ();
  1146. if (ch == EOF)
  1147. {
  1148. as_warn (_("end of file in comment; newline inserted"));
  1149. PUT ('\n');
  1150. }
  1151. else /* IS_NEWLINE (ch) */
  1152. {
  1153. /* To process non-zero add_newlines. */
  1154. UNGET (ch);
  1155. }
  1156. state = 0;
  1157. break;
  1158. }
  1159. /* Looks like `# 123 "filename"' from cpp. */
  1160. UNGET (ch);
  1161. old_state = 4;
  1162. state = -1;
  1163. if (scrub_m68k_mri)
  1164. out_string = "\tlinefile ";
  1165. else
  1166. out_string = "\t.linefile ";
  1167. PUT (*out_string++);
  1168. break;
  1169. }
  1170. #ifdef TC_D10V
  1171. /* All insns end in a char for which LEX_IS_SYMBOL_COMPONENT is true.
  1172. Trap is the only short insn that has a first operand that is
  1173. neither register nor label.
  1174. We must prevent exef0f ||trap #1 to degenerate to exef0f ||trap#1 .
  1175. We can't make '#' LEX_IS_SYMBOL_COMPONENT because it is
  1176. already LEX_IS_LINE_COMMENT_START. However, it is the
  1177. only character in line_comment_chars for d10v, hence we
  1178. can recognize it as such. */
  1179. /* An alternative approach would be to reset the state to 1 when
  1180. we see '||', '<'- or '->', but that seems to be overkill. */
  1181. if (state == 10)
  1182. PUT (' ');
  1183. #endif
  1184. /* We have a line comment character which is not at the
  1185. start of a line. If this is also a normal comment
  1186. character, fall through. Otherwise treat it as a default
  1187. character. */
  1188. if (strchr (tc_comment_chars, ch) == NULL
  1189. && (! scrub_m68k_mri
  1190. || (ch != '!' && ch != '*')))
  1191. goto de_fault;
  1192. if (scrub_m68k_mri
  1193. && (ch == '!' || ch == '*' || ch == '#')
  1194. && state != 1
  1195. && state != 10)
  1196. goto de_fault;
  1197. /* Fall through. */
  1198. case LEX_IS_COMMENT_START:
  1199. #if defined TC_ARM && defined OBJ_ELF
  1200. /* On the ARM, `@' is the comment character.
  1201. Unfortunately this is also a special character in ELF .symver
  1202. directives (and .type, though we deal with those another way).
  1203. So we check if this line is such a directive, and treat
  1204. the character as default if so. This is a hack. */
  1205. if ((symver_state != NULL) && (*symver_state == 0))
  1206. goto de_fault;
  1207. #endif
  1208. /* Care is needed not to damage occurrences of \<comment-char>
  1209. by stripping the <comment-char> onwards. Yuck. */
  1210. if ((to > tostart ? to[-1] : last_char) == '\\')
  1211. /* Do not treat the <comment-char> as a start-of-comment. */
  1212. goto de_fault;
  1213. #ifdef WARN_COMMENTS
  1214. if (!found_comment)
  1215. found_comment_file = as_where (&found_comment);
  1216. #endif
  1217. do
  1218. {
  1219. ch = GET ();
  1220. }
  1221. while (ch != EOF && !IS_NEWLINE (ch));
  1222. if (ch == EOF)
  1223. as_warn (_("end of file in comment; newline inserted"));
  1224. state = 0;
  1225. PUT ('\n');
  1226. break;
  1227. #ifdef H_TICK_HEX
  1228. case LEX_IS_H:
  1229. /* Look for strings like H'[0-9A-Fa-f] and if found, replace
  1230. the H' with 0x to make them gas-style hex characters. */
  1231. if (enable_h_tick_hex)
  1232. {
  1233. char quot;
  1234. quot = GET ();
  1235. if (quot == '\'')
  1236. {
  1237. UNGET ('x');
  1238. ch = '0';
  1239. }
  1240. else
  1241. UNGET (quot);
  1242. }
  1243. #endif
  1244. /* Fall through. */
  1245. case LEX_IS_SYMBOL_COMPONENT:
  1246. if (state == 10)
  1247. {
  1248. /* This is a symbol character following another symbol
  1249. character, with whitespace in between. We skipped
  1250. the whitespace earlier, so output it now. */
  1251. UNGET (ch);
  1252. state = 3;
  1253. PUT (' ');
  1254. break;
  1255. }
  1256. #ifdef TC_Z80
  1257. /* "af'" is a symbol containing '\''. */
  1258. if (state == 3 && (ch == 'a' || ch == 'A'))
  1259. {
  1260. state = 16;
  1261. PUT (ch);
  1262. ch = GET ();
  1263. if (ch == 'f' || ch == 'F')
  1264. {
  1265. state = 17;
  1266. PUT (ch);
  1267. break;
  1268. }
  1269. else
  1270. {
  1271. state = 9;
  1272. if (ch == EOF || !IS_SYMBOL_COMPONENT (ch))
  1273. {
  1274. if (ch != EOF)
  1275. UNGET (ch);
  1276. break;
  1277. }
  1278. }
  1279. }
  1280. #endif
  1281. if (state == 3)
  1282. state = 9;
  1283. /* This is a common case. Quickly copy CH and all the
  1284. following symbol component or normal characters. */
  1285. if (to + 1 < toend
  1286. && mri_state == NULL
  1287. #if defined TC_ARM && defined OBJ_ELF
  1288. && symver_state == NULL
  1289. #endif
  1290. )
  1291. {
  1292. char *s;
  1293. ptrdiff_t len;
  1294. for (s = from; s < fromend; s++)
  1295. {
  1296. int type;
  1297. ch2 = *(unsigned char *) s;
  1298. type = lex[ch2];
  1299. if (type != 0
  1300. && type != LEX_IS_SYMBOL_COMPONENT)
  1301. break;
  1302. }
  1303. if (s > from)
  1304. /* Handle the last character normally, for
  1305. simplicity. */
  1306. --s;
  1307. len = s - from;
  1308. if (len > (toend - to) - 1)
  1309. len = (toend - to) - 1;
  1310. if (len > 0)
  1311. {
  1312. PUT (ch);
  1313. memcpy (to, from, len);
  1314. to += len;
  1315. from += len;
  1316. if (to >= toend)
  1317. goto tofull;
  1318. ch = GET ();
  1319. }
  1320. }
  1321. /* Fall through. */
  1322. default:
  1323. de_fault:
  1324. /* Some relatively `normal' character. */
  1325. if (state == 0)
  1326. {
  1327. state = 11; /* Now seeing label definition. */
  1328. }
  1329. else if (state == 1)
  1330. {
  1331. state = 2; /* Ditto. */
  1332. }
  1333. else if (state == 9)
  1334. {
  1335. if (!IS_SYMBOL_COMPONENT (ch))
  1336. state = 3;
  1337. }
  1338. else if (state == 10)
  1339. {
  1340. if (ch == '\\')
  1341. {
  1342. /* Special handling for backslash: a backslash may
  1343. be the beginning of a formal parameter (of a
  1344. macro) following another symbol character, with
  1345. whitespace in between. If that is the case, we
  1346. output a space before the parameter. Strictly
  1347. speaking, correct handling depends upon what the
  1348. macro parameter expands into; if the parameter
  1349. expands into something which does not start with
  1350. an operand character, then we don't want to keep
  1351. the space. We don't have enough information to
  1352. make the right choice, so here we are making the
  1353. choice which is more likely to be correct. */
  1354. if (to + 1 >= toend)
  1355. {
  1356. /* If we're near the end of the buffer, save the
  1357. character for the next time round. Otherwise
  1358. we'll lose our state. */
  1359. UNGET (ch);
  1360. goto tofull;
  1361. }
  1362. *to++ = ' ';
  1363. }
  1364. state = 3;
  1365. }
  1366. PUT (ch);
  1367. break;
  1368. }
  1369. }
  1370. /*NOTREACHED*/
  1371. fromeof:
  1372. /* We have reached the end of the input. */
  1373. if (to > tostart)
  1374. last_char = to[-1];
  1375. return to - tostart;
  1376. tofull:
  1377. /* The output buffer is full. Save any input we have not yet
  1378. processed. */
  1379. if (fromend > from)
  1380. {
  1381. saved_input = from;
  1382. saved_input_len = fromend - from;
  1383. }
  1384. else
  1385. saved_input = NULL;
  1386. if (to > tostart)
  1387. last_char = to[-1];
  1388. return to - tostart;
  1389. }