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

Subversion Repositories sc2v

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

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

powered by: WebSVN 2.1.0

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