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

Subversion Repositories sc2v

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

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

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

powered by: WebSVN 2.1.0

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