Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / tbg / vhdl.y
1 %{
2
3 #include "tbg.h"
4
5 t_port *port;
6 int right_entity = 0;
7
8 int yyerror ();
9 int yylex ();
10
11 chain_list *ch;
12
13 %}
14
15 %union {
16 char *t_pchar;
17 long t_long;
18 struct {int B0; int B1;} t_range;
19 struct chain *t_chain;
20 };
21
22 %token _ENTITY
23 %token _INTEGER
24 %token _STD_LOGIC
25 %token _STD_LOGIC_VECTOR
26 %token _IN
27 %token _INOUT
28 %token _OUT
29 %token _PORT
30 %token _GENERIC
31 %token _DOWNTO
32 %token _TO
33 %token _END
34 %token <t_pchar> _IDENTIFIER
35 %token _IS
36 %token <t_long> _NUMBER
37
38 %left '-' '+'
39 %left '*' '/'
40 %left NEG
41
42 %type <t_range> range
43 %type <t_long> direction
44 %type <t_long> bound
45 %type <t_chain> idlist;
46
47 %start entity
48
49
50 %%
51
52 entity : _ENTITY _IDENTIFIER {if (!strcasecmp ($2, DESIGN_NAME)) right_entity = 1;} _IS gen_decl port_decl _END
53 ;
54
55 gen_decl : _GENERIC '(' gen_list gen ')' ';'
56 | _GENERIC '(' ')' ';'
57 | /* empty */
58 ;
59
60 gen_list : gen_list gen ';'
61 | gen ';'
62
63 gen : idlist ':' _INTEGER
64 {
65 }
66 ;
67
68 port_decl : _PORT '(' port_list port ')' ';'
69 | _PORT '(' ')' ';'
70 ;
71
72 port_list : port_list port ';'
73 | port ';'
74 ;
75
76 port : idlist ':' direction type range
77 {
78 if (right_entity) {
79 for (ch = reverse ($1); ch; ch = ch->NEXT) {
80 if (!HEAD_PORT) {
81 HEAD_PORT = (t_port*)mbkalloc (sizeof (struct t_port));
82 HEAD_PORT->NAME = (char*)ch->DATA;
83 HEAD_PORT->NEXT = NULL;
84 HEAD_PORT->FLAG = 0;
85 HEAD_PORT->VALUE = NULL;
86 HEAD_PORT->DIRECTION = $3;
87 HEAD_PORT->B0 = $5.B0;
88 HEAD_PORT->B1 = $5.B1;
89 port = HEAD_PORT;
90 } else {
91 port->NEXT = (t_port*)mbkalloc (sizeof (struct t_port));
92 port = port->NEXT;
93 port->NEXT = NULL;
94 port->FLAG = 0;
95 port->VALUE = NULL;
96 port->NAME = (char*)ch->DATA;
97 port->DIRECTION = $3;
98 port->B0 = $5.B0;
99 port->B1 = $5.B1;
100 }
101 }
102 }
103 }
104 ;
105
106 idlist : idlist ',' _IDENTIFIER
107 {
108 $$ = addchain ($$, $3);
109 }
110 | _IDENTIFIER
111 {
112 $$ = addchain (NULL, $1);
113 }
114 ;
115
116 direction : _IN
117 {
118 $$ = T_IN;
119 }
120 | _INOUT
121 {
122 $$ = T_INOUT;
123 }
124 | _OUT
125 {
126 $$ = T_OUT;
127 }
128 ;
129
130 type : _STD_LOGIC_VECTOR
131 | _STD_LOGIC
132 ;
133
134 range : '(' bound _TO bound ')'
135 {
136 $$.B0 = $2;
137 $$.B1 = $4;
138 }
139 | '(' bound _DOWNTO bound ')'
140 {
141 $$.B0 = $2;
142 $$.B1 = $4;
143 }
144 | /* empty */
145 {
146 $$.B0 = -1;
147 $$.B1 = -1;
148 }
149 ;
150
151 bound : _NUMBER
152 {
153 $$ = $1;
154 }
155 | _IDENTIFIER
156 {
157 long val = gethtitem (GENERICS_HT, namealloc ($1));
158 if (val == EMPTYHT) {
159 fprintf (stderr, "Please provide a value for %s\n", $1);
160 EXIT (0);
161 } else
162 $$ = val;
163 }
164 /* Arithmetic operation */
165 | bound '+' bound
166 {
167 $$ = $1 + $3;
168 }
169 | bound '-' bound
170 {
171 $$ = $1 - $3;
172 }
173 | bound '*' bound
174 {
175 $$ = $1 * $3;
176 }
177 | bound '/' bound
178 {
179 $$ = $1 / $3;
180 }
181 | '-' bound %prec NEG
182 {
183 $$ = - $2;
184 }
185 | '(' bound ')'
186 {
187 $$ = $2;
188 }
189 ;
190 %%
191
192 int yyerror ()
193 {
194 fprintf (stderr, "syntax error line %d\n", LINE);
195 return 0;
196 }
197