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

Subversion Repositories sc2v

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

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

powered by: WebSVN 2.1.0

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