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

Subversion Repositories sc2v

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

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 2 jcastillo
 
62 12 jcastillo
  int openedcase = 0;
63 2 jcastillo
 
64 12 jcastillo
  int default_break_found = 0;
65
  int default_found;
66 2 jcastillo
 
67 4 jcastillo
//Directives variables
68 12 jcastillo
  int translate;
69
  int verilog;
70
  int writemethod;
71 4 jcastillo
 
72 12 jcastillo
  void yyerror (const char *str)
73
  {
74 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 27 jcastillo
%token PIFDEF PIFNDEF PENDDEF PELSE
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
  minorequal;
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
      if (processfound)
528
        {
529 23 jcastillo
          if(lastswitch){
530
            openedcase=0;
531
          }else if (openedcase)
532 12 jcastillo
            {
533
              fprintf (file, " :\n");
534
 
535
              for (i = 0; i < openedkeys; i++)
536
                fprintf (file, "   ");
537
 
538 23 jcastillo
              fprintf(file,"begin\n");
539
              openedcase=0;
540 12 jcastillo
            }
541
 
542
          strcpy (lastword, (char *) $1);
543
 
544
          if (reg_found)
545
            {
546 25 jcastillo
              if(writelenght){
547
               writelenght=0;
548
               if(reglenght==0)
549
                fprintf (regs_file, "reg ");
550
               else
551
                fprintf (regs_file, "reg[%d:0] ", (-1 +reglenght));
552
              }
553
 
554 19 jcastillo
              regname = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + 1));
555
              regname2 = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + strlen (processname)) + 1);
556
              strcpy (regname, (char *) $1);
557
              strcpy (regname2, (char *) $1);
558
              strcat (regname2, processname);
559
              fprintf (regs_file, "%s", regname2);
560 12 jcastillo
 
561 19 jcastillo
              regslist = InsertReg (regslist, regname, regname2);
562
              free (regname);
563
              free (regname2);
564
            }
565
          else if(integer_found){
566
              regname = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + 1));
567
              regname2 = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + strlen (processname)) + 1);
568 12 jcastillo
              strcpy (regname, (char *) $1);
569
              strcpy (regname2, (char *) $1);
570
              strcat (regname2, processname);
571 19 jcastillo
              fprintf (regs_file, "%s;\n", regname2);
572 16 jcastillo
 
573
              regslist = InsertReg (regslist, regname, regname2);
574
 
575 19 jcastillo
              //After adding to list print it
576
              fprintf (file, "%s ", regname2);
577
              integer_found=0;
578 16 jcastillo
              free (regname);
579 12 jcastillo
              free (regname2);
580 19 jcastillo
 
581
          }else
582 12 jcastillo
            {
583
              if (newline)
584
                {
585
                  for (i = 0; i < openedkeys; i++)
586
                    fprintf (file, "   ");
587
                }
588 16 jcastillo
              regname2 = IsReg (regslist, (char *) $1);
589 12 jcastillo
              if (regname2 == NULL)
590
                {
591 16 jcastillo
 
592
                  if (IsDefine (defineslist, (char *) $1))
593 12 jcastillo
                    {
594
                      if (ifdeffound == 0)
595 2 jcastillo
                        {
596 12 jcastillo
                          fprintf (file, "`%s", (char *) $1);
597
                          defineinvocationfound = 1;
598 2 jcastillo
                        }
599 12 jcastillo
                      else
600 2 jcastillo
                        {
601 12 jcastillo
                          fprintf (file, "%s", (char *) $1);
602
                          ifdeffound = 0;
603 2 jcastillo
                        }
604 12 jcastillo
                    }
605
                  else
606
                    {
607
                      fprintf (file, "%s ", (char *) $1);
608
                    }
609
                }
610
              else
611
                fprintf (file, "%s", regname2);
612 2 jcastillo
 
613 12 jcastillo
              newline = 0;
614
            }
615
 
616
        }
617
      else if (definefound)
618
        {
619 16 jcastillo
 
620
          if (IsDefine (defineslist, (char *) $1))
621 12 jcastillo
            {
622
 
623
              fprintf (FILE_DEFINES, "`%s", (char *) $1);
624
            }
625
          else
626
            {
627
              fprintf (FILE_DEFINES, "%s ", (char *) $1);
628
            }
629
        }
630
    }
631
  else if (verilog == 1)
632 19 jcastillo
    fprintf (file, "%s ", (char *) $1);
633 23 jcastillo
  lastswitch=0;
634 12 jcastillo
};
635
 
636 2 jcastillo
symbol:
637 12 jcastillo
SYMBOL
638
{
639
  defineparenthesis = 0;
640
  if (translate == 1 && verilog == 0)
641
    {
642
      if (processfound)
643
        {
644
          if (reg_found)
645
            fprintf (regs_file, "%s", (char *) $1);
646
          else
647
            fprintf (file, "%s", (char *) $1);
648
        }
649
      else if (definefound)
650
        {
651
          fprintf (FILE_DEFINES, "%s", (char *) $1);
652
        }
653
    }
654
  else if (verilog == 1)
655
    fprintf (file, "%s", (char *) $1);
656
};
657 2 jcastillo
 
658 19 jcastillo
equal:
659
EQUALS
660
{
661
  defineparenthesis = 0;
662
  reg_found=0;
663
  if (translate == 1 && verilog == 0)
664
  {
665
      if (processfound)
666
        fprintf (file, "=");
667
  }
668
  else if (definefound)
669
    fprintf (FILE_DEFINES, "=");
670
  else if (verilog == 1)
671
    fprintf (file, "=");
672
 
673
}
674 12 jcastillo
 
675 2 jcastillo
write:
676 12 jcastillo
WRITE
677
{
678
  defineparenthesis = 0;
679
  if (translate == 1 && verilog == 0)
680
    {
681
      writemethod = 1;
682
      if (processfound)
683
        {
684
          fprintf (file, " <= ");
685
          fprintf (FILE_WRITES, "%s\n", lastword);
686
        }
687
      else if (definefound)
688
        {
689
          fprintf (FILE_DEFINES, " <= ");
690
        }
691 2 jcastillo
 
692 12 jcastillo
    }
693
  else if (verilog == 1)
694
    {
695
      fprintf (file, ".write");
696
    }
697
};
698
 
699 2 jcastillo
newline:
700 12 jcastillo
NEWLINE
701
{
702
  defineparenthesis = 0;
703
  if (translate == 1 && verilog == 0)
704
    {
705
      if (processfound & !reg_found & !openedcase)
706
        {
707
          fprintf (file, "\n");
708
          newline = 1;
709
        }
710
      else if (definefound)
711
        {
712
          fprintf (FILE_DEFINES, "\n");
713
        }
714 2 jcastillo
 
715 12 jcastillo
    }
716
  else if (verilog == 1)
717
    fprintf (file, "\n");
718
};
719
 
720 2 jcastillo
colon:
721 12 jcastillo
COLON
722
{
723
  defineparenthesis = 0;
724
  if (translate == 1 && verilog == 0)
725
    {
726
      if (processfound)
727
        {
728
          if (reg_found)
729
            {
730
              fprintf (regs_file, ",");
731
            }
732
          else
733
            fprintf (file, ",");
734
        }
735
      else if (definefound)
736
        {
737
          fprintf (FILE_DEFINES, ",");
738
        }
739
    }
740
  else if (verilog == 1)
741
    fprintf (file, ",");
742
};
743 2 jcastillo
 
744
semicolon:
745 12 jcastillo
SEMICOLON
746
{
747
  defineparenthesis = 0;
748
  if (translate == 1 && verilog == 0)
749
    {
750
      if (processfound)
751
        {
752
          if (reg_found)
753
            {
754
              fprintf (regs_file, ";\n");
755
              reg_found = 0;
756
            }
757
          else
758
            {
759
              if (defineinvocationfound == 0)
760
                fprintf (file, ";");
761
            }
762
        }
763
      else if (definefound)
764
        {
765
          fprintf (FILE_DEFINES, ";");
766
        }
767
    }
768
  else if (verilog == 1)
769
    fprintf (file, ";");
770 2 jcastillo
 
771 12 jcastillo
  defineinvocationfound = 0;
772
};
773
 
774
 
775 2 jcastillo
openpar:
776 12 jcastillo
OPENPAR
777
{
778
  defineparenthesis = 1;
779
  if (translate == 1 && verilog == 0 && defineinvocationfound == 0)
780
    {
781
      if (processfound)
782
        {
783
          fprintf (file, "(");
784
        }
785
      else if (definefound)
786
        {
787
          fprintf (FILE_DEFINES, "(");
788
        }
789
 
790
    }
791
  else if (verilog == 1)
792
    {
793
      fprintf (file, "(");
794
    }
795 24 jcastillo
  //If par after a sc_reg declaration the declaration is a type cast
796
  reg_found=0;
797 12 jcastillo
}
798
 
799 2 jcastillo
closepar:
800 12 jcastillo
CLOSEPAR
801
{
802
  if (translate == 1 && verilog == 0)
803
    {
804 2 jcastillo
 
805 12 jcastillo
      if (processfound)
806
        {
807
          if (defineparenthesis == 0)
808
            {
809
              fprintf (file, ")");
810
              defineinvocationfound = 0;
811
            }
812
        }
813
      else if (definefound)
814
        {
815
          fprintf (FILE_DEFINES, ")");
816
        }
817
    }
818
  else if (verilog == 1)
819
    fprintf (file, ")");
820
 
821
};
822
 
823
 
824 2 jcastillo
opencorch:
825 12 jcastillo
OPENCORCH
826
{
827
  defineparenthesis = 0;
828
  if (translate == 1 && verilog == 0)
829
    {
830
      if (processfound)
831
        {
832
          if (reg_found)
833
            {
834
              fprintf (regs_file, "[");
835
              opencorchfound = 1;
836
            }
837
          else
838
            fprintf (file, "[");
839
        }
840
      else if (definefound)
841
        {
842
          fprintf (FILE_DEFINES, "[");
843
 
844
        }
845
    }
846
  else if (verilog == 1)
847
    fprintf (file, "[");
848
};
849
 
850 2 jcastillo
closecorch:
851 12 jcastillo
CLOSECORCH
852
{
853
  defineparenthesis = 0;
854
  if (translate == 1 && verilog == 0)
855
    {
856
      if (processfound)
857
        {
858
          if (reg_found)
859
            {
860
              fprintf (regs_file, "]");
861
              opencorchfound = 0;
862
            }
863
          else
864
            fprintf (file, "]");
865
        }
866
      else if (definefound)
867
        {
868
          fprintf (FILE_DEFINES, "]");
869
        }
870
    }
871
  else if (verilog == 1)
872
    fprintf (file, "]");
873
};
874
 
875
 
876 2 jcastillo
openkey:
877 12 jcastillo
OPENKEY
878
{
879
  defineparenthesis = 0;
880
  if (translate == 1 && verilog == 0)
881
    {
882
      openedkeys++;
883
      if (!definefound)
884
        {
885
          if (openedkeys == 1)
886
            {
887 14 jcastillo
              printf ("Found process %s\n", processname);
888 12 jcastillo
              file = fopen (processname2, (char *) "w");
889
              regs_file = fopen (fileregs, (char *) "w");
890
              processfound = 1;
891 16 jcastillo
            }
892 12 jcastillo
          if (processfound)
893
            if (openedkeys != switchparenthesis[switchfound])
894
              {
895
                fprintf (file, "\n");
896
                for (i = 0; i < openedkeys; i++)
897
                  fprintf (file, "   ");
898
                fprintf (file, "begin\n");
899
                newline = 1;
900
              }
901
        }
902
    }
903
  else if (verilog == 1)
904
    fprintf (file, "{");
905
};
906 2 jcastillo
 
907
closekey:
908 12 jcastillo
CLOSEKEY
909
{
910
  defineparenthesis = 0;
911
  if (translate == 1 && verilog == 0)
912
    {
913
      if (processfound && !definefound)
914
        {
915
          if (openedkeys == switchparenthesis[switchfound] && switchfound > 0)
916
            {
917
              fprintf (file, "\n");
918
              if (default_found & !default_break_found)
919
                {
920
                  for (i = 0; i < openedkeys - 1; i++)
921
                    fprintf (file, "   ");
922
                  fprintf (file, "end\n");
923
                  default_found = 0;
924
                }
925
              for (i = 0; i < openedkeys - 1; i++)
926 16 jcastillo
                fprintf (file, "   ");
927 12 jcastillo
              fprintf (file, "endcase\n");
928
              newline = 1;
929
              switchparenthesis[switchfound] = 0;
930
              switchfound--;
931 2 jcastillo
 
932 12 jcastillo
            }
933
          else
934
            {
935
              fprintf (file, "\n");
936
              for (i = 0; i < openedkeys; i++)
937 16 jcastillo
                fprintf (file, "   ");
938 12 jcastillo
              fprintf (file, "end\n");
939
              newline = 1;
940
            }
941
        }
942 2 jcastillo
 
943 12 jcastillo
      openedkeys--;
944
      if (definefound)
945
        {
946
          definefound = 0;
947
          if (processfound)
948
            fprintf (file, "\n//Dummy Comment\n");
949
          else
950
            fprintf (FILE_DEFINES, "\n//Dummy Comment\n");
951
        }
952
      else if (openedkeys == 0)
953
        {
954
          fclose (file);
955
          fclose (regs_file);
956
          processfound = 0;
957
        }
958
    }
959
  else if (verilog == 1)
960
    fprintf (file, "}");
961
};
962
 
963
 
964 4 jcastillo
bigger:
965 12 jcastillo
BIGGER
966
{
967
  defineparenthesis = 0;
968
  if (translate == 1 && verilog == 0)
969
    {
970
      if (processfound)
971
        {
972
          fprintf (file, ">");
973
        }
974
      else if (definefound)
975
        {
976
          fprintf (FILE_DEFINES, ">");
977
        }
978
    }
979
  else if (verilog == 1)
980
    fprintf (file, ">");
981
};
982 2 jcastillo
 
983 4 jcastillo
lower:
984 12 jcastillo
LOWER
985
{
986
  defineparenthesis = 0;
987
  if (translate == 1 && verilog == 0)
988
    {
989
      if (processfound)
990
        {
991
          fprintf (file, "<");
992
        }
993
      else if (definefound)
994
        {
995
          fprintf (FILE_DEFINES, "<");
996
        }
997
    }
998
  else if (verilog == 1)
999
    fprintf (file, "<");
1000
};
1001 2 jcastillo
 
1002 12 jcastillo
 
1003 2 jcastillo
switch:
1004 12 jcastillo
SWITCH
1005
  {
1006
    defineparenthesis = 0;
1007 23 jcastillo
    lastswitch=1;
1008 12 jcastillo
    if (translate == 1 && verilog == 0)
1009
      {
1010 23 jcastillo
        if (processfound && !openedcase)
1011 12 jcastillo
          {
1012
            fprintf (file, "\n");
1013
            for (i = 0; i < openedkeys; i++)
1014
              fprintf (file, "   ");
1015
            fprintf (file, "case");
1016
            switchfound++;
1017
            switchparenthesis[switchfound] = openedkeys + 1;
1018 23 jcastillo
          }else if (processfound)
1019
          {
1020
            fprintf (file, ":\n");
1021
            for (i = 0; i < openedkeys; i++)
1022
              fprintf (file, "   ");
1023
            fprintf(file,"begin\n");
1024
            for (i = 0; i < openedkeys; i++)
1025
              fprintf (file, "   ");
1026
            fprintf (file, "case");
1027
            switchfound++;
1028
            switchparenthesis[switchfound] = openedkeys + 1;
1029 12 jcastillo
          }
1030
      }
1031
    else if (verilog == 1)
1032
      fprintf (file, "switch");
1033
  };
1034
 
1035 2 jcastillo
case_number:
1036 12 jcastillo
CASE NUMBER SYMBOL
1037
{
1038
  defineparenthesis = 0;
1039
  if (translate == 1 && verilog == 0)
1040
    {
1041
      if (processfound)
1042
        {
1043 23 jcastillo
         if (!openedcase)
1044 12 jcastillo
          for (i = 0; i < openedkeys; i++)
1045
            fprintf (file, "   ");
1046
          if (openedcase)
1047
            fprintf (file, ", %d", $2);
1048
          else
1049
            fprintf (file, "%d", $2);
1050 4 jcastillo
 
1051 12 jcastillo
          newline = 1;
1052
          openedcase = 1;
1053
 
1054
        }
1055
    }
1056
  else if (verilog == 1)
1057
    fprintf (file, "case %d %s", $2, (char *) $3);
1058
};
1059
 
1060 19 jcastillo
case_hexnumber:
1061
CASE HEXA NUMBER SYMBOL
1062
{
1063 24 jcastillo
  //Is a dec number
1064 19 jcastillo
  defineparenthesis = 0;
1065
  if (translate == 1 && verilog == 0)
1066
    {
1067
      if (processfound)
1068
        {
1069 23 jcastillo
         if (!openedcase)
1070 19 jcastillo
          for (i = 0; i < openedkeys; i++)
1071
            fprintf (file, "   ");
1072
          if (openedcase)
1073
            fprintf (file, ", 'h%d", $3);
1074
          else
1075
            fprintf (file, "'h%d", $3);
1076
 
1077
          newline = 1;
1078
          openedcase = 1;
1079
 
1080
        }
1081
    }
1082
  else if (verilog == 1)
1083
    fprintf (file, "case %d %s", $3, (char *) $4);
1084
};
1085
 
1086 24 jcastillo
case_hexword:
1087
CASE HEXA WORD SYMBOL
1088
{
1089
  //Begin with a-F
1090
  defineparenthesis = 0;
1091
  if (translate == 1 && verilog == 0)
1092
    {
1093
      if (processfound)
1094
        {
1095
         if (!openedcase)
1096
          for (i = 0; i < openedkeys; i++)
1097
            fprintf (file, "   ");
1098
          if (openedcase)
1099
            fprintf (file, ", 'h%s", (char *)$3);
1100
          else
1101
            fprintf (file, "'h%s", (char *)$3);
1102
 
1103
          newline = 1;
1104
          openedcase = 1;
1105
 
1106
        }
1107
    }
1108
  else if (verilog == 1)
1109
    fprintf (file, "case 0x%s %s", (char *)$3, (char *) $4);
1110
};
1111
 
1112
case_hexnumberword:
1113
CASE HEXA NUMBER WORD SYMBOL
1114
{
1115
  //Hex number beginning with dec number
1116
  defineparenthesis = 0;
1117
  if (translate == 1 && verilog == 0)
1118
    {
1119
      if (processfound)
1120
        {
1121
         if (!openedcase)
1122
          for (i = 0; i < openedkeys; i++)
1123
            fprintf (file, "   ");
1124
          if (openedcase)
1125
            fprintf (file, ", 'h%d%s", $3,(char *)$4);
1126
          else
1127
            fprintf (file, "'h%d%s", $3,(char *)$4);
1128
 
1129
          newline = 1;
1130
          openedcase = 1;
1131
 
1132
        }
1133
    }
1134
  else if (verilog == 1)
1135
    fprintf (file, "case %d%s %s", $3, (char *) $4, (char *)$5);
1136
};
1137
 
1138 4 jcastillo
case_word:
1139 12 jcastillo
CASE WORD SYMBOL
1140
{
1141
  defineparenthesis = 0;
1142
  if (translate == 1 && verilog == 0)
1143
    {
1144
      if (processfound)
1145
        {
1146 23 jcastillo
         if (!openedcase)
1147 12 jcastillo
          for (i = 0; i < openedkeys; i++)
1148
            fprintf (file, "   ");
1149
          if (openedcase)
1150
            fprintf (file, ", %s", (char *) $2);
1151
          else
1152
            fprintf (file, "%s", (char *) $2);
1153
 
1154
          newline = 1;
1155
          openedcase = 1;
1156
 
1157
        }
1158
    }
1159
  else if (verilog == 1)
1160
    fprintf (file, "case %s %s", (char *) $2, (char *) $3);
1161
};
1162
 
1163 2 jcastillo
case_default:
1164 12 jcastillo
DEFAULT SYMBOL
1165
{
1166
  defineparenthesis = 0;
1167
  if (translate == 1 && verilog == 0)
1168
    {
1169
      if (processfound)
1170
        {
1171 23 jcastillo
         if (!openedcase)
1172 12 jcastillo
          for (i = 0; i < openedkeys; i++)
1173
            fprintf (file, "   ");
1174
          fprintf (file, "default:\n");
1175
          for (i = 0; i < openedkeys; i++)
1176
            fprintf (file, "   ");
1177
          fprintf (file, "begin\n");
1178
          newline = 1;
1179
          default_found = 1;
1180
        }
1181
    }
1182
  else if (verilog == 1)
1183
    fprintf (file, "default %s", (char *) $2);
1184
};
1185 2 jcastillo
 
1186 4 jcastillo
case_only:
1187 12 jcastillo
CASE OPENPAR
1188
{
1189
  defineparenthesis = 0;
1190
  //This rule occurs when in Verilog mode a case appears
1191
  if (verilog == 1)
1192
    fprintf (file, "case(");
1193
};
1194 4 jcastillo
 
1195 2 jcastillo
break:
1196 12 jcastillo
BREAK SEMICOLON
1197
{
1198
  defineparenthesis = 0;
1199
  if (translate == 1 && verilog == 0)
1200
    {
1201
      if (processfound)
1202
        {
1203
          if (newline == 0)
1204
            fprintf (file, "\n");
1205
          for (i = 0; i < openedkeys; i++)
1206
            fprintf (file, "   ");
1207
          fprintf (file, "end\n");
1208
          if (default_found)
1209
            {
1210
              default_break_found = 1;
1211
            }
1212
        }
1213
    }
1214
  else if (verilog == 1)
1215
    fprintf (file, "break;");
1216
};
1217 2 jcastillo
 
1218
hexa:
1219 12 jcastillo
HEXA
1220
{
1221
  defineparenthesis = 0;
1222
  if (translate == 1 && verilog == 0)
1223
    {
1224
      if (processfound)
1225
        {
1226
          fprintf (file, "'h");
1227
        }
1228
      else if (definefound)
1229
        {
1230
          fprintf (FILE_DEFINES, "'h");
1231
        }
1232
    }
1233
  else if (verilog == 1)
1234
    fprintf (file, "0x");
1235
};
1236
 
1237 4 jcastillo
translateoff:
1238 12 jcastillo
TRANSLATEOFF
1239
{
1240
  defineparenthesis = 0;
1241
  translate = 0;
1242 15 jcastillo
  fprintf (stderr, "line: %d Found Translate off directive \n", lineno);
1243 12 jcastillo
};
1244 4 jcastillo
 
1245
translateon:
1246 12 jcastillo
TRANSLATEON
1247
{
1248
  defineparenthesis = 0;
1249
  translate = 1;
1250 15 jcastillo
  fprintf (stderr, "line: %d Found Translate on directive \n", lineno);
1251 12 jcastillo
};
1252
 
1253 4 jcastillo
verilogbegin:
1254 12 jcastillo
VERILOGBEGIN
1255
{
1256
  defineparenthesis = 0;
1257
  verilog = 1;
1258 15 jcastillo
  fprintf (stderr, "line: %d Found Verilog Begin directive \n", lineno);
1259 12 jcastillo
};
1260 4 jcastillo
 
1261
verilogend:
1262 12 jcastillo
VERILOGEND
1263
{
1264
  defineparenthesis = 0;
1265
  verilog = 0;
1266 15 jcastillo
  fprintf (stderr, "line: %d Found Verilog End directive \n", lineno);
1267 12 jcastillo
};
1268 4 jcastillo
 
1269
ifdef:
1270 12 jcastillo
PIFDEF
1271
{
1272
  defineparenthesis = 0;
1273
  if (translate == 1 && verilog == 0)
1274
    {
1275
      if (processfound)
1276
        {
1277
          ifdeffound = 1;
1278
          fprintf (file, "`ifdef");
1279
        }
1280
      else if (definefound)
1281
        {
1282
          fprintf (FILE_DEFINES, "`ifdef");
1283
        }
1284
    }
1285
  else if (verilog == 1)
1286
    fprintf (file, "#ifdef");
1287
};
1288
 
1289 27 jcastillo
ifndef:
1290
PIFNDEF
1291
{
1292
  defineparenthesis = 0;
1293
  if (translate == 1 && verilog == 0)
1294
    {
1295
      if (processfound)
1296
        {
1297
          ifdeffound = 1;
1298
          fprintf (file, "`ifndef");
1299
        }
1300
      else if (definefound)
1301
        {
1302
          fprintf (FILE_DEFINES, "`ifndef");
1303
        }
1304
    }
1305
  else if (verilog == 1)
1306
    fprintf (file, "#ifndef");
1307
};
1308
 
1309 4 jcastillo
endif:
1310 12 jcastillo
PENDDEF
1311
{
1312
  defineparenthesis = 0;
1313
  if (translate == 1 && verilog == 0)
1314
    {
1315
      if (processfound)
1316
        {
1317
          fprintf (file, "`endif");
1318
        }
1319
      else if (definefound)
1320
        {
1321
          fprintf (FILE_DEFINES, "`endif");
1322
        }
1323
    }
1324
  else if (verilog == 1)
1325
    fprintf (file, "#endif");
1326
};
1327
 
1328 6 jcastillo
pelse:
1329 12 jcastillo
PELSE
1330
{
1331
  defineparenthesis = 0;
1332
  if (translate == 1 && verilog == 0)
1333
    {
1334
      if (processfound)
1335
        {
1336
          fprintf (file, "`else");
1337
        }
1338
      else if (definefound)
1339
        {
1340
          fprintf (FILE_DEFINES, "`else");
1341
        }
1342
    }
1343
  else if (verilog == 1)
1344
    fprintf (file, "#else");
1345
};
1346
 
1347 6 jcastillo
ttrue:
1348 12 jcastillo
TTRUE
1349
{
1350
  defineparenthesis = 0;
1351
  if (translate == 1 && verilog == 0)
1352
    {
1353
      if (processfound)
1354
        {
1355
          fprintf (file, "1");
1356
        }
1357
    }
1358
  else if (verilog == 1)
1359
    fprintf (file, "1");
1360
};
1361 6 jcastillo
 
1362
 
1363
tfalse:
1364 12 jcastillo
TFALSE
1365
{
1366
  defineparenthesis = 0;
1367
  if (translate == 1 && verilog == 0)
1368
    {
1369
      if (processfound)
1370
        {
1371
          fprintf (file, "0");
1372
        }
1373
    }
1374
  else if (verilog == 1)
1375
    fprintf (file, "0");
1376
};

powered by: WebSVN 2.1.0

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