Subversion Repositories Vertical

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 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 "yywrap.h"
156
 
157
 
158
 
159
 
160
#define YYLMAX MAXIDLEN
161
 
162
#if !defined YY_START
163
#define YY_START (yybgin -1 -yysvec)
164
#endif
165
 
166
/* YY_INPUT redefinition
167
   keep the original definition, replace with a function which will
168
   check a flag and either use the original file reading version or read from
169
   a string */
170
 
171
 
172
 
173
 
174
/* Code below is taken from flex parser, and modified ..
175
   the first three lines are mine. I have added 
176
   a call to my own function my_yyinput if we are inputting from string.
177
   This code overrides that in the lexer by being already defined at start
178
   of compilation of lexer */ 
179
 
180
 
181
#define YY_INPUT(buf,result,max_size) \
182
    if(lex_from_string)                        /* MOD */\
183
        { result =my_yyinput(buf,max_size); }  /* MOD */\
184
	else                                       /* MOD */\
185
    if ( yy_current_buffer->yy_is_interactive ) \
186
		{ \
187
		int c = '*', n; \
188
		for ( n = 0; n < max_size && \
189
			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
190
			buf[n] = (char) c; \
191
		if ( c == '\n' ) \
192
			buf[n++] = (char) c; \
193
		if ( c == EOF && ferror( yyin ) ) \
194
			YY_FATAL_ERROR( "input in flex scanner failed" ); \
195
		result = n; \
196
		} \
197
	else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
198
		  && ferror( yyin ) ) \
199
		YY_FATAL_ERROR( "input in flex scanner failed" );
200
 
201
 
202
 
203
 
204
 
205
 
206
 
207
 
208
 
209
 
210
 
211
#define MAX_INCLUDE_DEPTH 10
212
 
213
 
214
 
215
 
216
#ident "@(#)$Header: C:/cvsroot/Vert03/acf_src/acf_lex.l,v 1.2 2004/06/22 21:44:10 mjames Exp $"
217
 
218
/* state stores for include files */
219
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
220
struct str * incl_first = NULL, * incl_last = NULL;
221
char * filename[MAX_INCLUDE_DEPTH];
222
int    old_linenumber[MAX_INCLUDE_DEPTH];
223
FILE * handles[MAX_INCLUDE_DEPTH];
224
 
225
 
226
int include_stack_ptr = 0;
227
 
228
 
229
char lex_from_string = 0;
230
 
231
extern int errorseen;
232
extern  int yyval;
233
extern int yydebug;
234
extern int lineno;
235
 
236
 
237
extern int inside_block; /* flag to help 'generic' context dependence */
238
 
239
generic_info_t info;
240
 
241
int prev_begin = -1;
242
int prev_begin_include = -1;
243
int read_state = 1; /* start off by reading */
244
 
245
int comment_type = 0;
246
 
247
void lex_exec_line(void);
248
 
249
void skip_to_eol(void);
250
void skip_c_comment(void);
251
void exit_lex_block(void);
252
 
253
 
254
int  my_yyinput(char * buf , int max_size);
255
 
256
 
257
static char * yyerr_start_names[] = {
258
 "INITIAL",
259
 "vhdl",
260
 "Verilog",
261
 "ACFplus",
262
 "skipping",
263
 "C (Verilog) comment",
264
 "VHDL comment",
265
 "Command line expression",
266
 "Include file area"
267
 };
268
 
269
/* token forced into LEX by method described in
270
   Lex & Yacc , O'Reilly page 206 */ 
271
  int start_grammar;
272
 
273
 
274
%}
275
 
276
 
277
/* removed '.' '-' ':' '/' ',' from here as it is now a unique token */
278
/* Permit '$' as this could become a variable to be expanded in make_string */
279
L   [A-Za-z0-9_\~\$]
280
L2  [A-Za-z0-9_\~\|\$]
281
/* do not permit square brackets in ACFP syntax inside strings (to be handled properly) */
282
L2A  [A-Za-z0-9_\~\|/\$]
283
L2D [A-Za-z0-9_\\$\.]
284
/* no / in this set, as its a valid arithmetic operator */
285
L2V [A-Za-z0-9_\~\|\$]
286
 
287
S [^\"]
288
Q [\"]
289
 
290
 
291
Ct [ -\~]
292
 
293
Cm [^\n]
294
 
295
 
296
 
297
D [0-9]
298
Spc [ \t]
299
 
300
/* lex directive */
301
%p 4000
302
%a 2500
303
%e 1500
304
%k 2000
305
%n 1000
306
 
307
/* can have VHDL Verilog and ACFP keywords defined exclusively */
308
/* s inclusive set */
309
%x vhdl
310
%x vlog
311
%x acfp
312
%x pragma
313
%x vert_c_comment
314
%x vert_vhdl_comment
315
/* expression tokens are used on the command line */
316
%x expr
317
/* copied almost verbatim from the examples given */
318
%x incl
319
 
320
 
321
 
322
%%
323
%{
324
 
325
/* Page 206, Lex & Yacc , O'Reilly */
326
/* solution to multiple lexers */
327
 
328
  if(start_grammar)    
329
    {
330
    int tmp = start_grammar;
331
    start_grammar = 0;
332
    return tmp;
333
    }
334
%}
335
 
336
 
337
<INITIAL,acfp,vhdl>include            { prev_begin_include = YY_START;  BEGIN(incl); }
338
 
339
<vlog>'include                        { prev_begin_include = YY_START;  BEGIN(incl); }
340
 
341
 
342
 <incl>[ \t]*      /* eat the whitespace */
343
 <incl>[^ \t\n]+   { /* got the include file name */
344
         if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
345
             {
346
             Log(LOG_ERROR, "-- Includes nested too deeply\n" );
347
             exit( 1 );
348
             }
349
         if(errorseen)
350
             {
351
             Log(LOG_ERROR, "-- skipping include: previous error\n" );
352
             exit( 1 );
353
             }
354
 
355
/*         printf("++ Using Begin=%s\n",yyerr_start_names[YY_START]); */
356
 
357
 
358
         include_stack[include_stack_ptr] =
359
             YY_CURRENT_BUFFER;
360
         /* expand arguments in string */
361
 
362
         old_linenumber[include_stack_ptr]= lineno;
363
 
364
         handles[include_stack_ptr] = yyin;
365
 
366
         include_stack_ptr++;
367
 
368
 
369
         filename[include_stack_ptr] = strdup(yytext);
370
 
371
         yyin = fopen( filename[include_stack_ptr], "r" );
372
 
373
         if ( ! yyin )
374
             {
375
             Log(LOG_ERROR, "-- cannot open include file '%s'\n",filename[include_stack_ptr]);
376
             include_stack_ptr -= 1;
377
             lineno = old_linenumber[include_stack_ptr];
378
/*             yy_switch_to_buffer(
379
                  include_stack[include_stack_ptr] );
380
*/
381
             yyin = handles[include_stack_ptr];
382
 
383
             }
384
         else
385
           {
386
         lineno = 1;
387
 
388
           yy_switch_to_buffer(
389
 
390
             yy_create_buffer( yyin, YY_BUF_SIZE ) );
391
           }
392
         BEGIN(prev_begin_include);
393
         }
394
 
395
<<EOF>> {
396
/*         rewind(yyin); */
397
/*           printf("-- +++ At level %d\n",include_stack_ptr); */
398
         if ( include_stack_ptr ==  0 )
399
             {
400
/*             printf("lex: termination\n");   */
401
/*              YY_FLUSH_BUFFER;
402
             yy_delete_buffer( YY_CURRENT_BUFFER );
403
*/
404
              exit_lex_block();
405
              yyterminate();
406
             }
407
 
408
         else
409
             {
410
/*             printf("lex: backup level in file buffer\n"); */
411
/*              YY_FLUSH_BUFFER; */
412
             include_stack_ptr --;
413
             yy_delete_buffer( YY_CURRENT_BUFFER );
414
             lineno = old_linenumber[include_stack_ptr];
415
             yyin = handles[include_stack_ptr];
416
             yy_switch_to_buffer(
417
                  include_stack[include_stack_ptr] );
418
             }
419
/*         printf("handle ending"); */
420
         break;
421
         }
422
 
423
 
424
 
425
<INITIAL,acfp,vlog,vhdl>"\""         { char t;
426
                    char * p;
427
                    char buff[MAXIDLEN];
428
 
429
                    int c;   /* quoted string using either type of quotes,
430
                              * including  escaped quotes */
431
 
432
                    t  = *yytext; /* determine terminator */
433
 
434
                    p =  buff; /* setup destination */
435
 
436
                    for(;;) { 
437
 
438
                      c = input();
439
                      if (c == t)
440
                        break;
441
 
442
                      if(c=='\n') { 
443
                        lineno++;
444
                        Log(LOG_GENERAL,"Carriage Return in string (line %d)\n",lineno);
445
                        continue;
446
                        }
447
 
448
                      if (c=='\\') {
449
                         *p++ = c;
450
                         c = input();
451
                         }
452
                      if(c==EOF) {
453
                        Log(LOG_GENERAL,"End of file in string\n");
454
                        break;
455
                        }
456
                      if(c<' ') {
457
                        Log(LOG_GENERAL,"Ctl char 0x%02X in string\n",c);
458
                        break; 
459
                        }
460
 
461
                        *p++ = c;
462
                      if((p - buff) >= MAXIDLEN-100) {
463
                        Log(LOG_GENERAL,"No closing quote after %d chars in string\n",MAXIDLEN-100);
464
                        break;
465
                        }
466
 
467
                    }
468
                    *p = 0;   
469
                    yylval.string = make_string(buff,&lx_first,&lx_last) ;
470
/*                    printf("quoted (yytext:'%s')\n",yylval.string); */
471
                    if(yydebug) fprintf(stderr,"String (quo) ='%s'\n",yylval.string); 
472
                    return(QUOTED_STRING); 
473
 }; 
474
 
475
<vlog>"\\"  { char * p;
476
              char buff[MAXIDLEN];
477
 
478
              int c;
479
              p =  buff; /* setup destination */
480
              while(1) { 
481
                c = input();
482
                if (!isalnum(c) && c!='[' && c!=']') /* any non-space char */
483
                  break;
484
                *p++ = c;
485
                }
486
 
487
             *p = 0;   
488
             yylval.string = make_string(buff,&lx_first,&lx_last) ;
489
             if(yydebug) fprintf(stderr,"String (escaped) ='%s'\n",yylval.string); 
490
             return(QUOTED_STRING); 
491
             }; 
492
 
493
 
494
 
495
 
496
 
497
 
498
<INITIAL,acfp,vhdl,pragma>"--" { 
499
/*
500
                                printf("-- vhdl comment"); 
501
*/
502
                            one_line_comment:
503
                                if(YY_START!=pragma)
504
                                  prev_begin=YY_START; 
505
                                comment_type= vert_vhdl_comment;
506
                                BEGIN(vert_vhdl_comment); 
507
                                break; };
508
<INITIAL,vlog>"//" { 
509
/*
510
                                printf("-- vhdl comment"); 
511
*/
512
                                goto one_line_comment;
513
                                 };
514
 
515
 
516
<INITIAL,acfp,vlog,pragma>"/*" {
517
/*
518
                                printf("-- C comment");  
519
*/
520
                                if(YY_START!=pragma)
521
                                  prev_begin=YY_START; 
522
                                comment_type= vert_c_comment;
523
                                BEGIN(vert_c_comment); 
524
                                break; 
525
};
526
 
527
 
528
<acfp>[rR][eE][aA][dD]_[oO][fF][fF] { 
529
/*
530
                              printf(" Read Off");
531
*/
532
                              if (comment_type == vert_c_comment) 
533
                                skip_c_comment();
534
                              if (comment_type == vert_vhdl_comment) 
535
                                skip_to_eol();
536
/*
537
                              printf(" Skipped comment\n");
538
*/
539
                              read_state = 0;
540
                              BEGIN(pragma);
541
			      break;
542
                              };
543
 
544
<acfp>[rR][eE][aA][dD]_[oO][nN] { 
545
/*
546
                              printf(" Read On");
547
*/
548
                              if (comment_type == vert_c_comment) 
549
                                skip_c_comment();
550
                              if (comment_type == vert_vhdl_comment) 
551
                                skip_to_eol(); 
552
/*
553
                              printf(" Skipped comment\n");
554
*/
555
                              read_state = 1;
556
                              if(prev_begin>= 0) 
557
                                 BEGIN(prev_begin);
558
                              break;
559
                              };
560
 
561
 
562
<pragma,vert_vhdl_comment,vert_c_comment>[Vv][Ee][Rr][Tt][Ii][Cc][Aa][Ll]{Spc}* {
563
/*
564
                              printf(" Vertical");
565
*/
566
                             /* the line is acfp syntax */ 
567
                BEGIN (acfp);  break; };
568
 
569
 
570
 
571
<vert_vhdl_comment,acfp>"\n" {
572
             lineno++;
573
             if (comment_type == vert_vhdl_comment )
574
               {
575
/*
576
               printf(" endline\n");
577
*/
578
               comment_type = -1; 
579
               lineno++;
580
               if(read_state==0) /* parser was not reading, so go back into pragma context */
581
                 BEGIN(pragma);
582
               else             /* parser was reading, so go back into pre-comment context */
583
                 BEGIN(prev_begin);
584
                break;
585
               }
586
             }; 
587
 
588
<vert_c_comment,acfp,vlog,INITIAL>"*/" {
589
               /* pickup only inside a pragma enclosed in a C comment */ 
590
/*
591
               printf(" end C comment\n");
592
*/
593
               if (comment_type != vert_c_comment )
594
                 Log(LOG_ERROR,"-- close comment unexpected\n");
595
               comment_type = -1;
596
               if(read_state==0) /* parser was not reading, so go back into pragma context */
597
                 BEGIN(pragma);
598
               else             /* parser was reading, so go back into pre-comment context */
599
                 BEGIN(prev_begin);
600
                break;
601
               }; 
602
 
603
 
604
 
605
 
606
<vert_c_comment>"\n"                { lineno++; break; };
607
 
608
<pragma>"\n"                          { lineno++; break; };
609
<vert_c_comment,pragma>"\r"              { break; };
610
 
611
<vert_vhdl_comment,vert_c_comment>{Spc} { break; }; 
612
 
613
<vert_vhdl_comment>. {skip_to_eol();
614
                      goto ignored_comment;
615
                      };
616
 
617
<vert_c_comment>.   { skip_c_comment();
618
                 ignored_comment:
619
                      comment_type = -1; 
620
                      if(read_state==0) /* parser was not reading, so go back into pragma context */
621
                        BEGIN(pragma);
622
                      else             /* parser was reading, so go back into pre-comment context */
623
                        BEGIN(prev_begin);
624
                       break; };
625
<pragma>. { break; };
626
 
627
 
628
<INITIAL,vlog,expr,vhdl>"\'"                  { return QUOTE;   };
629
<INITIAL,acfp,vhdl>"=>"                       { return CONNECTED; };
630
<INITIAL,acfp,vlog,vhdl,expr>":="             { return ASSIGN; };
631
<INITIAL,acfp,vhdl>"<="                       { return SIG_ASSIGN; };
632
<INITIAL,acfp,vlog,vhdl,expr>":"              { return (':'); };
633
<INITIAL,acfp,vlog,vhdl,expr>";"              { return (';');  };
634
<INITIAL,acfp,vlog,expr>"="                   { return ('='); };
635
<INITIAL,acfp,vlog,vhdl,expr>"("              { return ('(');  };
636
<INITIAL,acfp,vlog,vhdl,expr>")"              { return (')');  };
637
<INITIAL,acfp,vlog,vhdl>"."                   { return ('.');  }; 
638
<INITIAL,acfp,vlog,vhdl>"!"                   { return ('!');  }; 
639
<INITIAL,acfp,vlog,vhdl,expr>"+"              { return ('+');  };
640
<INITIAL,acfp,vlog,vhdl,expr>"-"              { return ('-');  };
641
<vhdl>"/="                                    { return (N_EQ); };
642
<INITIAL,acfp,vlog,vhdl,expr>"/"              { return ('/');  };
643
<INITIAL,acfp,vlog,expr>"%"                   { return ('%');  };
644
<INITIAL,acfp,vlog,expr>"?"                   { return ('?');  };
645
<INITIAL,acfp,vlog,expr>"<<"                  { return (SHL); };
646
<INITIAL,acfp,vlog,expr>">>"                  { return (SHR); };
647
<INITIAL,acfp,vlog,expr>"<"                   { return ('<'); };
648
<INITIAL,acfp,vlog,expr>">"                   { return ('>'); };
649
<INITIAL,acfp,vlog,expr>"^"                   { return ('^'); };
650
<INITIAL,acfp,vlog,expr>"~"                   { return ('~'); };
651
<INITIAL,acfp,vlog,expr>"&&"                  { return (LOG_AND); };
652
<INITIAL,acfp,vlog,expr>"&"                   { return ('&'); };
653
<INITIAL,acfp,vlog,expr>"||"                  { return (LOG_OR); };
654
<INITIAL,acfp,vlog,expr>"|"                   { return ('|'); };
655
 
656
 
657
<INITIAL,acfp,vlog,expr>"=="                  { return (EQ_EQ); };
658
<vhdl>"="                                     { return (EQ_EQ); };
659
<INITIAL,acfp,vlog,expr>"!="                  { return (N_EQ); };
660
<INITIAL,acfp,vhdl,expr>"**"                  { return (TO_POW);  };
661
<INITIAL,acfp,vlog,vhdl,expr>"*"              { return ('*');  };
662
<INITIAL,acfp,vlog,vhdl>","                   { return (',');  };
663
<vlog,acfp>"["                                { return ('['); };
664
<vlog,acfp>"]"                                { return (']'); };
665
 
666
 
667
<INITIAL,acfp,vlog,vhdl,expr>{Spc}    { break; };
668
 
669
<INITIAL,acfp,vlog,vhdl>"\n"              { lineno++; if(yydebug) printf("line %d\n",lineno); break; };
670
<INITIAL,acfp,vlog,vhdl>"\r"              { break; };
671
 
672
 
673
 
674
 
675
<acfp>[eE][xX][eE][cC]                   {  lex_exec_line();goto ignored_comment; /* commands to vertical */ };
676
 
677
 
678
<INITIAL>[aA][hH][dD][lL]                                   { BEGIN(acfp);prev_begin=acfp;
679
                                                                             Log(LOG_GENERAL,"Entering ACFP block\n");
680
                                                                             inside_block=1;
681
                                                                             return (AHDL); }  
682
<INITIAL>[cC][hH][iI][pP]                                   { BEGIN(acfp);prev_begin=acfp;
683
                                                                             inside_block=1;
684
                                                                             return (CHIP);  }
685
<INITIAL>[jJ][oO][iI][nN][eE][dD]_[nN][eE][tT][sS]          { BEGIN(acfp);prev_begin=acfp;
686
                                                                             inside_block=1;
687
                                                                             return (JOINED_NETS); } ;
688
<INITIAL>[cC][oO][mM][pP][oO][nN][eE][nN][tT][sS]           { BEGIN(acfp);prev_begin=acfp;
689
                                                                             inside_block=1;
690
                                                                             return (COMPONENTS); };
691
<INITIAL>[rR][eE][nN][aA][mM][eE]_[pP][iI][nN][sS]          { BEGIN(acfp);prev_begin=acfp;
692
                                                                             inside_block=1;
693
                                                                             return (RENAME_PINS); } ;
694
<INITIAL>[tT][eE][mM][pP][lL][aA][tT][eE]                   { BEGIN(acfp);prev_begin=acfp;
695
                                                                             inside_block=1;
696
                                                                             return (TEMPLATE); } ;
697
<INITIAL,acfp,vlog,vhdl>[vV][hH][dD][lL]                                   { BEGIN(vhdl);
698
                                                                             Log(LOG_GENERAL,"Entering VHDL block\n");
699
                                                                             inside_block=1;
700
                                                                             prev_begin=vhdl;
701
                                                                             return (VHDL); } ;
702
 
703
<INITIAL,acfp,vlog,vhdl>[vV][eE][rR][iI][lL][oO][gG]                      { BEGIN(vlog);
704
                                                                             Log(LOG_GENERAL,"Entering Verilog block\n");
705
                                                                             prev_begin=vlog;
706
                                                                             inside_block=1;
707
                                                                             return (VERILOG); } ;
708
 
709
<INITIAL,acfp,vlog,vhdl>[wW][iI][rR][eE][dD]_[nN][eE][tT][sS]              { BEGIN(acfp);prev_begin=acfp;
710
                                                                             inside_block=1;
711
                                                                             return (WIRED_NETS); };
712
<INITIAL,acfp,vlog,vhdl>[gG][eE][nN][eE][rR][iI][cC]                       { if (!inside_block) /* special */
713
                                                                             { inside_block=1;
714
                                                                               BEGIN(vhdl);prev_begin=vhdl; };
715
                                                                             return (GENERIC);};
716
<vhdl>[aA][lL][lL]                                           { return (ALL); } 
717
<vhdl>[aA][rR][cC][hH][iI][tT][eE][cC][tT][uU][rR][eE]       { return (ARCHITECTURE); } 
718
<acfp,vhdl>[aA][tT][tT][rR][iI][bB][uU][tT][eE]              { return (ATTRIBUTE); } 
719
<acfp>[aA][sS][sS][iI][gG][nN][eE][dD]                       { return (ASSIGNED); } 
720
<acfp,vhdl>[aA][lL][iI][aA][sS]                              { return (ALIAS); } 
721
<acfp>[aA][nN]                                               { return (AN); } 
722
<acfp,vlog,vhdl>[bB][eE][gG][iI][nN]                         { return (BEGIN_TOK); } 
723
<acfp>[bB][iI][dD][iI][rR]_[pP][iI][nN]                      { yylval.integer = BIDIR;  return(PINDIR); }
724
<acfp>[bB][iI][dD][iI][rR]                                   { yylval.integer = BIDIR;  return(PINDIR); }
725
<vhdl>[bB][oO][oO][lL][eE][aA][nN]                           { return(BOOLEAN); }
726
<vhdl>[iI][nN][oO][uU][tT]                                   { yylval.integer = BIDIR;  return(PINDIR); }
727
<vlog>[oO][uU][tT]                                           { yylval.integer = BIDIR;  return(PINDIR); }
728
<acfp>[bB][uU][fF][fF][eE][rR]_[pP][iI][nN]                  { yylval.integer = BUFFER; return(PINDIR);  }
729
<vhdl>[bB][uU][fF][fF][eE][rR]                               { yylval.integer = BUFFER; return(PINDIR);  }
730
<acfp>[cC][oO][nN][fF][iI][gG]_[pP][iI][nN]                  { yylval.integer = CONFIG; return(PINDIR); };
731
<vhdl>[cC][oO][mM][pP][oO][nN][eE][nN][tT]                   { return (COMPONENT); };
732
<vhdl>[cC][oO][nN][sS][tT][aA][nN][tT]                       { return (CONSTANT); };
733
<acfp>[cC][oO][nN][nN][eE][cC][tT][iI][oO][nN]               { return (CONN); };
734
<acfp>[vV][hH][dD][lL]_[cC][oO][nN][nN]                       { return (VHDL_CONN); };
735
<acfp>[dD][eE][cC][lL][aA][rR][aA][tT][iI][oO][nN]           { return (DECLARATION); };
736
<acfp>[dD][eE][vV][iI][cC][eE]                               { return (DEVICE); };
737
<vhdl,acfp,expr>[dD][oO][wW][nN][tT][oO]                          { return (DOWNTO);  };
738
<acfp,vlog,vhdl>[eE][nN][dD]                                 { return (END); /* do not free_strings here as it is too early !! */};
739
<acfp>[eE][nN][dD]_[cC][oO][nN][nN]                          { return (END_CONN); } ;
740
<vlog>endmodule                                              { return (ENDMODULE); };
741
<acfp,vhdl>[eE][nN][tT][iI][tT][yY]                          { return (ENTITY); };
742
<acfp>[eE][qQ][uU][iI][vV][aA][lL][eE][nN][tT]               { return (EQUIVALENT); };
743
<vhdl>[eE][nN][vV]_[sS][tT][rR][iI][nN][gG]                  { return (ENV_STRING); };
744
<vhdl,expr>[fF][aA][lL][sS][eE]                                   { return (FALSE); };
745
<acfp>[fF][iI][xX]_[lL][oO][cC][aA][tT][iI][oO][nN]          { return (FIX_LOCATION); }; 
746
<vhdl>[fF][oO][rR]                                           { return (FOR); };
747
<acfp>[gG][nN][dD]\*                                         { return (GND_RES_IO); };
748
<acfp>[gG][nN][dD]\+                                         { return (GND_RES_IN); };
749
<acfp>[gG][nN][dD]{L2}*                                      { yylval.string = make_string(yytext,&lx_first,&lx_last);
750
                                                               if(yydebug) fprintf(stderr,"String (GND) ='%s'\n",yytext); 
751
                                                               return (GND); };
752
<acfp>[iI][nN][pP][uU][tT]_[pP][iI][nN]                      { yylval.integer = INPUT;  return(PINDIR); };
753
<vhdl>[iI][nN]                                               { yylval.integer = INPUT;  return(PINDIR); };
754
<vlog,acfp>[iI][nN][pP][uU][tT]                                   { yylval.integer = INPUT;  return(PINDIR); };
755
<vlog>[iI][nN][oO][uU][tT]                                   { yylval.integer = BIDIR;  return(PINDIR); }
756
<acfp>[iI][nN][sS][tT][aA][nN][cC][eE]                       { return (INSTANCE); };
757
<acfp,vhdl>[iI][nN][tT][eE][gG][eE][rR]                      { return (INTEGER); };
758
<acfp,vhdl>[iI][sS]                                          { return (IS);  };
759
<acfp>[jJ][uU][mM][pP][eE][rR]                               { return (JUMPER); } ;
760
<vhdl>[lL][iI][bB][rR][aA][rR][yY]                           { return (LIBRARY); } ;
761
<acfp>[lL][oO][cC][aA][tT][iI][oO][nN]                       { return (LOCATION); } ;
762
<vhdl>[mM][aA][pP]                                           { return (MAP); };
763
<vlog>module                                                 { return (MODULE); };
764
<acfp>[nN][oO][nN][eE]                                       { yylval.integer = NONE;   return(PINDIR); };
765
<acfp>[nN][aA][mM][eE][dD]                                   { return (NAMED); } ;
766
<vhdl>[oO][fF]                                               { return (OF); };
767
<acfp>[oO][uU][tT][pP][uU][tT]_[pP][iI][nN]                  { yylval.integer = OUTPUT; return(PINDIR); };
768
<vlog,acfp>[oO][uU][tT][pP][uU][tT]                               { yylval.integer = OUTPUT; return(PINDIR); };
769
<vhdl>[oO][uU][tT]                                           { yylval.integer = OUTPUT; return(PINDIR); };
770
<vhdl>[oO][pP][eE][nN]                                       { return (OPEN); };
771
<vhdl>[pP][aA][cC][kK][aA][gG][eE]                           { return (PACKAGE); }; 
772
<vhdl>[pP][oO][rR][tT]                                       { return (PORT); };
773
<acfp>[pP][oO][wW][eE][rR]_[pP][iI][nN]                      { yylval.integer = POWER; return(PINDIR); };
774
<acfp,vlog,vhdl>[rR][aA][nN][gG][eE]                         { return (RANGE); };
775
<acfp>[rR][oO][uU][tT][eE]_[fF][lL][aA][gG][sS]              { return (ROUTE_FLAGS); };
776
<acfp>[rR][oO][uU][tT][eE][dD]                               { return (ROUTED); } ;
777
<vhdl>[sS][hH][lL]                                           { return (SHL); };
778
<vhdl>[sS][hH][rR]                                           { return (SHR); };
779
<vhdl>[sS][iI][gG][nN][aA][lL]                               { return (SIGNAL); };
780
<vhdl>[sS][tT][rR][iI][nN][gG]                               { return (STRING); };
781
<vlog>[sS][uU][bB][dD][eE][sS][iI][gG][nN]                   { return (SUBDESIGN); };
782
<acfp,vhdl,expr>[tT][oO]                                          { return (TO);  };
783
<vhdl,expr>[tT][rR][uU][eE]                                       { return (TRUE); };
784
<acfp>[uU][nN][rR][oO][uU][tT][eE][dD]                       { return (UNROUTED); } ;
785
<acfp>[vV][cC][cC]{L2}*                                      { yylval.string = make_string(yytext,&lx_first,&lx_last);
786
                                                               if(yydebug) fprintf(stderr,"String (VCC) ='%s'\n",yytext); 
787
                                                               return (VCC);  };
788
<vhdl>[uU][sS][eE]                                           { return (USE);  };
789
<vlog>wire                                                   { return (WIRE); };       
790
 
791
<INITIAL,acfp,expr>{D}{L2D}*   { yylval.string = make_string(yytext,&lx_first,&lx_last); /* do it anyway */
792
                           if(yydebug) fprintf(stderr,"String (num) ='%s'\n",yytext); 
793
                           return(NUM_STRING); };
794
 
795
<vlog,vhdl,expr>{D}{L2V}*     { yylval.string = make_string(yytext,&lx_first,&lx_last); /* do it anyway */
796
                     if(yydebug) fprintf(stderr,"String (num) ='%s'\n",yytext); 
797
                      return(NUM_STRING); };
798
 
799
<INITIAL,acfp,expr>{L}{L2A}*     { yylval.string = make_string(yytext,&lx_first,&lx_last); /* do it anyway */
800
                     if(yydebug) fprintf(stderr,"String (num) ='%s'\n",yytext); 
801
                      return(TXT_STRING); };
802
 
803
<vlog,vhdl,expr>{L}{L2V}*            {  yylval.string = make_string(yytext,&lx_first,&lx_last); /* do it anyway */
804
                     if(yydebug) fprintf(stderr,"String (txt) ='%s'\n",yytext); 
805
                      return(isdigit(yylval.string[0])?NUM_STRING : TXT_STRING); };
806
 
807
<vlog>"/"{L2D}+   { yylval.string = make_string(yytext,&lx_first,&lx_last); /* do it anyway */
808
                     if(yydebug) fprintf(stderr,"String (num) ='%s'\n",yytext); 
809
                      return(TXT_STRING); };
810
 
811
 
812
<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; };
813
 
814
 
815
%%
816
 
817
 
818
/* terminate an ACFP and VHDL comment */
819
void skip_to_eol(void) {
820
  int c;
821
  for(;;) {
822
    c=input();
823
    if (c=='\n' || c==EOF) {
824
      lineno++;
825
      return;
826
      }
827
    }/* VHDL comment */ 
828
  }
829
 
830
 
831
 
832
 
833
/* execute a command line command  */
834
  char stringbuff[MAXIDLEN];
835
void lex_exec_line(void) {
836
  int c,i;
837
  for(i=0;i<MAXIDLEN-2;) {
838
    c=input();
839
    stringbuff[i++] = c;
840
    if (c=='\n' || c==EOF) {
841
      lineno++;
842
      stringbuff[i]=0;
843
      ExecuteString (stringbuff ,yy_nArgs, yy_Args);
844
      return;
845
      }
846
    }
847
   stringbuff[i] = 0;
848
   ExecuteString (stringbuff ,yy_nArgs,yy_Args);
849
  }
850
 
851
 
852
 
853
 
854
/* supporting functions need to be in sane file so LEX macros work */
855
void skip_c_comment(void) {
856
  int c;
857
  for(;;) { 
858
    while(((c = input()) !=EOF) && (c != '*')) {
859
      if(c=='\n') 
860
        lineno++;
861
      }
862
    if (c=='*') {
863
      while((c = input()) == '*')    putchar(c); 
864
      if(c=='\n') 
865
        lineno++;
866
      if (c=='/')
867
        break;
868
      }
869
    if(c==EOF) {
870
      Log(LOG_GENERAL,"End of file in comment\n");
871
      break;
872
      }
873
    }
874
  }
875
 
876
void exit_lex_block(void) {
877
  inside_block = 0;
878
  prev_begin=INITIAL;
879
  BEGIN(INITIAL);
880
  }
881
 
882
void tidy_lex(void) 
883
  {
884
  errorseen = 0;
885
  include_stack_ptr = 0;
886
  exit_lex_block();
887
  start_grammar = FILEMODE;
888
  }
889
 
890
 
891
 
892
 
893
int yyerror(char * x)
894
  {
895
 
896
  if (!errorseen) {
897
    if(include_stack_ptr==0)
898
      { 
899
      Log(LOG_ERROR,"--  Error in %s syntax\n--  -->%s near string (%s) at line %d\n",
900
              yyerr_start_names[YY_START],x,yytext,lineno);
901
      }
902
    else
903
      {
904
      Log(LOG_ERROR,"--  File %s: Error in %s syntax\n--  -->%s near string (%s) at line %d\n",
905
             filename[include_stack_ptr],yyerr_start_names[YY_START],x,yytext,lineno);
906
      }
907
    }
908
  errorseen = 1;
909
  include_stack_ptr = 0;
910
  exit_lex_block();
911
  YY_FLUSH_BUFFER;
912
  yyterminate();
913
  return 1;
914
  }
915
 
916
 
917
 
918
/********************************************************/
919
/* Reading generic expressions from a string            */
920
/********************************************************/
921
 
922
static char * myinputptr;
923
static char * myinputlim;
924
/* this is exported */
925
expression_t * cmd_expression;
926
 
927
 
928
int my_yyinput(char * buf, int max_size)
929
  {
930
  int n;
931
  n =(max_size < (myinputlim-myinputptr))? max_size :myinputlim-myinputptr;
932
  if(n>0)
933
    {
934
    memcpy(buf,myinputptr,n);
935
    myinputptr+=n;
936
    }
937
  return n;
938
  }
939
 
940
 
941
/* this function requires a large number of declarations from 
942
  lex. */
943
 
944
 
945
 
946
expression_t * compile_expression_from_string(char * s)
947
  {
948
  int prev_expr_begin;
949
  myinputptr = s;
950
  myinputlim = s+strlen(s);
951
  prev_expr_begin = YY_START;
952
 
953
  BEGIN(expr);
954
 
955
  start_grammar = CMDMODE;
956
  lex_from_string = 1;  
957
  yyparse();
958
 
959
  lex_from_string = 0;
960
  BEGIN(prev_expr_begin);
961
 
962
  return cmd_expression;
963
  }