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

Subversion Repositories sc2v

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

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

Line No. Rev Author Line
1 2 jcastillo
/* -----------------------------------------------------------------------------
2
 *
3 14 jcastillo
 *  SystemC to Verilog Translator v0.3
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 14 jcastillo
#include "sc2v_step1.h"
30 2 jcastillo
 
31 12 jcastillo
  int processfound = 0;
32
  int switchfound = 0;
33
  int switchparenthesis[256];
34
  int ifdeffound = 0;
35
  char *processname, *processname2;
36
  char *fileregs;
37
  char *filename;
38
  int openedkeys = 0;
39
  int newline = 0;
40
  int reg_found = 0;
41
  int regs_end;
42
  int i = 0;                    //for loops counter
43
  FILE *file;
44
  FILE *regs_file;
45
  char *regname, *regname2;
46
  char *lastword;               // Stores last WORD for use it in WRITE
47
  char *file_defines;
48
  FILE *FILE_DEFINES;
49
  char *file_writes;
50
  FILE *FILE_WRITES;            //FILE to store .write to know if it is a wire or reg
51
  int definefound = 0;
52
  int defineinvocationfound = 0;
53
  int opencorchfound = 0;
54
  int defineparenthesis = 0;
55 2 jcastillo
 
56 12 jcastillo
  int openedcase = 0;
57 2 jcastillo
 
58 12 jcastillo
  int default_break_found = 0;
59
  int default_found;
60 2 jcastillo
 
61 4 jcastillo
//Directives variables
62 12 jcastillo
  int translate;
63
  int verilog;
64
  int writemethod;
65 4 jcastillo
 
66 12 jcastillo
  void yyerror (const char *str)
67
  {
68
    fprintf (stderr, "error: %s\n", str);
69
  }
70 2 jcastillo
 
71 12 jcastillo
  int yywrap ()
72
  {
73
    return 1;
74
  }
75 2 jcastillo
 
76 12 jcastillo
  main ()
77
  {
78
    int i;
79 14 jcastillo
 
80
        defineslist=NULL;
81
        regslist=NULL;
82 10 jcastillo
 
83 14 jcastillo
        fprintf(stderr,"\nSystemC to Verilog Translator v0.3");
84
        fprintf(stderr,"\nProvided by OpenSoc http://www.opensocdesign.com\n\n");
85
        fprintf(stderr,"Parsing implementation file.......\n\n");
86 2 jcastillo
 
87 14 jcastillo
    processname = (char *) malloc (256 * sizeof (char));
88
    processname2 = (char *) malloc (256 * sizeof (char));
89
    fileregs = (char *) malloc (256 * sizeof (char));
90 12 jcastillo
 
91 14 jcastillo
    file_defines = (char *) malloc (256 * sizeof (char));
92 12 jcastillo
    strcpy (file_defines, (char *) "file_defines.sc2v");
93
    FILE_DEFINES = fopen (file_defines, (char *) "w");
94 14 jcastillo
 
95
    file_writes = (char *) malloc (256 * sizeof (char));
96 12 jcastillo
    strcpy (file_writes, (char *) "file_writes.sc2v");
97
    FILE_WRITES = fopen (file_writes, (char *) "w");
98
 
99 14 jcastillo
    lastword = (char *)malloc (sizeof (char) * 256);
100 12 jcastillo
 
101
    for (i = 0; i < 256; i++)
102
      switchparenthesis[i] = 0;
103
 
104
    translate = 1;
105
    verilog = 0;
106
    writemethod = 0;
107 14 jcastillo
 
108 12 jcastillo
    yyparse ();
109
    fclose (FILE_WRITES);
110
    fclose (FILE_DEFINES);
111 14 jcastillo
 
112
        fprintf(stderr,"\nDone\n\n");
113 12 jcastillo
  }
114
 
115 2 jcastillo
%}
116
 
117 12 jcastillo
%token NUMBER WORD SC_INT SC_UINT BOOL BIGGER LOWER OPENKEY CLOSEKEY WRITE WORD SYMBOL NEWLINE ENUM INCLUDE
118
%token COLON SEMICOLON RANGE OPENPAR CLOSEPAR TWODOUBLEPOINTS OPENCORCH CLOSECORCH SWITCH CASE DEFAULT BREAK
119
%token SC_BIGINT SC_BIGUINT HEXA DEFINE READ TRANSLATEOFF TRANSLATEON VERILOGBEGIN VERILOGEND TAB DOLLAR INTCONV
120
%token VOID TTRUE TFALSE
121
%token PIFDEF PENDDEF PELSE
122 2 jcastillo
 
123 12 jcastillo
%% commands:/* empty */
124
|commands command;
125 2 jcastillo
 
126
 
127
command:
128 12 jcastillo
  voidword
129
  |
130
  include
131
  |
132
  dollar
133
  |
134
  intconv
135
  |
136
  tab
137
  |
138
  read
139
  |
140
  sc_int
141
  |
142
  sc_uint
143
  |
144
  sc_bigint
145
  |
146
  sc_biguint
147
  |
148
  number
149
  |
150
  bool
151
  |
152
  word
153
  |
154
  symbol
155
  |
156
  write
157
  |
158
  newline
159
  |
160
  openkey
161
  |
162
  closekey
163
  |
164
  colon
165
  |
166
  semicolon
167
  |
168
  range
169
  |
170
  openpar
171
  |
172
  closepar
173
  |
174
  void
175
  |
176
  opencorch
177
  |
178
  closecorch
179
  |
180
  bigger
181
  |
182
  lower
183
  |
184
  switch
185
  |
186
  case_only
187
  |
188
  case_number
189
  |
190
  case_word
191
  |
192
  case_default
193
  |
194
  break
195
  |
196
  hexa
197
  |
198
  definemacro
199
  |
200
  defineword
201
  |
202
  definenumber
203
  |
204
  translateoff
205
  |
206
  translateon
207
  |
208
  verilogbegin
209
  |
210
  verilogend
211
  |
212
  ifdef
213
  |
214
  endif
215
  |
216
  pelse
217
  |
218
  ttrue
219
  |
220
  tfalse;
221 2 jcastillo
 
222 4 jcastillo
 
223 12 jcastillo
 
224 4 jcastillo
voidword:
225 12 jcastillo
VOID
226
{
227
  defineparenthesis = 0;
228
  if (verilog == 1)
229
    fprintf (file, " void");
230
};
231 4 jcastillo
 
232 12 jcastillo
 
233 4 jcastillo
include:
234 12 jcastillo
INCLUDE
235
{
236
  defineparenthesis = 0;
237
  if (verilog == 1)
238
    fprintf (file, " #include");
239
};
240 4 jcastillo
 
241
 
242
dollar:
243 12 jcastillo
DOLLAR
244
{
245
  defineparenthesis = 0;
246
  if (verilog == 1)
247
    fprintf (file, " $");
248
};
249 4 jcastillo
 
250
intconv:
251 12 jcastillo
INTCONV
252
{
253
  defineparenthesis = 0;
254
  if (verilog == 1)
255
    fprintf (file, " (int)");
256
};
257 4 jcastillo
 
258
tab:
259 12 jcastillo
TAB
260
{
261
  defineparenthesis = 0;
262
  if (verilog == 1)
263
    fprintf (file, " \t");
264
};
265
 
266 2 jcastillo
read:
267 12 jcastillo
READ OPENPAR CLOSEPAR
268
{
269
  defineparenthesis = 0;
270
  if (verilog == 1)
271
    fprintf (file, ".read()");
272 4 jcastillo
 
273 12 jcastillo
}
274
 
275
defineword:
276
DEFINE WORD WORD
277
{
278 14 jcastillo
 
279 12 jcastillo
  defineparenthesis = 0;
280
  if (translate == 1 && verilog == 0)
281
    {
282
      if (processfound)
283
        {
284
          fprintf (file, "`define %s %s\n", (char *) $2, (char *) $3);
285 14 jcastillo
          defineslist=InsertDefine(defineslist,(char *)$2);
286 12 jcastillo
        }
287
      else
288
        {
289
          fprintf (FILE_DEFINES, "`define %s %s\n", (char *) $2, (char *) $3);
290 14 jcastillo
          defineslist=InsertDefine(defineslist,(char *)$2);
291 12 jcastillo
        }
292
    }
293
  else if (verilog == 1)
294
    fprintf (file, "#define %s %s\n", (char *) $2, (char *) $3);
295
 
296
};
297
 
298
definenumber:
299
DEFINE WORD NUMBER
300
{
301 14 jcastillo
 
302 12 jcastillo
  defineparenthesis = 0;
303
  if (translate == 1 && verilog == 0)
304
    {
305
      if (processfound)
306
        {
307
          fprintf (file, "`define %s %d\n", (char *) $2, (int) $3);
308 14 jcastillo
          defineslist=InsertDefine(defineslist,(char *)$2);
309 12 jcastillo
        }
310
      else
311
        {
312
          fprintf (FILE_DEFINES, "`define %s %d\n", (char *) $2, (int) $3);
313 14 jcastillo
      defineslist=InsertDefine(defineslist,(char *)$2);
314 12 jcastillo
        }
315
    }
316
  else if (verilog == 1)
317
    fprintf (file, "#define %s %d\n", (char *) $2, (int) $3);
318
 
319
};
320
 
321
 
322
definemacro:
323
DEFINE WORD OPENPAR CLOSEPAR
324
{
325 14 jcastillo
 
326
 
327 12 jcastillo
  defineparenthesis = 0;
328
  //Macro found
329
  if (translate == 1 && verilog == 0)
330
    {
331 14 jcastillo
          defineslist=InsertDefine(defineslist,(char *)$2);
332
 
333 12 jcastillo
      definefound = 1;
334
      if (processfound)
335
        fprintf (file, "`define %s ", (char *) $2);
336
      else
337
        fprintf (FILE_DEFINES, "`define %s ", (char *) $2);
338
    }
339
  else if (verilog == 1)
340
    fprintf (file, "#define %s ()", (char *) $2);
341
}
342
 
343 2 jcastillo
void:
344 12 jcastillo
WORD TWODOUBLEPOINTS WORD OPENPAR CLOSEPAR
345
{
346
  defineparenthesis = 0;
347
  if (translate == 1 && verilog == 0)
348
    {
349
      strcpy (processname, (char *) $4);
350
      strcpy (processname2, (char *) $4);
351
      strcat (processname2, (char *) ".sc2v");
352
      strcpy (fileregs, (char *) $4);
353
      strcat (fileregs, (char *) "_regs.sc2v");
354
    }
355
  else if (verilog == 1)
356
    fprintf (file, " %s::%s()", (char *) $1, (char *) $3);
357
 
358
}
359
 
360 2 jcastillo
sc_int:
361 12 jcastillo
SC_INT LOWER NUMBER BIGGER
362
{
363
  defineparenthesis = 0;
364
  if (translate == 1 && verilog == 0)
365
    {
366
      if (processfound)
367
        {
368
          fprintf (regs_file, "reg[%d:0] ", (-1 + $3));
369
          reg_found = 1;
370
        }
371
    }
372
  else if (verilog == 1)
373
    fprintf (file, "sc_int<%d>", $3);
374 2 jcastillo
 
375 12 jcastillo
}
376
 
377
;
378
 
379 2 jcastillo
sc_uint:
380 12 jcastillo
SC_UINT LOWER NUMBER BIGGER
381
{
382
  defineparenthesis = 0;
383
  if (translate == 1 && verilog == 0)
384
    {
385
      if (processfound)
386
        {
387
          fprintf (regs_file, "reg[%d:0] ", (-1 + $3));
388
          reg_found = 1;
389
        }
390
    }
391
  else if (verilog == 1)
392
    fprintf (file, "sc_uint<%d>", $3);
393
}
394
 
395
;
396
 
397 2 jcastillo
sc_bigint:
398 12 jcastillo
SC_BIGINT LOWER NUMBER BIGGER
399
{
400
  defineparenthesis = 0;
401
  if (translate == 1 && verilog == 0)
402
    {
403
      if (processfound)
404
        {
405
          fprintf (regs_file, "reg[%d:0] ", (-1 + $3));
406
          reg_found = 1;
407
        }
408
    }
409
  else if (verilog == 1)
410
    fprintf (file, "sc_bigint<%d> ", $3);
411
}
412 2 jcastillo
 
413 12 jcastillo
;
414
 
415 2 jcastillo
sc_biguint:
416 12 jcastillo
SC_BIGUINT LOWER NUMBER BIGGER
417
{
418
  defineparenthesis = 0;
419
  if (translate == 1 && verilog == 0)
420
    {
421
      if (processfound)
422
        {
423
          fprintf (regs_file, "reg[%d:0] ", (-1 + $3));
424
          reg_found = 1;
425
        }
426
    }
427
  else if (verilog == 1)
428
    fprintf (file, "sc_biguint<%d> ", $3);
429
}
430 2 jcastillo
 
431 12 jcastillo
;
432
 
433 2 jcastillo
bool:
434 12 jcastillo
BOOL
435
{
436
  defineparenthesis = 0;
437
  if (translate == 1 && verilog == 0)
438
    {
439
      if (processfound)
440
        {
441
          fprintf (regs_file, "reg ");
442
          reg_found = 1;
443
        }
444
    }
445
  else if (verilog == 1)
446
    fprintf (file, "bool");
447
}
448 2 jcastillo
 
449 12 jcastillo
;
450
 
451 2 jcastillo
range:
452 12 jcastillo
RANGE OPENPAR NUMBER COLON NUMBER CLOSEPAR
453
{
454
  defineparenthesis = 0;
455
  if (translate == 1 && verilog == 0)
456
    {
457
      if (processfound)
458
        fprintf (file, "[%d:%d]", $3, $5);
459
      else if (definefound)
460
        fprintf (FILE_DEFINES, "[%d:%d]", $3, $5);
461
    }
462
  else if (verilog == 1)
463
    fprintf (file, ".range(%d,%d)", $3, $5);
464
}
465
 
466
;
467
 
468
number:
469
NUMBER
470
{
471
  defineparenthesis = 0;
472
  if (translate == 1 && verilog == 0)
473
    {
474
      if (processfound)
475
        if (reg_found)
476
          {
477
            if (opencorchfound)
478
              fprintf (regs_file, "%d:0", -1 + $1);
479
            else
480
              fprintf (regs_file, "%d", $1);
481
          }
482
        else
483
          fprintf (file, "%d", $1);
484
      else if (definefound)
485
        fprintf (FILE_DEFINES, "%d", $1);
486
    }
487
  else if (verilog == 1)
488
    fprintf (file, "%d", $1);
489
}
490
 
491
;
492
word:
493
WORD
494
{
495 14 jcastillo
 
496 12 jcastillo
  defineparenthesis = 0;
497
  if (translate == 1 && verilog == 0)
498
    {
499
      if (processfound)
500
        {
501
          if (openedcase)
502
            {
503
              fprintf (file, " :\n");
504
 
505
              for (i = 0; i < openedkeys; i++)
506
                fprintf (file, "   ");
507
 
508
              fprintf (file, "begin\n");
509
              openedcase = 0;
510
            }
511
 
512
          strcpy (lastword, (char *) $1);
513
 
514
          if (reg_found)
515
            {
516
 
517 14 jcastillo
              regname = (char *)malloc (sizeof (char) * (strlen ((char *) $1) + 1));
518
              regname2 =(char *)malloc (sizeof (char) *(strlen ((char *) $1) + strlen (processname)) + 1);
519 12 jcastillo
 
520
              strcpy (regname, (char *) $1);
521
              strcpy (regname2, (char *) $1);
522
              strcat (regname2, processname);
523
              fprintf (regs_file, "%s", regname2);
524 14 jcastillo
 
525
                  regslist=InsertReg(regslist,regname,regname2);
526
 
527
              free (regname);
528 12 jcastillo
              free (regname2);
529
            }
530
          else
531
            {
532
              if (newline)
533
                {
534
                  for (i = 0; i < openedkeys; i++)
535
                    fprintf (file, "   ");
536
                }
537 14 jcastillo
              regname2 = IsReg (regslist,(char *) $1);
538 12 jcastillo
              if (regname2 == NULL)
539
                {
540 14 jcastillo
 
541
                  if (IsDefine(defineslist,(char *)$1))
542 12 jcastillo
                    {
543
                      if (ifdeffound == 0)
544 2 jcastillo
                        {
545 12 jcastillo
                          fprintf (file, "`%s", (char *) $1);
546
                          defineinvocationfound = 1;
547 2 jcastillo
                        }
548 12 jcastillo
                      else
549 2 jcastillo
                        {
550 12 jcastillo
                          fprintf (file, "%s", (char *) $1);
551
                          ifdeffound = 0;
552 2 jcastillo
                        }
553 12 jcastillo
                    }
554
                  else
555
                    {
556
                      fprintf (file, "%s ", (char *) $1);
557
                    }
558
                }
559
              else
560
                fprintf (file, "%s", regname2);
561 2 jcastillo
 
562 12 jcastillo
              newline = 0;
563
            }
564
 
565
        }
566
      else if (definefound)
567
        {
568 14 jcastillo
 
569
         if (IsDefine(defineslist,(char *)$1))
570 12 jcastillo
            {
571
 
572
              fprintf (FILE_DEFINES, "`%s", (char *) $1);
573
            }
574
          else
575
            {
576
              fprintf (FILE_DEFINES, "%s ", (char *) $1);
577
            }
578
        }
579
    }
580
  else if (verilog == 1)
581
    fprintf (file, " %s", (char *) $1);
582
};
583
 
584 2 jcastillo
symbol:
585 12 jcastillo
SYMBOL
586
{
587
  defineparenthesis = 0;
588
  if (translate == 1 && verilog == 0)
589
    {
590
      if (processfound)
591
        {
592
          if (reg_found)
593
            fprintf (regs_file, "%s", (char *) $1);
594
          else
595
            fprintf (file, "%s", (char *) $1);
596
        }
597
      else if (definefound)
598
        {
599
          fprintf (FILE_DEFINES, "%s", (char *) $1);
600
        }
601
    }
602
  else if (verilog == 1)
603
    fprintf (file, "%s", (char *) $1);
604
};
605 2 jcastillo
 
606 12 jcastillo
 
607 2 jcastillo
write:
608 12 jcastillo
WRITE
609
{
610
  defineparenthesis = 0;
611
  if (translate == 1 && verilog == 0)
612
    {
613
      writemethod = 1;
614
      if (processfound)
615
        {
616
          fprintf (file, " <= ");
617
          fprintf (FILE_WRITES, "%s\n", lastword);
618
        }
619
      else if (definefound)
620
        {
621
          fprintf (FILE_DEFINES, " <= ");
622
        }
623 2 jcastillo
 
624 12 jcastillo
    }
625
  else if (verilog == 1)
626
    {
627
      fprintf (file, ".write");
628
    }
629
};
630
 
631 2 jcastillo
newline:
632 12 jcastillo
NEWLINE
633
{
634
  defineparenthesis = 0;
635
  if (translate == 1 && verilog == 0)
636
    {
637
      if (processfound & !reg_found & !openedcase)
638
        {
639
          fprintf (file, "\n");
640
          newline = 1;
641
        }
642
      else if (definefound)
643
        {
644
          fprintf (FILE_DEFINES, "\n");
645
        }
646 2 jcastillo
 
647 12 jcastillo
    }
648
  else if (verilog == 1)
649
    fprintf (file, "\n");
650
};
651
 
652 2 jcastillo
colon:
653 12 jcastillo
COLON
654
{
655
  defineparenthesis = 0;
656
  if (translate == 1 && verilog == 0)
657
    {
658
      if (processfound)
659
        {
660
          if (reg_found)
661
            {
662
              fprintf (regs_file, ",");
663
            }
664
          else
665
            fprintf (file, ",");
666
        }
667
      else if (definefound)
668
        {
669
          fprintf (FILE_DEFINES, ",");
670
        }
671
    }
672
  else if (verilog == 1)
673
    fprintf (file, ",");
674
};
675 2 jcastillo
 
676
semicolon:
677 12 jcastillo
SEMICOLON
678
{
679
  defineparenthesis = 0;
680
  if (translate == 1 && verilog == 0)
681
    {
682
      if (processfound)
683
        {
684
          if (reg_found)
685
            {
686
              fprintf (regs_file, ";\n");
687
              reg_found = 0;
688
            }
689
          else
690
            {
691
              if (defineinvocationfound == 0)
692
                fprintf (file, ";");
693
            }
694
        }
695
      else if (definefound)
696
        {
697
          fprintf (FILE_DEFINES, ";");
698
        }
699
    }
700
  else if (verilog == 1)
701
    fprintf (file, ";");
702 2 jcastillo
 
703 12 jcastillo
  defineinvocationfound = 0;
704
};
705
 
706
 
707 2 jcastillo
openpar:
708 12 jcastillo
OPENPAR
709
{
710
  defineparenthesis = 1;
711
  if (translate == 1 && verilog == 0 && defineinvocationfound == 0)
712
    {
713
      if (processfound)
714
        {
715
          fprintf (file, "(");
716
        }
717
      else if (definefound)
718
        {
719
          fprintf (FILE_DEFINES, "(");
720
        }
721
 
722
    }
723
  else if (verilog == 1)
724
    {
725
      fprintf (file, "(");
726
    }
727
}
728
 
729 2 jcastillo
closepar:
730 12 jcastillo
CLOSEPAR
731
{
732
  if (translate == 1 && verilog == 0)
733
    {
734 2 jcastillo
 
735 12 jcastillo
      if (processfound)
736
        {
737
          if (defineparenthesis == 0)
738
            {
739
              fprintf (file, ")");
740
              defineinvocationfound = 0;
741
            }
742
 
743
        }
744
      else if (definefound)
745
        {
746
          fprintf (FILE_DEFINES, ")");
747
        }
748
    }
749
  else if (verilog == 1)
750
    fprintf (file, ")");
751
 
752
};
753
 
754
 
755 2 jcastillo
opencorch:
756 12 jcastillo
OPENCORCH
757
{
758
  defineparenthesis = 0;
759
  if (translate == 1 && verilog == 0)
760
    {
761
      if (processfound)
762
        {
763
          if (reg_found)
764
            {
765
              fprintf (regs_file, "[");
766
              opencorchfound = 1;
767
            }
768
          else
769
            fprintf (file, "[");
770
        }
771
      else if (definefound)
772
        {
773
          fprintf (FILE_DEFINES, "[");
774
 
775
        }
776
    }
777
  else if (verilog == 1)
778
    fprintf (file, "[");
779
};
780
 
781 2 jcastillo
closecorch:
782 12 jcastillo
CLOSECORCH
783
{
784
  defineparenthesis = 0;
785
  if (translate == 1 && verilog == 0)
786
    {
787
      if (processfound)
788
        {
789
          if (reg_found)
790
            {
791
              fprintf (regs_file, "]");
792
              opencorchfound = 0;
793
            }
794
          else
795
            fprintf (file, "]");
796
        }
797
      else if (definefound)
798
        {
799
          fprintf (FILE_DEFINES, "]");
800
        }
801
    }
802
  else if (verilog == 1)
803
    fprintf (file, "]");
804
};
805
 
806
 
807 2 jcastillo
openkey:
808 12 jcastillo
OPENKEY
809
{
810
  defineparenthesis = 0;
811
  if (translate == 1 && verilog == 0)
812
    {
813
      openedkeys++;
814
      if (!definefound)
815
        {
816
          if (openedkeys == 1)
817
            {
818 14 jcastillo
              printf ("Found process %s\n", processname);
819 12 jcastillo
              file = fopen (processname2, (char *) "w");
820
              regs_file = fopen (fileregs, (char *) "w");
821
              processfound = 1;
822 14 jcastillo
            }
823 12 jcastillo
          if (processfound)
824
            if (openedkeys != switchparenthesis[switchfound])
825
              {
826
                fprintf (file, "\n");
827
                for (i = 0; i < openedkeys; i++)
828
                  fprintf (file, "   ");
829
                fprintf (file, "begin\n");
830
                newline = 1;
831
              }
832
        }
833
    }
834
  else if (verilog == 1)
835
    fprintf (file, "{");
836
};
837 2 jcastillo
 
838
closekey:
839 12 jcastillo
CLOSEKEY
840
{
841
  defineparenthesis = 0;
842
  if (translate == 1 && verilog == 0)
843
    {
844
      if (processfound && !definefound)
845
        {
846
          if (openedkeys == switchparenthesis[switchfound] && switchfound > 0)
847
            {
848
              fprintf (file, "\n");
849
              if (default_found & !default_break_found)
850
                {
851
                  for (i = 0; i < openedkeys - 1; i++)
852
                    fprintf (file, "   ");
853
                  fprintf (file, "end\n");
854
                  default_found = 0;
855
                }
856
              for (i = 0; i < openedkeys - 1; i++)
857 14 jcastillo
                  fprintf (file, "   ");
858 12 jcastillo
              fprintf (file, "endcase\n");
859
              newline = 1;
860
              switchparenthesis[switchfound] = 0;
861
              switchfound--;
862 2 jcastillo
 
863 12 jcastillo
            }
864
          else
865
            {
866
              fprintf (file, "\n");
867
              for (i = 0; i < openedkeys; i++)
868 14 jcastillo
                    fprintf (file, "   ");
869 12 jcastillo
              fprintf (file, "end\n");
870
              newline = 1;
871
            }
872
        }
873 2 jcastillo
 
874 12 jcastillo
      openedkeys--;
875
      if (definefound)
876
        {
877
          definefound = 0;
878
          if (processfound)
879
            fprintf (file, "\n//Dummy Comment\n");
880
          else
881
            fprintf (FILE_DEFINES, "\n//Dummy Comment\n");
882
        }
883
      else if (openedkeys == 0)
884
        {
885
          fclose (file);
886
          fclose (regs_file);
887
          processfound = 0;
888
        }
889
    }
890
  else if (verilog == 1)
891
    fprintf (file, "}");
892
};
893
 
894
 
895 4 jcastillo
bigger:
896 12 jcastillo
BIGGER
897
{
898
  defineparenthesis = 0;
899
  if (translate == 1 && verilog == 0)
900
    {
901
      if (processfound)
902
        {
903
          fprintf (file, ">");
904
        }
905
      else if (definefound)
906
        {
907
          fprintf (FILE_DEFINES, ">");
908
        }
909
    }
910
  else if (verilog == 1)
911
    fprintf (file, ">");
912
};
913 2 jcastillo
 
914 4 jcastillo
lower:
915 12 jcastillo
LOWER
916
{
917
  defineparenthesis = 0;
918
  if (translate == 1 && verilog == 0)
919
    {
920
      if (processfound)
921
        {
922
          fprintf (file, "<");
923
        }
924
      else if (definefound)
925
        {
926
          fprintf (FILE_DEFINES, "<");
927
        }
928
    }
929
  else if (verilog == 1)
930
    fprintf (file, "<");
931
};
932 2 jcastillo
 
933 12 jcastillo
 
934 2 jcastillo
switch:
935 12 jcastillo
SWITCH
936
  {
937
    defineparenthesis = 0;
938
    if (translate == 1 && verilog == 0)
939
      {
940
        if (processfound)
941
          {
942
            fprintf (file, "\n");
943
            for (i = 0; i < openedkeys; i++)
944
              fprintf (file, "   ");
945
            fprintf (file, "case");
946
            switchfound++;
947
            switchparenthesis[switchfound] = openedkeys + 1;
948
          }
949
      }
950
    else if (verilog == 1)
951
      fprintf (file, "switch");
952
  };
953
 
954 2 jcastillo
case_number:
955 12 jcastillo
CASE NUMBER SYMBOL
956
{
957
  defineparenthesis = 0;
958
  if (translate == 1 && verilog == 0)
959
    {
960
      if (processfound)
961
        {
962
          for (i = 0; i < openedkeys; i++)
963
            fprintf (file, "   ");
964
          if (openedcase)
965
            fprintf (file, ", %d", $2);
966
          else
967
            fprintf (file, "%d", $2);
968 4 jcastillo
 
969 12 jcastillo
          newline = 1;
970
          openedcase = 1;
971
 
972
        }
973
    }
974
  else if (verilog == 1)
975
    fprintf (file, "case %d %s", $2, (char *) $3);
976
};
977
 
978 4 jcastillo
case_word:
979 12 jcastillo
CASE WORD SYMBOL
980
{
981
  defineparenthesis = 0;
982
  if (translate == 1 && verilog == 0)
983
    {
984
      if (processfound)
985
        {
986
          for (i = 0; i < openedkeys; i++)
987
            fprintf (file, "   ");
988
          if (openedcase)
989
            fprintf (file, ", %s", (char *) $2);
990
          else
991
            fprintf (file, "%s", (char *) $2);
992
 
993
          newline = 1;
994
          openedcase = 1;
995
 
996
        }
997
    }
998
  else if (verilog == 1)
999
    fprintf (file, "case %s %s", (char *) $2, (char *) $3);
1000
};
1001
 
1002 2 jcastillo
case_default:
1003 12 jcastillo
DEFAULT SYMBOL
1004
{
1005
  defineparenthesis = 0;
1006
  if (translate == 1 && verilog == 0)
1007
    {
1008
      if (processfound)
1009
        {
1010
          for (i = 0; i < openedkeys; i++)
1011
            fprintf (file, "   ");
1012
          fprintf (file, "default:\n");
1013
          for (i = 0; i < openedkeys; i++)
1014
            fprintf (file, "   ");
1015
          fprintf (file, "begin\n");
1016
          newline = 1;
1017
          default_found = 1;
1018
        }
1019
    }
1020
  else if (verilog == 1)
1021
    fprintf (file, "default %s", (char *) $2);
1022
};
1023 2 jcastillo
 
1024 4 jcastillo
case_only:
1025 12 jcastillo
CASE OPENPAR
1026
{
1027
  defineparenthesis = 0;
1028
  //This rule occurs when in Verilog mode a case appears
1029
  if (verilog == 1)
1030
    fprintf (file, "case(");
1031
};
1032 4 jcastillo
 
1033 2 jcastillo
break:
1034 12 jcastillo
BREAK SEMICOLON
1035
{
1036
  defineparenthesis = 0;
1037
  if (translate == 1 && verilog == 0)
1038
    {
1039
      if (processfound)
1040
        {
1041
          if (newline == 0)
1042
            fprintf (file, "\n");
1043
          for (i = 0; i < openedkeys; i++)
1044
            fprintf (file, "   ");
1045
          fprintf (file, "end\n");
1046
          if (default_found)
1047
            {
1048
              default_break_found = 1;
1049
            }
1050
        }
1051
    }
1052
  else if (verilog == 1)
1053
    fprintf (file, "break;");
1054
};
1055 2 jcastillo
 
1056
hexa:
1057 12 jcastillo
HEXA
1058
{
1059
  defineparenthesis = 0;
1060
  if (translate == 1 && verilog == 0)
1061
    {
1062
      if (processfound)
1063
        {
1064
          fprintf (file, "'h");
1065
        }
1066
      else if (definefound)
1067
        {
1068
          fprintf (FILE_DEFINES, "'h");
1069
        }
1070
    }
1071
  else if (verilog == 1)
1072
    fprintf (file, "0x");
1073
};
1074
 
1075 4 jcastillo
translateoff:
1076 12 jcastillo
TRANSLATEOFF
1077
{
1078
  defineparenthesis = 0;
1079
  translate = 0;
1080
  fprintf (stderr, "Found Translate off directive \n");
1081
};
1082 4 jcastillo
 
1083
translateon:
1084 12 jcastillo
TRANSLATEON
1085
{
1086
  defineparenthesis = 0;
1087
  translate = 1;
1088
  fprintf (stderr, "Found Translate on directive \n");
1089
};
1090
 
1091 4 jcastillo
verilogbegin:
1092 12 jcastillo
VERILOGBEGIN
1093
{
1094
  defineparenthesis = 0;
1095
  verilog = 1;
1096
  fprintf (stderr, "Found Verilog Begin directive \n");
1097
};
1098 4 jcastillo
 
1099
verilogend:
1100 12 jcastillo
VERILOGEND
1101
{
1102
  defineparenthesis = 0;
1103
  verilog = 0;
1104
  fprintf (stderr, "Found Verilog End directive \n");
1105
};
1106 4 jcastillo
 
1107
ifdef:
1108 12 jcastillo
PIFDEF
1109
{
1110
  defineparenthesis = 0;
1111
  if (translate == 1 && verilog == 0)
1112
    {
1113
      if (processfound)
1114
        {
1115
          ifdeffound = 1;
1116
          fprintf (file, "`ifdef");
1117
        }
1118
      else if (definefound)
1119
        {
1120
          fprintf (FILE_DEFINES, "`ifdef");
1121
        }
1122
    }
1123
  else if (verilog == 1)
1124
    fprintf (file, "#ifdef");
1125
};
1126
 
1127 4 jcastillo
endif:
1128 12 jcastillo
PENDDEF
1129
{
1130
  defineparenthesis = 0;
1131
  if (translate == 1 && verilog == 0)
1132
    {
1133
      if (processfound)
1134
        {
1135
          fprintf (file, "`endif");
1136
        }
1137
      else if (definefound)
1138
        {
1139
          fprintf (FILE_DEFINES, "`endif");
1140
        }
1141
    }
1142
  else if (verilog == 1)
1143
    fprintf (file, "#endif");
1144
};
1145
 
1146 6 jcastillo
pelse:
1147 12 jcastillo
PELSE
1148
{
1149
  defineparenthesis = 0;
1150
  if (translate == 1 && verilog == 0)
1151
    {
1152
      if (processfound)
1153
        {
1154
          fprintf (file, "`else");
1155
        }
1156
      else if (definefound)
1157
        {
1158
          fprintf (FILE_DEFINES, "`else");
1159
        }
1160
    }
1161
  else if (verilog == 1)
1162
    fprintf (file, "#else");
1163
};
1164
 
1165 6 jcastillo
ttrue:
1166 12 jcastillo
TTRUE
1167
{
1168
  defineparenthesis = 0;
1169
  if (translate == 1 && verilog == 0)
1170
    {
1171
      if (processfound)
1172
        {
1173
          fprintf (file, "1");
1174
        }
1175
    }
1176
  else if (verilog == 1)
1177
    fprintf (file, "1");
1178
};
1179 6 jcastillo
 
1180
 
1181
tfalse:
1182 12 jcastillo
TFALSE
1183
{
1184
  defineparenthesis = 0;
1185
  if (translate == 1 && verilog == 0)
1186
    {
1187
      if (processfound)
1188
        {
1189
          fprintf (file, "0");
1190
        }
1191
    }
1192
  else if (verilog == 1)
1193
    fprintf (file, "0");
1194
};

powered by: WebSVN 2.1.0

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