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

Subversion Repositories sc2v

[/] [sc2v/] [trunk/] [src/] [sc2v_step1.y] - Diff between revs 31 and 33

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 31 Rev 33
Line 21... Line 21...
 
 
 
 
%{
%{
#include 
#include 
#include 
#include 
 
#include "sglib.h"
#include "sc2v_step1.h"
#include "sc2v_step1.h"
 
 
  int lineno = 1;
  int lineno = 1;
  int processfound = 0;
  int processfound = 0;
  int switchfound = 0;
  int switchfound = 0;
Line 60... Line 60...
  int writingvar=0;
  int writingvar=0;
 
 
  int default_break_found = 0;
  int default_break_found = 0;
  int default_found;
  int default_found;
 
 
 
  int struct_found=0;
 
  int end_struct=0;
 
  int ignore_semicolon=0;
 
  char *structname;
 
 
//Directives variables
//Directives variables
  int translate;
  int translate;
  int verilog;
  int verilog;
  int writemethod;
  int writemethod;
 
 
Line 81... Line 86...
  {
  {
    int i;
    int i;
 
 
    defineslist = NULL;
    defineslist = NULL;
    regslist = NULL;
    regslist = NULL;
 
    structslist = NULL;
 
    structsreglist = NULL;
 
 
    fprintf (stderr, "\nSystemC to Verilog Translator v0.4");
    fprintf (stderr, "\nSystemC to Verilog Translator v0.4");
    fprintf (stderr,
    fprintf (stderr,
             "\nProvided by OpenSoc http://www.opensocdesign.com\n\n");
             "\nProvided by URJC(Universidad Rey Juan Carlos)\nhttp://www.escet.urjc.es/~jmartine\n\n");
    fprintf (stderr, "Parsing implementation file.......\n\n");
    fprintf (stderr, "Parsing implementation file.......\n\n");
 
 
    processname = (char *) malloc (256 * sizeof (char));
    processname = (char *) malloc (256 * sizeof (char));
    processname2 = (char *) malloc (256 * sizeof (char));
    processname2 = (char *) malloc (256 * sizeof (char));
    fileregs = (char *) malloc (256 * sizeof (char));
    fileregs = (char *) malloc (256 * sizeof (char));
Line 100... Line 107...
    file_writes = (char *) malloc (256 * sizeof (char));
    file_writes = (char *) malloc (256 * sizeof (char));
    strcpy (file_writes, (char *) "file_writes.sc2v");
    strcpy (file_writes, (char *) "file_writes.sc2v");
    FILE_WRITES = fopen (file_writes, (char *) "w");
    FILE_WRITES = fopen (file_writes, (char *) "w");
 
 
    lastword = (char *) malloc (sizeof (char) * 256);
    lastword = (char *) malloc (sizeof (char) * 256);
 
    structname = (char *) malloc (sizeof (char) * 256);
 
 
    for (i = 0; i < 256; i++)
    for (i = 0; i < 256; i++)
      switchparenthesis[i] = 0;
      switchparenthesis[i] = 0;
 
 
    translate = 1;
    translate = 1;
Line 123... Line 131...
 
 
%token NUMBER WORD SC_REG BOOL BIGGER LOWER OPENKEY CLOSEKEY WRITE WORD SYMBOL NEWLINE ENUM INCLUDE
%token NUMBER WORD SC_REG BOOL BIGGER LOWER OPENKEY CLOSEKEY WRITE WORD SYMBOL NEWLINE ENUM INCLUDE
%token COLON SEMICOLON RANGE OPENPAR CLOSEPAR TWODOUBLEPOINTS OPENCORCH CLOSECORCH SWITCH CASE DEFAULT BREAK
%token COLON SEMICOLON RANGE OPENPAR CLOSEPAR TWODOUBLEPOINTS OPENCORCH CLOSECORCH SWITCH CASE DEFAULT BREAK
%token HEXA DEFINE READ TRANSLATEOFF TRANSLATEON VERILOGBEGIN VERILOGEND TAB DOLLAR MINEQ
%token HEXA DEFINE READ TRANSLATEOFF TRANSLATEON VERILOGBEGIN VERILOGEND TAB DOLLAR MINEQ
%token VOID TTRUE TFALSE ENDFUNC INC DEC INTEGER EQUALS
%token VOID TTRUE TFALSE ENDFUNC INC DEC INTEGER EQUALS
%token PIFDEF PIFNDEF PENDDEF PELSE COMMENT
%token PIFDEF PIFNDEF PENDDEF PELSE COMMENT STRUCT DOT
 
 
%% commands:    /* empty */
%% commands:    /* empty */
|commands command;
|commands command;
 
 
 
 
command:
command:
 
  struct_dec
 
  |
endfunc
endfunc
  |
  |
  voidword
  voidword
  |
  |
  include
  include
Line 236... Line 245...
  |
  |
  equal
  equal
  |
  |
  minorequal
  minorequal
  |
  |
  comment;
  comment
 
  |
 
  struct_access
 
  ;
 
 
 
struct_access:
 
WORD DOT WORD
 
{
 
/*Struct access
 
 Check if it is a var acess or a reg*/
 
 if (newline){
 
   for (i = 0; i < openedkeys; i++)
 
      fprintf (file, "   ");
 
 }
 
 strcpy(structname,(char *)$3);
 
 strcat(structname,(char *)$1);
 
 regname2 = IsReg (regslist, structname);
 
 if (regname2 == NULL)
 
  fprintf (file, "%s ", structname);
 
 else
 
  fprintf (file, "%s", regname2);
 
 
 
  newline = 0;
 
 
 
 free(regname2);
 
 
 
 printf("Access to struct %s.%s\n",(char *)$1,(char *)$3);
 
}
 
 
minorequal:
minorequal:
MINEQ
MINEQ
{
{
 //This rule is needed because <= in the step two could be confused with a non-blocking assignment
 //This rule is needed because <= in the step two could be confused with a non-blocking assignment
Line 530... Line 566...
 
 
      if (processfound)
      if (processfound)
        {
        {
          if(lastswitch){
          if(lastswitch){
            openedcase=0;
            openedcase=0;
          }else if (openedcase)
          }else if (openedcase){
            {
 
              fprintf (file, " :\n");
              fprintf (file, " :\n");
 
 
              for (i = 0; i < openedkeys; i++)
              for (i = 0; i < openedkeys; i++)
                fprintf (file, "   ");
                fprintf (file, "   ");
 
 
              fprintf(file,"begin\n");
              fprintf(file,"begin\n");
              openedcase=0;
              openedcase=0;
            }
            }
 
          if (end_struct){
                if (reg_found)
             end_struct=0;
 
             struct_found=0;
 
             ignore_semicolon=1;
 
             structslist=InsertStruct(structslist,(char *)$1,structsreglist);
 
 
 
             //ShowStructs(structslist);
 
 
 
             /*Now we should convert all the elements of the struct into regs*/
 
             StructRegNode *srll;
 
             SGLIB_LIST_MAP_ON_ELEMENTS (StructRegNode,structsreglist, srll,next,
            {
            {
 
               if(srll->length==0)
 
                 fprintf (regs_file, "reg ");
 
               else
 
                 fprintf (regs_file, "reg[%d:0] ", (-1 +srll->length));
 
 
 
               regname =(char *) malloc (sizeof (char) * (strlen (srll->name) + 1));
 
               regname2 = (char *) malloc (sizeof (char) * (strlen (srll->name) + strlen (processname)+strlen((char *)$1)) + 1);
 
               strcpy (regname, srll->name);
 
               strcpy (regname2, srll->name);
 
               strcat (regname, (char *)$1);
 
               strcat (regname2, (char *)$1);
 
               strcat (regname2, processname);
 
               fprintf (regs_file, "%s;\n", regname2); /*By the moment no arrays inside the struct supported*/
 
 
 
               regslist = InsertReg (regslist, regname, regname2);
 
               free (regname);
 
               free (regname2);
 
               structsreglist=NULL;
 
               reg_found=0; /*To avoid arrays in sructs the interpretation finish here*/
 
             );}
 
 
 
          }else if(struct_found && reg_found){
 
              structsreglist=InsertStructReg(structsreglist,(char *)$1,reglenght);
 
 
 
          }else if (reg_found){
              if(writelenght){
              if(writelenght){
               writelenght=0;
               writelenght=0;
               if(reglenght==0)
               if(reglenght==0)
                fprintf (regs_file, "reg ");
                fprintf (regs_file, "reg ");
               else
               else
Line 561... Line 630...
              fprintf (regs_file, "%s", regname2);
              fprintf (regs_file, "%s", regname2);
 
 
              regslist = InsertReg (regslist, regname, regname2);
              regslist = InsertReg (regslist, regname, regname2);
              free (regname);
              free (regname);
              free (regname2);
              free (regname2);
            }
          }else if(integer_found){
          else if(integer_found){
 
              regname = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + 1));
              regname = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + 1));
              regname2 = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + strlen (processname)) + 1);
              regname2 = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + strlen (processname)) + 1);
              strcpy (regname, (char *) $1);
              strcpy (regname, (char *) $1);
              strcpy (regname2, (char *) $1);
              strcpy (regname2, (char *) $1);
              strcat (regname2, processname);
              strcat (regname2, processname);
Line 578... Line 646...
              fprintf (file, "%s ", regname2);
              fprintf (file, "%s ", regname2);
              integer_found=0;
              integer_found=0;
              free (regname);
              free (regname);
              free (regname2);
              free (regname2);
 
 
          }else
          }else{
            {
 
              if (newline)
              if (newline){
                {
 
                  for (i = 0; i < openedkeys; i++)
                  for (i = 0; i < openedkeys; i++)
                    fprintf (file, "   ");
                    fprintf (file, "   ");
                }
                }
              regname2 = IsReg (regslist, (char *) $1);
 
              if (regname2 == NULL)
 
                {
 
 
 
                  if (IsDefine (defineslist, (char *) $1))
              regname2 = IsReg (regslist, (char *) $1);
                    {
              if (regname2 == NULL){
                      if (ifdeffound == 0)
                if (IsDefine (defineslist, (char *) $1)){
                        {
                   if (ifdeffound == 0){
                          fprintf (file, "`%s", (char *) $1);
                          fprintf (file, "`%s", (char *) $1);
                          defineinvocationfound = 1;
                          defineinvocationfound = 1;
                        }
                   }else{
                      else
 
                        {
 
                          fprintf (file, "%s", (char *) $1);
                          fprintf (file, "%s", (char *) $1);
                          ifdeffound = 0;
                          ifdeffound = 0;
                        }
                        }
                    }
                }else{
                  else
 
                    {
 
                      fprintf (file, "%s ", (char *) $1);
                      fprintf (file, "%s ", (char *) $1);
                    }
                    }
                }
             }else
              else
 
                fprintf (file, "%s", regname2);
                fprintf (file, "%s", regname2);
 
 
              newline = 0;
              newline = 0;
            }
            }
 
 
        }
        }else if (definefound)
      else if (definefound)
 
        {
        {
 
 
          if (IsDefine (defineslist, (char *) $1))
          if (IsDefine (defineslist, (char *) $1))
            {
            {
 
 
Line 749... Line 807...
SEMICOLON
SEMICOLON
{
{
  defineparenthesis = 0;
  defineparenthesis = 0;
  if (translate == 1 && verilog == 0)
  if (translate == 1 && verilog == 0)
    {
    {
      if (processfound)
      if (processfound && !struct_found && !ignore_semicolon)
        {
        {
          if (reg_found)
          if (reg_found)
            {
            {
              fprintf (regs_file, ";\n");
              fprintf (regs_file, ";\n");
              reg_found = 0;
              reg_found = 0;
Line 772... Line 830...
  else if (verilog == 1)
  else if (verilog == 1)
    fprintf (file, ";");
    fprintf (file, ";");
 
 
  writingvar=0;
  writingvar=0;
  defineinvocationfound = 0;
  defineinvocationfound = 0;
 
  ignore_semicolon=0;
};
};
 
 
 
 
openpar:
openpar:
OPENPAR
OPENPAR
Line 911... Line 970...
 
 
closekey:
closekey:
CLOSEKEY
CLOSEKEY
{
{
  defineparenthesis = 0;
  defineparenthesis = 0;
  if (translate == 1 && verilog == 0)
  if(struct_found){
    {
    end_struct=1;
      if (processfound && !definefound)
  }else if (translate == 1 && verilog == 0){
        {
      if (processfound && !definefound){
          if (openedkeys == switchparenthesis[switchfound] && switchfound > 0)
          if (openedkeys == switchparenthesis[switchfound] && switchfound > 0){
            {
 
              fprintf (file, "\n");
              fprintf (file, "\n");
              if (default_found & !default_break_found)
              if (default_found & !default_break_found){
                {
 
                  for (i = 0; i < openedkeys - 1; i++)
                  for (i = 0; i < openedkeys - 1; i++)
                    fprintf (file, "   ");
                    fprintf (file, "   ");
                  fprintf (file, "end\n");
                  fprintf (file, "end\n");
                  default_found = 0;
                  default_found = 0;
                }
                }
              for (i = 0; i < openedkeys - 1; i++)
              for (i = 0; i < openedkeys - 1; i++)
                fprintf (file, "   ");
                fprintf (file, "   ");
 
 
              fprintf (file, "endcase\n");
              fprintf (file, "endcase\n");
              newline = 1;
              newline = 1;
              switchparenthesis[switchfound] = 0;
              switchparenthesis[switchfound] = 0;
              switchfound--;
              switchfound--;
 
          }else{
            }
 
          else
 
            {
 
              fprintf (file, "\n");
              fprintf (file, "\n");
              for (i = 0; i < openedkeys; i++)
              for (i = 0; i < openedkeys; i++)
                fprintf (file, "   ");
                fprintf (file, "   ");
              fprintf (file, "end\n");
              fprintf (file, "end\n");
              newline = 1;
              newline = 1;
Line 957... Line 1012...
      else if (openedkeys == 0)
      else if (openedkeys == 0)
        {
        {
          fclose (file);
          fclose (file);
          fclose (regs_file);
          fclose (regs_file);
          processfound = 0;
          processfound = 0;
 
          /*Clear process struct list*/
 
          structslist=NULL;
        }
        }
    }
    }
  else if (verilog == 1)
  else if (verilog == 1)
    fprintf (file, "}");
    fprintf (file, "}");
};
};
Line 1407... Line 1464...
        newline=0;
        newline=0;
  }
  }
  fprintf (file, " %s", (char *)$1);
  fprintf (file, " %s", (char *)$1);
 }
 }
}
}
 No newline at end of file
 No newline at end of file
 
 
 
struct_dec:
 
STRUCT OPENKEY
 
{
 
  struct_found=1;
 
}
 
 

powered by: WebSVN 2.1.0

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