Subversion Repositories Vertical

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 mjames 1
%{
2
/*
3
 * $Id: acf_lex.l,v 1.2 2004/06/22 21:44:10 mjames Exp $ * 
4
 *
5
 * $Log: acf_lex.l,v $
6
 * Revision 1.2  2004/06/22 21:44:10  mjames
7
 * Firrst build most files
8
 *
9
 * Revision 1.30  2002/10/02 18:46:34  MJAMES
10
 * attribute is recognised in acfp syntax as well as vhdl
11
 *
12
 * Revision 1.29  2002/09/27 22:24:14  MJAMES
13
 * Separated out a quote as a token
14
 * Added VHDL_CONN token
15
 *
16
 * Revision 1.28  2002/09/16 11:03:50  mjames
17
 * Added some of the generic string  types  to the input parser.
18
 *
19
 * Revision 1.27  2002/09/09 10:14:58  mjames
20
 * Modified expression parser to match CC as previous one was
21
 * broken
22
 *
23
 * Revision 1.26  2002/08/23 14:21:55  mjames
24
 * Added the <VHDL> string keyword.
25
 *
26
 * Revision 1.25  2002/08/19 14:31:27  mjames
27
 * Removed an incompatibility with env_string generics where the output
28
 * of Vertical caused an error under some circumstances.
29
 *
30
 * Revision 1.24  2002/08/14 11:58:43  mjames
31
 * Corrected end-of-file behaviour that resulted in an infinite loop
32
 *
33
 * Revision 1.23  2002/08/06 12:56:21  mjames
34
 * Merge in from latest version
35
 *
36
 *
37
 * Revision 1.25  2002/08/06 09:25:23  mjames
38
 * Changed file include handler for an improved one.
39
 * Improvements created as a part of a microcode assembler
40
 *
41
 * Revision 1.24  2002/03/22 16:16:28  mjames
42
 * Modifications to undo over-zealous checking of
43
 * current chip even in incorrect scenarios.
44
 *
45
 * Revision 1.23  2002/03/21 17:11:32  mjames
46
 * Allowed '[' and ']' in acfp file syntax for pin identifiers in Quartus
47
 *
48
 * Revision 1.22  2002/01/21 09:28:49  mjames
49
 * coredump when opening non-existent Verilog include file due to
50
 * use of NULL file pointer. Avoided by not using file pointer until certain
51
 * that file was opened properly.
52
 *
53
 * Revision 1.21  2002/01/16 10:04:35  mjames
54
 * Added package definitions to VHDL syntax
55
 * According to report by John Marquis
56
 *
57
 * Revision 1.20  2001/12/13 22:12:16  mjames
58
 * Vertical now supports nested include database files
59
 * This allows wrappers around 'pure' VHDL or Verilog files
60
 *
61
 * Revision 1.19  2001/12/11 21:29:56  mjames
62
 * Verilog syntax now read in by Vertical allows pin templates
63
 * defined  by Certify to be used.
64
 *
65
 * Revision 1.18  2001/11/30 22:21:19  mjames
66
 * Modifying Verilog reading syntax to accept valid code.
67
 *
68
 * Revision 1.17  2001/11/19 10:41:54  mjames
69
 * Merged back DTC release
70
 *
71
 * Revision 1.16.2.1  2001/11/16 15:10:59  mjames
72
 * Removed an unecessary local variable
73
 *
74
 * Revision 1.16  2001/10/31 22:19:56  mjames
75
 * Tidying up problematical comments caused by CVS
76
 * 'intelligent' comment guessing
77
 *
78
 * Revision 1.15  2001/09/28 14:34:13  mjames
79
 * FIxed yydebug variable to exist when YYDEBUG macro
80
 * is not defined. Otherwise linker error will be reported.
81
 *
82
 * Revision 1.14  2001/09/16 20:01:06  mjames
83
 * tidying
84
 *
85
 * Revision 1.13  2001/07/09 09:36:30  mjames
86
 * Amending the syntax and end of file behaviour to allow Quartus pin fit files
87
 * to be read .
88
 * They are harder to read because they are not block structured. The end of file is used as a marker. Vertical has been persuaded to handle end of file events properly.
89
 *
90
 * Revision 1.12  2001/07/06 12:50:36  mjames
91
 * Added the ability to read in Quartus pinfit files
92
 *
93
 * Revision 1.11  2001/07/05 15:12:36  MJAMES
94
 * Amended to read Quartus pin files. not fully working
95
 *
96
 * Revision 1.10  2001/06/06 12:10:27  mjames
97
 * Move from HPUX
98
 *
99
 * Revision 1.9  2001/04/30 10:01:08  Administrator
100
 * Have finally got the Verilog/VHDL comment pragma parser working.
101
 *
102
 * Revision 1.8  2001/04/30 07:55:53  mjames
103
 * Improving parsing of Verilog, still a few loose ends
104
 *
105
 * Revision 1.7  2001/04/27 22:30:10  mjames
106
 * Starting to get comment and pragma handling OK.
107
 * Added correct header file includes to lx_support.c
108
 *
109
 * Revision 1.6  2001/03/29 08:27:06  mjames
110
 * Converted frbread for use with the newer files from the drawing office
111
 *
112
 * Revision 1.5  2001/02/21 16:37:33  mjames
113
 * Provided a new method of defining port maps with VHDL which allows for short
114
 * cut definitions.
115
 *
116
 * Cleaned up TCL/Tk interfacing issues
117
 *
118
 * Revision 1.4  2001/01/02 07:53:51  mjames
119
 * Made changes to allow for interface with TCL/Tk
120
 *
121
 * Revision 1.3  2000/12/04 12:55:48  mjames
122
 * Copied files back from HPUX to create definitive CygWin version
123
 *
124
 * Then amended the syntax of ACFP files so that a/2 was no longer
125
 * seen as "a/2" but instead as "a" divided_by 2. This was a throwback
126
 * to some of the earlier efforts at variant syntax for VHDL and ACFP
127
 * parsing.
128
 *
129
 * Revision 1.2  2000/10/19 22:19:49  mjames
130
 * removed header lines
131
 *
132
 * Revision 1.1.1.1  2000/10/19 21:58:34  mjames
133
 * Mike put it here
134
 *
135
 *
136
 */
137
 
138
 
139
#include <stdio.h>
140
#include <stdlib.h>
141
#include <ctype.h>
142
#include <string.h>
143
 
144
/* see makefile for how this appears */
145
 
146
#include "vertcl_main.h"
147
#include "expression.h"
148
#include "generic.h"
149
#include "database.h"
150
#include "acf_yacc.h"
151
#include "lx_support.h"
152
#include "cmdparse.h"
153
#include "cmdlog.h"
154
#include "cmdutil.h"
155
#include "yyinput.h"
156
 
157
 
158
#define YYLMAX MAXIDLEN
159
 
160
#if !defined YY_START
161
#define YY_START (yybgin -1 -yysvec)
162
#endif
163
 
164
 
165
 
166
 
167
#define MAX_INCLUDE_DEPTH 10
168
 
169
 
170
#ident "@(#)$Header: C:/cvsroot/Vert03/acf_src/acf_lex.l,v 1.2 2004/06/22 21:44:10 mjames Exp $"
171
 
172
/* state stores for include files */
173
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
174
struct str * incl_first = NULL, * incl_last = NULL;
175
char * filename[MAX_INCLUDE_DEPTH];
176
int    old_linenumber[MAX_INCLUDE_DEPTH];
177
FILE * handles[MAX_INCLUDE_DEPTH];
178
 
179
 
180
int include_stack_ptr = 0;
181
 
182
char lex_from_string = 0;
183
 
184
extern int errorseen;
185
extern  int yyval;
186
extern int yydebug;
187
extern int lineno;
188
 
189
 
190
extern int inside_block; /* flag to help 'generic' context dependence */
191
 
192
generic_info_t info;
193
 
194
int prev_begin = -1;
195
int prev_begin_include = -1;
196
int read_state = 1; /* start off by reading */
197
 
198
int comment_type = 0;
199
 
200
void lex_exec_line(void);
201
 
202
void skip_to_eol(void);
203
void skip_c_comment(void);
204
void exit_lex_block(void);
205
 
206
 
207
int  my_yyinput(char * buf , int max_size);
208
 
209
 
210
static char * yyerr_start_names[] = {
211
 "INITIAL",
212
 "vhdl",
213
 "Verilog",
214
 "ACFplus",
215
 "skipping",
216
 "C (Verilog) comment",
217
 "VHDL comment",
218
 "Command line expression",
219
 "Include file area"
220
 };
221
 
222
/* token forced into LEX by method described in
223
   Lex & Yacc , O'Reilly page 206 */ 
224
  int start_grammar;
225
 
226
 
227
%}
228
 
229
 
230
/* removed '.' '-' ':' '/' ',' from here as it is now a unique token */
231
/* Permit '$' as this could become a variable to be expanded in make_string */
232
L   [A-Za-z0-9_\~\$]
233
L2  [A-Za-z0-9_\~\|\$]
234
/* do not permit square brackets in ACFP syntax inside strings (to be handled properly) */
235
L2A  [A-Za-z0-9_\~\|/\$]
236
L2D [A-Za-z0-9_\\$\.]
237
/* no / in this set, as its a valid arithmetic operator */
238
L2V [A-Za-z0-9_\~\|\$]
239
 
240
S [^\"]
241
Q [\"]
242
 
243
 
244
Ct [ -\~]
245
 
246
Cm [^\n]
247
 
248
 
249
 
250
D [0-9]
251
Spc [ \t]
252
 
253
/* lex directive */
254
%p 4000
255
%a 2500
256
%e 1500
257
%k 2000
258
%n 1000
259
 
260
/* can have VHDL Verilog and ACFP keywords defined exclusively */
261
/* s inclusive set */
262
%x vhdl
263
%x vlog
264
%x acfp
265
%x pragma
266
%x vert_c_comment
267
%x vert_vhdl_comment
268
/* expression tokens are used on the command line */
269
%x expr
270
/* copied almost verbatim from the examples given */
271
%x incl
272
 
273
 
274
 
275
%%
276
%{
277
 
278
/* Page 206, Lex & Yacc , O'Reilly */
279
/* solution to multiple lexers */
280
 
281
  if(start_grammar)    
282
    {
283
    int tmp = start_grammar;
284
    start_grammar = 0;
285
    return tmp;
286
    }
287
%}
288
 
289
 
290
<INITIAL,acfp,vhdl>include            { prev_begin_include = YY_START;  BEGIN(incl); }
291
 
292
<vlog>'include                        { prev_begin_include = YY_START;  BEGIN(incl); }
293
 
294
 
295
 <incl>[ \t]*      /* eat the whitespace */
296
 <incl>[^ \t\n]+   { /* got the include file name */
297
         if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
298
             {
299
             Log(LOG_ERROR, "-- Includes nested too deeply\n" );
300
             exit( 1 );
301
             }
302
         if(errorseen)
303
             {
304
             Log(LOG_ERROR, "-- skipping include: previous error\n" );
305
             exit( 1 );
306
             }
307
 
308
/*         printf("++ Using Begin=%s\n",yyerr_start_names[YY_START]); */
309
 
310
 
311
         include_stack[include_stack_ptr] =
312
             YY_CURRENT_BUFFER;
313
         /* expand arguments in string */
314
 
315
         old_linenumber[include_stack_ptr]= lineno;
316
 
317
         handles[include_stack_ptr] = yyin;
318
 
319
         include_stack_ptr++;
320
 
321
 
322
         filename[include_stack_ptr] = strdup(yytext);
323
 
324
         yyin = fopen( filename[include_stack_ptr], "r" );
325
 
326
         if ( ! yyin )
327
             {
328
             Log(LOG_ERROR, "-- cannot open include file '%s'\n",filename[include_stack_ptr]);
329
             include_stack_ptr -= 1;
330
             lineno = old_linenumber[include_stack_ptr];
331
/*             yy_switch_to_buffer(
332
                  include_stack[include_stack_ptr] );
333
*/
334
             yyin = handles[include_stack_ptr];
335
 
336
             }
337
         else
338
           {
339
         lineno = 1;
340
 
341
           yy_switch_to_buffer(
342
 
343
             yy_create_buffer( yyin, YY_BUF_SIZE ) );
344
           }
345
         BEGIN(prev_begin_include);
346
         }
347
 
348
<<EOF>> {
349
/*         rewind(yyin); */
350
/*           printf("-- +++ At level %d\n",include_stack_ptr); */
351
         if ( include_stack_ptr ==  0 )
352
             {
353
/*             printf("lex: termination\n");   */
354
/*              YY_FLUSH_BUFFER;
355
             yy_delete_buffer( YY_CURRENT_BUFFER );
356
*/
357
              exit_lex_block();
358
              yyterminate();
359
             }
360
 
361
         else
362
             {
363
/*             printf("lex: backup level in file buffer\n"); */
364
/*              YY_FLUSH_BUFFER; */
365
             include_stack_ptr --;
366
             yy_delete_buffer( YY_CURRENT_BUFFER );
367
             lineno = old_linenumber[include_stack_ptr];
368
             yyin = handles[include_stack_ptr];
369
             yy_switch_to_buffer(
370
                  include_stack[include_stack_ptr] );
371
             }
372
/*         printf("handle ending"); */
373
         break;
374
         }
375
 
376
 
377
 
378
<INITIAL,acfp,vlog,vhdl>"\""         { char t;
379
                    char * p;
380
                    char buff[MAXIDLEN];
381
 
382
                    int c;   /* quoted string using either type of quotes,
383
                              * including  escaped quotes */
384
 
385
                    t  = *yytext; /* determine terminator */
386
 
387
                    p =  buff; /* setup destination */
388
 
389
                    for(;;) { 
390
 
391
                      c = input();
392
                      if (c == t)
393
                        break;
394
 
395
                      if(c=='\n') { 
396
                        lineno++;
397
                        Log(LOG_GENERAL,"Carriage Return in string (line %d)\n",lineno);
398
                        continue;
399
                        }
400
 
401
                      if (c=='\\') {
402
                         *p++ = c;
403
                         c = input();
404
                         }
405
                      if(c==EOF) {
406
                        Log(LOG_GENERAL,"End of file in string\n");
407
                        break;
408
                        }
409
                      if(c<' ') {
410
                        Log(LOG_GENERAL,"Ctl char 0x%02X in string\n",c);
411
                        break; 
412
                        }
413
 
414
                        *p++ = c;
415
                      if((p - buff) >= MAXIDLEN-100) {
416
                        Log(LOG_GENERAL,"No closing quote after %d chars in string\n",MAXIDLEN-100);
417
                        break;
418
                        }
419
 
420
                    }
421
                    *p = 0;   
422
                    yylval.string = make_string(buff,&lx_first,&lx_last) ;
423
/*                    printf("quoted (yytext:'%s')\n",yylval.string); */
424
                    if(yydebug) fprintf(stderr,"String (quo) ='%s'\n",yylval.string); 
425
                    return(QUOTED_STRING); 
426
 }; 
427
 
428
<vlog>"\\"  { char * p;
429
              char buff[MAXIDLEN];
430
 
431
              int c;
432
              p =  buff; /* setup destination */
433
              while(1) { 
434
                c = input();
435
                if (!isalnum(c) && c!='[' && c!=']') /* any non-space char */
436
                  break;
437
                *p++ = c;
438
                }
439
 
440
             *p = 0;   
441
             yylval.string = make_string(buff,&lx_first,&lx_last) ;
442
             if(yydebug) fprintf(stderr,"String (escaped) ='%s'\n",yylval.string); 
443
             return(QUOTED_STRING); 
444
             }; 
445
 
446
 
447
 
448
 
449
 
450
 
451
<INITIAL,acfp,vhdl,pragma>"--" { 
452
/*
453
                                printf("-- vhdl comment"); 
454
*/
455
                            one_line_comment:
456
                                if(YY_START!=pragma)
457
                                  prev_begin=YY_START; 
458
                                comment_type= vert_vhdl_comment;
459
                                BEGIN(vert_vhdl_comment); 
460
                                break; };
461
<INITIAL,vlog>"//" { 
462
/*
463
                                printf("-- vhdl comment"); 
464
*/
465
                                goto one_line_comment;
466
                                 };
467
 
468
 
469
<INITIAL,acfp,vlog,pragma>"/*" {
470
/*
471
                                printf("-- C comment");  
472
*/
473
                                if(YY_START!=pragma)
474
                                  prev_begin=YY_START; 
475
                                comment_type= vert_c_comment;
476
                                BEGIN(vert_c_comment); 
477
                                break; 
478
};
479
 
480
 
481
<acfp>[rR][eE][aA][dD]_[oO][fF][fF] { 
482
/*
483
                              printf(" Read Off");
484
*/
485
                              if (comment_type == vert_c_comment) 
486
                                skip_c_comment();
487
                              if (comment_type == vert_vhdl_comment) 
488
                                skip_to_eol();
489
/*
490
                              printf(" Skipped comment\n");
491
*/
492
                              read_state = 0;
493
                              BEGIN(pragma);
494
			      break;
495
                              };
496
 
497
<acfp>[rR][eE][aA][dD]_[oO][nN] { 
498
/*
499
                              printf(" Read On");
500
*/
501
                              if (comment_type == vert_c_comment) 
502
                                skip_c_comment();
503
                              if (comment_type == vert_vhdl_comment) 
504
                                skip_to_eol(); 
505
/*
506
                              printf(" Skipped comment\n");
507
*/
508
                              read_state = 1;
509
                              if(prev_begin>= 0) 
510
                                 BEGIN(prev_begin);
511
                              break;
512
                              };
513
 
514
 
515
<pragma,vert_vhdl_comment,vert_c_comment>[Vv][Ee][Rr][Tt][Ii][Cc][Aa][Ll]{Spc}* {
516
/*
517
                              printf(" Vertical");
518
*/
519
                             /* the line is acfp syntax */ 
520
                BEGIN (acfp);  break; };
521
 
522
 
523
 
524
<vert_vhdl_comment,acfp>"\n" {
525
             lineno++;
526
             if (comment_type == vert_vhdl_comment )
527
               {
528
/*
529
               printf(" endline\n");
530
*/
531
               comment_type = -1; 
532
               lineno++;
533
               if(read_state==0) /* parser was not reading, so go back into pragma context */
534
                 BEGIN(pragma);
535
               else             /* parser was reading, so go back into pre-comment context */
536
                 BEGIN(prev_begin);
537
                break;
538
               }
539
             }; 
540
 
541
<vert_c_comment,acfp,vlog,INITIAL>"*/" {
542
               /* pickup only inside a pragma enclosed in a C comment */ 
543
/*
544
               printf(" end C comment\n");
545
*/
546
               if (comment_type != vert_c_comment )
547
                 Log(LOG_ERROR,"-- close comment unexpected\n");
548
               comment_type = -1;
549
               if(read_state==0) /* parser was not reading, so go back into pragma context */
550
                 BEGIN(pragma);
551
               else             /* parser was reading, so go back into pre-comment context */
552
                 BEGIN(prev_begin);
553
                break;
554
               }; 
555
 
556
 
557
 
558
 
559
<vert_c_comment>"\n"                { lineno++; break; };
560
 
561
<pragma>"\n"                          { lineno++; break; };
562
<vert_c_comment,pragma>"\r"              { break; };
563
 
564
<vert_vhdl_comment,vert_c_comment>{Spc} { break; }; 
565
 
566
<vert_vhdl_comment>. {skip_to_eol();
567
                      goto ignored_comment;
568
                      };
569
 
570
<vert_c_comment>.   { skip_c_comment();
571
                 ignored_comment:
572
                      comment_type = -1; 
573
                      if(read_state==0) /* parser was not reading, so go back into pragma context */
574
                        BEGIN(pragma);
575
                      else             /* parser was reading, so go back into pre-comment context */
576
                        BEGIN(prev_begin);
577
                       break; };
578
<pragma>. { break; };
579
 
580
 
581
<INITIAL,vlog,expr,vhdl>"\'"                  { return QUOTE;   };
582
<INITIAL,acfp,vhdl>"=>"                       { return CONNECTED; };
583
<INITIAL,acfp,vlog,vhdl,expr>":="             { return ASSIGN; };
584
<INITIAL,acfp,vhdl>"<="                       { return SIG_ASSIGN; };
585
<INITIAL,acfp,vlog,vhdl,expr>":"              { return (':'); };
586
<INITIAL,acfp,vlog,vhdl,expr>";"              { return (';');  };
587
<INITIAL,acfp,vlog,expr>"="                   { return ('='); };
588
<INITIAL,acfp,vlog,vhdl,expr>"("              { return ('(');  };
589
<INITIAL,acfp,vlog,vhdl,expr>")"              { return (')');  };
590
<INITIAL,acfp,vlog,vhdl>"."                   { return ('.');  }; 
591
<INITIAL,acfp,vlog,vhdl>"!"                   { return ('!');  }; 
592
<INITIAL,acfp,vlog,vhdl,expr>"+"              { return ('+');  };
593
<INITIAL,acfp,vlog,vhdl,expr>"-"              { return ('-');  };
594
<vhdl>"/="                                    { return (N_EQ); };
595
<INITIAL,acfp,vlog,vhdl,expr>"/"              { return ('/');  };
596
<INITIAL,acfp,vlog,expr>"%"                   { return ('%');  };
597
<INITIAL,acfp,vlog,expr>"?"                   { return ('?');  };
598
<INITIAL,acfp,vlog,expr>"<<"                  { return (SHL); };
599
<INITIAL,acfp,vlog,expr>">>"                  { return (SHR); };
600
<INITIAL,acfp,vlog,expr>"<"                   { return ('<'); };
601
<INITIAL,acfp,vlog,expr>">"                   { return ('>'); };
602
<INITIAL,acfp,vlog,expr>"^"                   { return ('^'); };
603
<INITIAL,acfp,vlog,expr>"~"                   { return ('~'); };
604
<INITIAL,acfp,vlog,expr>"&&"                  { return (LOG_AND); };
605
<INITIAL,acfp,vlog,expr>"&"                   { return ('&'); };
606
<INITIAL,acfp,vlog,expr>"||"                  { return (LOG_OR); };
607
<INITIAL,acfp,vlog,expr>"|"                   { return ('|'); };
608
 
609
 
610
<INITIAL,acfp,vlog,expr>"=="                  { return (EQ_EQ); };
611
<vhdl>"="                                     { return (EQ_EQ); };
612
<INITIAL,acfp,vlog,expr>"!="                  { return (N_EQ); };
613
<INITIAL,acfp,vhdl,expr>"**"                  { return (TO_POW);  };
614
<INITIAL,acfp,vlog,vhdl,expr>"*"              { return ('*');  };
615
<INITIAL,acfp,vlog,vhdl>","                   { return (',');  };
616
<vlog,acfp>"["                                { return ('['); };
617
<vlog,acfp>"]"                                { return (']'); };
618
 
619
 
620
<INITIAL,acfp,vlog,vhdl,expr>{Spc}    { break; };
621
 
622
<INITIAL,acfp,vlog,vhdl>"\n"              { lineno++; if(yydebug) printf("line %d\n",lineno); break; };
623
<INITIAL,acfp,vlog,vhdl>"\r"              { break; };
624
 
625
 
626
 
627
 
628
<acfp>[eE][xX][eE][cC]                   {  lex_exec_line();goto ignored_comment; /* commands to vertical */ };
629
 
630
 
631
<INITIAL>[aA][hH][dD][lL]                                   { BEGIN(acfp);prev_begin=acfp;
632
                                                                             Log(LOG_GENERAL,"Entering ACFP block\n");
633
                                                                             inside_block=1;
634
                                                                             return (AHDL); }  
635
<INITIAL>[cC][hH][iI][pP]                                   { BEGIN(acfp);prev_begin=acfp;
636
                                                                             inside_block=1;
637
                                                                             return (CHIP);  }
638
<INITIAL>[jJ][oO][iI][nN][eE][dD]_[nN][eE][tT][sS]          { BEGIN(acfp);prev_begin=acfp;
639
                                                                             inside_block=1;
640
                                                                             return (JOINED_NETS); } ;
641
<INITIAL>[cC][oO][mM][pP][oO][nN][eE][nN][tT][sS]           { BEGIN(acfp);prev_begin=acfp;
642
                                                                             inside_block=1;
643
                                                                             return (COMPONENTS); };
644
<INITIAL>[rR][eE][nN][aA][mM][eE]_[pP][iI][nN][sS]          { BEGIN(acfp);prev_begin=acfp;
645
                                                                             inside_block=1;
646
                                                                             return (RENAME_PINS); } ;
647
<INITIAL>[tT][eE][mM][pP][lL][aA][tT][eE]                   { BEGIN(acfp);prev_begin=acfp;
648
                                                                             inside_block=1;
649
                                                                             return (TEMPLATE); } ;
650
<INITIAL,acfp,vlog,vhdl>[vV][hH][dD][lL]                                   { BEGIN(vhdl);
651
                                                                             Log(LOG_GENERAL,"Entering VHDL block\n");
652
                                                                             inside_block=1;
653
                                                                             prev_begin=vhdl;
654
                                                                             return (VHDL); } ;
655
 
656
<INITIAL,acfp,vlog,vhdl>[vV][eE][rR][iI][lL][oO][gG]                      { BEGIN(vlog);
657
                                                                             Log(LOG_GENERAL,"Entering Verilog block\n");
658
                                                                             prev_begin=vlog;
659
                                                                             inside_block=1;
660
                                                                             return (VERILOG); } ;
661
 
662
<INITIAL,acfp,vlog,vhdl>[wW][iI][rR][eE][dD]_[nN][eE][tT][sS]              { BEGIN(acfp);prev_begin=acfp;
663
                                                                             inside_block=1;
664
                                                                             return (WIRED_NETS); };
665
<INITIAL,acfp,vlog,vhdl>[gG][eE][nN][eE][rR][iI][cC]                       { if (!inside_block) /* special */
666
                                                                             { inside_block=1;
667
                                                                               BEGIN(vhdl);prev_begin=vhdl; };
668
                                                                             return (GENERIC);};
669
<vhdl>[aA][lL][lL]                                           { return (ALL); } 
670
<vhdl>[aA][rR][cC][hH][iI][tT][eE][cC][tT][uU][rR][eE]       { return (ARCHITECTURE); } 
671
<acfp,vhdl>[aA][tT][tT][rR][iI][bB][uU][tT][eE]              { return (ATTRIBUTE); } 
672
<acfp>[aA][sS][sS][iI][gG][nN][eE][dD]                       { return (ASSIGNED); } 
673
<acfp,vhdl>[aA][lL][iI][aA][sS]                              { return (ALIAS); } 
674
<acfp>[aA][nN]                                               { return (AN); } 
675
<acfp,vlog,vhdl>[bB][eE][gG][iI][nN]                         { return (BEGIN_TOK); } 
676
<acfp>[bB][iI][dD][iI][rR]_[pP][iI][nN]                      { yylval.integer = BIDIR;  return(PINDIR); }
677
<acfp>[bB][iI][dD][iI][rR]                                   { yylval.integer = BIDIR;  return(PINDIR); }
678
<vhdl>[bB][oO][oO][lL][eE][aA][nN]                           { return(BOOLEAN); }
679
<vhdl>[iI][nN][oO][uU][tT]                                   { yylval.integer = BIDIR;  return(PINDIR); }
680
<vlog>[oO][uU][tT]                                           { yylval.integer = BIDIR;  return(PINDIR); }
681
<acfp>[bB][uU][fF][fF][eE][rR]_[pP][iI][nN]                  { yylval.integer = BUFFER; return(PINDIR);  }
682
<vhdl>[bB][uU][fF][fF][eE][rR]                               { yylval.integer = BUFFER; return(PINDIR);  }
683
<acfp>[cC][oO][nN][fF][iI][gG]_[pP][iI][nN]                  { yylval.integer = CONFIG; return(PINDIR); };
684
<vhdl>[cC][oO][mM][pP][oO][nN][eE][nN][tT]                   { return (COMPONENT); };
685
<vhdl>[cC][oO][nN][sS][tT][aA][nN][tT]                       { return (CONSTANT); };
686
<acfp>[cC][oO][nN][nN][eE][cC][tT][iI][oO][nN]               { return (CONN); };
687
<acfp>[vV][hH][dD][lL]_[cC][oO][nN][nN]                       { return (VHDL_CONN); };
688
<acfp>[dD][eE][cC][lL][aA][rR][aA][tT][iI][oO][nN]           { return (DECLARATION); };
689
<acfp>[dD][eE][vV][iI][cC][eE]                               { return (DEVICE); };
690
<vhdl,acfp,expr>[dD][oO][wW][nN][tT][oO]                          { return (DOWNTO);  };
691
<acfp,vlog,vhdl>[eE][nN][dD]                                 { return (END); /* do not free_strings here as it is too early !! */};
692
<acfp>[eE][nN][dD]_[cC][oO][nN][nN]                          { return (END_CONN); } ;
693
<vlog>endmodule                                              { return (ENDMODULE); };
694
<acfp,vhdl>[eE][nN][tT][iI][tT][yY]                          { return (ENTITY); };
695
<acfp>[eE][qQ][uU][iI][vV][aA][lL][eE][nN][tT]               { return (EQUIVALENT); };
696
<vhdl>[eE][nN][vV]_[sS][tT][rR][iI][nN][gG]                  { return (ENV_STRING); };
697
<vhdl,expr>[fF][aA][lL][sS][eE]                                   { return (FALSE); };
698
<acfp>[fF][iI][xX]_[lL][oO][cC][aA][tT][iI][oO][nN]          { return (FIX_LOCATION); }; 
699
<vhdl>[fF][oO][rR]                                           { return (FOR); };
700
<acfp>[gG][nN][dD]\*                                         { return (GND_RES_IO); };
701
<acfp>[gG][nN][dD]\+                                         { return (GND_RES_IN); };
702
<acfp>[gG][nN][dD]{L2}*                                      { yylval.string = make_string(yytext,&lx_first,&lx_last);
703
                                                               if(yydebug) fprintf(stderr,"String (GND) ='%s'\n",yytext); 
704
                                                               return (GND); };
705
<acfp>[iI][nN][pP][uU][tT]_[pP][iI][nN]                      { yylval.integer = INPUT;  return(PINDIR); };
706
<vhdl>[iI][nN]                                               { yylval.integer = INPUT;  return(PINDIR); };
707
<vlog,acfp>[iI][nN][pP][uU][tT]                                   { yylval.integer = INPUT;  return(PINDIR); };
708
<vlog>[iI][nN][oO][uU][tT]                                   { yylval.integer = BIDIR;  return(PINDIR); }
709
<acfp>[iI][nN][sS][tT][aA][nN][cC][eE]                       { return (INSTANCE); };
710
<acfp,vhdl>[iI][nN][tT][eE][gG][eE][rR]                      { return (INTEGER); };
711
<acfp,vhdl>[iI][sS]                                          { return (IS);  };
712
<acfp>[jJ][uU][mM][pP][eE][rR]                               { return (JUMPER); } ;
713
<vhdl>[lL][iI][bB][rR][aA][rR][yY]                           { return (LIBRARY); } ;
714
<acfp>[lL][oO][cC][aA][tT][iI][oO][nN]                       { return (LOCATION); } ;
715
<vhdl>[mM][aA][pP]                                           { return (MAP); };
716
<vlog>module                                                 { return (MODULE); };
717
<acfp>[nN][oO][nN][eE]                                       { yylval.integer = NONE;   return(PINDIR); };
718
<acfp>[nN][aA][mM][eE][dD]                                   { return (NAMED); } ;
719
<vhdl>[oO][fF]                                               { return (OF); };
720
<acfp>[oO][uU][tT][pP][uU][tT]_[pP][iI][nN]                  { yylval.integer = OUTPUT; return(PINDIR); };
721
<vlog,acfp>[oO][uU][tT][pP][uU][tT]                               { yylval.integer = OUTPUT; return(PINDIR); };
722
<vhdl>[oO][uU][tT]                                           { yylval.integer = OUTPUT; return(PINDIR); };
723
<vhdl>[oO][pP][eE][nN]                                       { return (OPEN); };
724
<vhdl>[pP][aA][cC][kK][aA][gG][eE]                           { return (PACKAGE); }; 
725
<vhdl>[pP][oO][rR][tT]                                       { return (PORT); };
726
<acfp>[pP][oO][wW][eE][rR]_[pP][iI][nN]                      { yylval.integer = POWER; return(PINDIR); };
727
<acfp,vlog,vhdl>[rR][aA][nN][gG][eE]                         { return (RANGE); };
728
<acfp>[rR][oO][uU][tT][eE]_[fF][lL][aA][gG][sS]              { return (ROUTE_FLAGS); };
729
<acfp>[rR][oO][uU][tT][eE][dD]                               { return (ROUTED); } ;
730
<vhdl>[sS][hH][lL]                                           { return (SHL); };
731
<vhdl>[sS][hH][rR]                                           { return (SHR); };
732
<vhdl>[sS][iI][gG][nN][aA][lL]                               { return (SIGNAL); };
733
<vhdl>[sS][tT][rR][iI][nN][gG]                               { return (STRING); };
734
<vlog>[sS][uU][bB][dD][eE][sS][iI][gG][nN]                   { return (SUBDESIGN); };
735
<acfp,vhdl,expr>[tT][oO]                                          { return (TO);  };
736
<vhdl,expr>[tT][rR][uU][eE]                                       { return (TRUE); };
737
<acfp>[uU][nN][rR][oO][uU][tT][eE][dD]                       { return (UNROUTED); } ;
738
<acfp>[vV][cC][cC]{L2}*                                      { yylval.string = make_string(yytext,&lx_first,&lx_last);
739
                                                               if(yydebug) fprintf(stderr,"String (VCC) ='%s'\n",yytext); 
740
                                                               return (VCC);  };
741
<vhdl>[uU][sS][eE]                                           { return (USE);  };
742
<vlog>wire                                                   { return (WIRE); };       
743
 
744
<INITIAL,acfp,expr>{D}{L2D}*   { yylval.string = make_string(yytext,&lx_first,&lx_last); /* do it anyway */
745
                           if(yydebug) fprintf(stderr,"String (num) ='%s'\n",yytext); 
746
                           return(NUM_STRING); };
747
 
748
<vlog,vhdl,expr>{D}{L2V}*     { yylval.string = make_string(yytext,&lx_first,&lx_last); /* do it anyway */
749
                     if(yydebug) fprintf(stderr,"String (num) ='%s'\n",yytext); 
750
                      return(NUM_STRING); };
751
 
752
<INITIAL,acfp,expr>{L}{L2A}*     { yylval.string = make_string(yytext,&lx_first,&lx_last); /* do it anyway */
753
                     if(yydebug) fprintf(stderr,"String (num) ='%s'\n",yytext); 
754
                      return(TXT_STRING); };
755
 
756
<vlog,vhdl,expr>{L}{L2V}*            {  yylval.string = make_string(yytext,&lx_first,&lx_last); /* do it anyway */
757
                     if(yydebug) fprintf(stderr,"String (txt) ='%s'\n",yytext); 
758
                      return(isdigit(yylval.string[0])?NUM_STRING : TXT_STRING); };
759
 
760
<vlog>"/"{L2D}+   { yylval.string = make_string(yytext,&lx_first,&lx_last); /* do it anyway */
761
                     if(yydebug) fprintf(stderr,"String (num) ='%s'\n",yytext); 
762
                      return(TXT_STRING); };
763
 
764
 
765
<INITIAL,acfp,vlog,vhdl>.                { printf("-- error in %s syntax: found character code 0x%02X (%c) at line %d\n",yyerr_start_names[YY_START],yytext[0],yytext[0]>32?yytext[0]:'.',lineno); break; };
766
 
767
 
768
%%
769
 
770
 
771
/* terminate an ACFP and VHDL comment */
772
void skip_to_eol(void) {
773
  int c;
774
  for(;;) {
775
    c=input();
776
    if (c=='\n' || c==EOF) {
777
      lineno++;
778
      return;
779
      }
780
    }/* VHDL comment */ 
781
  }
782
 
783
 
784
 
785
 
786
/* execute a command line command  */
787
  char stringbuff[MAXIDLEN];
788
void lex_exec_line(void) {
789
  int c,i;
790
  for(i=0;i<MAXIDLEN-2;) {
791
    c=input();
792
    stringbuff[i++] = c;
793
    if (c=='\n' || c==EOF) {
794
      lineno++;
795
      stringbuff[i]=0;
796
      ExecuteString (stringbuff ,yy_nArgs, yy_Args);
797
      return;
798
      }
799
    }
800
   stringbuff[i] = 0;
801
   ExecuteString (stringbuff ,yy_nArgs,yy_Args);
802
  }
803
 
804
 
805
 
806
 
807
/* supporting functions need to be in sane file so LEX macros work */
808
void skip_c_comment(void) {
809
  int c;
810
  for(;;) { 
811
    while(((c = input()) !=EOF) && (c != '*')) {
812
      if(c=='\n') 
813
        lineno++;
814
      }
815
    if (c=='*') {
816
      while((c = input()) == '*')    putchar(c); 
817
      if(c=='\n') 
818
        lineno++;
819
      if (c=='/')
820
        break;
821
      }
822
    if(c==EOF) {
823
      Log(LOG_GENERAL,"End of file in comment\n");
824
      break;
825
      }
826
    }
827
  }
828
 
829
void exit_lex_block(void) {
830
  inside_block = 0;
831
  prev_begin=INITIAL;
832
  BEGIN(INITIAL);
833
  }
834
 
835
void tidy_lex(void) 
836
  {
837
  errorseen = 0;
838
  include_stack_ptr = 0;
839
  exit_lex_block();
840
  start_grammar = FILEMODE;
841
  }
842
 
843
 
844
 
845
 
846
int yyerror(char * x)
847
  {
848
 
849
  if (!errorseen) {
850
    if(include_stack_ptr==0)
851
      { 
852
      Log(LOG_ERROR,"--  Error in %s syntax\n--  -->%s near string (%s) at line %d\n",
853
              yyerr_start_names[YY_START],x,yytext,lineno);
854
      }
855
    else
856
      {
857
      Log(LOG_ERROR,"--  File %s: Error in %s syntax\n--  -->%s near string (%s) at line %d\n",
858
             filename[include_stack_ptr],yyerr_start_names[YY_START],x,yytext,lineno);
859
      }
860
    }
861
  errorseen = 1;
862
  include_stack_ptr = 0;
863
  exit_lex_block();
864
  YY_FLUSH_BUFFER;
865
  yyterminate();
866
  return 1;
867
  }
868
 
869
 
870
 
871
/********************************************************/
872
/* Reading generic expressions from a string            */
873
/********************************************************/
874
 
875
static char * myinputptr;
876
static char * myinputlim;
877
/* this is exported */
878
expression_t * cmd_expression;
879
 
880
 
881
int my_yyinput(char * buf, int max_size)
882
  {
883
  int n;
884
  n =(max_size < (myinputlim-myinputptr))? max_size :myinputlim-myinputptr;
885
  if(n>0)
886
    {
887
    memcpy(buf,myinputptr,n);
888
    myinputptr+=n;
889
    }
890
  return n;
891
  }
892
 
893
 
894
/* this function requires a large number of declarations from 
895
  lex. */
896
 
897
 
898
 
899
expression_t * compile_expression_from_string(char * s)
900
  {
901
  int prev_expr_begin;
902
  myinputptr = s;
903
  myinputlim = s+strlen(s);
904
  prev_expr_begin = YY_START;
905
 
906
  BEGIN(expr);
907
 
908
  start_grammar = CMDMODE;
909
  lex_from_string = 1;  
910
  yyparse();
911
 
912
  lex_from_string = 0;
913
  BEGIN(prev_expr_begin);
914
 
915
  return cmd_expression;
916
  }