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

Subversion Repositories sc2v

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

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 23 jcastillo
  int lastswitch=0;
35 12 jcastillo
  int switchparenthesis[256];
36
  int ifdeffound = 0;
37
  char *processname, *processname2;
38
  char *fileregs;
39
  char *filename;
40
  int openedkeys = 0;
41
  int newline = 0;
42
  int reg_found = 0;
43 25 jcastillo
  int reglenght = 0;
44
  int writelenght = 0;
45 20 jcastillo
  int array_size=0;
46 19 jcastillo
  int integer_found=0;
47 12 jcastillo
  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
  int openedcase = 0;
62 28 jcastillo
  int writingvar=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 15 jcastillo
    fprintf (stderr, "line: %d error: %s\n", lineno, str);
75 12 jcastillo
  }
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 16 jcastillo
    defineslist = NULL;
87
    regslist = NULL;
88 2 jcastillo
 
89 18 jcastillo
    fprintf (stderr, "\nSystemC to Verilog Translator v0.4");
90 16 jcastillo
    fprintf (stderr,
91
             "\nProvided by OpenSoc http://www.opensocdesign.com\n\n");
92
    fprintf (stderr, "Parsing implementation file.......\n\n");
93
 
94 14 jcastillo
    processname = (char *) malloc (256 * sizeof (char));
95
    processname2 = (char *) malloc (256 * sizeof (char));
96
    fileregs = (char *) malloc (256 * sizeof (char));
97 12 jcastillo
 
98 14 jcastillo
    file_defines = (char *) malloc (256 * sizeof (char));
99 12 jcastillo
    strcpy (file_defines, (char *) "file_defines.sc2v");
100
    FILE_DEFINES = fopen (file_defines, (char *) "w");
101 16 jcastillo
 
102 14 jcastillo
    file_writes = (char *) malloc (256 * sizeof (char));
103 12 jcastillo
    strcpy (file_writes, (char *) "file_writes.sc2v");
104
    FILE_WRITES = fopen (file_writes, (char *) "w");
105
 
106 16 jcastillo
    lastword = (char *) malloc (sizeof (char) * 256);
107 12 jcastillo
 
108
    for (i = 0; i < 256; i++)
109
      switchparenthesis[i] = 0;
110
 
111
    translate = 1;
112
    verilog = 0;
113
    writemethod = 0;
114 16 jcastillo
 
115
    FILE *yyin = stdin;
116
    FILE *yyout = stdout;
117 12 jcastillo
    yyparse ();
118
    fclose (FILE_WRITES);
119
    fclose (FILE_DEFINES);
120 16 jcastillo
 
121
    fprintf (stderr, "\nDone\n\n");
122 12 jcastillo
  }
123
 
124 2 jcastillo
%}
125
 
126 16 jcastillo
%token NUMBER WORD SC_REG BOOL BIGGER LOWER OPENKEY CLOSEKEY WRITE WORD SYMBOL NEWLINE ENUM INCLUDE
127
%token COLON SEMICOLON RANGE OPENPAR CLOSEPAR TWODOUBLEPOINTS OPENCORCH CLOSECORCH SWITCH CASE DEFAULT BREAK
128 19 jcastillo
%token HEXA DEFINE READ TRANSLATEOFF TRANSLATEON VERILOGBEGIN VERILOGEND TAB DOLLAR MINEQ
129
%token VOID TTRUE TFALSE ENDFUNC INC DEC INTEGER EQUALS
130 28 jcastillo
%token PIFDEF PIFNDEF PENDDEF PELSE COMMENT
131 2 jcastillo
 
132 16 jcastillo
%% commands:    /* empty */
133 12 jcastillo
|commands command;
134 2 jcastillo
 
135
 
136
command:
137 16 jcastillo
endfunc
138
  |
139 12 jcastillo
  voidword
140
  |
141
  include
142
  |
143
  dollar
144
  |
145
  tab
146
  |
147
  read
148
  |
149 16 jcastillo
  sc_reg
150 12 jcastillo
  |
151 19 jcastillo
  integer
152
  |
153 12 jcastillo
  number
154
  |
155
  bool
156
  |
157
  word
158
  |
159
  symbol
160
  |
161
  write
162
  |
163
  newline
164
  |
165
  openkey
166
  |
167
  closekey
168
  |
169
  colon
170
  |
171
  semicolon
172
  |
173
  range
174
  |
175
  openpar
176
  |
177 19 jcastillo
  closepar
178
  |
179
  void
180
  |
181
  opencorch
182
  |
183
  closecorch
184
  |
185
  bigger
186
  |
187
  lower
188
  |
189
  switch
190
  |
191
  case_only
192
  |
193
  case_number
194
  |
195
  case_hexnumber
196
  |
197 24 jcastillo
  case_hexword
198
  |
199
  case_hexnumberword
200
  |
201 19 jcastillo
  case_word
202
  |
203
  case_default
204
  |
205
  break
206
  |
207
  hexa
208
  |
209
  definemacro
210
  |
211
  defineword
212
  |
213
  definenumber
214
  |
215
  translateoff
216
  |
217
  translateon
218
  |
219
  verilogbegin
220
  |
221
  verilogend
222
  |
223
  ifdef
224 27 jcastillo
  |
225
  ifndef
226 19 jcastillo
  |
227
  endif
228
  |
229
  pelse
230
  |
231
  ttrue
232
  |
233
  tfalse
234
  |
235
  increment
236
  |
237
  decrement
238
  |
239
  equal
240
  |
241 28 jcastillo
  minorequal
242
  |
243
  comment;
244 2 jcastillo
 
245 19 jcastillo
minorequal:
246
MINEQ
247
{
248
 //This rule is needed because <= in the step two could be confused with a non-blocking assignment
249
 defineparenthesis = 0;
250
  if (translate == 1 && verilog == 0)
251
    {
252
      if (processfound)
253
        {
254
          fprintf (file, "<1+");
255
        }
256
    }
257
  else if (verilog == 1)
258
    fprintf (file, "<=");
259
};
260 4 jcastillo
 
261 16 jcastillo
endfunc:
262
ENDFUNC
263
{
264
  defineparenthesis = 0;
265
  if (translate == 1 && verilog == 0)
266
    {
267
      if (processfound)
268
        {
269
          for (i = 0; i < openedkeys; i++)
270
            fprintf (file, "   ");
271
          fprintf (file, "%s = ", processname);
272
        }
273
    }
274
  else if (verilog == 1)
275
    fprintf (file, "return ");
276
};
277 12 jcastillo
 
278 16 jcastillo
 
279 4 jcastillo
voidword:
280 12 jcastillo
VOID
281
{
282
  defineparenthesis = 0;
283
  if (verilog == 1)
284
    fprintf (file, " void");
285
};
286 4 jcastillo
 
287 12 jcastillo
 
288 4 jcastillo
include:
289 12 jcastillo
INCLUDE
290
{
291
  defineparenthesis = 0;
292
  if (verilog == 1)
293
    fprintf (file, " #include");
294
};
295 4 jcastillo
 
296
 
297
dollar:
298 12 jcastillo
DOLLAR
299
{
300
  defineparenthesis = 0;
301
  if (verilog == 1)
302
    fprintf (file, " $");
303
};
304 4 jcastillo
 
305
 
306
tab:
307 12 jcastillo
TAB
308
{
309
  defineparenthesis = 0;
310
  if (verilog == 1)
311
    fprintf (file, " \t");
312
};
313
 
314 2 jcastillo
read:
315 12 jcastillo
READ OPENPAR CLOSEPAR
316
{
317
  defineparenthesis = 0;
318
  if (verilog == 1)
319
    fprintf (file, ".read()");
320 4 jcastillo
 
321 12 jcastillo
}
322
 
323
defineword:
324
DEFINE WORD WORD
325
{
326 16 jcastillo
 
327 12 jcastillo
  defineparenthesis = 0;
328
  if (translate == 1 && verilog == 0)
329
    {
330
      if (processfound)
331
        {
332
          fprintf (file, "`define %s %s\n", (char *) $2, (char *) $3);
333 16 jcastillo
          defineslist = InsertDefine (defineslist, (char *) $2);
334 12 jcastillo
        }
335
      else
336
        {
337
          fprintf (FILE_DEFINES, "`define %s %s\n", (char *) $2, (char *) $3);
338 16 jcastillo
          defineslist = InsertDefine (defineslist, (char *) $2);
339 12 jcastillo
        }
340
    }
341
  else if (verilog == 1)
342
    fprintf (file, "#define %s %s\n", (char *) $2, (char *) $3);
343
 
344
};
345
 
346
definenumber:
347
DEFINE WORD NUMBER
348
{
349 16 jcastillo
 
350 12 jcastillo
  defineparenthesis = 0;
351
  if (translate == 1 && verilog == 0)
352
    {
353
      if (processfound)
354
        {
355
          fprintf (file, "`define %s %d\n", (char *) $2, (int) $3);
356 16 jcastillo
          defineslist = InsertDefine (defineslist, (char *) $2);
357 12 jcastillo
        }
358
      else
359
        {
360
          fprintf (FILE_DEFINES, "`define %s %d\n", (char *) $2, (int) $3);
361 16 jcastillo
          defineslist = InsertDefine (defineslist, (char *) $2);
362 12 jcastillo
        }
363
    }
364
  else if (verilog == 1)
365
    fprintf (file, "#define %s %d\n", (char *) $2, (int) $3);
366
 
367
};
368
 
369
 
370
definemacro:
371
DEFINE WORD OPENPAR CLOSEPAR
372
{
373
  defineparenthesis = 0;
374
  //Macro found
375
  if (translate == 1 && verilog == 0)
376
    {
377 16 jcastillo
      defineslist = InsertDefine (defineslist, (char *) $2);
378
 
379 12 jcastillo
      definefound = 1;
380
      if (processfound)
381
        fprintf (file, "`define %s ", (char *) $2);
382
      else
383
        fprintf (FILE_DEFINES, "`define %s ", (char *) $2);
384
    }
385
  else if (verilog == 1)
386
    fprintf (file, "#define %s ()", (char *) $2);
387
}
388
 
389 19 jcastillo
void:
390
WORD TWODOUBLEPOINTS WORD OPENPAR
391 12 jcastillo
{
392
  defineparenthesis = 0;
393
  if (translate == 1 && verilog == 0)
394
    {
395
      strcpy (processname, (char *) $4);
396
      strcpy (processname2, (char *) $4);
397
      strcat (processname2, (char *) ".sc2v");
398
      strcpy (fileregs, (char *) $4);
399
      strcat (fileregs, (char *) "_regs.sc2v");
400
    }
401
  else if (verilog == 1)
402
    fprintf (file, " %s::%s()", (char *) $1, (char *) $3);
403
 
404
}
405
 
406 16 jcastillo
sc_reg:
407
SC_REG LOWER NUMBER BIGGER
408 12 jcastillo
{
409
  defineparenthesis = 0;
410
  if (translate == 1 && verilog == 0)
411
    {
412
      if (processfound)
413
        {
414 25 jcastillo
          writelenght=1;
415
          reglenght = $3;
416 12 jcastillo
          reg_found = 1;
417
        }
418
    }
419 16 jcastillo
};
420 2 jcastillo
 
421 19 jcastillo
integer:
422
INTEGER
423
{
424
  defineparenthesis = 0;
425
  if (translate == 1 && verilog == 0)
426
    {
427
      if (processfound)
428
        {
429
          fprintf (regs_file, "integer ");
430
          integer_found = 1;
431
        }
432
    }
433
};
434
 
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 25 jcastillo
          writelenght=1;
445
          reglenght=0;
446 12 jcastillo
          reg_found = 1;
447
        }
448
    }
449
  else if (verilog == 1)
450
    fprintf (file, "bool");
451
}
452 2 jcastillo
 
453 12 jcastillo
;
454
 
455 2 jcastillo
range:
456 12 jcastillo
RANGE OPENPAR NUMBER COLON NUMBER CLOSEPAR
457
{
458
  defineparenthesis = 0;
459
  if (translate == 1 && verilog == 0)
460
    {
461
      if (processfound)
462
        fprintf (file, "[%d:%d]", $3, $5);
463
      else if (definefound)
464
        fprintf (FILE_DEFINES, "[%d:%d]", $3, $5);
465
    }
466
  else if (verilog == 1)
467
    fprintf (file, ".range(%d,%d)", $3, $5);
468
}
469
 
470
;
471
 
472
number:
473
NUMBER
474
{
475
  defineparenthesis = 0;
476
  if (translate == 1 && verilog == 0)
477
    {
478
      if (processfound)
479 25 jcastillo
       if(opencorchfound && reg_found)
480
        fprintf (regs_file, "%d:0",$1-1);
481
       else
482
        fprintf (file, "%d", $1);
483 12 jcastillo
      else if (definefound)
484
        fprintf (FILE_DEFINES, "%d", $1);
485
    }
486
  else if (verilog == 1)
487
    fprintf (file, "%d", $1);
488 19 jcastillo
};
489 12 jcastillo
 
490 19 jcastillo
increment:
491
WORD INC
492
{
493
  defineparenthesis = 0;
494
  if (translate == 1 && verilog == 0)
495
       if (processfound){
496
        regname2 = IsReg (regslist, (char *) $1);
497
        if (regname2 == NULL){
498
            fprintf (file, "%s=%s+1", (char *) $1,(char *)$1);
499
        }else
500
            fprintf (file, "%s=%s+1", regname2,regname2);
501
       }
502
  else if (verilog == 1)
503
    fprintf (file, "%s++ ", (char *) $1);
504
};
505
 
506
decrement:
507
WORD DEC
508
{
509
  defineparenthesis = 0;
510
  if (translate == 1 && verilog == 0)
511
      if (processfound){
512
        regname2 = IsReg (regslist, (char *) $1);
513
        if (regname2 == NULL){
514
            fprintf (file, "%s=%s+1", (char *) $1,(char *)$1);
515
        }else
516
            fprintf (file, "%s=%s+1", regname2,regname2);
517
      }
518
  else if (verilog == 1)
519
    fprintf (file, "%s-- ", (char *) $1);
520
};
521 20 jcastillo
 
522 12 jcastillo
word:
523
WORD
524
{
525 16 jcastillo
 
526 12 jcastillo
  defineparenthesis = 0;
527
  if (translate == 1 && verilog == 0)
528
    {
529 28 jcastillo
          if(opencorchfound==0){
530
                strcpy (lastword, (char *) $1);
531
          }
532
 
533 12 jcastillo
      if (processfound)
534
        {
535 23 jcastillo
          if(lastswitch){
536
            openedcase=0;
537
          }else if (openedcase)
538 12 jcastillo
            {
539
              fprintf (file, " :\n");
540
 
541
              for (i = 0; i < openedkeys; i++)
542
                fprintf (file, "   ");
543
 
544 23 jcastillo
              fprintf(file,"begin\n");
545
              openedcase=0;
546 12 jcastillo
            }
547
 
548 28 jcastillo
                if (reg_found)
549 12 jcastillo
            {
550 25 jcastillo
              if(writelenght){
551
               writelenght=0;
552
               if(reglenght==0)
553
                fprintf (regs_file, "reg ");
554
               else
555
                fprintf (regs_file, "reg[%d:0] ", (-1 +reglenght));
556
              }
557
 
558 19 jcastillo
              regname = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + 1));
559
              regname2 = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + strlen (processname)) + 1);
560
              strcpy (regname, (char *) $1);
561
              strcpy (regname2, (char *) $1);
562
              strcat (regname2, processname);
563
              fprintf (regs_file, "%s", regname2);
564 12 jcastillo
 
565 19 jcastillo
              regslist = InsertReg (regslist, regname, regname2);
566
              free (regname);
567
              free (regname2);
568
            }
569
          else if(integer_found){
570
              regname = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + 1));
571
              regname2 = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + strlen (processname)) + 1);
572 12 jcastillo
              strcpy (regname, (char *) $1);
573
              strcpy (regname2, (char *) $1);
574
              strcat (regname2, processname);
575 19 jcastillo
              fprintf (regs_file, "%s;\n", regname2);
576 16 jcastillo
 
577
              regslist = InsertReg (regslist, regname, regname2);
578
 
579 19 jcastillo
              //After adding to list print it
580
              fprintf (file, "%s ", regname2);
581
              integer_found=0;
582 16 jcastillo
              free (regname);
583 12 jcastillo
              free (regname2);
584 19 jcastillo
 
585
          }else
586 12 jcastillo
            {
587
              if (newline)
588
                {
589
                  for (i = 0; i < openedkeys; i++)
590
                    fprintf (file, "   ");
591
                }
592 16 jcastillo
              regname2 = IsReg (regslist, (char *) $1);
593 12 jcastillo
              if (regname2 == NULL)
594
                {
595 16 jcastillo
 
596
                  if (IsDefine (defineslist, (char *) $1))
597 12 jcastillo
                    {
598
                      if (ifdeffound == 0)
599 2 jcastillo
                        {
600 12 jcastillo
                          fprintf (file, "`%s", (char *) $1);
601
                          defineinvocationfound = 1;
602 2 jcastillo
                        }
603 12 jcastillo
                      else
604 2 jcastillo
                        {
605 12 jcastillo
                          fprintf (file, "%s", (char *) $1);
606
                          ifdeffound = 0;
607 2 jcastillo
                        }
608 12 jcastillo
                    }
609
                  else
610
                    {
611
                      fprintf (file, "%s ", (char *) $1);
612
                    }
613
                }
614
              else
615
                fprintf (file, "%s", regname2);
616 2 jcastillo
 
617 12 jcastillo
              newline = 0;
618
            }
619
 
620
        }
621
      else if (definefound)
622
        {
623 16 jcastillo
 
624
          if (IsDefine (defineslist, (char *) $1))
625 12 jcastillo
            {
626
 
627
              fprintf (FILE_DEFINES, "`%s", (char *) $1);
628
            }
629
          else
630
            {
631
              fprintf (FILE_DEFINES, "%s ", (char *) $1);
632
            }
633
        }
634
    }
635
  else if (verilog == 1)
636 19 jcastillo
    fprintf (file, "%s ", (char *) $1);
637 23 jcastillo
  lastswitch=0;
638 12 jcastillo
};
639
 
640 2 jcastillo
symbol:
641 12 jcastillo
SYMBOL
642
{
643
  defineparenthesis = 0;
644
  if (translate == 1 && verilog == 0)
645
    {
646
      if (processfound)
647
        {
648
          if (reg_found)
649
            fprintf (regs_file, "%s", (char *) $1);
650
          else
651
            fprintf (file, "%s", (char *) $1);
652
        }
653
      else if (definefound)
654
        {
655
          fprintf (FILE_DEFINES, "%s", (char *) $1);
656
        }
657
    }
658
  else if (verilog == 1)
659
    fprintf (file, "%s", (char *) $1);
660
};
661 2 jcastillo
 
662 19 jcastillo
equal:
663
EQUALS
664
{
665
  defineparenthesis = 0;
666
  reg_found=0;
667
  if (translate == 1 && verilog == 0)
668
  {
669 28 jcastillo
   if (processfound)
670 19 jcastillo
        fprintf (file, "=");
671 28 jcastillo
        writingvar=1;
672 19 jcastillo
  }
673
  else if (definefound)
674
    fprintf (FILE_DEFINES, "=");
675
  else if (verilog == 1)
676
    fprintf (file, "=");
677
 
678
}
679 12 jcastillo
 
680 2 jcastillo
write:
681 12 jcastillo
WRITE
682
{
683
  defineparenthesis = 0;
684
  if (translate == 1 && verilog == 0)
685
    {
686
      writemethod = 1;
687
      if (processfound)
688
        {
689
          fprintf (file, " <= ");
690
          fprintf (FILE_WRITES, "%s\n", lastword);
691
        }
692
      else if (definefound)
693
        {
694
          fprintf (FILE_DEFINES, " <= ");
695
        }
696 2 jcastillo
 
697 12 jcastillo
    }
698
  else if (verilog == 1)
699
    {
700
      fprintf (file, ".write");
701
    }
702
};
703
 
704 2 jcastillo
newline:
705 12 jcastillo
NEWLINE
706
{
707
  defineparenthesis = 0;
708 28 jcastillo
  writingvar=0;
709 12 jcastillo
  if (translate == 1 && verilog == 0)
710
    {
711
      if (processfound & !reg_found & !openedcase)
712
        {
713
          fprintf (file, "\n");
714
          newline = 1;
715
        }
716
      else if (definefound)
717
        {
718
          fprintf (FILE_DEFINES, "\n");
719
        }
720 2 jcastillo
 
721 12 jcastillo
    }
722
  else if (verilog == 1)
723
    fprintf (file, "\n");
724
};
725
 
726 2 jcastillo
colon:
727 12 jcastillo
COLON
728
{
729
  defineparenthesis = 0;
730
  if (translate == 1 && verilog == 0)
731
    {
732
      if (processfound)
733
        {
734
          if (reg_found)
735
            {
736
              fprintf (regs_file, ",");
737
            }
738
          else
739
            fprintf (file, ",");
740
        }
741
      else if (definefound)
742
        {
743
          fprintf (FILE_DEFINES, ",");
744
        }
745
    }
746
  else if (verilog == 1)
747
    fprintf (file, ",");
748
};
749 2 jcastillo
 
750
semicolon:
751 12 jcastillo
SEMICOLON
752
{
753
  defineparenthesis = 0;
754
  if (translate == 1 && verilog == 0)
755
    {
756
      if (processfound)
757
        {
758
          if (reg_found)
759
            {
760
              fprintf (regs_file, ";\n");
761
              reg_found = 0;
762
            }
763
          else
764
            {
765 28 jcastillo
            if (defineinvocationfound == 0 || writingvar)
766
                  fprintf (file, ";");
767 12 jcastillo
            }
768
        }
769
      else if (definefound)
770
        {
771
          fprintf (FILE_DEFINES, ";");
772
        }
773
    }
774
  else if (verilog == 1)
775
    fprintf (file, ";");
776 28 jcastillo
 
777
  writingvar=0;
778 12 jcastillo
  defineinvocationfound = 0;
779
};
780
 
781
 
782 2 jcastillo
openpar:
783 12 jcastillo
OPENPAR
784
{
785
  defineparenthesis = 1;
786
  if (translate == 1 && verilog == 0 && defineinvocationfound == 0)
787
    {
788
      if (processfound)
789
        {
790
          fprintf (file, "(");
791
        }
792
      else if (definefound)
793
        {
794
          fprintf (FILE_DEFINES, "(");
795
        }
796
 
797
    }
798
  else if (verilog == 1)
799
    {
800
      fprintf (file, "(");
801
    }
802 24 jcastillo
  //If par after a sc_reg declaration the declaration is a type cast
803
  reg_found=0;
804 12 jcastillo
}
805
 
806 2 jcastillo
closepar:
807 12 jcastillo
CLOSEPAR
808
{
809
  if (translate == 1 && verilog == 0)
810
    {
811 2 jcastillo
 
812 12 jcastillo
      if (processfound)
813
        {
814
          if (defineparenthesis == 0)
815
            {
816
              fprintf (file, ")");
817
              defineinvocationfound = 0;
818
            }
819
        }
820
      else if (definefound)
821
        {
822
          fprintf (FILE_DEFINES, ")");
823
        }
824
    }
825
  else if (verilog == 1)
826
    fprintf (file, ")");
827
 
828
};
829
 
830
 
831 2 jcastillo
opencorch:
832 12 jcastillo
OPENCORCH
833
{
834
  defineparenthesis = 0;
835
  if (translate == 1 && verilog == 0)
836
    {
837
      if (processfound)
838
        {
839 28 jcastillo
          opencorchfound = 1;
840 12 jcastillo
          if (reg_found)
841
            {
842
              fprintf (regs_file, "[");
843
            }
844
          else
845
            fprintf (file, "[");
846
        }
847
      else if (definefound)
848
        {
849
          fprintf (FILE_DEFINES, "[");
850
 
851
        }
852
    }
853
  else if (verilog == 1)
854
    fprintf (file, "[");
855
};
856
 
857 2 jcastillo
closecorch:
858 12 jcastillo
CLOSECORCH
859
{
860
  defineparenthesis = 0;
861
  if (translate == 1 && verilog == 0)
862
    {
863
      if (processfound)
864 28 jcastillo
          {
865
          opencorchfound = 0;
866 12 jcastillo
          if (reg_found)
867
            {
868
              fprintf (regs_file, "]");
869
            }
870
          else
871
            fprintf (file, "]");
872
        }
873
      else if (definefound)
874
        {
875
          fprintf (FILE_DEFINES, "]");
876
        }
877
    }
878
  else if (verilog == 1)
879
    fprintf (file, "]");
880
};
881
 
882
 
883 2 jcastillo
openkey:
884 12 jcastillo
OPENKEY
885
{
886
  defineparenthesis = 0;
887
  if (translate == 1 && verilog == 0)
888
    {
889
      openedkeys++;
890
      if (!definefound)
891
        {
892
          if (openedkeys == 1)
893
            {
894 14 jcastillo
              printf ("Found process %s\n", processname);
895 12 jcastillo
              file = fopen (processname2, (char *) "w");
896
              regs_file = fopen (fileregs, (char *) "w");
897
              processfound = 1;
898 16 jcastillo
            }
899 12 jcastillo
          if (processfound)
900
            if (openedkeys != switchparenthesis[switchfound])
901
              {
902
                fprintf (file, "\n");
903
                for (i = 0; i < openedkeys; i++)
904
                  fprintf (file, "   ");
905
                fprintf (file, "begin\n");
906
                newline = 1;
907
              }
908
        }
909
    }
910
  else if (verilog == 1)
911
    fprintf (file, "{");
912
};
913 2 jcastillo
 
914
closekey:
915 12 jcastillo
CLOSEKEY
916
{
917
  defineparenthesis = 0;
918
  if (translate == 1 && verilog == 0)
919
    {
920
      if (processfound && !definefound)
921
        {
922
          if (openedkeys == switchparenthesis[switchfound] && switchfound > 0)
923
            {
924
              fprintf (file, "\n");
925
              if (default_found & !default_break_found)
926
                {
927
                  for (i = 0; i < openedkeys - 1; i++)
928
                    fprintf (file, "   ");
929
                  fprintf (file, "end\n");
930
                  default_found = 0;
931
                }
932
              for (i = 0; i < openedkeys - 1; i++)
933 16 jcastillo
                fprintf (file, "   ");
934 12 jcastillo
              fprintf (file, "endcase\n");
935
              newline = 1;
936
              switchparenthesis[switchfound] = 0;
937
              switchfound--;
938 2 jcastillo
 
939 12 jcastillo
            }
940
          else
941
            {
942
              fprintf (file, "\n");
943
              for (i = 0; i < openedkeys; i++)
944 16 jcastillo
                fprintf (file, "   ");
945 12 jcastillo
              fprintf (file, "end\n");
946
              newline = 1;
947
            }
948
        }
949 2 jcastillo
 
950 12 jcastillo
      openedkeys--;
951
      if (definefound)
952
        {
953
          definefound = 0;
954
          if (processfound)
955
            fprintf (file, "\n//Dummy Comment\n");
956
          else
957
            fprintf (FILE_DEFINES, "\n//Dummy Comment\n");
958
        }
959
      else if (openedkeys == 0)
960
        {
961
          fclose (file);
962
          fclose (regs_file);
963
          processfound = 0;
964
        }
965
    }
966
  else if (verilog == 1)
967
    fprintf (file, "}");
968
};
969
 
970
 
971 4 jcastillo
bigger:
972 12 jcastillo
BIGGER
973
{
974
  defineparenthesis = 0;
975
  if (translate == 1 && verilog == 0)
976
    {
977
      if (processfound)
978
        {
979
          fprintf (file, ">");
980
        }
981
      else if (definefound)
982
        {
983
          fprintf (FILE_DEFINES, ">");
984
        }
985
    }
986
  else if (verilog == 1)
987
    fprintf (file, ">");
988
};
989 2 jcastillo
 
990 4 jcastillo
lower:
991 12 jcastillo
LOWER
992
{
993
  defineparenthesis = 0;
994
  if (translate == 1 && verilog == 0)
995
    {
996
      if (processfound)
997
        {
998
          fprintf (file, "<");
999
        }
1000
      else if (definefound)
1001
        {
1002
          fprintf (FILE_DEFINES, "<");
1003
        }
1004
    }
1005
  else if (verilog == 1)
1006
    fprintf (file, "<");
1007
};
1008 2 jcastillo
 
1009 12 jcastillo
 
1010 2 jcastillo
switch:
1011 12 jcastillo
SWITCH
1012
  {
1013
    defineparenthesis = 0;
1014 23 jcastillo
    lastswitch=1;
1015 12 jcastillo
    if (translate == 1 && verilog == 0)
1016
      {
1017 23 jcastillo
        if (processfound && !openedcase)
1018 12 jcastillo
          {
1019
            fprintf (file, "\n");
1020
            for (i = 0; i < openedkeys; i++)
1021
              fprintf (file, "   ");
1022
            fprintf (file, "case");
1023
            switchfound++;
1024
            switchparenthesis[switchfound] = openedkeys + 1;
1025 23 jcastillo
          }else if (processfound)
1026
          {
1027
            fprintf (file, ":\n");
1028
            for (i = 0; i < openedkeys; i++)
1029
              fprintf (file, "   ");
1030
            fprintf(file,"begin\n");
1031
            for (i = 0; i < openedkeys; i++)
1032
              fprintf (file, "   ");
1033
            fprintf (file, "case");
1034
            switchfound++;
1035
            switchparenthesis[switchfound] = openedkeys + 1;
1036 12 jcastillo
          }
1037
      }
1038
    else if (verilog == 1)
1039
      fprintf (file, "switch");
1040
  };
1041
 
1042 2 jcastillo
case_number:
1043 12 jcastillo
CASE NUMBER SYMBOL
1044
{
1045
  defineparenthesis = 0;
1046
  if (translate == 1 && verilog == 0)
1047
    {
1048
      if (processfound)
1049
        {
1050 23 jcastillo
         if (!openedcase)
1051 12 jcastillo
          for (i = 0; i < openedkeys; i++)
1052
            fprintf (file, "   ");
1053
          if (openedcase)
1054
            fprintf (file, ", %d", $2);
1055
          else
1056
            fprintf (file, "%d", $2);
1057 4 jcastillo
 
1058 12 jcastillo
          newline = 1;
1059
          openedcase = 1;
1060
 
1061
        }
1062
    }
1063
  else if (verilog == 1)
1064
    fprintf (file, "case %d %s", $2, (char *) $3);
1065
};
1066
 
1067 19 jcastillo
case_hexnumber:
1068
CASE HEXA NUMBER SYMBOL
1069
{
1070 24 jcastillo
  //Is a dec number
1071 19 jcastillo
  defineparenthesis = 0;
1072
  if (translate == 1 && verilog == 0)
1073
    {
1074
      if (processfound)
1075
        {
1076 23 jcastillo
         if (!openedcase)
1077 19 jcastillo
          for (i = 0; i < openedkeys; i++)
1078
            fprintf (file, "   ");
1079
          if (openedcase)
1080
            fprintf (file, ", 'h%d", $3);
1081
          else
1082
            fprintf (file, "'h%d", $3);
1083
 
1084
          newline = 1;
1085
          openedcase = 1;
1086
 
1087
        }
1088
    }
1089
  else if (verilog == 1)
1090
    fprintf (file, "case %d %s", $3, (char *) $4);
1091
};
1092
 
1093 24 jcastillo
case_hexword:
1094
CASE HEXA WORD SYMBOL
1095
{
1096
  //Begin with a-F
1097
  defineparenthesis = 0;
1098
  if (translate == 1 && verilog == 0)
1099
    {
1100
      if (processfound)
1101
        {
1102
         if (!openedcase)
1103
          for (i = 0; i < openedkeys; i++)
1104
            fprintf (file, "   ");
1105
          if (openedcase)
1106
            fprintf (file, ", 'h%s", (char *)$3);
1107
          else
1108
            fprintf (file, "'h%s", (char *)$3);
1109
 
1110
          newline = 1;
1111
          openedcase = 1;
1112
 
1113
        }
1114
    }
1115
  else if (verilog == 1)
1116
    fprintf (file, "case 0x%s %s", (char *)$3, (char *) $4);
1117
};
1118
 
1119
case_hexnumberword:
1120
CASE HEXA NUMBER WORD SYMBOL
1121
{
1122
  //Hex number beginning with dec number
1123
  defineparenthesis = 0;
1124
  if (translate == 1 && verilog == 0)
1125
    {
1126
      if (processfound)
1127
        {
1128
         if (!openedcase)
1129
          for (i = 0; i < openedkeys; i++)
1130
            fprintf (file, "   ");
1131
          if (openedcase)
1132
            fprintf (file, ", 'h%d%s", $3,(char *)$4);
1133
          else
1134
            fprintf (file, "'h%d%s", $3,(char *)$4);
1135
 
1136
          newline = 1;
1137
          openedcase = 1;
1138
 
1139
        }
1140
    }
1141
  else if (verilog == 1)
1142
    fprintf (file, "case %d%s %s", $3, (char *) $4, (char *)$5);
1143
};
1144
 
1145 4 jcastillo
case_word:
1146 12 jcastillo
CASE WORD SYMBOL
1147
{
1148
  defineparenthesis = 0;
1149
  if (translate == 1 && verilog == 0)
1150
    {
1151
      if (processfound)
1152
        {
1153 23 jcastillo
         if (!openedcase)
1154 12 jcastillo
          for (i = 0; i < openedkeys; i++)
1155
            fprintf (file, "   ");
1156 28 jcastillo
          if (openedcase){
1157
            if (IsDefine (defineslist, (char *) $2))
1158
              fprintf (file, ", `%s", (char *) $2);
1159
                else
1160
                  fprintf (file, ", %s", (char *) $2);
1161
          }else{
1162
            if (IsDefine (defineslist, (char *) $2))
1163
              fprintf (file, "`%s", (char *) $2);
1164
                else
1165
                  fprintf (file, "%s", (char *) $2);
1166
      }
1167 12 jcastillo
          newline = 1;
1168
          openedcase = 1;
1169
 
1170
        }
1171
    }
1172
  else if (verilog == 1)
1173
    fprintf (file, "case %s %s", (char *) $2, (char *) $3);
1174
};
1175
 
1176 2 jcastillo
case_default:
1177 12 jcastillo
DEFAULT SYMBOL
1178
{
1179
  defineparenthesis = 0;
1180
  if (translate == 1 && verilog == 0)
1181
    {
1182
      if (processfound)
1183
        {
1184 23 jcastillo
         if (!openedcase)
1185 12 jcastillo
          for (i = 0; i < openedkeys; i++)
1186
            fprintf (file, "   ");
1187
          fprintf (file, "default:\n");
1188
          for (i = 0; i < openedkeys; i++)
1189
            fprintf (file, "   ");
1190
          fprintf (file, "begin\n");
1191
          newline = 1;
1192
          default_found = 1;
1193
        }
1194
    }
1195
  else if (verilog == 1)
1196
    fprintf (file, "default %s", (char *) $2);
1197
};
1198 2 jcastillo
 
1199 4 jcastillo
case_only:
1200 12 jcastillo
CASE OPENPAR
1201
{
1202
  defineparenthesis = 0;
1203
  //This rule occurs when in Verilog mode a case appears
1204
  if (verilog == 1)
1205
    fprintf (file, "case(");
1206
};
1207 4 jcastillo
 
1208 2 jcastillo
break:
1209 12 jcastillo
BREAK SEMICOLON
1210
{
1211
  defineparenthesis = 0;
1212
  if (translate == 1 && verilog == 0)
1213
    {
1214
      if (processfound)
1215
        {
1216
          if (newline == 0)
1217
            fprintf (file, "\n");
1218
          for (i = 0; i < openedkeys; i++)
1219
            fprintf (file, "   ");
1220
          fprintf (file, "end\n");
1221
          if (default_found)
1222
            {
1223
              default_break_found = 1;
1224
            }
1225
        }
1226
    }
1227
  else if (verilog == 1)
1228
    fprintf (file, "break;");
1229
};
1230 2 jcastillo
 
1231
hexa:
1232 12 jcastillo
HEXA
1233
{
1234
  defineparenthesis = 0;
1235
  if (translate == 1 && verilog == 0)
1236
    {
1237
      if (processfound)
1238
        {
1239
          fprintf (file, "'h");
1240
        }
1241
      else if (definefound)
1242
        {
1243
          fprintf (FILE_DEFINES, "'h");
1244
        }
1245
    }
1246
  else if (verilog == 1)
1247
    fprintf (file, "0x");
1248
};
1249
 
1250 4 jcastillo
translateoff:
1251 12 jcastillo
TRANSLATEOFF
1252
{
1253
  defineparenthesis = 0;
1254
  translate = 0;
1255 15 jcastillo
  fprintf (stderr, "line: %d Found Translate off directive \n", lineno);
1256 12 jcastillo
};
1257 4 jcastillo
 
1258
translateon:
1259 12 jcastillo
TRANSLATEON
1260
{
1261
  defineparenthesis = 0;
1262
  translate = 1;
1263 15 jcastillo
  fprintf (stderr, "line: %d Found Translate on directive \n", lineno);
1264 12 jcastillo
};
1265
 
1266 4 jcastillo
verilogbegin:
1267 12 jcastillo
VERILOGBEGIN
1268
{
1269
  defineparenthesis = 0;
1270
  verilog = 1;
1271 15 jcastillo
  fprintf (stderr, "line: %d Found Verilog Begin directive \n", lineno);
1272 12 jcastillo
};
1273 4 jcastillo
 
1274
verilogend:
1275 12 jcastillo
VERILOGEND
1276
{
1277
  defineparenthesis = 0;
1278
  verilog = 0;
1279 15 jcastillo
  fprintf (stderr, "line: %d Found Verilog End directive \n", lineno);
1280 12 jcastillo
};
1281 4 jcastillo
 
1282
ifdef:
1283 12 jcastillo
PIFDEF
1284
{
1285
  defineparenthesis = 0;
1286
  if (translate == 1 && verilog == 0)
1287
    {
1288
      if (processfound)
1289
        {
1290
          ifdeffound = 1;
1291
          fprintf (file, "`ifdef");
1292
        }
1293
      else if (definefound)
1294
        {
1295
          fprintf (FILE_DEFINES, "`ifdef");
1296
        }
1297
    }
1298
  else if (verilog == 1)
1299
    fprintf (file, "#ifdef");
1300
};
1301
 
1302 27 jcastillo
ifndef:
1303
PIFNDEF
1304
{
1305
  defineparenthesis = 0;
1306
  if (translate == 1 && verilog == 0)
1307
    {
1308
      if (processfound)
1309
        {
1310
          ifdeffound = 1;
1311
          fprintf (file, "`ifndef");
1312
        }
1313
      else if (definefound)
1314
        {
1315
          fprintf (FILE_DEFINES, "`ifndef");
1316
        }
1317
    }
1318
  else if (verilog == 1)
1319
    fprintf (file, "#ifndef");
1320
};
1321
 
1322 4 jcastillo
endif:
1323 12 jcastillo
PENDDEF
1324
{
1325
  defineparenthesis = 0;
1326
  if (translate == 1 && verilog == 0)
1327
    {
1328
      if (processfound)
1329
        {
1330
          fprintf (file, "`endif");
1331
        }
1332
      else if (definefound)
1333
        {
1334
          fprintf (FILE_DEFINES, "`endif");
1335
        }
1336
    }
1337
  else if (verilog == 1)
1338
    fprintf (file, "#endif");
1339
};
1340
 
1341 6 jcastillo
pelse:
1342 12 jcastillo
PELSE
1343
{
1344
  defineparenthesis = 0;
1345
  if (translate == 1 && verilog == 0)
1346
    {
1347
      if (processfound)
1348
        {
1349
          fprintf (file, "`else");
1350
        }
1351
      else if (definefound)
1352
        {
1353
          fprintf (FILE_DEFINES, "`else");
1354
        }
1355
    }
1356
  else if (verilog == 1)
1357
    fprintf (file, "#else");
1358
};
1359
 
1360 6 jcastillo
ttrue:
1361 12 jcastillo
TTRUE
1362
{
1363
  defineparenthesis = 0;
1364
  if (translate == 1 && verilog == 0)
1365
    {
1366
      if (processfound)
1367
        {
1368
          fprintf (file, "1");
1369
        }
1370
    }
1371
  else if (verilog == 1)
1372
    fprintf (file, "1");
1373
};
1374 6 jcastillo
 
1375
 
1376
tfalse:
1377 12 jcastillo
TFALSE
1378
{
1379
  defineparenthesis = 0;
1380
  if (translate == 1 && verilog == 0)
1381
    {
1382
      if (processfound)
1383
        {
1384
          fprintf (file, "0");
1385
        }
1386
    }
1387
  else if (verilog == 1)
1388
    fprintf (file, "0");
1389
};
1390 28 jcastillo
 
1391
comment:
1392
COMMENT
1393
{
1394
if(processfound){
1395
  //To manage comments inside switch statements
1396
  if(lastswitch){
1397
        openedcase=0;
1398
  }else if (openedcase){
1399
        fprintf (file, " :\n");
1400
      for (i = 0; i < openedkeys; i++)
1401
                fprintf (file, "   ");
1402
        fprintf(file,"begin\n");
1403
        openedcase=0;
1404
  }
1405
  //indent
1406
  if(newline){
1407
    for (i = 0; i < openedkeys; i++)
1408
          fprintf (file, "   ");
1409
        newline=0;
1410
  }
1411
  fprintf (file, " %s", (char *)$1);
1412
 }
1413
}

powered by: WebSVN 2.1.0

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