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

Subversion Repositories sc2v

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

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

powered by: WebSVN 2.1.0

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