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

Subversion Repositories sc2v

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

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