rtl.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. /* Manage RTL for C-Compiler
  2. Copyright (C) 1987 Free Software Foundation, Inc.
  3. This file is part of GNU CC.
  4. GNU CC is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY. No author or distributor
  6. accepts responsibility to anyone for the consequences of using it
  7. or for whether it serves any particular purpose or works at all,
  8. unless he says so in writing. Refer to the GNU CC General Public
  9. License for full details.
  10. Everyone is granted permission to copy, modify and redistribute
  11. GNU CC, but only under the conditions described in the
  12. GNU CC General Public License. A copy of this license is
  13. supposed to have been given to you along with GNU CC so you
  14. can know your rights and responsibilities. It should be in a
  15. file named COPYING. Among other things, the copyright notice
  16. and this notice must be preserved on all copies. */
  17. /* This file contains the low level primitives for allocating,
  18. printing and reading rtl expressions and vectors.
  19. It also contains some functions for semantic analysis
  20. on rtl expressions. */
  21. #include "config.h"
  22. #include <ctype.h>
  23. #include <stdio.h>
  24. #include <strings.h>
  25. #include "rtl.h"
  26. #include <obstack.h>
  27. #define obstack_chunk_alloc xmalloc
  28. #define obstack_chunk_free free
  29. extern int xmalloc ();
  30. extern void free ();
  31. /* We use the same obstack used for the tree.
  32. That way, the TREE_RTL of top-level variables and functions
  33. is permanent. */
  34. extern struct obstack *current_obstack;
  35. #define MIN(x,y) ((x < y) ? x : y)
  36. extern long ftell();
  37. /* Indexed by rtx code, gives number of operands for an rtx with that code.
  38. Does NOT include rtx header data (code and links).
  39. This array is initialized in init_rtx. */
  40. int rtx_length[NUM_RTX_CODE + 1];
  41. /* Indexed by rtx code, gives the name of that kind of rtx, as a C string. */
  42. #define DEF_RTL_EXPR(ENUM, NAME, FORMAT) NAME ,
  43. char *rtx_name[] = {
  44. #include "rtl.def" /* rtl expressions are documented here */
  45. };
  46. #undef DEF_RTL_EXPR
  47. /* Indexed by machine mode, gives the name of that machine mode.
  48. This name does not include the letters "mode". */
  49. #define DEF_MACHMODE(SYM, NAME, TYPE, SIZE, UNIT) NAME,
  50. char *mode_name[] = {
  51. #include "machmode.def"
  52. };
  53. #undef DEF_MACHMODE
  54. /* Indexed by machine mode, gives the length of the mode, in bytes.
  55. GET_MODE_SIZE uses this. */
  56. #define DEF_MACHMODE(SYM, NAME, TYPE, SIZE, UNIT) SIZE,
  57. int mode_size[] = {
  58. #include "machmode.def"
  59. };
  60. #undef DEF_MACHMODE
  61. /* Indexed by machine mode, gives the length of the mode's subunit.
  62. GET_MODE_UNIT_SIZE uses this. */
  63. #define DEF_MACHMODE(SYM, NAME, TYPE, SIZE, UNIT) UNIT,
  64. int mode_unit_size[] = {
  65. #include "machmode.def" /* machine modes are documented here */
  66. };
  67. #undef DEF_MACHMODE
  68. /* Indexed by rtx code, gives a sequence of operand-types for
  69. rtx's of that code. The sequence is a C string in which
  70. each charcter describes one operand. */
  71. char *rtx_format[] = {
  72. /* "*" undefined.
  73. can cause a warning message
  74. "0" field is unused (or used in a phase-dependent manner)
  75. prints nothing
  76. "i" an integer
  77. prints the integer
  78. "s" a pointer to a string
  79. prints the string
  80. "e" a pointer to an rtl expression
  81. prints the expression
  82. "E" a pointer to a vector that points to a number of rtl expressions
  83. prints a list of the rtl expressions
  84. "u" a pointer to another insn
  85. prints the uid of the insn. */
  86. #define DEF_RTL_EXPR(ENUM, NAME, FORMAT) FORMAT ,
  87. #include "rtl.def" /* rtl expressions are defined here */
  88. #undef DEF_RTL_EXPR
  89. };
  90. /* Allocate an rtx vector of N elements.
  91. Store the length, and initialize all elements to zero. */
  92. rtvec
  93. rtvec_alloc (n)
  94. int n;
  95. {
  96. rtvec rt;
  97. int i;
  98. rt = (rtvec) obstack_alloc (current_obstack,
  99. sizeof (struct rtvec_def)
  100. + (( n - 1) * sizeof (rtunion)));
  101. /* clear out the vector */
  102. PUT_NUM_ELEM(rt, n);
  103. for (i=0; i < n; i++)
  104. rt->elem[i].rtvec = NULL; /* @@ not portable due to rtunion */
  105. return rt;
  106. }
  107. /* Allocate an rtx of code CODE. The CODE is stored in the rtx;
  108. all the rest is initialized to zero. */
  109. rtx
  110. rtx_alloc (code)
  111. RTX_CODE code;
  112. {
  113. rtx rt;
  114. register int nelts = GET_RTX_LENGTH (code);
  115. register int length = sizeof (struct rtx_def)
  116. + (nelts - 1) * sizeof (rtunion);
  117. rt = (rtx) obstack_alloc (current_obstack, length);
  118. * (int *) rt = 0;
  119. PUT_CODE (rt, code);
  120. return rt;
  121. }
  122. /* Create a new copy of an rtx.
  123. Recursively copies the operands of the rtx,
  124. except for those few rtx codes that are sharable. */
  125. rtx
  126. copy_rtx (orig)
  127. register rtx orig;
  128. {
  129. register rtx copy;
  130. register int i, j;
  131. register RTX_CODE code;
  132. register char *format_ptr;
  133. code = GET_CODE (orig);
  134. if (code == REG
  135. || code == CONST_INT
  136. || code == CONST_DOUBLE
  137. || code == SYMBOL_REF
  138. || code == CODE_LABEL
  139. || code == PC
  140. || code == CC0)
  141. return orig;
  142. copy = rtx_alloc (code);
  143. PUT_MODE (copy, GET_MODE (orig));
  144. format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
  145. for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
  146. {
  147. switch (*format_ptr++)
  148. {
  149. case 'e':
  150. XEXP (copy, i) = copy_rtx (XEXP (orig, i));
  151. break;
  152. case 'E':
  153. XVEC (copy, i) = XVEC (orig, i);
  154. if (XVEC (orig, i) != NULL)
  155. {
  156. XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
  157. for (j = 0; j < XVECLEN (copy, i); j++)
  158. XVECEXP (copy, i, j) = copy_rtx (XVECEXP (orig, i, j));
  159. }
  160. break;
  161. default:
  162. XINT (copy, i) = XINT (orig, i);
  163. break;
  164. }
  165. }
  166. return copy;
  167. }
  168. /* Return 1 unless X is a value effectively constant.
  169. The frame pointer, arg pointer, etc. are considered constant. */
  170. int
  171. rtx_varies_p (x)
  172. rtx x;
  173. {
  174. register RTX_CODE code = GET_CODE (x);
  175. register int i;
  176. register char *fmt;
  177. if (code == MEM || code == QUEUED)
  178. return 1;
  179. if (code == CONST || code == CONST_INT || code == UNCHANGING)
  180. return 0;
  181. if (code == REG)
  182. return ! (REGNO (x) == FRAME_POINTER_REGNUM
  183. || REGNO (x) == ARG_POINTER_REGNUM);
  184. fmt = GET_RTX_FORMAT (code);
  185. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  186. if (fmt[i] == 'e')
  187. if (rtx_varies_p (XEXP (x, i)))
  188. return 1;
  189. return 0;
  190. }
  191. /* Return 1 if X refers to a memory location whose address
  192. is not effectively constant, or if X refers to a BLKmode memory object. */
  193. int
  194. rtx_addr_varies_p (x)
  195. rtx x;
  196. {
  197. register RTX_CODE code = GET_CODE (x);
  198. register int i;
  199. register char *fmt;
  200. if (code == MEM)
  201. return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0));
  202. fmt = GET_RTX_FORMAT (code);
  203. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  204. if (fmt[i] == 'e')
  205. if (rtx_addr_varies_p (XEXP (x, i)))
  206. return 1;
  207. return 0;
  208. }
  209. /* Return nonzero if INSN alters memory at an address that is not fixed. */
  210. int
  211. insn_store_addr_varies_p (insn)
  212. rtx insn;
  213. {
  214. register rtx x = PATTERN (insn);
  215. if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
  216. return rtx_addr_varies_p (SET_DEST (x));
  217. else if (GET_CODE (x) == PARALLEL)
  218. {
  219. register int i;
  220. for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  221. {
  222. register rtx y = XVECEXP (x, 0, i);
  223. if (GET_CODE (y) == SET || GET_CODE (y) == CLOBBER)
  224. if (rtx_addr_varies_p (SET_DEST (y)))
  225. return 1;
  226. }
  227. }
  228. return 0;
  229. }
  230. /* Nonzero if register REG appears somewhere within IN. */
  231. int
  232. reg_mentioned_p (reg, in)
  233. register rtx reg, in;
  234. {
  235. register char *fmt;
  236. register int i;
  237. register enum rtx_code code = GET_CODE (in);
  238. if (GET_CODE (in) == REG)
  239. return REGNO (in) == REGNO (reg);
  240. fmt = GET_RTX_FORMAT (code);
  241. for (i = GET_RTX_LENGTH (code); i >= 0; i--)
  242. {
  243. if (fmt[i] == 'E')
  244. {
  245. register int j;
  246. for (j = XVECLEN (in, i) - 1; j >= 0; j--)
  247. if (reg_mentioned_p (reg, XVECEXP (in, i, j)))
  248. return 1;
  249. }
  250. else if (fmt[i] == 'e'
  251. && reg_mentioned_p (reg, XEXP (in, i)))
  252. return 1;
  253. }
  254. return 0;
  255. }
  256. /* Nonzero if register REG is used in an insn between
  257. FROM_INSN and TO_INSN (exclusive of those two). */
  258. int
  259. reg_used_between_p (reg, from_insn, to_insn)
  260. rtx reg, from_insn, to_insn;
  261. {
  262. register rtx insn;
  263. register RTX_CODE code;
  264. for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
  265. if (((code = GET_CODE (insn)) == INSN
  266. || code == JUMP_INSN || code == CALL_INSN)
  267. && reg_mentioned_p (reg, PATTERN (insn)))
  268. return 1;
  269. return 0;
  270. }
  271. /* Call FUN on each register or MEM that is stored into or clobbered by X.
  272. (X would be the pattern of an insn).
  273. FUN receives two arguments:
  274. the REG, MEM, CC0 or PC being stored in or clobbered,
  275. the SET or CLOBBER rtx that does the store. */
  276. void
  277. note_stores (x, fun)
  278. register rtx x;
  279. void (*fun) ();
  280. {
  281. if ((GET_CODE (x) == SET || GET_CODE (x) == CLOBBER))
  282. {
  283. register rtx dest = SET_DEST (x);
  284. while (GET_CODE (dest) == SUBREG
  285. || GET_CODE (dest) == VOLATILE
  286. || GET_CODE (dest) == ZERO_EXTRACT
  287. || GET_CODE (dest) == SIGN_EXTRACT
  288. || GET_CODE (dest) == STRICT_LOW_PART)
  289. dest = XEXP (dest, 0);
  290. (*fun) (dest, x);
  291. }
  292. else if (GET_CODE (x) == PARALLEL)
  293. {
  294. register int i;
  295. for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  296. {
  297. register rtx y = XVECEXP (x, 0, i);
  298. if (GET_CODE (y) == SET || GET_CODE (y) == CLOBBER)
  299. {
  300. register rtx dest = SET_DEST (y);
  301. while (GET_CODE (dest) == SUBREG
  302. || GET_CODE (dest) == VOLATILE
  303. || GET_CODE (dest) == ZERO_EXTRACT
  304. || GET_CODE (dest) == SIGN_EXTRACT
  305. || GET_CODE (dest) == STRICT_LOW_PART)
  306. dest = XEXP (dest, 0);
  307. (*fun) (dest, y);
  308. }
  309. }
  310. }
  311. }
  312. /* Return nonzero if register REG's old contents don't survive after INSN.
  313. This can be because REG dies in INSN or because INSN entirely sets REG.
  314. "Entirely set" means set directly and not through a SUBREG,
  315. ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
  316. REG may be a hard or pseudo reg. Renumbering is not taken into account,
  317. but for this use that makes no difference, since regs don't overlap
  318. during their lifetimes. Therefore, this function may be used
  319. at any time after deaths have been computed (in flow.c). */
  320. int
  321. dead_or_set_p (insn, reg)
  322. rtx insn;
  323. rtx reg;
  324. {
  325. register rtx link;
  326. register int regno = REGNO (reg);
  327. for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  328. if (REGNO (XEXP (link, 0)) == regno
  329. && ((enum reg_note) GET_MODE (link) == REG_DEAD
  330. || (enum reg_note) GET_MODE (link) == REG_INC))
  331. return 1;
  332. if (GET_CODE (PATTERN (insn)) == SET)
  333. return SET_DEST (PATTERN (insn)) == reg;
  334. else if (GET_CODE (PATTERN (insn)) == PARALLEL)
  335. {
  336. register int i;
  337. for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
  338. {
  339. if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET
  340. && SET_DEST (XVECEXP (PATTERN (insn), 0, i)) == reg)
  341. return 1;
  342. }
  343. }
  344. return 0;
  345. }
  346. /* Printing rtl for debugging dumps. */
  347. static FILE *outfile;
  348. char spaces[] = " ";
  349. static int sawclose = 0;
  350. /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
  351. static void
  352. print_rtx (in_rtx)
  353. register rtx in_rtx;
  354. {
  355. static int indent;
  356. register int i, j;
  357. register char *format_ptr;
  358. if (sawclose)
  359. {
  360. fprintf (outfile, "\n%s",
  361. (spaces + (sizeof spaces - indent * 2)));
  362. sawclose = 0;
  363. }
  364. if (in_rtx == 0)
  365. {
  366. fprintf (outfile, "(nil)");
  367. sawclose = 1;
  368. return;
  369. }
  370. /* print name of expression code */
  371. fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
  372. if (in_rtx->in_struct)
  373. fprintf (outfile, "/s");
  374. if (GET_MODE (in_rtx) != VOIDmode)
  375. fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
  376. format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
  377. for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
  378. switch (*format_ptr++)
  379. {
  380. case 's':
  381. if (XSTR (in_rtx, i) == 0)
  382. fprintf (outfile, " \"\"");
  383. else
  384. fprintf (outfile, " (\"%s\")", XSTR (in_rtx, i));
  385. sawclose = 1;
  386. break;
  387. /* 0 indicates a field for internal use that should not be printed. */
  388. case '0':
  389. break;
  390. case 'e':
  391. indent += 2;
  392. if (!sawclose)
  393. fprintf (outfile, " ");
  394. print_rtx (XEXP (in_rtx, i));
  395. indent -= 2;
  396. break;
  397. case 'E':
  398. indent += 2;
  399. if (sawclose)
  400. {
  401. fprintf (outfile, "\n%s",
  402. (spaces + (sizeof spaces - indent * 2)));
  403. sawclose = 0;
  404. }
  405. fprintf (outfile, "[ ");
  406. if (NULL != XVEC (in_rtx, i))
  407. {
  408. indent += 2;
  409. if (XVECLEN (in_rtx, i))
  410. sawclose = 1;
  411. for (j = 0; j < XVECLEN (in_rtx, i); j++)
  412. print_rtx (XVECEXP (in_rtx, i, j));
  413. indent -= 2;
  414. }
  415. if (sawclose)
  416. fprintf (outfile, "\n%s",
  417. (spaces + (sizeof spaces - indent * 2)));
  418. fprintf (outfile, "] ");
  419. sawclose = 1;
  420. indent -= 2;
  421. break;
  422. case 'i':
  423. fprintf (outfile, " %d", XINT (in_rtx, i));
  424. sawclose = 0;
  425. break;
  426. case 'u':
  427. if (XEXP (in_rtx, i) != NULL)
  428. fprintf(outfile, " %d", INSN_UID (XEXP (in_rtx, i)));
  429. else
  430. fprintf(outfile, " 0");
  431. sawclose = 0;
  432. break;
  433. default:
  434. fprintf (stderr,
  435. "switch format wrong in rtl.print_rtx(). format was: %c.\n",
  436. format_ptr[-1]);
  437. abort ();
  438. }
  439. fprintf (outfile, ")");
  440. sawclose = 1;
  441. }
  442. /* External entry point for printing a chain of INSNs
  443. starting with RTX_FIRST onto file OUTF. */
  444. void
  445. print_rtl (outf, rtx_first)
  446. FILE *outf;
  447. rtx rtx_first;
  448. {
  449. register rtx tmp_rtx;
  450. outfile = outf;
  451. sawclose = 0;
  452. for (tmp_rtx = rtx_first; NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx))
  453. {
  454. print_rtx (tmp_rtx);
  455. fprintf (outfile, "\n");
  456. }
  457. }
  458. /* Subroutines of read_rtx. */
  459. /* Dump code after printing a message. Used when read_rtx finds
  460. invalid data. */
  461. static void
  462. dump_and_abort (expected_c, actual_c, infile)
  463. int expected_c, actual_c;
  464. FILE *infile;
  465. {
  466. int c, i;
  467. fprintf (stderr,
  468. "Expected character %c. Read character %c. At file position: %ld\n",
  469. expected_c, actual_c, ftell (infile));
  470. fprintf (stderr, "Following characters are:\n\t");
  471. for (i = 0; i < 200; i++)
  472. {
  473. c = getc (infile);
  474. if (EOF == c) break;
  475. putc (c, stderr);
  476. }
  477. fprintf (stderr, "Aborting.\n");
  478. abort ();
  479. }
  480. /* Read chars from INFILE until a non-whitespace char
  481. and return that. Comments, both Lisp style and C style,
  482. are treated as whitespace.
  483. Tools such as genflags use this function. */
  484. int
  485. read_skip_spaces (infile)
  486. FILE *infile;
  487. {
  488. register int c;
  489. while (c = getc (infile))
  490. {
  491. if (c == ' ' || c == '\n' || c == '\t' || c == '\f')
  492. ;
  493. else if (c == ';')
  494. {
  495. while ((c = getc (infile)) && c != '\n') ;
  496. }
  497. else if (c == '/')
  498. {
  499. register int prevc;
  500. c = getc (infile);
  501. if (c != '*')
  502. dump_and_abort ('*', c, infile);
  503. prevc = 0;
  504. while (c = getc (infile))
  505. {
  506. if (prevc == '*' && c == '/')
  507. break;
  508. prevc = c;
  509. }
  510. }
  511. else break;
  512. }
  513. return c;
  514. }
  515. /* Read an rtx code name into the buffer STR[].
  516. It is terminated by any of the punctuation chars of rtx printed syntax. */
  517. static void
  518. read_name (str, infile)
  519. char *str;
  520. FILE *infile;
  521. {
  522. register char *p;
  523. register int c;
  524. c = read_skip_spaces(infile);
  525. p = str;
  526. while (1)
  527. {
  528. if (c == ' ' || c == '\n' || c == '\t' || c == '\f')
  529. break;
  530. if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/'
  531. || c == '(' || c == '[')
  532. {
  533. ungetc (c, infile);
  534. break;
  535. }
  536. *p++ = c;
  537. c = getc (infile);
  538. }
  539. *p = NULL;
  540. }
  541. /* Read an rtx in printed representation from INFILE
  542. and return an actual rtx in core constructed accordingly.
  543. read_rtx is not used in the compiler proper, but rather in
  544. the utilities gen*.c that construct C code from machine descriptions. */
  545. rtx
  546. read_rtx (infile)
  547. FILE *infile;
  548. {
  549. register int i, j, list_counter;
  550. RTX_CODE tmp_code;
  551. register char *format_ptr;
  552. /* tmp_char is a buffer used for reading decimal integers
  553. and names of rtx types and machine modes.
  554. Therefore, 256 must be enough. */
  555. char tmp_char[256];
  556. rtx return_rtx;
  557. register int c;
  558. int tmp_int;
  559. /* Linked list structure for making RTXs: */
  560. struct rtx_list
  561. {
  562. struct rtx_list *next;
  563. rtx value; /* Value of this node... */
  564. };
  565. c = read_skip_spaces (infile); /* Should be open paren. */
  566. if (c != '(')
  567. dump_and_abort ('(', c, infile);
  568. read_name (tmp_char, infile);
  569. tmp_code = UNKNOWN;
  570. for (i=0; i < NUM_RTX_CODE; i++) /* @@ might speed this search up */
  571. {
  572. if (!(strcmp (tmp_char, GET_RTX_NAME (i))))
  573. {
  574. tmp_code = (RTX_CODE) i; /* get value for name */
  575. break;
  576. }
  577. }
  578. if (tmp_code == UNKNOWN)
  579. {
  580. fprintf (stderr,
  581. "Unknown rtx read in rtl.read_rtx(). Code name was %s .",
  582. tmp_char);
  583. }
  584. /* (NIL) stands for an expression that isn't there. */
  585. if (tmp_code == NIL)
  586. {
  587. /* Discard the closeparen. */
  588. while ((c = getc (infile)) && c != ')');
  589. return 0;
  590. }
  591. return_rtx = rtx_alloc (tmp_code); /* if we end up with an insn expression
  592. then we free this space below. */
  593. format_ptr = GET_RTX_FORMAT (GET_CODE (return_rtx));
  594. /* If what follows is `: mode ', read it and
  595. store the mode in the rtx. */
  596. i = read_skip_spaces (infile);
  597. if (i == ':')
  598. {
  599. register int k;
  600. read_name (tmp_char, infile);
  601. for (k = 0; k < NUM_MACHINE_MODE; k++)
  602. if (!strcmp (GET_MODE_NAME (k), tmp_char))
  603. break;
  604. PUT_MODE (return_rtx, (enum machine_mode) k );
  605. }
  606. else
  607. ungetc (i, infile);
  608. for (i = 0; i < GET_RTX_LENGTH (GET_CODE (return_rtx)); i++)
  609. switch (*format_ptr++)
  610. {
  611. /* 0 means a field for internal use only.
  612. Don't expect it to be present in the input. */
  613. case '0':
  614. break;
  615. case 'e':
  616. case 'u':
  617. XEXP (return_rtx, i) = read_rtx (infile);
  618. break;
  619. case 'E':
  620. {
  621. register struct rtx_list *next_rtx, *rtx_list_link;
  622. struct rtx_list *list_rtx;
  623. c = read_skip_spaces (infile);
  624. if (c != '[')
  625. dump_and_abort ('[', c, infile);
  626. /* add expressions to a list, while keeping a count */
  627. next_rtx = NULL;
  628. list_counter = 0;
  629. while ((c = read_skip_spaces (infile)) && c != ']')
  630. {
  631. ungetc (c, infile);
  632. list_counter++;
  633. rtx_list_link = (struct rtx_list *)
  634. alloca (sizeof (struct rtx_list));
  635. rtx_list_link->value = read_rtx (infile);
  636. if (next_rtx == 0)
  637. list_rtx = rtx_list_link;
  638. else
  639. next_rtx->next = rtx_list_link;
  640. next_rtx = rtx_list_link;
  641. rtx_list_link->next = 0;
  642. }
  643. /* get vector length and allocate it */
  644. XVEC (return_rtx, i) = (list_counter
  645. ? rtvec_alloc (list_counter)
  646. : NULL);
  647. if (list_counter > 0)
  648. {
  649. next_rtx = list_rtx;
  650. for (j = 0; j < list_counter; j++,
  651. next_rtx = next_rtx->next)
  652. XVECEXP (return_rtx, i, j) = next_rtx->value;
  653. }
  654. /* close bracket gotten */
  655. }
  656. break;
  657. case 's':
  658. {
  659. int saw_paren = 0;
  660. register char *stringbuf;
  661. int stringbufsize;
  662. c = read_skip_spaces (infile);
  663. if (c == '(')
  664. {
  665. saw_paren = 1;
  666. c = read_skip_spaces (infile);
  667. }
  668. if (c != '"')
  669. dump_and_abort ('"', c, infile);
  670. j = 0;
  671. stringbufsize = 10;
  672. stringbuf = (char *) xmalloc (stringbufsize + 1);
  673. while (1)
  674. {
  675. if (j >= stringbufsize - 4)
  676. {
  677. stringbufsize *= 2;
  678. stringbuf = (char *) xrealloc (stringbuf, stringbufsize + 1);
  679. }
  680. stringbuf[j] = getc (infile); /* Read the string */
  681. if (stringbuf[j] == '\\')
  682. {
  683. stringbuf[j] = getc (infile); /* Read the string */
  684. /* \; makes stuff for a C string constant containing
  685. newline and tab. */
  686. if (stringbuf[j] == ';')
  687. {
  688. strcpy (&stringbuf[j], "\\n\\t");
  689. j += 3;
  690. }
  691. }
  692. else if (stringbuf[j] == '"')
  693. break;
  694. j++;
  695. }
  696. stringbuf[j] = 0; /* NUL terminate the string */
  697. stringbuf = (char *) xrealloc (stringbuf, j + 1);
  698. if (saw_paren)
  699. {
  700. c = read_skip_spaces (infile);
  701. if (c != ')')
  702. dump_and_abort (')', c, infile);
  703. }
  704. XSTR (return_rtx, i) = stringbuf;
  705. }
  706. break;
  707. case 'i':
  708. read_name (tmp_char, infile);
  709. tmp_int = atoi (tmp_char);
  710. XINT (return_rtx, i) = tmp_int;
  711. break;
  712. default:
  713. fprintf (stderr,
  714. "switch format wrong in rtl.read_rtx(). format was: %c.\n",
  715. format_ptr[-1]);
  716. fprintf (stderr, "\tfile position: %ld\n", ftell (infile));
  717. abort ();
  718. }
  719. c = read_skip_spaces (infile);
  720. if (c != ')')
  721. dump_and_abort (')', c, infile);
  722. return return_rtx;
  723. }
  724. /* This is called once per compilation, before any rtx's are constructed.
  725. It initializes the vector `rtx_length'. */
  726. void
  727. init_rtl()
  728. {
  729. int i;
  730. for (i = 0; i < NUM_RTX_CODE; i++)
  731. rtx_length[i] = strlen (rtx_format[i]);
  732. }