OpenCores
URL https://opencores.org/ocsvn/sc2v/sc2v/trunk

Subversion Repositories sc2v

[/] [sc2v/] [trunk/] [src/] [sc2v_step1.y] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jcastillo
/* -----------------------------------------------------------------------------
2
 *
3 4 jcastillo
 *  SystemC to Verilog Translator v0.2
4 2 jcastillo
 *  Provided by OpenSoc Design
5
 *
6
 *  www.opensocdesign.com
7
 *
8
 * -----------------------------------------------------------------------------
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Library General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
 */
23
 
24
 
25
%{
26
#include 
27
#include 
28
 
29
#include "list.h"
30
 
31
/* Global var to store Regs */
32
RegsList *regslist;
33
/* Global var to store Defines */
34
DefinesList *defineslist;
35
 
36
 
37
int processfound = 0;
38
int switchfound = 0;
39
int switchparenthesis = 0;
40
char *processname, *processname2;
41
char *fileregs;
42
char *filename ;
43
int openedkeys = 0;
44
int newline = 0;
45
int reg_found = 0;
46
int regs_end;
47
int i = 0; //for loops counter
48
FILE *file;
49
FILE *regs_file;
50
char *regname, *regname2;
51
char *lastword; // Stores last WORD for use it in WRITE
52
char *file_defines;
53
FILE *FILE_DEFINES;
54
char *file_writes;
55
FILE *FILE_WRITES; //FILE to store .write to know if it is a wire or reg
56
int definefound = 0;
57
int defineinvocationfound = 0;
58
int opencorchfound = 0;
59
 
60
int openedcase = 0;
61
 
62
int default_break_found = 0;
63
int default_found;
64
 
65 4 jcastillo
//Directives variables
66
int translate;
67
int verilog;
68
int writemethod;
69
 
70 2 jcastillo
void yyerror(const char *str)
71
{
72
        fprintf(stderr,"error: %s\n",str);
73
}
74
 
75
int yywrap()
76
{
77
        return 1;
78
}
79
 
80
main()
81
{
82
        regslist = (RegsList *)malloc(sizeof(RegsList));
83
        InitializeRegsList(regslist);
84
        defineslist = (DefinesList *)malloc(sizeof(DefinesList));
85
        InitializeDefinesList(defineslist);
86
 
87
        processname = (char *)malloc(256*sizeof(int));
88
        processname2 = (char *)malloc(256*sizeof(int));
89
        fileregs = (char *)malloc(256*sizeof(int));
90
 
91
        file_defines = (char *)malloc(256*sizeof(int));
92
        strcpy(file_defines, (char *)"file_defines.sc2v");
93
        FILE_DEFINES = fopen(file_defines,(char *)"w");
94
 
95
        file_writes = (char *)malloc(256*sizeof(int));
96
        strcpy(file_writes, (char *)"file_writes.sc2v");
97
        FILE_WRITES = fopen(file_writes,(char *)"w");
98
 
99 10 jcastillo
        if(FILE_WRITES!=NULL)
100
          printf("\nopening file => filename = %s\n",file_writes);
101
 
102
        lastword=malloc(sizeof(char)*256);
103
 
104
        translate=1;
105 4 jcastillo
        verilog=0;
106
        writemethod=0;
107
 
108 2 jcastillo
        yyparse();
109
        fclose(FILE_WRITES);
110
        fclose(FILE_DEFINES);
111
}
112
 
113
%}
114
 
115 4 jcastillo
%token NUMBER WORD SC_INT SC_UINT BOOL BIGGER LOWER OPENKEY CLOSEKEY WRITE WORD SYMBOL NEWLINE ENUM INCLUDE
116
%token COLON SEMICOLON RANGE OPENPAR CLOSEPAR TWODOUBLEPOINTS OPENCORCH CLOSECORCH SWITCH CASE DEFAULT BREAK
117
%token SC_BIGINT SC_BIGUINT HEXA DEFINE READ TRANSLATEOFF TRANSLATEON VERILOGBEGIN VERILOGEND TAB DOLLAR INTCONV
118 6 jcastillo
%token VOID TTRUE TFALSE
119 4 jcastillo
%token PIFDEF PENDDEF PELSE
120 2 jcastillo
 
121
%%
122
 
123
commands: /* empty */
124
        | commands command
125
        ;
126
 
127
 
128
command:
129 4 jcastillo
    voidword
130
        |
131
    include
132
        |
133
    dollar
134
        |
135
        intconv
136
        |
137
        tab
138
        |
139 2 jcastillo
        read
140
        |
141
        sc_int
142
        |
143
        sc_uint
144
        |
145
        sc_bigint
146
        |
147
        sc_biguint
148
        |
149
        number
150
        |
151
        bool
152
        |
153
        word
154
        |
155
        symbol
156
        |
157
        write
158
        |
159
        newline
160
        |
161
        openkey
162
        |
163
        closekey
164
        |
165
        colon
166
        |
167
        semicolon
168
        |
169
        range
170
        |
171
        openpar
172
        |
173
        closepar
174
        |
175
        void
176
        |
177
        opencorch
178
        |
179
        closecorch
180
        |
181 4 jcastillo
        bigger
182 2 jcastillo
        |
183 4 jcastillo
        lower
184 2 jcastillo
        |
185
        switch
186
        |
187 4 jcastillo
        case_only
188 2 jcastillo
        |
189 4 jcastillo
    case_number
190
        |
191
        case_word
192
        |
193 2 jcastillo
        case_default
194
        |
195
        break
196
        |
197
        hexa
198
        |
199
        define
200 4 jcastillo
        |
201
        translateoff
202
        |
203
        translateon
204
        |
205
        verilogbegin
206
        |
207
        verilogend
208
        |
209
        ifdef
210
        |
211
        endif
212
        |
213 6 jcastillo
        pelse
214
        |
215
        ttrue
216
        |
217
        tfalse
218 2 jcastillo
        ;
219
 
220 4 jcastillo
 
221
 
222
voidword:
223
    VOID
224
        {
225
        if(verilog==1)
226
          fprintf(file," void");
227
        };
228
 
229
 
230
include:
231
    INCLUDE
232
        {
233
        if(verilog==1)
234
          fprintf(file," #include");
235
        };
236
 
237
 
238
dollar:
239
    DOLLAR
240
        {
241
        if(verilog==1)
242
          fprintf(file," $");
243
        };
244
 
245
intconv:
246
    INTCONV
247
        {
248
        if(verilog==1)
249
          fprintf(file," (int)");
250
        };
251
 
252
tab:
253
    TAB
254
        {
255
        if(verilog==1)
256
          fprintf(file," \t");
257
        };
258
 
259 2 jcastillo
read:
260
        READ OPENPAR CLOSEPAR
261
                {
262 4 jcastillo
                if(verilog==1)
263
                  fprintf(file,".read()");
264 2 jcastillo
 
265
                }
266 4 jcastillo
 
267 2 jcastillo
define:
268
        DEFINE WORD OPENPAR CLOSEPAR
269
                {
270 4 jcastillo
                  if(translate==1 && verilog==0){
271 2 jcastillo
                        InsertDefine(defineslist, (char *)$2);
272
                        definefound = 1;
273
                        fprintf(FILE_DEFINES,"`define %s ",(char *)$2);
274 4 jcastillo
                  }else if(verilog==1)
275
                    fprintf(file,"#define %s ()",(char *)$2);
276 2 jcastillo
                }
277
void:
278 4 jcastillo
        WORD TWODOUBLEPOINTS WORD OPENPAR CLOSEPAR
279 2 jcastillo
                {
280 4 jcastillo
                if(translate==1&& verilog==0){
281 2 jcastillo
                        strcpy(processname ,(char *)$4);
282
                        strcpy(processname2 ,(char *)$4);
283
                        strcat(processname2, (char *)".sc2v");
284
                        strcpy(fileregs ,(char *)$4);
285
                        strcat(fileregs, (char *)"_regs.sc2v");
286
                        /*
287
                        strcpy(file_writes, (char *)$4);
288
                        strcat(file_writes, (char *)"_writes.sc2v");
289
                        */
290 4 jcastillo
                }else if(verilog==1)
291
                  fprintf(file," %s::%s()",(char *)$1,(char *)$3);
292
 
293 2 jcastillo
                }
294
sc_int:
295 4 jcastillo
        SC_INT LOWER NUMBER BIGGER
296
                {
297
        if(translate==1&& verilog==0){
298 2 jcastillo
                        if(processfound)
299
                        {
300
                                fprintf(regs_file,"reg[%d:0] ",(-1 + $3));
301
                                reg_found = 1;
302
                        }
303 4 jcastillo
                }else if(verilog==1)
304
                  fprintf(file,"sc_int<%d>",$3);
305
 
306 2 jcastillo
                }
307
                ;
308
 
309
sc_uint:
310 4 jcastillo
        SC_UINT LOWER NUMBER BIGGER
311 2 jcastillo
                {
312 4 jcastillo
                if(translate==1&& verilog==0){
313 2 jcastillo
                        if(processfound)
314
                        {
315
                                fprintf(regs_file,"reg[%d:0] ",(-1 + $3));
316
                                reg_found = 1;
317
                        }
318 4 jcastillo
                }else if(verilog==1)
319
                  fprintf(file,"sc_uint<%d>",$3);
320 2 jcastillo
                }
321
                ;
322
 
323
sc_bigint:
324 4 jcastillo
        SC_BIGINT LOWER NUMBER BIGGER
325 2 jcastillo
                {
326 4 jcastillo
                if(translate==1&& verilog==0){
327 2 jcastillo
                        if(processfound)
328
                        {
329
                                fprintf(regs_file,"reg[%d:0] ",(-1 + $3));
330
                                reg_found = 1;
331
                        }
332 4 jcastillo
                }else if(verilog==1)
333
                 fprintf(file,"sc_bigint<%d> ",$3);
334 2 jcastillo
                }
335
                ;
336
 
337
sc_biguint:
338 4 jcastillo
        SC_BIGUINT LOWER NUMBER BIGGER
339 2 jcastillo
                {
340 4 jcastillo
                if(translate==1&& verilog==0){
341 2 jcastillo
                        if(processfound)
342
                        {
343
                                fprintf(regs_file,"reg[%d:0] ",(-1 + $3));
344
                                reg_found = 1;
345
                        }
346 4 jcastillo
                }else if(verilog==1)
347
                  fprintf(file,"sc_biguint<%d> ",$3);
348 2 jcastillo
                }
349
                ;
350
 
351
bool:
352
                BOOL
353
                        {
354 4 jcastillo
                    if(translate==1&& verilog==0){
355 2 jcastillo
                                if(processfound)
356
                                {
357
                                        fprintf(regs_file,"reg ");
358
                                        reg_found = 1;
359
                                }
360 4 jcastillo
                        }else if(verilog==1)
361
                       fprintf(file,"bool");
362 2 jcastillo
                        }
363
                        ;
364
 
365
range:
366
                RANGE OPENPAR NUMBER COLON NUMBER CLOSEPAR
367
                        {
368 4 jcastillo
                    if(translate==1&& verilog==0){
369 2 jcastillo
                                if(processfound)
370
                                        fprintf(file,"[%d:%d]",$3,$5);
371
                                else if(definefound)
372
                                        fprintf(FILE_DEFINES,"[%d:%d]",$3,$5);
373 4 jcastillo
                        }else if(verilog==1)
374
                      fprintf(file,".range(%d,%d)",$3,$5);
375 2 jcastillo
                        }
376
                        ;
377
 
378
number:
379
                NUMBER
380
                        {
381 4 jcastillo
                        if(translate==1&& verilog==0){
382 2 jcastillo
                                if(processfound)
383
                                        if(reg_found)
384
                                        {
385
                                            if(opencorchfound)
386
                                                fprintf(regs_file,"%d:0", -1 + $1);
387
                                            else
388
                                                fprintf(regs_file,"%d",$1);
389
                                        }
390
                                        else
391
                                                fprintf(file,"%d",$1);
392
                                else if(definefound)
393
                                        fprintf(FILE_DEFINES,"%d",$1);
394 4 jcastillo
                        }else if(verilog==1)
395
                       fprintf(file,"%d",$1);
396 2 jcastillo
                        }
397
                        ;
398
word:
399
                WORD
400
                        {
401 4 jcastillo
                    if(translate==1&& verilog==0){
402 2 jcastillo
                          if(processfound)
403
                          {
404
                             if(openedcase)
405
                             {
406
                                fprintf(file," :\n");
407 4 jcastillo
 
408
                                    for(i = 0; i < openedkeys; i++)
409
                                            fprintf(file,"   ");
410
 
411
                                    fprintf(file,"begin\n");
412
                                    openedcase = 0;
413 2 jcastillo
                             }
414 10 jcastillo
 
415
                             strcpy(lastword, (char *)$1);
416 2 jcastillo
 
417
                             if(reg_found)
418
                             {
419 10 jcastillo
 
420
                              regname=malloc(sizeof(char)*(strlen((char *)$1)+1));
421
                              regname2=malloc(sizeof(char)*(strlen((char *)$1)+strlen(processname))+1);
422
 
423 2 jcastillo
                              strcpy(regname ,(char *)$1);
424 10 jcastillo
                              strcpy(regname2 ,(char *)$1);
425 2 jcastillo
                              strcat(regname2, processname);
426
                              fprintf(regs_file,"%s",regname2);
427
                              InsertReg(regslist, regname, regname2);
428 10 jcastillo
                              free(regname);
429
                              free(regname2);
430 2 jcastillo
                             }
431
                             else
432
                             {
433 4 jcastillo
                               if(newline)
434
                                   {
435
                                   for(i = 0; i < openedkeys; i++)
436
                                         fprintf(file,"   ");
437
                                   }
438
                                   regname2 = IsReg(regslist, (char *)$1);
439
                                   if(regname2 == NULL)
440
                                   {
441
                                         if(IsDefine(defineslist, (char *)$1))
442
                                         {
443
                                           fprintf(file,"`%s", (char *)$1);
444
                                           defineinvocationfound = 1;
445
                                         }
446
                                         else
447
                                         {
448 6 jcastillo
                                           fprintf(file,"%s ",(char *)$1);
449 4 jcastillo
                                         }
450
                                   }
451
                                   else
452
                                         fprintf(file,"%s",regname2);
453
 
454
                                   newline = 0;
455 2 jcastillo
                             }
456 10 jcastillo
 
457 2 jcastillo
                          }
458
                          else if(definefound)
459
                          {
460
                                if(IsDefine(defineslist, (char *)$1))
461
                                {
462 4 jcastillo
                                        fprintf(FILE_DEFINES,"`%s",(char *)$1);
463 2 jcastillo
                                }
464
                                else
465
                                {
466
                                        fprintf(FILE_DEFINES,"%s ",(char *)$1);
467
                                }
468
                          }
469 4 jcastillo
                        }else if(verilog==1)
470
                       fprintf(file," %s",(char *)$1);
471
                    };
472 2 jcastillo
 
473
symbol:
474
                SYMBOL
475
                        {
476 4 jcastillo
                        if(translate==1&& verilog==0){
477 2 jcastillo
                                if(processfound)
478
                                {
479
                                   if(reg_found)
480
                                        fprintf(regs_file,"%s",(char *)$1);
481
                                   else
482
                                        fprintf(file,"%s",(char *)$1);
483
                                }
484
                                else if(definefound)
485
                                {
486
                                   fprintf(FILE_DEFINES,"%s",(char *)$1);
487
                                }
488 4 jcastillo
                        }else if(verilog==1)
489
                       fprintf(file,"%s",(char *)$1);
490
                        };
491 2 jcastillo
 
492
 
493
write:
494
                WRITE
495
                        {
496 4 jcastillo
                        if(translate==1&& verilog==0){
497 10 jcastillo
                                writemethod=1;
498 2 jcastillo
                                if(processfound)
499
                                {
500
                                        fprintf(file," = ");
501
                                        fprintf(FILE_WRITES, "%s\n", lastword);
502
                                }
503
                                else if(definefound)
504
                                {
505
                                        fprintf(FILE_DEFINES," = ");
506
                                }
507 4 jcastillo
 
508
                        }else if(verilog==1){
509
                            fprintf(file,".write");
510
                         }
511
                        };
512 2 jcastillo
 
513
newline:
514
                NEWLINE
515
                        {
516 4 jcastillo
                    if(translate==1&& verilog==0){
517 2 jcastillo
                                if(processfound & !reg_found & !openedcase)
518
                                {
519
                                        fprintf(file,"\n");
520
                                        newline = 1;
521
                                }
522
                                else if(definefound)
523
                                {
524
                                        fprintf(FILE_DEFINES,"\n");
525
                                }
526 4 jcastillo
 
527
                        }else if(verilog==1)
528
                       fprintf(file,"\n");
529
                        };
530 2 jcastillo
 
531
colon:
532 4 jcastillo
                COLON
533 2 jcastillo
                        {
534 4 jcastillo
                        if(translate==1&& verilog==0){
535 2 jcastillo
                                if(processfound)
536
                                {
537
                                  if(reg_found)
538
                                  {
539
                                        fprintf(regs_file,",");
540
                                  }
541
                                  else
542
                                        fprintf(file,",");
543
                                }
544
                                else if(definefound)
545
                                {
546
                                        fprintf(FILE_DEFINES,",");
547
                                }
548 4 jcastillo
                        }else if(verilog==1)
549
                       fprintf(file,",");
550
                        };
551 2 jcastillo
 
552
semicolon:
553
                SEMICOLON
554
                        {
555 4 jcastillo
                    if(translate==1&& verilog==0){
556 2 jcastillo
                                if(processfound)
557
                                {
558
                                  if(reg_found)
559
                                  {
560
                                        fprintf(regs_file,";\n");
561
                                        reg_found = 0;
562
                                  }
563
                                  else if(defineinvocationfound)
564
                                  {
565
                                        defineinvocationfound = 0;
566
                                  }
567
                                  else
568
                                  {
569
                                        fprintf(file,";");
570
                                  }
571
                                }
572
                                else if(definefound)
573
                                {
574
                                        fprintf(FILE_DEFINES,";");
575
                                }
576 4 jcastillo
                        }else if(verilog==1)
577
                       fprintf(file,";");
578
                        };
579 2 jcastillo
 
580
openpar:
581 4 jcastillo
                OPENPAR
582 2 jcastillo
                        {
583 4 jcastillo
            if(translate==1 && verilog==0){
584 2 jcastillo
                                if(processfound)
585
                                {
586
                                        fprintf(file,"(");
587
                                }
588
                                else if(definefound)
589
                                {
590
                                        fprintf(FILE_DEFINES,"(");
591
                                }
592 4 jcastillo
                        }else if(verilog==1)
593
                       fprintf(file,"(");
594
                        };
595 2 jcastillo
 
596
closepar:
597
                CLOSEPAR
598
                        {
599 4 jcastillo
                    if(translate==1&& verilog==0){
600 2 jcastillo
                                if(processfound)
601
                                {
602
                                        fprintf(file,")");
603
                                }
604
                                else if(definefound)
605
                                {
606
                                        fprintf(FILE_DEFINES,")");
607
                                }
608 4 jcastillo
                        }else if(verilog==1)
609
                       fprintf(file,")");
610
                        };
611 2 jcastillo
 
612
opencorch:
613
                OPENCORCH
614
                        {
615 4 jcastillo
                        if(translate==1&& verilog==0){
616 2 jcastillo
                                if(processfound)
617
                                {
618
                                  if(reg_found)
619
                                  {
620
                                        fprintf(regs_file,"[");
621
                                        opencorchfound = 1;
622
                                  }
623
                                  else
624
                                        fprintf(file,"[");
625
                                }
626
                                else if(definefound)
627
                                {
628
                                        fprintf(FILE_DEFINES,"[");
629
 
630
                                }
631 4 jcastillo
                        }else if(verilog==1)
632
                       fprintf(file,"[");
633
                        };
634 2 jcastillo
 
635
closecorch:
636
                CLOSECORCH
637
                        {
638 4 jcastillo
                    if(translate==1&& verilog==0){
639 2 jcastillo
                                if(processfound)
640
                                {
641
                                  if(reg_found)
642
                                  {
643
                                        fprintf(regs_file,"]");
644
                                        opencorchfound = 0;
645
                                  }
646
                                  else
647
                                        fprintf(file,"]");
648
                                }
649
                                else if(definefound)
650
                                {
651
                                        fprintf(FILE_DEFINES,"]");
652
                                }
653 4 jcastillo
                        }else if(verilog==1)
654
                       fprintf(file,"]");
655
                        };
656 2 jcastillo
 
657
 
658
openkey:
659
                OPENKEY
660
                        {
661 4 jcastillo
                    if(translate==1 && verilog==0){
662 2 jcastillo
                                openedkeys++;
663
                                if(openedkeys==1 & !definefound)
664
                                {
665
                                        printf("opening file => filename = %s\n",processname2);
666
                                        file = fopen(processname2,(char *)"w");
667
                                        printf("opening file => filename = %s\n",fileregs);
668
                                        regs_file = fopen(fileregs,(char *)"w");
669
                                        processfound = 1;
670
                                        regslist = (RegsList *)malloc(sizeof(RegsList));
671
                                        InitializeRegsList(regslist);
672 10 jcastillo
                        /*              regname = (char *)malloc(256*sizeof(int));
673
                                        regname2 = (char *)malloc(256*sizeof(int));*/
674 2 jcastillo
                                }
675
                                if(processfound)
676
                                        if(openedkeys != switchparenthesis)
677
                                        {
678 6 jcastillo
                                            fprintf(file,"\n");
679 2 jcastillo
                                                for(i = 0; i < openedkeys; i++)
680
                                                        fprintf(file,"   ");
681
                                                fprintf(file,"begin\n");
682
                                                newline = 1;
683
                                        }
684 4 jcastillo
 
685
                        }else if(verilog==1)
686
                       fprintf(file,"{");
687 2 jcastillo
                        }
688
                        ;
689
 
690
closekey:
691
                CLOSEKEY
692
                        {
693 4 jcastillo
            if(translate==1&& verilog==0){
694 2 jcastillo
                                if(processfound)
695
                                {
696
                                        if(openedkeys==switchparenthesis & switchfound == 1)
697
                                        {
698
                                                fprintf(file,"\n");
699
                                                if(default_found & !default_break_found)
700
                                                {
701
                                                for(i = 0; i < openedkeys; i++)
702
                                                        fprintf(file,"   ");
703
                                                fprintf(file,"end\n");
704
                                                default_found = 0;
705
                                                }
706
                                                for(i = 0; i < openedkeys; i++)
707
                                                        fprintf(file,"   ");
708
                                                fprintf(file,"endcase\n");
709
                                                newline = 1;
710
                                                switchfound = 0;
711
                                                switchparenthesis = 0;
712
                                        }
713
                                        else
714
                                        {
715
                                                fprintf(file,"\n");
716
                                                for(i = 0; i < openedkeys; i++)
717
                                                        fprintf(file,"   ");
718
                                                fprintf(file,"end\n");
719
                                                newline = 1;
720
                                        }
721
                                }
722
 
723
                                openedkeys--;
724
                                if(definefound)
725
                                {
726
                                        definefound = 0;
727
                                        fprintf(FILE_DEFINES,"\n//Dummy Comment\n");
728
                                }
729
                                else if(openedkeys==0)
730
                                {
731
                                        fclose(file);
732
                                        fclose(regs_file);
733
                                        free(regslist);
734 10 jcastillo
/*                                      free(regname);
735
                                        free(regname2);*/
736 2 jcastillo
                                        processfound = 0;
737
                                }
738 4 jcastillo
                        }else if(verilog==1)
739
                       fprintf(file,"}");
740
                        };
741 2 jcastillo
 
742
 
743 4 jcastillo
bigger:
744
                BIGGER
745 2 jcastillo
                        {
746 4 jcastillo
            if(translate==1&& verilog==0){
747 2 jcastillo
                                if(processfound)
748
                                {
749
                                        fprintf(file,">");
750
                                }
751
                                else if(definefound)
752
                                {
753
                                        fprintf(FILE_DEFINES,">");
754
                                }
755 4 jcastillo
                        }else if(verilog==1)
756
                       fprintf(file,">");
757
                        };
758 2 jcastillo
 
759 4 jcastillo
lower:
760
                LOWER
761 2 jcastillo
                        {
762 4 jcastillo
                        if(translate==1&& verilog==0){
763 2 jcastillo
                                if(processfound)
764
                                {
765
                                        fprintf(file,"<");
766
                                }
767
                                else if(definefound)
768
                                {
769
                                        fprintf(FILE_DEFINES,"<");
770
                                }
771 4 jcastillo
                        }else if(verilog==1)
772
                       fprintf(file,"<");
773
                        };
774 2 jcastillo
 
775
 
776
switch:
777
                SWITCH
778
                        {
779 4 jcastillo
                        if(translate==1&& verilog==0){
780
                          if(processfound)
781 2 jcastillo
                                {
782
                                        fprintf(file,"\n");
783
                                        for(i = 0; i < openedkeys; i++)
784
                                                fprintf(file,"   ");
785
                                        fprintf(file,"case");
786
                                        switchfound = 1;
787
                                        switchparenthesis = openedkeys + 1;
788
                                }
789 4 jcastillo
                        }else if(verilog==1)
790
                       fprintf(file,"switch");
791 2 jcastillo
                        };
792 4 jcastillo
 
793 2 jcastillo
case_number:
794
                CASE NUMBER SYMBOL
795
                        {
796 4 jcastillo
                        if(translate==1&& verilog==0){
797
                          if(processfound)
798 2 jcastillo
                          {
799
                                for(i = 0; i < openedkeys; i++)
800
                                        fprintf(file,"   ");
801
                                if(openedcase)
802
                                        fprintf(file,", %d",$2);
803
                                else
804
                                        fprintf(file,"%d",$2);
805 4 jcastillo
 
806 2 jcastillo
                                newline = 1;
807
                                openedcase = 1;
808
 
809
                          }
810 4 jcastillo
                        }else if(verilog==1)
811
                       fprintf(file,"case %d %s",$2,(char *)$3);
812 2 jcastillo
                        };
813 4 jcastillo
case_word:
814
                CASE WORD SYMBOL
815
                        {
816
                        if(translate==1&& verilog==0){
817
                          if(processfound)
818
                          {
819
                                for(i = 0; i < openedkeys; i++)
820
                                        fprintf(file,"   ");
821
                                if(openedcase)
822
                                        fprintf(file,", %s",(char *)$2);
823
                                else
824
                                        fprintf(file,"%s",(char *)$2);
825
 
826
                                newline = 1;
827
                                openedcase = 1;
828
 
829
                          }
830
                        }else if(verilog==1)
831
                       fprintf(file,"case %s %s",(char *)$2,(char *)$3);
832
                        };
833 2 jcastillo
 
834
case_default:
835
                DEFAULT SYMBOL
836
                        {
837 4 jcastillo
                        if(translate==1&& verilog==0){
838
                          if(processfound)
839 2 jcastillo
                          {
840
                                for(i = 0; i < openedkeys; i++)
841
                                        fprintf(file,"   ");
842
                                fprintf(file,"default:\n");
843
                                for(i = 0; i < openedkeys; i++)
844
                                        fprintf(file,"   ");
845
                                fprintf(file,"begin\n");
846
                                newline = 1;
847
                                default_found = 1;
848
                          }
849 4 jcastillo
                        }else if(verilog==1)
850
                       fprintf(file,"default %s",(char *)$2);
851 2 jcastillo
                        };
852
 
853 4 jcastillo
case_only:
854
        CASE OPENPAR
855
                {
856
                //This rule occurs when in Verilog mode a case appears
857
                if(verilog==1)
858
                  fprintf(file,"case(");
859
        };
860
 
861 2 jcastillo
break:
862
                BREAK SEMICOLON
863
                        {
864 4 jcastillo
                        if(translate==1&& verilog==0){
865 2 jcastillo
                         if(processfound)
866
                         {
867
                                if(newline == 0)
868
                                        fprintf(file,"\n");
869
                                for(i = 0; i < openedkeys; i++)
870
                                        fprintf(file,"   ");
871 4 jcastillo
                                fprintf(file,"end\n");
872 2 jcastillo
                                if(default_found)
873
                                        {
874
                                                default_break_found = 1;
875
                                        }
876
                         }
877 4 jcastillo
                        }else if(verilog==1)
878
                       fprintf(file,"break;");
879 2 jcastillo
                        };
880
 
881
hexa:
882
                HEXA
883
                        {
884 4 jcastillo
                    if(translate==1&& verilog==0){
885 2 jcastillo
                        if(processfound)
886
                        {
887
                                fprintf(file,"'h");
888
                        }
889
                        else if(definefound)
890
                        {
891
                                fprintf(FILE_DEFINES,"'h");
892
                        }
893 4 jcastillo
                        }else if(verilog==1)
894
                       fprintf(file,"0x");
895
                        };
896 2 jcastillo
 
897 4 jcastillo
translateoff:
898
        TRANSLATEOFF
899
                {
900
                  translate=0;
901
                  fprintf(stderr,"Found Translate off directive \n");
902
        };
903
 
904
translateon:
905
        TRANSLATEON
906
                {
907
                  translate=1;
908
                  fprintf(stderr,"Found Translate on directive \n");
909
        };
910
 
911
verilogbegin:
912
        VERILOGBEGIN
913
                {
914
                  verilog=1;
915
                  fprintf(stderr,"Found Verilog Begin directive \n");
916
        };
917
 
918
verilogend:
919
        VERILOGEND
920
                {
921
                  verilog=0;
922
                  fprintf(stderr,"Found Verilog End directive \n");
923
        };
924
 
925
ifdef:
926
       PIFDEF
927
           {
928
            if(translate==1&& verilog==0){
929
                                if(processfound)
930
                                {
931
                                        fprintf(file,"`ifdef");
932
                                }
933
                                else if(definefound)
934
                                {
935
                                        fprintf(FILE_DEFINES,"`ifdef");
936
                                }
937
                        }else if(verilog==1)
938
                       fprintf(file,"#ifdef");
939 2 jcastillo
                        };
940 4 jcastillo
endif:
941
       PENDDEF
942
           {
943
            if(translate==1&& verilog==0){
944
                                if(processfound)
945
                                {
946
                                        fprintf(file,"`endif");
947
                                }
948
                                else if(definefound)
949
                                {
950
                                        fprintf(FILE_DEFINES,"`endif");
951
                                }
952
                        }else if(verilog==1)
953
                       fprintf(file,"#endif");
954
                        };
955 6 jcastillo
pelse:
956 4 jcastillo
       PELSE
957
           {
958
            if(translate==1&& verilog==0){
959
                                if(processfound)
960
                                {
961
                                        fprintf(file,"`else");
962
                                }
963
                                else if(definefound)
964
                                {
965
                                        fprintf(FILE_DEFINES,"`else");
966
                                }
967
                        }else if(verilog==1)
968
                       fprintf(file,"#else");
969
                        };
970 6 jcastillo
ttrue:
971
      TTRUE
972
          {
973
                if(translate==1&& verilog==0){
974
                                if(processfound)
975
                                {
976
                                        fprintf(file,"1");
977
                                }
978
                        }else if(verilog==1)
979
                       fprintf(file,"1");
980
                        };
981
 
982
 
983
tfalse:
984
      TFALSE
985
          {
986
                if(translate==1&& verilog==0){
987
                                if(processfound)
988
                                {
989
                                        fprintf(file,"0");
990
                                }
991
                        }else if(verilog==1)
992
                       fprintf(file,"0");
993
                        };

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.