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

Subversion Repositories sc2v

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

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

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

powered by: WebSVN 2.1.0

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