(distribute_notes, case REG_DEAD): If a call uses a
[official-gcc.git] / gcc / bi-parser.y
blob5b3be52b2099bf8ac45aca2c46fcc8cbc37179df
1 /* Bytecode definition file parser.
2 Copyright (C) 1993 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC 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.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include <stdio.h>
24 #include "hconfig.h"
25 #include "bi-defs.h"
27 extern char yytext[];
28 extern int yyleng;
31 /* Chain of all defs built by the parser. */
32 struct def *defs;
33 int ndefs;
35 static struct node *makenode ();
36 static struct variation *makevar ();
37 static struct def *makedef ();
39 void yyerror ();
43 %union
45 char *string;
46 struct def *def;
47 struct variation *variation;
48 struct node *node;
51 %token <string> DEFOP STRING
52 %type <string> opt_string
53 %type <def> defs def
54 %type <variation> variations variation
55 %type <node> list items item
59 top:
60 defs
61 { defs = $1; }
64 defs:
65 def
66 | defs def
67 { $2->next = $1; $$ = $2; }
70 def:
71 DEFOP '(' STRING ',' opt_string ',' '(' variations ')' ')'
72 { $$ = makedef ($3, $5, $8); }
75 variations:
76 variation
77 | variations ',' variation
78 { $3->next = $1; $$ = $3; }
81 variation:
82 '(' opt_string ')'
83 { $$ = makevar ($2, (struct node *) NULL, (struct node *) NULL, (struct node *) NULL); }
84 | '(' opt_string ',' list ')'
85 { $$ = makevar ($2, $4, (struct node *) NULL, (struct node *) NULL); }
86 | '(' opt_string ',' list ',' list ')'
87 { $$ = makevar ($2, $4, $6, (struct node *) NULL); }
88 | '(' opt_string ',' list ',' list ',' list ')'
89 { $$ = makevar ($2, $4, $6, $8); }
92 opt_string:
93 /* empty */ { $$ = ""; }
94 | STRING { $$ = $1; }
97 list:
98 '(' items ')'
99 { $$ = $2; }
100 | /* empty */
101 { $$ = NULL; }
104 items:
105 item
106 /* Note right recursion. */
107 | item ',' items
108 { $1->next = $3; $$ = $1; }
111 item:
112 STRING
113 { $$ = makenode ($1); }
118 static struct node *
119 makenode (s)
120 char *s;
122 struct node *n;
124 n = (struct node *) malloc (sizeof (struct node));
125 n->text = s;
126 n->next = NULL;
127 return n;
130 static struct variation *
131 makevar (name, inputs, outputs, literals)
132 char *name;
133 struct node *inputs, *outputs, *literals;
135 struct variation *v;
137 v = (struct variation *) malloc (sizeof (struct variation));
138 v->name = name;
139 v->code = ndefs++;
140 v->inputs = inputs;
141 v->outputs = outputs;
142 v->literals = literals;
143 v->next = NULL;
144 return v;
147 static struct def *
148 makedef (name, template, vars)
149 char *name, *template;
150 struct variation *vars;
152 struct def *d;
154 d = (struct def *) malloc (sizeof (struct def));
155 d->basename = name;
156 d->template = template;
157 d->variations = vars;
158 d->next = NULL;
159 return d;
162 void
163 yyerror (s)
164 char *s;
166 fprintf (stderr, "syntax error in input\n");
167 exit (FATAL_EXIT_CODE);