File: sdf_parse.y

package info (click to toggle)
iverilog 12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,148 kB
  • sloc: cpp: 109,972; ansic: 62,713; yacc: 10,216; sh: 3,470; vhdl: 3,246; perl: 1,814; makefile: 1,774; python: 78; csh: 2
file content (560 lines) | stat: -rw-r--r-- 13,647 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560

%{
/*
 * Copyright (c) 1998-2019 Stephen Williams (steve@icarus.com)
 *
 *    This source code is free software; you can redistribute it
 *    and/or modify it in source code form under the terms of the GNU
 *    General Public License as published by the Free Software
 *    Foundation; either version 2 of the License, or (at your option)
 *    any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

extern int sdflex(void);
static void yyerror(const char*msg);
# include  "vpi_user.h"
# include  "sdf_parse_priv.h"
# include  "sdf_priv.h"
# include  <stdio.h>
# include  <string.h>
# include  <stdlib.h>
# include  "ivl_alloc.h"

/* This is the hierarchy separator to use. */
char sdf_use_hchar = '.';

%}

%union {
      unsigned long int_val;
      double real_val;
      char*  string_val;

      struct sdf_delay_s delay;
      struct port_with_edge_s port_with_edge;
      struct sdf_delval_list_s delval_list;
};

%token K_ABSOLUTE K_CELL K_CELLTYPE K_COND K_CONDELSE K_DATE K_DELAYFILE
%token K_DELAY K_DESIGN K_DIVIDER K_HOLD K_INCREMENT K_INSTANCE
%token K_INTERCONNECT K_IOPATH K_NEGEDGE K_PATHPULSE K_PATHPULSEPERCENT
%token K_PERIOD K_POSEDGE K_PROCESS K_PROGRAM
%token K_RECREM K_RECOVERY K_REMOVAL K_SDFVERSION K_SETUP K_SETUPHOLD
%token K_TEMPERATURE K_TIMESCALE K_TIMINGCHECK K_VENDOR K_VERSION
%token K_VOLTAGE K_WIDTH
%token K_01 K_10 K_0Z K_Z1 K_1Z K_Z0
%token K_EQ K_NE K_CEQ K_CNE K_LOGICAL_ONE K_LOGICAL_ZERO
%token K_LAND K_LOR

%token HCHAR
%token <string_val> QSTRING IDENTIFIER
%token <real_val> REAL_NUMBER
%token <int_val> INTEGER

%type <string_val> celltype
%type <string_val> cell_instance
%type <string_val> hierarchical_identifier
%type <string_val> port port_instance port_interconnect

%type <real_val> signed_real_number
%type <delay> delval rvalue_opt rvalue rtriple signed_real_number_opt

%type <int_val> edge_identifier
%type <port_with_edge> port_edge port_spec

%type <delval_list> delval_list

%left K_LOR
%left K_LAND
%left K_EQ K_NE K_CEQ K_CNE

%%

source_file
  : '(' K_DELAYFILE sdf_header_list cell_list ')'
  | '(' K_DELAYFILE error ')'
      { vpi_printf("%s:%d:SDF ERROR: Invalid DELAYFILE format\n",
		   sdf_parse_path, @2.first_line);
      }
  ;

sdf_header_list
  : sdf_header_list sdf_header_item
  | sdf_header_item
  ;

sdf_header_item
  : sdfversion
  | design_name
  | date
  | vendor
  | program_name
  | program_version
  | hierarchy_divider
  | voltage
  | process
  | temperature
  | time_scale
  ;

sdfversion
  : '(' K_SDFVERSION QSTRING ')'
    { free($3);
    }
  ;

design_name
  : '(' K_DESIGN QSTRING ')'
      { if (sdf_flag_inform) vpi_printf("%s:%d:SDF INFO: Design: %s\n",
					sdf_parse_path, @2.first_line, $3);
        free($3);
      }
  ;

date
  : '(' K_DATE QSTRING ')'
      { if (sdf_flag_inform) vpi_printf("%s:%d:SDF INFO: Date: %s\n",
					sdf_parse_path, @2.first_line, $3);
        free($3);
      }
  ;

vendor
  : '(' K_VENDOR QSTRING ')'
      { if (sdf_flag_inform) vpi_printf("%s:%d:SDF INFO: Vendor: %s\n",
					sdf_parse_path, @2.first_line, $3);
        free($3);
      }
  ;

program_name
  : '(' K_PROGRAM QSTRING ')'
      { if (sdf_flag_inform) vpi_printf("%s:%d:SDF INFO: Program: %s\n",
					sdf_parse_path, @2.first_line, $3);
        free($3);
      }
  ;

program_version
  : '(' K_VERSION QSTRING ')'
      { if (sdf_flag_inform) vpi_printf("%s:%d:SDF INFO: Program Version: %s\n",
					sdf_parse_path, @2.first_line, $3);
	free($3);
      }
  ;

hierarchy_divider
  : '(' K_DIVIDER '.' ')' { sdf_use_hchar = '.'; }
  | '(' K_DIVIDER '/' ')' { sdf_use_hchar = '/'; }
  | '(' K_DIVIDER HCHAR ')' { /* sdf_use_hchar no-change */; }
  ;

voltage
  : '(' K_VOLTAGE rtriple ')'
  | '(' K_VOLTAGE signed_real_number ')'
  ;

process
  : '(' K_PROCESS QSTRING ')'
      { if (sdf_flag_inform) vpi_printf("%s:%d:SDF INFO: Process: %s\n",
					sdf_parse_path, @2.first_line, $3);
	free($3);
      }
  ;

temperature
  : '(' K_TEMPERATURE rtriple ')'
  | '(' K_TEMPERATURE signed_real_number ')'
  ;

time_scale
  : '(' K_TIMESCALE REAL_NUMBER IDENTIFIER ')'
      { if (sdf_flag_inform) vpi_printf("%s:%d:SDF INFO: TIMESCALE : %f%s\n",
					sdf_parse_path, @2.first_line, $3, $4);
	free($4);
      }
  | '(' K_TIMESCALE INTEGER IDENTIFIER ')'
      { if (sdf_flag_inform) vpi_printf("%s:%d:SDF INFO: TIMESCALE : %lu%s\n",
					sdf_parse_path, @2.first_line, $3, $4);
	free($4);
      }
  ;

cell_list
  : cell_list cell
  | cell
  ;

cell
  : '(' K_CELL celltype cell_instance
      { sdf_select_instance($3, $4); /* find the instance in the design */}
    timing_spec_list_opt
    ')'
      { free($3);
	if ($4) free($4);
      }
  | '(' K_CELL error ')'
      { vpi_printf("%s:%d: Syntax error in CELL\n",
		   sdf_parse_path, @2.first_line); }
  ;

celltype
  : '(' K_CELLTYPE QSTRING ')'
      { $$ = $3; }
  ;

cell_instance
  : '(' K_INSTANCE hierarchical_identifier ')'
      { $$ = $3; }
  | '(' K_INSTANCE ')'
      { $$ = strdup(""); }
  | '(' K_INSTANCE '*' ')'
      { $$ = 0; }
  | '(' K_INSTANCE error ')'
      { vpi_printf("%s:%d:SDF ERROR: Invalid/malformed INSTANCE argument\n",
		   sdf_parse_path, @2.first_line);
	    $$ = strdup(""); }
  ;

timing_spec_list_opt
  : /* Empty */
  | timing_spec_list_opt timing_spec
  ;

timing_spec
  : '(' K_DELAY deltype_list ')'
  | '(' K_DELAY error ')'
      { vpi_printf("%s:%d: Syntax error in CELL DELAY SPEC\n",
		   sdf_parse_path, @2.first_line); }
  | '(' K_TIMINGCHECK tchk_def_list ')'
  | '(' K_TIMINGCHECK error ')'
      { vpi_printf("%s:%d: Syntax error in TIMINGCHECK SPEC\n",
		   sdf_parse_path, @2.first_line); }
  ;

deltype_list
  : deltype_list deltype
  | deltype
  ;

deltype
  : '(' K_PATHPULSE input_output_path_opt rvalue rvalue_opt ')'
  | '(' K_PATHPULSEPERCENT input_output_path_opt rvalue rvalue_opt ')'
  | '(' K_ABSOLUTE del_def_list ')'
  | '(' K_INCREMENT del_def_list ')'
  | '(' error ')'
    { vpi_printf("%s:%d: SDF ERROR: Invalid/malformed delay type\n",
		 sdf_parse_path, @1.first_line); }
  ;

del_def_list
  : del_def_list del_def
  | del_def
  ;

del_def
  : '(' K_IOPATH port_spec port_instance delval_list ')'
      { sdf_iopath_delays($3.vpi_edge, $3.string_val, $4, &$5);
	free($3.string_val);
	free($4);
      }
  | '(' K_IOPATH error ')'
      { vpi_printf("%s:%d: SDF ERROR: Invalid/malformed IOPATH\n",
		   sdf_parse_path, @2.first_line); }
  | '(' K_COND conditional_port_expr
    '(' K_IOPATH port_spec port_instance delval_list ')' ')'
      { if (sdf_flag_warning) vpi_printf("%s:%d: SDF WARNING: "
					 "COND not supported.\n",
					 sdf_parse_path, @2.first_line);
	free($6.string_val);
	free($7);
      }
  | '(' K_COND QSTRING conditional_port_expr
    '(' K_IOPATH port_spec port_instance delval_list ')' ')'
      { if (sdf_flag_warning) vpi_printf("%s:%d: SDF WARNING: "
					 "COND not supported.\n",
					 sdf_parse_path, @2.first_line);
	free($3);
	free($7.string_val);
	free($8);
      }
  | '(' K_COND error ')'
      { vpi_printf("%s:%d: SDF ERROR: Invalid/malformed COND\n",
		   sdf_parse_path, @2.first_line); }
  | '(' K_CONDELSE '(' K_IOPATH port_spec port_instance delval_list ')' ')'
      { if (sdf_flag_warning) vpi_printf("%s:%d: SDF WARNING: "
					 "CONDELSE not supported.\n",
					 sdf_parse_path, @2.first_line);
	free($5.string_val);
	free($6);
      }
  | '(' K_CONDELSE error ')'
      { vpi_printf("%s:%d: SDF ERROR: Invalid/malformed CONDELSE\n",
		   sdf_parse_path, @2.first_line); }
  /* | '(' K_INTERCONNECT port_instance port_instance delval_list ')' */
  | '(' K_INTERCONNECT port_interconnect port_interconnect delval_list ')'
      { if (sdf_flag_warning) vpi_printf("%s:%d: SDF WARNING: "
					 "INTERCONNECT not supported.\n",
					 sdf_parse_path, @2.first_line);
	free($3);
	free($4);
      }
  | '(' K_INTERCONNECT error ')'
      { vpi_printf("%s:%d: SDF ERROR: Invalid/malformed INTERCONNECT\n",
		   sdf_parse_path, @2.first_line); }
  ;

tchk_def_list
  : tchk_def_list tchk_def
  | tchk_def
  ;

  /* Timing checks are ignored. */
tchk_def
  : '(' K_SETUP port_tchk port_tchk rvalue ')'
  | '(' K_HOLD port_tchk port_tchk rvalue ')'
  | '(' K_SETUPHOLD port_tchk port_tchk rvalue rvalue ')'
  | '(' K_RECOVERY port_tchk port_tchk rvalue ')'
  | '(' K_RECREM port_tchk port_tchk rvalue rvalue ')'
  | '(' K_REMOVAL port_tchk port_tchk rvalue ')'
  | '(' K_WIDTH port_tchk rvalue ')'
  | '(' K_PERIOD port_tchk rvalue ')'
  ;

port_tchk
  : port_instance
      { free($1); }
  /* This must only be an edge. For now we just accept everything. */
  | cond_edge_start port_instance ')'
      { free($2); }
  /* These must only be a cond. For now we just accept everything. */
  | cond_edge_start timing_check_condition port_spec ')'
      { free($3.string_val); }
  | cond_edge_start QSTRING timing_check_condition port_spec ')'
      { free($2);
	free($4.string_val);
      }
  ;

cond_edge_start
  : '(' { start_edge_id(1); } cond_edge_identifier { stop_edge_id(); }
  ;

cond_edge_identifier
  : K_POSEDGE
  | K_NEGEDGE
  | K_01
  | K_10
  | K_0Z
  | K_Z1
  | K_1Z
  | K_Z0
  | K_COND
  ;

timing_check_condition
  : port_interconnect
      { free($1); }
  | '~' port_interconnect
      { free($2); }
  | '!' port_interconnect
      { free($2); }
  | port_interconnect equality_operator scalar_constant
      { free($1); }
  ;

  /* This is not complete! */
conditional_port_expr
  : port
      { free($1); }
  | scalar_constant
  | '(' conditional_port_expr ')'
  | conditional_port_expr K_LAND conditional_port_expr
  | conditional_port_expr K_LOR conditional_port_expr
  | conditional_port_expr K_EQ conditional_port_expr
  | conditional_port_expr K_NE conditional_port_expr
  | conditional_port_expr K_CEQ conditional_port_expr
  | conditional_port_expr K_CNE conditional_port_expr
  ;

equality_operator
  : K_EQ
  | K_NE
  | K_CEQ
  | K_CNE
  ;

scalar_constant
  : K_LOGICAL_ONE
  | K_LOGICAL_ZERO
  ;

input_output_path_opt
  : input_output_path
  |
  ;

input_output_path
  : port_instance port_instance
  ;

port_spec
  : port_instance { $$.vpi_edge = vpiNoEdge; $$.string_val = $1; }
  | port_edge     { $$ = $1; }
  ;

port_instance
  : port { $$ = $1; }
  ;

port
  : hierarchical_identifier
      { $$ = $1; }
    /* | hierarchical_identifier '[' INTEGER ']' */
  ;

  /* Since INTERCONNECT is ignored we can also ignore a vector bit. */
port_interconnect
  : hierarchical_identifier
      { $$ = $1; }
  | hierarchical_identifier '[' INTEGER ']'
      { $$ = $1;}
  ;

port_edge
  : '(' {start_edge_id(0);} edge_identifier {stop_edge_id();} port_instance ')'
      { $$.vpi_edge = $3; $$.string_val = $5; }
  ;

edge_identifier
  : K_POSEDGE { $$ = vpiPosedge; }
  | K_NEGEDGE { $$ = vpiNegedge; }
  | K_01      { $$ = vpiEdge01; }
  | K_10      { $$ = vpiEdge10; }
  | K_0Z      { $$ = vpiEdge0x; }
  | K_Z1      { $$ = vpiEdgex1; }
  | K_1Z      { $$ = vpiEdge1x; }
  | K_Z0      { $$ = vpiEdgex0; }
  ;

delval_list
  : delval_list delval
      { int idx;
	$$.count = $1.count;
	for (idx = 0 ; idx < $$.count ; idx += 1)
	      $$.val[idx] = $1.val[idx];
// Is this correct?
	if ($$.count < 12) {
	      $$.val[$$.count] = $2;
	      $$.count += 1;
	}
      }
  | delval
      { $$.count = 1;
	$$.val[0] = $1;
      }
  ;

delval
  : rvalue
      { $$ = $1; }
  | '(' rvalue rvalue ')'
      { $$ = $2;
	vpi_printf("%s:%d: SDF WARNING: Pulse rejection limits ignored\n",
		   sdf_parse_path, @3.first_line);
      }
  | '(' rvalue rvalue rvalue ')'
      { $$ = $2;
	vpi_printf("%s:%d: SDF WARNING: Pulse rejection limits ignored\n",
		   sdf_parse_path, @3.first_line);
      }
  ;

rvalue_opt
  : /* When missing. */
      { $$.value = 0.0;
	$$.defined = 0;
      }
  | rvalue
  ;

rvalue
  : '(' signed_real_number ')'
      { $$.defined = 1;
        $$.value = $2; }
  | '(' rtriple ')'
      { $$ = $2; }
  | '(' ')'
      { $$.defined = 0;
        $$.value = 0.0; }
  ;

hierarchical_identifier
  : IDENTIFIER
      { $$ = $1; }
  | hierarchical_identifier HCHAR IDENTIFIER
      { int len = strlen($1) + strlen($3) + 2;
	char*tmp = realloc($1, len);
	strcat(tmp, ".");
	strcat(tmp, $3);
	free($3);
	$$ = tmp;
      }
  ;

rtriple
  : signed_real_number_opt ':' signed_real_number_opt ':' signed_real_number_opt
      { switch(sdf_min_typ_max) {
	    case _vpiDelaySelMinimum:
	       $$ = $1;
	       break;
	    case _vpiDelaySelTypical:
	       $$ = $3;
	       break;
	    case _vpiDelaySelMaximum:
	       $$ = $5;
	       break;
	}
	  /* At least one of the values must be defined. */
	if (! ($1.defined || $3.defined || $5.defined)) {
	      vpi_printf("%s:%d: SDF ERROR: rtriple must have at least one "
	                 "defined value.\n", sdf_parse_path, @1.first_line);
	}
      }
  ;

signed_real_number_opt
  : /* When missing. */
      { $$.value = 0.0;
	$$.defined = 0;
      }
  | signed_real_number
      { $$.value = $1;
	$$.defined = 1;
      }
  ;

signed_real_number
  :     REAL_NUMBER { $$ = $1; }
  | '+' REAL_NUMBER { $$ = $2; }
  | '-' REAL_NUMBER { $$ = -$2; }
  |     INTEGER { $$ = $1; }
  | '+' INTEGER { $$ = $2; }
  | '-' INTEGER { $$ = -$2; }
  ;

%%

void yyerror(const char*msg)
{
      vpi_printf("%s:SDF ERROR: Too many errors: %s\n", sdf_parse_path, msg);
}