1 /* functions, procedures and interfaces
2
3 Copyright (C) 1994-1997 University of Dortmund
4 Department of Electrical Engineering, AG SIV
5
6 VAUL is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 VAUL is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General
14 Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with VAUL; see the file COPYING.LIB. If not, write
18 to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 Boston, MA 02111-1307 USA.
20
21
22 */
23
24 #include <freehdl/vaul-parser.h>
25 #include <freehdl/vaul-chunk.h>
26 #include <freehdl/vaul-dunit.h>
27 #include <freehdl/vaul-util.h>
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <assert.h>
32
33 #define psr vaul_parser
34
35 static bool
check_for_proper_type(pIIR_Type t)36 check_for_proper_type (pIIR_Type t)
37 {
38 if (t->is(IR_ACCESS_TYPE)
39 || t->is(IR_FILE_TYPE))
40 return false;
41 else if (t->is(IR_ARRAY_TYPE))
42 return check_for_proper_type (pIIR_ArrayType(t)->element_type);
43 else if (t->is(IR_RECORD_TYPE))
44 {
45 for (pIIR_ElementDeclarationList el =
46 pIIR_RecordType(t)->element_declarations;
47 el; el = el->rest)
48 if (!check_for_proper_type (el->first->subtype->base))
49 return false;
50 }
51 return true;
52 }
53
54 pIIR_InterfaceDeclaration
build_Interface(pIIR_TextLiteral declarator,pIIR_Type subtype,pIIR_Expression value,VAUL_ObjectClass obj_class,IR_Mode mode,bool bus)55 psr::build_Interface (pIIR_TextLiteral declarator,
56 pIIR_Type subtype,
57 pIIR_Expression value,
58 VAUL_ObjectClass obj_class,
59 IR_Mode mode,
60 bool bus)
61 {
62 // XXX - merge the validate functions with this.
63
64 if (declarator == NULL || subtype == NULL)
65 return NULL;
66
67 if (obj_class == VAUL_ObjClass_None)
68 obj_class = cur_default_obj_class;
69 if (obj_class != VAUL_ObjClass_File && mode == IR_UNKNOWN_MODE)
70 mode = IR_IN_MODE;
71 if (obj_class == VAUL_ObjClass_None)
72 {
73 if (mode == IR_IN_MODE)
74 obj_class = VAUL_ObjClass_Constant;
75 else
76 obj_class = VAUL_ObjClass_Variable;
77 }
78
79 if (obj_class == VAUL_ObjClass_Constant
80 || obj_class == VAUL_ObjClass_Signal)
81 {
82 if (!check_for_proper_type (subtype->base))
83 error ("%:%n is an illegal type for %n",
84 declarator, subtype, declarator);
85 }
86 else if (obj_class == VAUL_ObjClass_File)
87 {
88 if (!subtype->base->is (IR_FILE_TYPE))
89 error ("%:file parameter %n must have a file type",
90 declarator, declarator);
91 }
92
93 switch (obj_class)
94 {
95 case VAUL_ObjClass_Constant:
96 return mIIR_ConstantInterfaceDeclaration (declarator->pos,
97 declarator,
98 subtype,
99 value,
100 mode,
101 bus);
102 case VAUL_ObjClass_Variable:
103 return mIIR_VariableInterfaceDeclaration (declarator->pos,
104 declarator,
105 subtype,
106 value,
107 mode,
108 bus);
109 case VAUL_ObjClass_Signal:
110 return mIIR_SignalInterfaceDeclaration (declarator->pos,
111 declarator,
112 subtype,
113 value,
114 mode,
115 bus,
116 IR_NO_SIGNAL_KIND);
117 case VAUL_ObjClass_File:
118 return mIIR_FileInterfaceDeclaration (declarator->pos,
119 declarator,
120 subtype,
121 value,
122 mode,
123 bus);
124 default:
125 info ("XXX - no object class for interface?");
126 return NULL;
127 }
128 }
129
130 void
validate_interface(pIIR_SubprogramDeclaration s,pIIR_InterfaceDeclaration i)131 psr::validate_interface (pIIR_SubprogramDeclaration s,
132 pIIR_InterfaceDeclaration i)
133 {
134 if (s == NULL || i == NULL)
135 return;
136
137 VAUL_ObjectClass obj_class = vaul_get_class (i);
138
139 if (obj_class == VAUL_ObjClass_File)
140 {
141 if (i->mode != IR_UNKNOWN_MODE)
142 {
143 error ("%:file parameters can not have a mode", i);
144 i->mode = IR_UNKNOWN_MODE;
145 }
146 }
147 else if (i->mode == IR_UNKNOWN_MODE)
148 i->mode = IR_IN_MODE;
149
150 if (s->is(IR_PROCEDURE_DECLARATION))
151 {
152 if (i->mode == IR_BUFFER_MODE || i->mode == IR_LINKAGE_MODE)
153 {
154 error ("%:illegal mode for %n", i, i);
155 i->mode = IR_INOUT_MODE;
156 }
157 }
158 else
159 {
160 if (i->mode != IR_IN_MODE)
161 {
162 error("%:%n must have mode 'in'", i, i);
163 i->mode = IR_IN_MODE;
164 }
165 }
166
167 if (i->initial_value)
168 {
169 // Check whether a default value is allowed.
170
171 if (obj_class == VAUL_ObjClass_Signal)
172 {
173 error ("%: %n can not have a default value because it is a signal",
174 i->initial_value, i);
175 i->initial_value = NULL;
176 }
177 else if (obj_class == VAUL_ObjClass_Variable
178 && i->mode != IR_IN_MODE)
179 {
180 error ("%: %n can not have a default value because it is a variable"
181 " of mode other than `in'", i->initial_value, i);
182 i->initial_value = NULL;
183 }
184 }
185
186
187 }
188
189 void
validate_port(pIIR_InterfaceDeclaration i)190 psr::validate_port (pIIR_InterfaceDeclaration i)
191 {
192 if (i == NULL)
193 return;
194
195 VAUL_ObjectClass obj_class = vaul_get_class (i);
196
197 if (obj_class != VAUL_ObjClass_Signal)
198 error ("%:port %n must be a signal", i, i);
199 if (i->mode == IR_UNKNOWN_MODE)
200 i->mode = IR_IN_MODE;
201
202 if (i->initial_value)
203 {
204 // Check whether a default value is allowed.
205
206 if (i->mode == IR_LINKAGE_MODE)
207 {
208 error ("%: %n can not have a default value because it has mode"
209 " linkage", i->initial_value, i);
210 i->initial_value = NULL;
211 }
212 }
213 }
214
215 void
validate_generic(pIIR_InterfaceDeclaration i)216 psr::validate_generic (pIIR_InterfaceDeclaration i)
217 {
218 if (i == NULL)
219 return;
220
221 VAUL_ObjectClass obj_class = vaul_get_class (i);
222
223 if (obj_class != VAUL_ObjClass_Constant)
224 error("%:generic %n must be a constant", i, i);
225 if (i->mode != IR_IN_MODE)
226 {
227 if (i->mode != IR_UNKNOWN_MODE)
228 error ("%:generic must have mode 'in'", i, i);
229 i->mode = IR_IN_MODE;
230 }
231 }
232