1 /* m68k.y -- bison grammar for m68k operand parsing
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Written by Ken Raeburn and Ian Lance Taylor, Cygnus Support
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This file holds a bison grammar to parse m68k operands. The m68k
23 has a complicated operand syntax, and gas supports two main
24 variations of it. Using a grammar is probably overkill, but at
25 least it makes clear exactly what we do support. */
31 #include "m68k-parse.h"
33 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
34 etc), as well as gratuitiously global symbol names If other parser
35 generators (bison, byacc, etc) produce additional global names that
36 conflict at link time, then those parser generators need to be
37 fixed instead of adding those names to this list. */
39 #define yymaxdepth m68k_maxdepth
40 #define yyparse m68k_parse
41 #define yylex m68k_lex
42 #define yyerror m68k_error
43 #define yylval m68k_lval
44 #define yychar m68k_char
45 #define yydebug m68k_debug
46 #define yypact m68k_pact
49 #define yydef m68k_def
50 #define yychk m68k_chk
51 #define yypgo m68k_pgo
52 #define yyact m68k_act
53 #define yyexca m68k_exca
54 #define yyerrflag m68k_errflag
55 #define yynerrs m68k_nerrs
59 #define yy_yys m68k_yys
60 #define yystate m68k_state
61 #define yytmp m68k_tmp
63 #define yy_yyv m68k_yyv
64 #define yyval m68k_val
65 #define yylloc m68k_lloc
66 #define yyreds m68k_reds /* With YYDEBUG defined */
67 #define yytoks m68k_toks /* With YYDEBUG defined */
68 #define yylhs m68k_yylhs
69 #define yylen m68k_yylen
70 #define yydefred m68k_yydefred
71 #define yydgoto m68k_yydgoto
72 #define yysindex m68k_yysindex
73 #define yyrindex m68k_yyrindex
74 #define yygindex m68k_yygindex
75 #define yytable m68k_yytable
76 #define yycheck m68k_yycheck
82 /* Internal functions. */
84 static enum m68k_register m68k_reg_parse PARAMS ((char **));
85 static int yylex PARAMS (());
86 static void yyerror PARAMS ((const char *));
88 /* The parser sets fields pointed to by this global variable. */
89 static struct m68k_op *op;
95 struct m68k_indexreg indexreg;
96 enum m68k_register reg;
102 %token <reg> DR AR FPR FPCR LPC ZAR ZDR LZPC CREG
103 %token <indexreg> INDEXREG
106 %type <indexreg> zireg zdireg
107 %type <reg> zadr zdr apc zapc zpc optzapc optczapc
108 %type <exp> optcexpr optexprc
109 %type <mask> reglist ireglist reglistpair
110 %type <onereg> reglistreg
122 /* A generic operand. */
172 /* An operand in Motorola syntax. This includes MRI syntax as well,
173 which may or may not be different in that it permits commutativity
174 of index and base registers, and permits an offset expression to
175 appear inside or outside of the parentheses. */
193 | '(' EXPR ',' zapc ')'
197 if (($4 >= ZADDR0 && $4 <= ZADDR7)
207 if (($3 >= ZADDR0 && $3 <= ZADDR7)
223 | '(' EXPR ',' zapc ',' zireg ')'
230 | '(' EXPR ',' zapc ',' zpc ')'
232 if ($4 == PC || $4 == ZPC)
233 yyerror ("syntax error");
238 op->index.size = SIZE_UNSPEC;
241 | '(' EXPR ',' zdireg optczapc ')'
248 | EXPR '(' zapc ',' zireg ')'
255 | '(' zapc ',' zireg ')'
261 | EXPR '(' zapc ',' zpc ')'
263 if ($3 == PC || $3 == ZPC)
264 yyerror ("syntax error");
269 op->index.size = SIZE_UNSPEC;
272 | '(' zapc ',' zpc ')'
274 if ($2 == PC || $2 == ZPC)
275 yyerror ("syntax error");
279 op->index.size = SIZE_UNSPEC;
282 | EXPR '(' zdireg optczapc ')'
289 | '(' zdireg optczapc ')'
295 | '(' '[' EXPR optczapc ']' ',' zireg optcexpr ')'
303 | '(' '[' EXPR optczapc ']' optcexpr ')'
310 | '(' '[' zapc ']' ',' zireg optcexpr ')'
317 | '(' '[' zapc ']' optcexpr ')'
323 | '(' '[' EXPR ',' zapc ',' zireg ']' optcexpr ')'
331 | '(' '[' zapc ',' zireg ']' optcexpr ')'
338 | '(' '[' EXPR ',' zapc ',' zpc ']' optcexpr ')'
340 if ($5 == PC || $5 == ZPC)
341 yyerror ("syntax error");
346 op->index.size = SIZE_UNSPEC;
350 | '(' '[' zapc ',' zpc ']' optcexpr ')'
352 if ($3 == PC || $3 == ZPC)
353 yyerror ("syntax error");
357 op->index.size = SIZE_UNSPEC;
361 | '(' '[' optexprc zdireg optczapc ']' optcexpr ')'
371 /* An operand in MIT syntax. */
376 /* We use optzapc to avoid a shift/reduce conflict. */
377 if ($1 < ADDR0 || $1 > ADDR7)
378 yyerror ("syntax error");
384 /* We use optzapc to avoid a shift/reduce conflict. */
385 if ($1 < ADDR0 || $1 > ADDR7)
386 yyerror ("syntax error");
392 /* We use optzapc to avoid a shift/reduce conflict. */
393 if ($1 < ADDR0 || $1 > ADDR7)
394 yyerror ("syntax error");
398 | optzapc '@' '(' EXPR ')'
402 if (($1 >= ZADDR0 && $1 <= ZADDR7)
408 | optzapc '@' '(' optexprc zireg ')'
415 | optzapc '@' '(' EXPR ')' '@' '(' optexprc zireg ')'
423 | optzapc '@' '(' EXPR ')' '@' '(' EXPR ')'
430 | optzapc '@' '(' optexprc zireg ')' '@' '(' EXPR ')'
440 /* An index register, possibly suppressed, which need not have a size
448 $$.size = SIZE_UNSPEC;
453 /* A register which may be an index register, but which may not be an
454 address register. This nonterminal is used to avoid ambiguity when
455 trying to parse something like (0,d5,a6) as compared to (0,a6,d5). */
462 $$.size = SIZE_UNSPEC;
467 /* An address or data register, or a suppressed address or data
476 /* A data register which may be suppressed. */
483 /* Either an address register or the PC. */
490 /* Either an address register, or the PC, or a suppressed address
491 register, or a suppressed PC. */
499 /* An optional zapc. */
509 /* The PC, optionally suppressed. */
516 /* ',' zapc when it may be omitted. */
529 /* ',' EXPR when it may be omitted. */
534 $$.exp.X_op = O_absent;
535 $$.size = SIZE_UNSPEC;
543 /* EXPR ',' when it may be omitted. */
548 $$.exp.X_op = O_absent;
549 $$.size = SIZE_UNSPEC;
557 /* A register list for the movem instruction. */
561 | reglistpair '/' ireglist
565 | reglistreg '/' ireglist
571 /* We use ireglist when we know we are looking at a reglist, and we
572 can safely reduce a simple register to reglistreg. If we permitted
573 reglist to reduce to reglistreg, it would be ambiguous whether a
574 plain register were a DREG/AREG/FPREG or a REGLST. */
582 | reglistpair '/' ireglist
586 | reglistreg '/' ireglist
593 reglistreg '-' reglistreg
595 $$ = (1 << ($3 + 1)) - 1 - ((1 << $1) - 1);
625 /* The string to parse is stored here, and modified by yylex. */
629 /* The original string pointer. */
631 static char *strorig;
633 /* If *CCP could be a register, return the register number and advance
634 *CCP. Otherwise don't change *CCP, and return 0. */
636 static enum m68k_register
645 if (flag_reg_prefix_optional)
647 if (*start == REGISTER_PREFIX)
653 if (*start != REGISTER_PREFIX)
658 if (! is_name_beginner (*p))
662 while (is_part_of_name (*p) && *p != '.' && *p != ':' && *p != '*')
667 symbolp = symbol_find (start);
670 if (symbolp != NULL && S_GET_SEGMENT (symbolp) == reg_section)
673 return S_GET_VALUE (symbolp);
684 enum m68k_register reg;
696 /* Various special characters are just returned directly. */
709 /* It so happens that a '+' can only appear at the end of an
710 operand. If it appears anywhere else, it must be a unary
711 plus on an expression. */
716 /* A '-' can only appear in -(ar), rn-rn, or ar@-. If it
717 appears anywhere else, it must be a unary minus on an
724 if (m68k_reg_parse (&s) != 0)
728 /* A '(' can only appear in `(reg)', `(expr,...', `([', `@(', or
729 `)('. If it appears anywhere else, it must be starting an
737 if (m68k_reg_parse (&s) != 0)
739 /* Check for the case of '(expr,...' by scanning ahead. If we
740 find a comma outside of balanced parentheses, we return '('.
741 If we find an unbalanced right parenthesis, then presumably
742 the '(' really starts an expression. */
744 for (s = str + 1; *s != '\0'; s++)
754 else if (*s == ',' && parens == 0)
756 /* A comma can not normally appear in an expression, so
757 this is a case of '(expr,...'. */
763 /* See if it's a register. */
765 reg = m68k_reg_parse (&str);
772 if (reg >= DATA0 && reg <= DATA7)
774 else if (reg >= ADDR0 && reg <= ADDR7)
776 else if (reg >= FP0 && reg <= FP7)
784 else if (reg >= ZDATA0 && reg <= ZDATA7)
786 else if (reg >= ZADDR0 && reg <= ZADDR7)
793 /* If we get here, we have a data or address register. We
794 must check for a size or scale; if we find one, we must
799 if (*s != '.' && *s != ':' && *s != '*')
802 yylval.indexreg.reg = reg;
804 if (*s != '.' && *s != ':')
805 yylval.indexreg.size = SIZE_UNSPEC;
813 yylval.indexreg.size = SIZE_WORD;
818 yylval.indexreg.size = SIZE_LONG;
822 yyerror ("illegal size specification");
823 yylval.indexreg.size = SIZE_UNSPEC;
828 if (*s != '*' && *s != ':')
829 yylval.indexreg.scale = 1;
839 yylval.indexreg.scale = *s - '0';
843 yyerror ("illegal scale specification");
844 yylval.indexreg.scale = 1;
854 /* It must be an expression. Before we call expression, we need to
855 look ahead to see if there is a size specification. We must do
856 that first, because otherwise foo.l will be treated as the symbol
857 foo.l, rather than as the symbol foo with a long size
858 specification. The grammar requires that all expressions end at
859 the end of the operand, or with ',', '(', ']', ')'. */
862 for (s = str; *s != '\0'; s++)
868 && (s[-1] == ')' || isalnum ((unsigned char) s[-1])))
879 && (*s == ',' || *s == ']'))
883 yylval.exp.size = SIZE_UNSPEC;
885 || (s[-2] != '.' && s[-2] != ':'))
895 yylval.exp.size = SIZE_BYTE;
899 yylval.exp.size = SIZE_WORD;
903 yylval.exp.size = SIZE_LONG;
909 if (yylval.exp.size != SIZE_UNSPEC)
916 hold = input_line_pointer;
917 input_line_pointer = str;
918 expression (&yylval.exp.exp);
919 str = input_line_pointer;
920 input_line_pointer = hold;
931 /* Parse an m68k operand. This is the only function which is called
932 from outside this file. */
935 m68k_ip_op (s, oparg)
937 struct m68k_op *oparg;
939 memset (oparg, 0, sizeof *oparg);
941 oparg->index.reg = ZDATA0;
942 oparg->index.scale = 1;
943 oparg->disp.exp.X_op = O_absent;
944 oparg->odisp.exp.X_op = O_absent;
952 /* The error handler. */