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

Subversion Repositories sc2v

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

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

powered by: WebSVN 2.1.0

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