PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/binutils-2.17/gas/config/m68k-parse.y

http://android-gcc-objc2-0.googlecode.com/
Happy | 1091 lines | 984 code | 107 blank | 0 comment | 0 complexity | 6ab2b3a5241216fed607e91002631087 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  1. /* m68k.y -- bison grammar for m68k operand parsing
  2. Copyright 1995, 1996, 1997, 1998, 2001, 2003, 2004, 2005
  3. Free Software Foundation, Inc.
  4. Written by Ken Raeburn and Ian Lance Taylor, Cygnus Support
  5. This file is part of GAS, the GNU Assembler.
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10. GAS is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GAS; see the file COPYING. If not, write to the Free
  16. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  17. 02110-1301, USA. */
  18. /* This file holds a bison grammar to parse m68k operands. The m68k
  19. has a complicated operand syntax, and gas supports two main
  20. variations of it. Using a grammar is probably overkill, but at
  21. least it makes clear exactly what we do support. */
  22. %{
  23. #include "as.h"
  24. #include "tc-m68k.h"
  25. #include "m68k-parse.h"
  26. #include "safe-ctype.h"
  27. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
  28. etc), as well as gratuitously global symbol names If other parser
  29. generators (bison, byacc, etc) produce additional global names that
  30. conflict at link time, then those parser generators need to be
  31. fixed instead of adding those names to this list. */
  32. #define yymaxdepth m68k_maxdepth
  33. #define yyparse m68k_parse
  34. #define yylex m68k_lex
  35. #define yyerror m68k_error
  36. #define yylval m68k_lval
  37. #define yychar m68k_char
  38. #define yydebug m68k_debug
  39. #define yypact m68k_pact
  40. #define yyr1 m68k_r1
  41. #define yyr2 m68k_r2
  42. #define yydef m68k_def
  43. #define yychk m68k_chk
  44. #define yypgo m68k_pgo
  45. #define yyact m68k_act
  46. #define yyexca m68k_exca
  47. #define yyerrflag m68k_errflag
  48. #define yynerrs m68k_nerrs
  49. #define yyps m68k_ps
  50. #define yypv m68k_pv
  51. #define yys m68k_s
  52. #define yy_yys m68k_yys
  53. #define yystate m68k_state
  54. #define yytmp m68k_tmp
  55. #define yyv m68k_v
  56. #define yy_yyv m68k_yyv
  57. #define yyval m68k_val
  58. #define yylloc m68k_lloc
  59. #define yyreds m68k_reds /* With YYDEBUG defined */
  60. #define yytoks m68k_toks /* With YYDEBUG defined */
  61. #define yylhs m68k_yylhs
  62. #define yylen m68k_yylen
  63. #define yydefred m68k_yydefred
  64. #define yydgoto m68k_yydgoto
  65. #define yysindex m68k_yysindex
  66. #define yyrindex m68k_yyrindex
  67. #define yygindex m68k_yygindex
  68. #define yytable m68k_yytable
  69. #define yycheck m68k_yycheck
  70. #ifndef YYDEBUG
  71. #define YYDEBUG 1
  72. #endif
  73. /* Internal functions. */
  74. static enum m68k_register m68k_reg_parse (char **);
  75. static int yylex (void);
  76. static void yyerror (const char *);
  77. /* The parser sets fields pointed to by this global variable. */
  78. static struct m68k_op *op;
  79. %}
  80. %union
  81. {
  82. struct m68k_indexreg indexreg;
  83. enum m68k_register reg;
  84. struct m68k_exp exp;
  85. unsigned long mask;
  86. int onereg;
  87. int trailing_ampersand;
  88. }
  89. %token <reg> DR AR FPR FPCR LPC ZAR ZDR LZPC CREG
  90. %token <indexreg> INDEXREG
  91. %token <exp> EXPR
  92. %type <indexreg> zireg zdireg
  93. %type <reg> zadr zdr apc zapc zpc optzapc optczapc
  94. %type <exp> optcexpr optexprc
  95. %type <mask> reglist ireglist reglistpair
  96. %type <onereg> reglistreg
  97. %type <trailing_ampersand> optional_ampersand
  98. %%
  99. /* An operand. */
  100. operand:
  101. generic_operand
  102. | motorola_operand optional_ampersand
  103. {
  104. op->trailing_ampersand = $2;
  105. }
  106. | mit_operand optional_ampersand
  107. {
  108. op->trailing_ampersand = $2;
  109. }
  110. ;
  111. /* A trailing ampersand(for MAC/EMAC mask addressing). */
  112. optional_ampersand:
  113. /* empty */
  114. { $$ = 0; }
  115. | '&'
  116. { $$ = 1; }
  117. ;
  118. /* A generic operand. */
  119. generic_operand:
  120. '<' '<'
  121. {
  122. op->mode = LSH;
  123. }
  124. | '>' '>'
  125. {
  126. op->mode = RSH;
  127. }
  128. | DR
  129. {
  130. op->mode = DREG;
  131. op->reg = $1;
  132. }
  133. | AR
  134. {
  135. op->mode = AREG;
  136. op->reg = $1;
  137. }
  138. | FPR
  139. {
  140. op->mode = FPREG;
  141. op->reg = $1;
  142. }
  143. | FPCR
  144. {
  145. op->mode = CONTROL;
  146. op->reg = $1;
  147. }
  148. | CREG
  149. {
  150. op->mode = CONTROL;
  151. op->reg = $1;
  152. }
  153. | EXPR
  154. {
  155. op->mode = ABSL;
  156. op->disp = $1;
  157. }
  158. | '#' EXPR
  159. {
  160. op->mode = IMMED;
  161. op->disp = $2;
  162. }
  163. | '&' EXPR
  164. {
  165. op->mode = IMMED;
  166. op->disp = $2;
  167. }
  168. | reglist
  169. {
  170. op->mode = REGLST;
  171. op->mask = $1;
  172. }
  173. ;
  174. /* An operand in Motorola syntax. This includes MRI syntax as well,
  175. which may or may not be different in that it permits commutativity
  176. of index and base registers, and permits an offset expression to
  177. appear inside or outside of the parentheses. */
  178. motorola_operand:
  179. '(' AR ')'
  180. {
  181. op->mode = AINDR;
  182. op->reg = $2;
  183. }
  184. | '(' AR ')' '+'
  185. {
  186. op->mode = AINC;
  187. op->reg = $2;
  188. }
  189. | '-' '(' AR ')'
  190. {
  191. op->mode = ADEC;
  192. op->reg = $3;
  193. }
  194. | '(' EXPR ',' zapc ')'
  195. {
  196. op->reg = $4;
  197. op->disp = $2;
  198. if (($4 >= ZADDR0 && $4 <= ZADDR7)
  199. || $4 == ZPC)
  200. op->mode = BASE;
  201. else
  202. op->mode = DISP;
  203. }
  204. | '(' zapc ',' EXPR ')'
  205. {
  206. op->reg = $2;
  207. op->disp = $4;
  208. if (($2 >= ZADDR0 && $2 <= ZADDR7)
  209. || $2 == ZPC)
  210. op->mode = BASE;
  211. else
  212. op->mode = DISP;
  213. }
  214. | EXPR '(' zapc ')'
  215. {
  216. op->reg = $3;
  217. op->disp = $1;
  218. if (($3 >= ZADDR0 && $3 <= ZADDR7)
  219. || $3 == ZPC)
  220. op->mode = BASE;
  221. else
  222. op->mode = DISP;
  223. }
  224. | '(' LPC ')'
  225. {
  226. op->mode = DISP;
  227. op->reg = $2;
  228. }
  229. | '(' ZAR ')'
  230. {
  231. op->mode = BASE;
  232. op->reg = $2;
  233. }
  234. | '(' LZPC ')'
  235. {
  236. op->mode = BASE;
  237. op->reg = $2;
  238. }
  239. | '(' EXPR ',' zapc ',' zireg ')'
  240. {
  241. op->mode = BASE;
  242. op->reg = $4;
  243. op->disp = $2;
  244. op->index = $6;
  245. }
  246. | '(' EXPR ',' zapc ',' zpc ')'
  247. {
  248. if ($4 == PC || $4 == ZPC)
  249. yyerror (_("syntax error"));
  250. op->mode = BASE;
  251. op->reg = $6;
  252. op->disp = $2;
  253. op->index.reg = $4;
  254. op->index.size = SIZE_UNSPEC;
  255. op->index.scale = 1;
  256. }
  257. | '(' EXPR ',' zdireg optczapc ')'
  258. {
  259. op->mode = BASE;
  260. op->reg = $5;
  261. op->disp = $2;
  262. op->index = $4;
  263. }
  264. | '(' zdireg ',' EXPR ')'
  265. {
  266. op->mode = BASE;
  267. op->disp = $4;
  268. op->index = $2;
  269. }
  270. | EXPR '(' zapc ',' zireg ')'
  271. {
  272. op->mode = BASE;
  273. op->reg = $3;
  274. op->disp = $1;
  275. op->index = $5;
  276. }
  277. | '(' zapc ',' zireg ')'
  278. {
  279. op->mode = BASE;
  280. op->reg = $2;
  281. op->index = $4;
  282. }
  283. | EXPR '(' zapc ',' zpc ')'
  284. {
  285. if ($3 == PC || $3 == ZPC)
  286. yyerror (_("syntax error"));
  287. op->mode = BASE;
  288. op->reg = $5;
  289. op->disp = $1;
  290. op->index.reg = $3;
  291. op->index.size = SIZE_UNSPEC;
  292. op->index.scale = 1;
  293. }
  294. | '(' zapc ',' zpc ')'
  295. {
  296. if ($2 == PC || $2 == ZPC)
  297. yyerror (_("syntax error"));
  298. op->mode = BASE;
  299. op->reg = $4;
  300. op->index.reg = $2;
  301. op->index.size = SIZE_UNSPEC;
  302. op->index.scale = 1;
  303. }
  304. | EXPR '(' zdireg optczapc ')'
  305. {
  306. op->mode = BASE;
  307. op->reg = $4;
  308. op->disp = $1;
  309. op->index = $3;
  310. }
  311. | '(' zdireg optczapc ')'
  312. {
  313. op->mode = BASE;
  314. op->reg = $3;
  315. op->index = $2;
  316. }
  317. | '(' '[' EXPR optczapc ']' ',' zireg optcexpr ')'
  318. {
  319. op->mode = POST;
  320. op->reg = $4;
  321. op->disp = $3;
  322. op->index = $7;
  323. op->odisp = $8;
  324. }
  325. | '(' '[' EXPR optczapc ']' optcexpr ')'
  326. {
  327. op->mode = POST;
  328. op->reg = $4;
  329. op->disp = $3;
  330. op->odisp = $6;
  331. }
  332. | '(' '[' zapc ']' ',' zireg optcexpr ')'
  333. {
  334. op->mode = POST;
  335. op->reg = $3;
  336. op->index = $6;
  337. op->odisp = $7;
  338. }
  339. | '(' '[' zapc ']' optcexpr ')'
  340. {
  341. op->mode = POST;
  342. op->reg = $3;
  343. op->odisp = $5;
  344. }
  345. | '(' '[' EXPR ',' zapc ',' zireg ']' optcexpr ')'
  346. {
  347. op->mode = PRE;
  348. op->reg = $5;
  349. op->disp = $3;
  350. op->index = $7;
  351. op->odisp = $9;
  352. }
  353. | '(' '[' zapc ',' zireg ']' optcexpr ')'
  354. {
  355. op->mode = PRE;
  356. op->reg = $3;
  357. op->index = $5;
  358. op->odisp = $7;
  359. }
  360. | '(' '[' EXPR ',' zapc ',' zpc ']' optcexpr ')'
  361. {
  362. if ($5 == PC || $5 == ZPC)
  363. yyerror (_("syntax error"));
  364. op->mode = PRE;
  365. op->reg = $7;
  366. op->disp = $3;
  367. op->index.reg = $5;
  368. op->index.size = SIZE_UNSPEC;
  369. op->index.scale = 1;
  370. op->odisp = $9;
  371. }
  372. | '(' '[' zapc ',' zpc ']' optcexpr ')'
  373. {
  374. if ($3 == PC || $3 == ZPC)
  375. yyerror (_("syntax error"));
  376. op->mode = PRE;
  377. op->reg = $5;
  378. op->index.reg = $3;
  379. op->index.size = SIZE_UNSPEC;
  380. op->index.scale = 1;
  381. op->odisp = $7;
  382. }
  383. | '(' '[' optexprc zdireg optczapc ']' optcexpr ')'
  384. {
  385. op->mode = PRE;
  386. op->reg = $5;
  387. op->disp = $3;
  388. op->index = $4;
  389. op->odisp = $7;
  390. }
  391. ;
  392. /* An operand in MIT syntax. */
  393. mit_operand:
  394. optzapc '@'
  395. {
  396. /* We use optzapc to avoid a shift/reduce conflict. */
  397. if ($1 < ADDR0 || $1 > ADDR7)
  398. yyerror (_("syntax error"));
  399. op->mode = AINDR;
  400. op->reg = $1;
  401. }
  402. | optzapc '@' '+'
  403. {
  404. /* We use optzapc to avoid a shift/reduce conflict. */
  405. if ($1 < ADDR0 || $1 > ADDR7)
  406. yyerror (_("syntax error"));
  407. op->mode = AINC;
  408. op->reg = $1;
  409. }
  410. | optzapc '@' '-'
  411. {
  412. /* We use optzapc to avoid a shift/reduce conflict. */
  413. if ($1 < ADDR0 || $1 > ADDR7)
  414. yyerror (_("syntax error"));
  415. op->mode = ADEC;
  416. op->reg = $1;
  417. }
  418. | optzapc '@' '(' EXPR ')'
  419. {
  420. op->reg = $1;
  421. op->disp = $4;
  422. if (($1 >= ZADDR0 && $1 <= ZADDR7)
  423. || $1 == ZPC)
  424. op->mode = BASE;
  425. else
  426. op->mode = DISP;
  427. }
  428. | optzapc '@' '(' optexprc zireg ')'
  429. {
  430. op->mode = BASE;
  431. op->reg = $1;
  432. op->disp = $4;
  433. op->index = $5;
  434. }
  435. | optzapc '@' '(' EXPR ')' '@' '(' optexprc zireg ')'
  436. {
  437. op->mode = POST;
  438. op->reg = $1;
  439. op->disp = $4;
  440. op->index = $9;
  441. op->odisp = $8;
  442. }
  443. | optzapc '@' '(' EXPR ')' '@' '(' EXPR ')'
  444. {
  445. op->mode = POST;
  446. op->reg = $1;
  447. op->disp = $4;
  448. op->odisp = $8;
  449. }
  450. | optzapc '@' '(' optexprc zireg ')' '@' '(' EXPR ')'
  451. {
  452. op->mode = PRE;
  453. op->reg = $1;
  454. op->disp = $4;
  455. op->index = $5;
  456. op->odisp = $9;
  457. }
  458. ;
  459. /* An index register, possibly suppressed, which need not have a size
  460. or scale. */
  461. zireg:
  462. INDEXREG
  463. | zadr
  464. {
  465. $$.reg = $1;
  466. $$.size = SIZE_UNSPEC;
  467. $$.scale = 1;
  468. }
  469. ;
  470. /* A register which may be an index register, but which may not be an
  471. address register. This nonterminal is used to avoid ambiguity when
  472. trying to parse something like (0,d5,a6) as compared to (0,a6,d5). */
  473. zdireg:
  474. INDEXREG
  475. | zdr
  476. {
  477. $$.reg = $1;
  478. $$.size = SIZE_UNSPEC;
  479. $$.scale = 1;
  480. }
  481. ;
  482. /* An address or data register, or a suppressed address or data
  483. register. */
  484. zadr:
  485. zdr
  486. | AR
  487. | ZAR
  488. ;
  489. /* A data register which may be suppressed. */
  490. zdr:
  491. DR
  492. | ZDR
  493. ;
  494. /* Either an address register or the PC. */
  495. apc:
  496. AR
  497. | LPC
  498. ;
  499. /* Either an address register, or the PC, or a suppressed address
  500. register, or a suppressed PC. */
  501. zapc:
  502. apc
  503. | LZPC
  504. | ZAR
  505. ;
  506. /* An optional zapc. */
  507. optzapc:
  508. /* empty */
  509. {
  510. $$ = ZADDR0;
  511. }
  512. | zapc
  513. ;
  514. /* The PC, optionally suppressed. */
  515. zpc:
  516. LPC
  517. | LZPC
  518. ;
  519. /* ',' zapc when it may be omitted. */
  520. optczapc:
  521. /* empty */
  522. {
  523. $$ = ZADDR0;
  524. }
  525. | ',' zapc
  526. {
  527. $$ = $2;
  528. }
  529. ;
  530. /* ',' EXPR when it may be omitted. */
  531. optcexpr:
  532. /* empty */
  533. {
  534. $$.exp.X_op = O_absent;
  535. $$.size = SIZE_UNSPEC;
  536. }
  537. | ',' EXPR
  538. {
  539. $$ = $2;
  540. }
  541. ;
  542. /* EXPR ',' when it may be omitted. */
  543. optexprc:
  544. /* empty */
  545. {
  546. $$.exp.X_op = O_absent;
  547. $$.size = SIZE_UNSPEC;
  548. }
  549. | EXPR ','
  550. {
  551. $$ = $1;
  552. }
  553. ;
  554. /* A register list for the movem instruction. */
  555. reglist:
  556. reglistpair
  557. | reglistpair '/' ireglist
  558. {
  559. $$ = $1 | $3;
  560. }
  561. | reglistreg '/' ireglist
  562. {
  563. $$ = (1 << $1) | $3;
  564. }
  565. ;
  566. /* We use ireglist when we know we are looking at a reglist, and we
  567. can safely reduce a simple register to reglistreg. If we permitted
  568. reglist to reduce to reglistreg, it would be ambiguous whether a
  569. plain register were a DREG/AREG/FPREG or a REGLST. */
  570. ireglist:
  571. reglistreg
  572. {
  573. $$ = 1 << $1;
  574. }
  575. | reglistpair
  576. | reglistpair '/' ireglist
  577. {
  578. $$ = $1 | $3;
  579. }
  580. | reglistreg '/' ireglist
  581. {
  582. $$ = (1 << $1) | $3;
  583. }
  584. ;
  585. reglistpair:
  586. reglistreg '-' reglistreg
  587. {
  588. if ($1 <= $3)
  589. $$ = (1 << ($3 + 1)) - 1 - ((1 << $1) - 1);
  590. else
  591. $$ = (1 << ($1 + 1)) - 1 - ((1 << $3) - 1);
  592. }
  593. ;
  594. reglistreg:
  595. DR
  596. {
  597. $$ = $1 - DATA0;
  598. }
  599. | AR
  600. {
  601. $$ = $1 - ADDR0 + 8;
  602. }
  603. | FPR
  604. {
  605. $$ = $1 - FP0 + 16;
  606. }
  607. | FPCR
  608. {
  609. if ($1 == FPI)
  610. $$ = 24;
  611. else if ($1 == FPS)
  612. $$ = 25;
  613. else
  614. $$ = 26;
  615. }
  616. ;
  617. %%
  618. /* The string to parse is stored here, and modified by yylex. */
  619. static char *str;
  620. /* The original string pointer. */
  621. static char *strorig;
  622. /* If *CCP could be a register, return the register number and advance
  623. *CCP. Otherwise don't change *CCP, and return 0. */
  624. static enum m68k_register
  625. m68k_reg_parse (ccp)
  626. register char **ccp;
  627. {
  628. char *start = *ccp;
  629. char c;
  630. char *p;
  631. symbolS *symbolp;
  632. if (flag_reg_prefix_optional)
  633. {
  634. if (*start == REGISTER_PREFIX)
  635. start++;
  636. p = start;
  637. }
  638. else
  639. {
  640. if (*start != REGISTER_PREFIX)
  641. return 0;
  642. p = start + 1;
  643. }
  644. if (! is_name_beginner (*p))
  645. return 0;
  646. p++;
  647. while (is_part_of_name (*p) && *p != '.' && *p != ':' && *p != '*')
  648. p++;
  649. c = *p;
  650. *p = 0;
  651. symbolp = symbol_find (start);
  652. *p = c;
  653. if (symbolp != NULL && S_GET_SEGMENT (symbolp) == reg_section)
  654. {
  655. *ccp = p;
  656. return S_GET_VALUE (symbolp);
  657. }
  658. /* In MRI mode, something like foo.bar can be equated to a register
  659. name. */
  660. while (flag_mri && c == '.')
  661. {
  662. ++p;
  663. while (is_part_of_name (*p) && *p != '.' && *p != ':' && *p != '*')
  664. p++;
  665. c = *p;
  666. *p = '\0';
  667. symbolp = symbol_find (start);
  668. *p = c;
  669. if (symbolp != NULL && S_GET_SEGMENT (symbolp) == reg_section)
  670. {
  671. *ccp = p;
  672. return S_GET_VALUE (symbolp);
  673. }
  674. }
  675. return 0;
  676. }
  677. /* The lexer. */
  678. static int
  679. yylex ()
  680. {
  681. enum m68k_register reg;
  682. char *s;
  683. int parens;
  684. int c = 0;
  685. int tail = 0;
  686. char *hold;
  687. if (*str == ' ')
  688. ++str;
  689. if (*str == '\0')
  690. return 0;
  691. /* Various special characters are just returned directly. */
  692. switch (*str)
  693. {
  694. case '@':
  695. /* In MRI mode, this can be the start of an octal number. */
  696. if (flag_mri)
  697. {
  698. if (ISDIGIT (str[1])
  699. || ((str[1] == '+' || str[1] == '-')
  700. && ISDIGIT (str[2])))
  701. break;
  702. }
  703. /* Fall through. */
  704. case '#':
  705. case '&':
  706. case ',':
  707. case ')':
  708. case '/':
  709. case '[':
  710. case ']':
  711. case '<':
  712. case '>':
  713. return *str++;
  714. case '+':
  715. /* It so happens that a '+' can only appear at the end of an
  716. operand, or if it is trailed by an '&'(see mac load insn).
  717. If it appears anywhere else, it must be a unary. */
  718. if (str[1] == '\0' || (str[1] == '&' && str[2] == '\0'))
  719. return *str++;
  720. break;
  721. case '-':
  722. /* A '-' can only appear in -(ar), rn-rn, or ar@-. If it
  723. appears anywhere else, it must be a unary minus on an
  724. expression, unless it it trailed by a '&'(see mac load insn). */
  725. if (str[1] == '\0' || (str[1] == '&' && str[2] == '\0'))
  726. return *str++;
  727. s = str + 1;
  728. if (*s == '(')
  729. ++s;
  730. if (m68k_reg_parse (&s) != 0)
  731. return *str++;
  732. break;
  733. case '(':
  734. /* A '(' can only appear in `(reg)', `(expr,...', `([', `@(', or
  735. `)('. If it appears anywhere else, it must be starting an
  736. expression. */
  737. if (str[1] == '['
  738. || (str > strorig
  739. && (str[-1] == '@'
  740. || str[-1] == ')')))
  741. return *str++;
  742. s = str + 1;
  743. if (m68k_reg_parse (&s) != 0)
  744. return *str++;
  745. /* Check for the case of '(expr,...' by scanning ahead. If we
  746. find a comma outside of balanced parentheses, we return '('.
  747. If we find an unbalanced right parenthesis, then presumably
  748. the '(' really starts an expression. */
  749. parens = 0;
  750. for (s = str + 1; *s != '\0'; s++)
  751. {
  752. if (*s == '(')
  753. ++parens;
  754. else if (*s == ')')
  755. {
  756. if (parens == 0)
  757. break;
  758. --parens;
  759. }
  760. else if (*s == ',' && parens == 0)
  761. {
  762. /* A comma can not normally appear in an expression, so
  763. this is a case of '(expr,...'. */
  764. return *str++;
  765. }
  766. }
  767. }
  768. /* See if it's a register. */
  769. reg = m68k_reg_parse (&str);
  770. if (reg != 0)
  771. {
  772. int ret;
  773. yylval.reg = reg;
  774. if (reg >= DATA0 && reg <= DATA7)
  775. ret = DR;
  776. else if (reg >= ADDR0 && reg <= ADDR7)
  777. ret = AR;
  778. else if (reg >= FP0 && reg <= FP7)
  779. return FPR;
  780. else if (reg == FPI
  781. || reg == FPS
  782. || reg == FPC)
  783. return FPCR;
  784. else if (reg == PC)
  785. return LPC;
  786. else if (reg >= ZDATA0 && reg <= ZDATA7)
  787. ret = ZDR;
  788. else if (reg >= ZADDR0 && reg <= ZADDR7)
  789. ret = ZAR;
  790. else if (reg == ZPC)
  791. return LZPC;
  792. else
  793. return CREG;
  794. /* If we get here, we have a data or address register. We
  795. must check for a size or scale; if we find one, we must
  796. return INDEXREG. */
  797. s = str;
  798. if (*s != '.' && *s != ':' && *s != '*')
  799. return ret;
  800. yylval.indexreg.reg = reg;
  801. if (*s != '.' && *s != ':')
  802. yylval.indexreg.size = SIZE_UNSPEC;
  803. else
  804. {
  805. ++s;
  806. switch (*s)
  807. {
  808. case 'w':
  809. case 'W':
  810. yylval.indexreg.size = SIZE_WORD;
  811. ++s;
  812. break;
  813. case 'l':
  814. case 'L':
  815. yylval.indexreg.size = SIZE_LONG;
  816. ++s;
  817. break;
  818. default:
  819. yyerror (_("illegal size specification"));
  820. yylval.indexreg.size = SIZE_UNSPEC;
  821. break;
  822. }
  823. }
  824. yylval.indexreg.scale = 1;
  825. if (*s == '*' || *s == ':')
  826. {
  827. expressionS scale;
  828. ++s;
  829. hold = input_line_pointer;
  830. input_line_pointer = s;
  831. expression (&scale);
  832. s = input_line_pointer;
  833. input_line_pointer = hold;
  834. if (scale.X_op != O_constant)
  835. yyerror (_("scale specification must resolve to a number"));
  836. else
  837. {
  838. switch (scale.X_add_number)
  839. {
  840. case 1:
  841. case 2:
  842. case 4:
  843. case 8:
  844. yylval.indexreg.scale = scale.X_add_number;
  845. break;
  846. default:
  847. yyerror (_("invalid scale value"));
  848. break;
  849. }
  850. }
  851. }
  852. str = s;
  853. return INDEXREG;
  854. }
  855. /* It must be an expression. Before we call expression, we need to
  856. look ahead to see if there is a size specification. We must do
  857. that first, because otherwise foo.l will be treated as the symbol
  858. foo.l, rather than as the symbol foo with a long size
  859. specification. The grammar requires that all expressions end at
  860. the end of the operand, or with ',', '(', ']', ')'. */
  861. parens = 0;
  862. for (s = str; *s != '\0'; s++)
  863. {
  864. if (*s == '(')
  865. {
  866. if (parens == 0
  867. && s > str
  868. && (s[-1] == ')' || ISALNUM (s[-1])))
  869. break;
  870. ++parens;
  871. }
  872. else if (*s == ')')
  873. {
  874. if (parens == 0)
  875. break;
  876. --parens;
  877. }
  878. else if (parens == 0
  879. && (*s == ',' || *s == ']'))
  880. break;
  881. }
  882. yylval.exp.size = SIZE_UNSPEC;
  883. if (s <= str + 2
  884. || (s[-2] != '.' && s[-2] != ':'))
  885. tail = 0;
  886. else
  887. {
  888. switch (s[-1])
  889. {
  890. case 's':
  891. case 'S':
  892. case 'b':
  893. case 'B':
  894. yylval.exp.size = SIZE_BYTE;
  895. break;
  896. case 'w':
  897. case 'W':
  898. yylval.exp.size = SIZE_WORD;
  899. break;
  900. case 'l':
  901. case 'L':
  902. yylval.exp.size = SIZE_LONG;
  903. break;
  904. default:
  905. break;
  906. }
  907. if (yylval.exp.size != SIZE_UNSPEC)
  908. tail = 2;
  909. }
  910. #ifdef OBJ_ELF
  911. {
  912. /* Look for @PLTPC, etc. */
  913. char *cp;
  914. yylval.exp.pic_reloc = pic_none;
  915. cp = s - tail;
  916. if (cp - 6 > str && cp[-6] == '@')
  917. {
  918. if (strncmp (cp - 6, "@PLTPC", 6) == 0)
  919. {
  920. yylval.exp.pic_reloc = pic_plt_pcrel;
  921. tail += 6;
  922. }
  923. else if (strncmp (cp - 6, "@GOTPC", 6) == 0)
  924. {
  925. yylval.exp.pic_reloc = pic_got_pcrel;
  926. tail += 6;
  927. }
  928. }
  929. else if (cp - 4 > str && cp[-4] == '@')
  930. {
  931. if (strncmp (cp - 4, "@PLT", 4) == 0)
  932. {
  933. yylval.exp.pic_reloc = pic_plt_off;
  934. tail += 4;
  935. }
  936. else if (strncmp (cp - 4, "@GOT", 4) == 0)
  937. {
  938. yylval.exp.pic_reloc = pic_got_off;
  939. tail += 4;
  940. }
  941. }
  942. }
  943. #endif
  944. if (tail != 0)
  945. {
  946. c = s[-tail];
  947. s[-tail] = 0;
  948. }
  949. hold = input_line_pointer;
  950. input_line_pointer = str;
  951. expression (&yylval.exp.exp);
  952. str = input_line_pointer;
  953. input_line_pointer = hold;
  954. if (tail != 0)
  955. {
  956. s[-tail] = c;
  957. str = s;
  958. }
  959. return EXPR;
  960. }
  961. /* Parse an m68k operand. This is the only function which is called
  962. from outside this file. */
  963. int
  964. m68k_ip_op (s, oparg)
  965. char *s;
  966. struct m68k_op *oparg;
  967. {
  968. memset (oparg, 0, sizeof *oparg);
  969. oparg->error = NULL;
  970. oparg->index.reg = ZDATA0;
  971. oparg->index.scale = 1;
  972. oparg->disp.exp.X_op = O_absent;
  973. oparg->odisp.exp.X_op = O_absent;
  974. str = strorig = s;
  975. op = oparg;
  976. return yyparse ();
  977. }
  978. /* The error handler. */
  979. static void
  980. yyerror (s)
  981. const char *s;
  982. {
  983. op->error = s;
  984. }