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

Subversion Repositories sc2v

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

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

powered by: WebSVN 2.1.0

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