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

Subversion Repositories sc2v

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

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

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

powered by: WebSVN 2.1.0

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