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

Subversion Repositories sc2v

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

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

powered by: WebSVN 2.1.0

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