Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parse_vcd.y
Go to the documentation of this file.
1 /* -*-c++-*- */
2 
3 %{
4 /*
5  * parse_vcd.y - parser for a VCD data file
6  *
7  * Copyright (C) 2005 Raimund Jacob <raimi@lkcc.org>
8  * Copyright (C) 2006, 2008 Stefan Jahn <stefan@lkcc.org>
9  *
10  * This is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2, or (at your option)
13  * any later version.
14  *
15  * This software is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this package; see the file COPYING. If not, write to
22  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  *
25  * $Id$
26  *
27  */
28 
29 #if HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <ctype.h>
37 
38 #define YYERROR_VERBOSE 42
39 #define YYDEBUG 1
40 #define YYMAXDEPTH 10000000
41 
42 #include "check_vcd.h"
43 
44 %}
45 
46 %name-prefix="vcd_"
47 
48 %token t_END
49 %token t_COMMENT
50 %token t_DATE
51 %token t_ENDDEFINITIONS
52 %token t_SCOPE
53 %token t_TIMESCALE
54 %token t_UPSCOPE
55 %token t_VAR
56 %token t_VERSION
57 %token t_DUMPALL
58 %token t_DUMPOFF
59 %token t_DUMPON
60 %token t_DUMPVARS
61 
62 %token s_MODULE s_TASK s_FUNCTION s_FORK s_BEGIN
63 %token ONE B Z ZERO HASHMARK X R TEN HUNDRET
64 
65 %token PICO MICRO NANO FEMTO SECOND MILLI
66 
69 
70 %token Real
71 %token Binary
72 %token PositiveInteger
73 %token PositiveHugeInteger
74 %token Identifier /* proper identifiers */
75 %token IdentifierCode /* shortcuts used in the dump */
76 %token Reference
78 
79 %union {
80  char * ident;
81  char * value;
82  int integer;
83  double real;
84  enum vcd_vartypes vtype;
85  enum vcd_scopes stype;
86  struct vcd_vardef * vardef;
87  struct vcd_change * change;
88  struct vcd_scope * scope;
89  struct vcd_changeset * changeset;
90  struct vcd_range * range;
91 }
92 
94 %type <value> Value ZERO ONE Z X Binary Real
95 %type <integer> Size PositiveInteger TimeScale
96 %type <real> TimeUnit SimulationTime PositiveHugeInteger
97 %type <change> ScalarValueChange VectorValueChange ValueChangeList ValueChange
98 %type <changeset> ValueChangeset
99 %type <scope> ScopeDeclaration
100 %type <range> BitSelect
101 %type <vardef> VarDeclaration
102 %type <vtype> VarType
103 %type <stype> ScopeType
105 %%
107 ValueChangeDumpDefinitions:
108  DeclarationList SimulationCommandList
109 ;
111 DeclarationList: /* empty */
112  | Declaration DeclarationList
113 ;
115 Declaration:
116  t_COMMENT t_END
117  | t_DATE t_END
118  | t_ENDDEFINITIONS t_END
119  | t_SCOPE ScopeDeclaration t_END {
120  if (!vcd->scopes) {
121  /* no scope defined yet */
122  vcd->scopes = (struct vcd_scope *)
123  calloc (1, sizeof (struct vcd_scope));
124  vcd->scopes->ident = strdup (VCD_NOSCOPE);
125  vcd->scopes->scopes = $2;
126  $2->parent = vcd->scopes;
127  } else {
128  /* concatenate scope definitions */
129  $2->next = vcd->currentscope->scopes;
130  vcd->currentscope->scopes = $2;
131  $2->parent = vcd->currentscope;
132  }
134  }
135  | t_TIMESCALE TimeScaleDeclaration t_END
136  | t_UPSCOPE t_END {
137  if (vcd->currentscope->parent) {
138  /* up one scope */
140  } else {
141  fprintf (stderr, "vcd notice, unnecessary $upscope in line %d\n",
143  }
144  }
145  | t_VERSION t_END
146  | t_VAR VarDeclaration t_END {
147  if (!vcd->scopes) {
148  /* no scope defined yet */
149  vcd->scopes = (struct vcd_scope *)
150  calloc (1, sizeof (struct vcd_scope));
151  vcd->scopes->ident = strdup (VCD_NOSCOPE);
153  }
154  /* concatenate variable definitions */
155  $2->scope = vcd->currentscope;
156  $2->next = vcd->currentscope->vardefs;
157  vcd->currentscope->vardefs = $2;
158  }
159 ;
160 
161 ScopeDeclaration:
162  ScopeType Identifier {
163  $$ = (struct vcd_scope *) calloc (1, sizeof (struct vcd_scope));
164  $$->type = $1;
165  $$->ident = $2;
166  }
167 ;
168 
169 ScopeType:
170  s_MODULE { $$ = SCOPE_MODULE; }
171  | s_TASK { $$ = SCOPE_TASK; }
173  | s_BEGIN { $$ = SCOPE_BEGIN; }
174  | s_FORK { $$ = SCOPE_FORK; }
175 ;
176 
177 TimeScaleDeclaration:
178  TimeScale TimeUnit {
179  vcd->t = $1;
180  vcd->scale = $2;
181  }
182 ;
183 
184 TimeScale:
185  ONE { $$ = 1; }
186  | TEN { $$ = 10; }
187  | HUNDRET { $$ = 100; }
188 ;
189 
190 TimeUnit:
191  SECOND { $$ = 1; }
192  | MILLI { $$ = 1e-3; }
193  | MICRO { $$ = 1e-6; }
194  | NANO { $$ = 1e-9; }
195  | PICO { $$ = 1e-12; }
196  | FEMTO { $$ = 1e-15; }
197 ;
198 
199 VarDeclaration:
200  VarType Size IdentifierCode Reference BitSelect {
201  $$ = (struct vcd_vardef *) calloc (1, sizeof (struct vcd_vardef));
202  $$->type = $1;
203  $$->size = $2;
204  $$->code = $3;
205  $$->ident = $4;
206  $$->range = $5;
207  }
208 ;
209 
210 BitSelect: /* nothing */ { $$ = NULL; }
211  | '[' PositiveInteger ']' {
212  $$ = (struct vcd_range *) calloc (1, sizeof (struct vcd_range));
213  $$->l = -1;
214  $$->h = $2;
215  }
216  | '[' PositiveInteger ':' PositiveInteger ']' {
217  $$ = (struct vcd_range *) calloc (1, sizeof (struct vcd_range));
218  $$->l = $2;
219  $$->h = $4;
220  }
221  | '(' PositiveInteger ')' {
222  $$ = (struct vcd_range *) calloc (1, sizeof (struct vcd_range));
223  $$->l = $2;
224  $$->h = -1;
225  }
226 ;
227 
228 VarType:
229  EVENT { $$ = VAR_EVENT;
230  /* a special type to synchronize different statement blocks */ }
232  /* signed 32-bit variable */ }
234  /* a named constant - the default value of a parameter can be
235  overwritten, when declaring an instance of the associated module */ }
236  | REAL { $$ = VAR_REAL;
237  /* double-precision floating point */ }
238  | REG { $$ = VAR_REG;
239  /* unsigned variable of any bit size */ }
241  /* constant logic 0 (supply strength) */ }
243  /* constant logic 1 (supply strength) */ }
244  | TIME { $$ = VAR_TIME;
245  /* unsigned 64-bit variable */ }
246  | TRI { $$ = VAR_TRI;
247  /* simple interconnecting wire */ }
248  | TRIAND { $$ = VAR_TRIAND;
249  /* wired outputs AND together */ }
250  | TRIOR { $$ = VAR_TRIOR;
251  /* wired outputs OR together */ }
252  | TRIREG { $$ = VAR_TRIREG;
253  /* stores last value when tri-stated (capacitance strength) */ }
254  | TRI0 { $$ = VAR_TRI0;
255  /* pulls down when tri-stated */ }
256  | TRI1 { $$ = VAR_TRI1;
257  /* pulls up when tri-stated */ }
258  | WAND { $$ = VAR_WAND;
259  /* wired outputs AND together */ }
260  | WIRE { $$ = VAR_WIRE;
261  /* simple interconnecting wire */ }
262  | WOR { $$ = VAR_WOR;
263  /* wired outputs OR together */ }
264 ;
265 
266 Size:
268 ;
269 
270 SimulationCommandList: /* empty */
271  | SimulationCommand SimulationCommandList
272 ;
273 
274 SimulationCommand:
275  t_DUMPALL ValueChangeList t_END /* probably unsupported */
276  | t_DUMPOFF ValueChangeList t_END /* probably unsupported */
277  | t_DUMPON ValueChangeList t_END /* probably unsupported */
278  | t_DUMPVARS ValueChangeList t_END {
280  }
282  $1->next = vcd->changesets;
284  }
285 ;
286 
288  SimulationTime ValueChangeList {
289  $$ = (struct vcd_changeset *) calloc (1, sizeof (struct vcd_changeset));
290  $$->t = $1;
291  $$->changes = $2;
292  }
293 ;
294 
295 SimulationTime:
296  HASHMARK PositiveHugeInteger {
297  $$ = $2;
298  }
299 ;
300 
301 ValueChangeList: /* nothing */ { $$ = NULL; }
302  | ValueChange ValueChangeList {
303  $1->next = $2;
304  }
305 ;
306 
307 ValueChange:
308  ScalarValueChange
309  | VectorValueChange
310 ;
311 
312 ScalarValueChange:
313  Value IdentifierCode {
314  $$ = (struct vcd_change *) calloc (1, sizeof (struct vcd_change));
315  $$->value = $1;
316  $$->code = $2;
317  }
318 ;
319 
320 Value:
321  ZERO /* low level */
322  | ONE /* high level */
323  | X /* undefined/error */
324  | Z /* high impedance */
325 ;
326 
327 VectorValueChange:
328  'B' Binary IdentifierCode {
329  $$ = (struct vcd_change *) calloc (1, sizeof (struct vcd_change));
330  $$->value = $2;
331  $$->code = $3;
332  }
334  $$ = (struct vcd_change *) calloc (1, sizeof (struct vcd_change));
335  $$->value = $2;
336  $$->code = $3;
337  $$->isreal = 1;
338  }
339 ;
340 
341 
342 %%
343 
344 int vcd_error (const char * error) {
345  fprintf (stderr, "line %d: %s\n", vcd_lineno, error);
346  return 0;
347 }
INTEGER
Definition: parse_vcd.y:231
s_BEGIN
Definition: parse_vcd.y:173
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
WOR
Definition: parse_vcd.y:262
TRIREG
Definition: parse_vcd.y:252
NANO
Definition: parse_vcd.y:194
name
Definition: parse_mdl.y:352
struct vcd_scope * scopes
Definition: check_vcd.h:137
int vcd_error(const char *)
Definition: parse_vcd.y:344
Identifier
Definition: parse_csv.y:87
struct vcd_scope * scopes
Definition: check_vcd.h:109
REG
Definition: parse_vcd.y:238
TRIAND
Definition: parse_vcd.y:248
MILLI
Definition: parse_vcd.y:192
TRIOR
Definition: parse_vcd.y:250
TEN
Definition: parse_vcd.y:186
PARAMETER
Definition: parse_vcd.y:233
t_TIMESCALE TimeScaleDeclaration t_END t_UPSCOPE t_END
Definition: parse_vcd.y:136
FEMTO
Definition: parse_vcd.y:196
#define R(con)
PICO
Definition: parse_vcd.y:195
SUPPLY1
Definition: parse_vcd.y:242
PositiveInteger
Definition: parse_vcd.y:221
double scale
Definition: check_vcd.h:136
WAND
Definition: parse_vcd.y:258
s_TASK
Definition: parse_vcd.y:171
struct vcd_changeset * changesets
Definition: check_vcd.h:139
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
char * ident
Definition: check_vcd.h:107
t_TABLE String Real
Definition: parse_mdl.y:382
int vcd_lineno
R Real IdentifierCode
Definition: parse_vcd.y:333
value
Definition: parse_vcd.y:315
s_FORK
Definition: parse_vcd.y:174
ValueChangeset
Definition: parse_vcd.y:281
TRI
Definition: parse_vcd.y:246
#define B(con)
Definition: evaluate.cpp:70
ValueChange ValueChangeList
Definition: parse_vcd.y:302
struct vcd_scope * next
Definition: check_vcd.h:111
struct vcd_scope * currentscope
Definition: check_vcd.h:138
s_FUNCTION
Definition: parse_vcd.y:172
Reference
HUNDRET
Definition: parse_vcd.y:187
struct vcd_scope * parent
Definition: check_vcd.h:110
range
Definition: parse_vcd.y:206
__BEGIN_DECLS struct vcd_file * vcd
Definition: check_vcd.cpp:49
WIRE
Definition: parse_vcd.y:260
vcd scopes ident
Definition: parse_vcd.y:124
vcd_vartypes
Definition: check_vcd.h:58
name prefix
Definition: parse_vcd.y:46
TRI1
Definition: parse_vcd.y:256
struct vcd_vardef * vardefs
Definition: check_vcd.h:108
vcd_scopes
Definition: check_vcd.h:96
#define VCD_NOSCOPE
Definition: parse_vcd.y:76
TIME
Definition: parse_vcd.y:244
REAL
Definition: parse_vcd.y:236
MICRO
Definition: parse_vcd.y:193
TRI0
Definition: parse_vcd.y:254
SUPPLY0
Definition: parse_vcd.y:240
struct vcd_change * changes
Definition: check_vcd.h:126