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

Subversion Repositories sc2v

[/] [sc2v/] [trunk/] [src/] [sc2v_step2.y] - Diff between revs 12 and 14

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

Rev 12 Rev 14
Line 1... Line 1...
/* -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
 *
 *
 *  SystemC to Verilog Translator v0.2
 *  SystemC to Verilog Translator v0.3
 *  Provided by OpenSoc Design
 *  Provided by OpenSoc Design
 *
 *
 *  www.opensocdesign.com
 *  www.opensocdesign.com
 *
 *
 * -----------------------------------------------------------------------------
 * -----------------------------------------------------------------------------
Line 25... Line 25...
 
 
#include 
#include 
#include 
#include 
#include 
#include 
 
 
#include "list.h"
#include "sc2v_step2.h"
 
 
 
 
/*Global var to read from file_writes.sc2v*/
 
  WritesList *writeslist;
 
 
 
 
 
/*Global var to store ports*/
 
  PortList *portlist;
 
 
 
 
 
/* Global var to store signals*/
 
  SignalsList *signalslist;
 
 
 
 
 
/* Global var to store sensitivity list*/
 
  SensibilityList *sensibilitylist;
 
 
 
 
 
/* Global var to store instantiated modules*/
 
  InstancesList *instanceslist;
 
 
 
 
 
/* Global var to store process list*/
 
  ProcessList *processlist;
 
 
 
 
 
/*List of enumerates*/
 
  EnumeratesList *enumerateslist;
 
 
 
  EnumListList *enumlistlist;
 
 
 
  char *enumname;
  char *enumname;
 
 
  int reading_enumerates = 0;
  int reading_enumerates = 0;
 
 
 
 
/*Multiple Declarations*/
/*Multiple Declarations*/
  int multipledec;
  int multipledec;
 
 
  char *storedtype;
  char *storedtype;
 
 
 
 
/* Global var to store process module name*/
/* Global var to store process module name*/
  char *module_name;
  char *module_name;
 
 
  int module_name_found = 0;
  int module_name_found = 0;
 
 
 
 
/* Global var to store last port type*/
/* Global var to store last port type*/
  char *lastportkind;
  char *lastportkind;
 
 
  int lastportsize;
  int lastportsize;
 
 
  int activeport = 0;           // 1 -> reading port list
  int activeport = 0;           // 1 -> reading port list
 
 
/* Global var to store last signal type*/
/* Global var to store last signal type*/
  int lastsignalsize;
  int lastsignalsize;
 
 
  int signalactive = 0;
  int signalactive = 0;
 
 
 
 
/* Global var to store last SC_METHOD found*/
/* Global var to store last SC_METHOD found*/
  char *active_method;
  char *active_method;
 
 
  char *active_method_type;
  char *active_method_type;
 
 
  int method_found;
  int method_found;
 
 
 
 
/* Global var to store last sensitivity found*/
/* Global var to store last sensitivity found*/
  char *last_sensibility;
  char *last_sensibility;
 
 
  int sensibility_active = 0;
  int sensibility_active = 0;
 
 
 
 
 
 
  int translate;
  int translate;
 
 
 
 
  void yyerror (const char *str)
  void yyerror (const char *str)
  {
  {
 
 
    fprintf (stderr, "error: %s\n", str);
    fprintf (stderr, "error: %s\n", str);
 
 
  }
  }
 
 
  int yywrap ()
  int yywrap ()
  {
  {
 
 
    return 1;
    return 1;
 
 
  }
  }
 
 
 
 
  main ()
  main ()
  {
  {
 
 
    /*Initialize lists */
    /*Initialize lists */
 
    writeslist = NULL;
    writeslist = (WritesList *) malloc (sizeof (WritesList));
    portlist = NULL;;
 
    signalslist = NULL;
    InitializeWritesList (writeslist);
    sensibilitylist=NULL;
 
    processlist=NULL;
 
    instanceslist = NULL;
    portlist = (PortList *) malloc (sizeof (PortList));
    enumlistlist = NULL;
 
 
    InitializePortList (portlist);
 
 
 
 
 
    signalslist = (SignalsList *) malloc (sizeof (SignalsList));
 
 
 
    InitializeSignalsList (signalslist);
 
 
 
 
 
    sensibilitylist = (SensibilityList *) malloc (sizeof (SensibilityList));
 
 
 
    InitializeSensibilityList (sensibilitylist);
 
 
 
 
 
    instanceslist = (InstancesList *) malloc (sizeof (InstancesList));
 
 
 
    InitializeInstancesList (instanceslist);
 
 
 
 
 
    processlist = (ProcessList *) malloc (sizeof (ProcessList));
 
 
 
    InitializeProcessList (processlist);
 
 
 
 
 
    enumlistlist = (EnumListList *) malloc (sizeof (EnumListList));
 
 
 
    InitializeEnumListList (enumlistlist);
 
 
 
 
 
    translate = 1;
    translate = 1;
 
 
 
    fprintf(stderr,"\nSystemC to Verilog Translator v0.3\n\n");
 
        fprintf(stderr,"Parsing header file.......\n\n");
 
 
    yyparse ();
    yyparse ();
 
 
 
 
    printf ("module %s(", module_name);
    printf ("module %s(", module_name);
 
 
    EnumeratePorts (portlist);
    EnumeratePorts (portlist);
 
 
    printf (");\n");
    printf (");\n");
 
 
 
 
    ShowPortList (portlist);
    ShowPortList (portlist);
 
 
    printf ("\n");
    printf ("\n");
 
 
    RegOutputs (portlist);
    RegOutputs (portlist);
 
 
    printf ("\n");
    printf ("\n");
 
 
 
 
    ShowEnumListList (enumlistlist);
    ShowEnumListList (enumlistlist);
 
 
 
    writeslist=ReadWritesFile (writeslist,(char *) "file_writes.sc2v");
 
 
    ReadWritesFile (writeslist, (char *) "file_writes.sc2v");
    ShowSignalsList (signalslist);
 
 
 
 
    ShowSignalsList (signalslist, writeslist);
 
 
 
    printf ("\n");
    printf ("\n");
 
 
 
 
    ShowInstancedModules (instanceslist);
    ShowInstancedModules (instanceslist);
 
 
    printf ("\n");
    printf ("\n");
 
 
 
 
    ShowDefines ((char *) "file_defines.sc2v");
    ShowDefines ((char *) "file_defines.sc2v");
 
 
 
 
    ShowProcessCode (processlist);
    ShowProcessCode (processlist);
 
 
    printf ("\n");
    printf ("\n");
 
 
 
 
    printf ("endmodule\n");
    printf ("endmodule\n");
 
 
 
        fprintf(stderr,"\nDone\n");
  }
  }
 
 
%}
%}
 
 
%token NUMBER SC_MODULE WORD OPENPAR CLOSEPAR SC_IN SC_OUT SEMICOLON BOOL ENUM
%token NUMBER SC_MODULE WORD OPENPAR CLOSEPAR SC_IN SC_OUT SEMICOLON BOOL ENUM
Line 220... Line 139...
%token SC_CTOR VOID ASTERISCO TRANSLATEON TRANSLATEOFF
%token SC_CTOR VOID ASTERISCO TRANSLATEON TRANSLATEOFF
 
 
%% commands:    /* empty */
%% commands:    /* empty */
|commands command;
|commands command;
 
 
 
 
 
 
command:
command:
module
module
  |
  |
  in_bool
  in_bool
  |
  |
Line 513... Line 430...
 
 
      if (method_found)
      if (method_found)
 
 
        {
        {
 
 
          InsertProcess (processlist, active_method, sensibilitylist,
          processlist=InsertProcess (processlist, active_method, sensibilitylist,
                         active_method_type);
                         active_method_type);
 
 
        }
        }
 
 
      active_method = (char *) $3;
      active_method = (char *) $3;
 
 
      method_found = 1;
      method_found = 1;
 
 
      /* New sensitivity list */
      /* New sensitivity list */
      sensibilitylist = (SensibilityList *) malloc (sizeof (SensibilityList));
      sensibilitylist = NULL;
 
 
      InitializeSensibilityList (sensibilitylist);
 
 
 
    }
    }
 
 
};
};
 
 
Line 541... Line 456...
 
 
  if (translate == 1)
  if (translate == 1)
    {
    {
 
 
      active_method_type = (char *) "seq";      //comb
      active_method_type = (char *) "seq";      //comb
      InsertSensibility (sensibilitylist, (char *) $3, "negedge");
      sensibilitylist=InsertSensibility (sensibilitylist, (char *) $3, "negedge");
 
 
    }
    }
 
 
};
};
 
 
Line 557... Line 472...
 
 
  if (translate == 1)
  if (translate == 1)
    {
    {
 
 
      active_method_type = (char *) "seq";      //comb
      active_method_type = (char *) "seq";      //comb
      InsertSensibility (sensibilitylist, (char *) $3, "posedge");
      sensibilitylist=InsertSensibility (sensibilitylist, (char *) $3, "posedge");
 
 
    }
    }
 
 
};
};
 
 
Line 627... Line 542...
 
 
  if (translate == 1)
  if (translate == 1)
    {
    {
 
 
      active_method_type = (char *) "comb";     //comb
      active_method_type = (char *) "comb";     //comb
      InsertSensibility (sensibilitylist, (char *) $3, " ");
      sensibilitylist=InsertSensibility (sensibilitylist, (char *) $3, " ");
 
 
    }
    }
 
 
};
};
 
 
Line 643... Line 558...
{
{
 
 
  if (translate == 1)
  if (translate == 1)
    {
    {
 
 
      InsertSensibility (sensibilitylist, (char *) $2,
      sensibilitylist=InsertSensibility (sensibilitylist, (char *) $2,
                         (char *) last_sensibility);
                         (char *) last_sensibility);
 
 
    }
    }
 
 
};
};
Line 659... Line 574...
{
{
 
 
  if (translate == 1)
  if (translate == 1)
    {
    {
 
 
      InsertSensibility (sensibilitylist, (char *) $2,
      sensibilitylist=InsertSensibility (sensibilitylist, (char *) $2,
                         (char *) last_sensibility);
                         (char *) last_sensibility);
 
 
      if (sensibility_active)
      if (sensibility_active)
 
 
        {
        {
Line 674... Line 589...
 
 
    }
    }
 
 
};
};
 
 
 
 
 
 
closekey:
closekey:
CLOSEKEY
CLOSEKEY
{
{
 
 
  if (translate == 1)
  if (translate == 1)
Line 689... Line 602...
 
 
        {
        {
 
 
          method_found = 0;
          method_found = 0;
 
 
          InsertProcess (processlist, active_method, sensibilitylist,
          processlist=InsertProcess (processlist, active_method, sensibilitylist,
                         active_method_type);
                         active_method_type);
 
 
        }
        }
 
 
    }
    }
Line 711... Line 624...
 
 
      if (activeport)
      if (activeport)
 
 
        {
        {
 
 
          InsertPort (portlist, (char *) $1, lastportkind, lastportsize);
          portlist=InsertPort (portlist,(char *) $1, lastportkind, lastportsize);
 
 
          activeport = 0;
          activeport = 0;
 
 
        }
        }
 
 
      else if (signalactive)
      else if (signalactive)
 
 
        {
        {
 
 
          InsertSignal (signalslist, (char *) $1, lastsignalsize);
          signalslist=InsertSignal (signalslist,(char *) $1, lastsignalsize);
 
 
          signalactive = 0;
          signalactive = 0;
 
 
        }
        }
      else if (multipledec)
      else if (multipledec)
Line 745... Line 658...
 
 
              //Calculate the number of bits needed to represent the enumerate
              //Calculate the number of bits needed to represent the enumerate
              length = findEnumerateLength (enumlistlist, list_pos);
              length = findEnumerateLength (enumlistlist, list_pos);
 
 
 
 
              InsertSignal (signalslist, (char *) $1, length);
              signalslist=InsertSignal (signalslist,(char *) $1, length);
 
 
              InsertWrite (writeslist, (char *) $1);
              writeslist=InsertWrite (writeslist,(char *) $1);
 
 
              free (storedtype);
              free (storedtype);
 
 
              multipledec = 0;
              multipledec = 0;
 
 
Line 782... Line 695...
 
 
      if (activeport)
      if (activeport)
 
 
        {
        {
 
 
          InsertPort (portlist, (char *) $1, lastportkind, lastportsize);
          portlist=InsertPort (portlist,(char *) $1, lastportkind, lastportsize);
 
 
        }
        }
 
 
      else if (signalactive)
      else if (signalactive)
 
 
        {
        {
 
 
          InsertSignal (signalslist, (char *) $1, lastsignalsize);
          signalslist=InsertSignal (signalslist,(char *) $1, lastsignalsize);
 
 
        }
        }
 
 
      else if (reading_enumerates)
      else if (reading_enumerates)
 
 
        {
        {
 
 
          InsertEnumerates (enumerateslist, (char *) $1);
          enumerateslist=InsertEnumerates (enumerateslist, (char *) $1);
 
 
 
 
        }
        }
      else if (multipledec)
      else if (multipledec)
        {
        {
Line 821... Line 734...
 
 
              //Calculate the number of bits needed to represent the enumerate
              //Calculate the number of bits needed to represent the enumerate
              length = findEnumerateLength (enumlistlist, list_pos);
              length = findEnumerateLength (enumlistlist, list_pos);
 
 
 
 
              InsertSignal (signalslist, (char *) $1, length);
              signalslist=InsertSignal (signalslist,(char *) $1, length);
 
 
              InsertWrite (writeslist, (char *) $1);
              writeslist=InsertWrite (writeslist,(char *) $1);
 
 
              multipledec = 1;
              multipledec = 1;
 
 
            }
            }
          else
          else
Line 857... Line 770...
      //Finish enumerate var declaration
      //Finish enumerate var declaration
      if (reading_enumerates)
      if (reading_enumerates)
 
 
        {
        {
 
 
          InsertEnumerates (enumerateslist, (char *) $1);
          enumerateslist=InsertEnumerates (enumerateslist, (char *) $1);
 
 
          InsertEnumList (enumlistlist, enumerateslist, (char *) $4, 0);        //Insert also the variable name
          enumlistlist=InsertEnumList (enumlistlist, enumerateslist, (char *) $4, 0);   //Insert also the variable name
          reading_enumerates = 0;
          reading_enumerates = 0;
 
 
        }
        }
 
 
    }
    }
Line 882... Line 795...
      //Finish enumerate type declaration
      //Finish enumerate type declaration
      if (reading_enumerates)
      if (reading_enumerates)
 
 
        {
        {
 
 
          InsertEnumerates (enumerateslist, (char *) $1);
          enumerateslist=InsertEnumerates (enumerateslist, (char *) $1);
 
 
          InsertEnumList (enumlistlist, enumerateslist, enumname, 1);   //Insert also the variable name
          enumlistlist=InsertEnumList (enumlistlist, enumerateslist, enumname, 1);      //Insert also the variable name
          reading_enumerates = 0;
          reading_enumerates = 0;
 
 
        }
        }
 
 
    }
    }
Line 903... Line 816...
{
{
 
 
  if (translate == 1)
  if (translate == 1)
    {
    {
 
 
      InsertInstance (instanceslist, (char *) $1, (char *) $4);
      instanceslist=InsertInstance (instanceslist, (char *) $1, (char *) $4);
 
 
    }
    }
 
 
};
};
 
 
Line 918... Line 831...
{
{
 
 
  if (translate == 1)
  if (translate == 1)
    {
    {
 
 
      if (instanceslist->last == NULL)
      if (instanceslist == NULL){
 
 
        {
 
 
 
          fprintf (stderr, "error: no instances found\n");
          fprintf (stderr, "error: no instances found\n");
 
          }else{
 
 
        }
            InstanceNode *ill;
 
        SGLIB_LIST_MAP_ON_ELEMENTS (InstanceNode, instanceslist, ill, next,
      else
 
 
 
        {
 
 
 
          InstanceNode *aux;
 
 
 
          aux = instanceslist->first;
 
 
 
          while (1)
 
 
 
            {
            {
 
                    if (strcmp (ill->nameinstance, (char *) $1) == 0){
              if (strcmp (aux->nameinstance, (char *) $1) == 0)
               ill->bindslist=InsertBind (ill->bindslist, (char *) $3, (char *) $5);
 
 
                {
 
 
 
                  break;
                  break;
 
 
                }
                }
 
 
              else
 
 
 
                {
 
 
 
                  if (aux->next == NULL)
 
 
 
                    {
 
 
 
                      fprintf (stderr, "error: instance %s not found\n", $1);
 
 
 
                      exit (1);
 
 
 
                    }
 
 
 
                  else
 
 
 
                    {
 
 
 
                      aux = aux->next;
 
 
 
                    }
                    }
 
                );
                }
                }
 
 
            }
            }
 
 
          InsertBind (aux->bindslist, (char *) $3, (char *) $5);
 
 
 
        }
 
    }
 
 
 
};
};
 
 
 
 
 
 
sc_ctor:
sc_ctor:
SC_CTOR OPENPAR WORD CLOSEPAR OPENKEY
SC_CTOR OPENPAR WORD CLOSEPAR OPENKEY
{
{
 
 
 
 
Line 1021... Line 890...
 
 
  if (translate == 1)
  if (translate == 1)
    {
    {
 
 
      //New enumerate list
      //New enumerate list
      enumerateslist = (EnumeratesList *) malloc (sizeof (EnumeratesList));
      enumerateslist = NULL;
 
 
      InitializeEnumeratesList (enumerateslist);
 
 
 
      reading_enumerates = 1;
      reading_enumerates = 1;
 
 
    }
    }
 
 
Line 1041... Line 908...
 
 
  if (translate == 1)
  if (translate == 1)
    {
    {
 
 
      //In this case we define type e.g. enum state_t {S0,S1,S2};
      //In this case we define type e.g. enum state_t {S0,S1,S2};
      enumerateslist = (EnumeratesList *) malloc (sizeof (EnumeratesList));
      enumerateslist = NULL;
 
 
      InitializeEnumeratesList (enumerateslist);
 
 
 
      enumname = malloc (sizeof (char) * strlen ((char *) $2));
      enumname = (char *)malloc (sizeof (char) * strlen ((char *) $2));
 
 
      strcpy (enumname, (char *) $2);
      strcpy (enumname, (char *) $2);
 
 
      reading_enumerates = 1;
      reading_enumerates = 1;
 
 
Line 1080... Line 945...
 
 
          //Calculate the number of bits needed to represent the enumerate
          //Calculate the number of bits needed to represent the enumerate
          length = findEnumerateLength (enumlistlist, list_pos);
          length = findEnumerateLength (enumlistlist, list_pos);
 
 
 
 
          InsertSignal (signalslist, (char *) $2, length);
          signalslist=InsertSignal (signalslist,(char *) $2, length);
 
 
          InsertWrite (writeslist, (char *) $2);
          writeslist=InsertWrite (writeslist,(char *) $2);
 
 
        }
        }
      else
      else
        {
        {
 
 
Line 1123... Line 988...
 
 
          //Calculate the number of bits needed to represent the enumerate
          //Calculate the number of bits needed to represent the enumerate
          length = findEnumerateLength (enumlistlist, list_pos);
          length = findEnumerateLength (enumlistlist, list_pos);
 
 
 
 
          InsertSignal (signalslist, (char *) $5, length);
          signalslist=InsertSignal (signalslist,(char *) $5, length);
 
 
          InsertWrite (writeslist, (char *) $5);
          writeslist=InsertWrite (writeslist,(char *) $5);
 
 
        }
        }
      else
      else
        {
        {
 
 
Line 1165... Line 1030...
        {
        {
 
 
          //Calculate the number of bits needed to represent the enumerate
          //Calculate the number of bits needed to represent the enumerate
          length = findEnumerateLength (enumlistlist, list_pos);
          length = findEnumerateLength (enumlistlist, list_pos);
 
 
          storedtype = malloc (sizeof (char) * strlen ((char *) $1));
          storedtype = (char *)malloc (sizeof (char) * strlen ((char *) $1));
 
 
          strcpy (storedtype, (char *) $1);
          strcpy (storedtype, (char *) $1);
 
 
          InsertSignal (signalslist, (char *) $2, length);
          signalslist=InsertSignal (signalslist,(char *) $2, length);
 
 
          InsertWrite (writeslist, (char *) $2);
          writeslist=InsertWrite (writeslist,(char *) $2);
 
 
          multipledec = 1;
          multipledec = 1;
 
 
        }
        }
      else
      else
Line 1197... Line 1062...
SC_SIGNAL MENOR WORD MAYOR WORD COLON
SC_SIGNAL MENOR WORD MAYOR WORD COLON
{
{
 
 
  if (translate == 1)
  if (translate == 1)
    {
    {
 
 
      int length, list_pos;
      int length, list_pos;
 
 
      length = 0;
      length = 0;
 
 
      list_pos = 0;
      list_pos = 0;
 
 
      //Look in the enumerated list if it was declared e.j state_t state;
      //Look in the enumerated list if it was declared e.j state_t state;
      list_pos = findEnumList (enumlistlist, (char *) $3);
      list_pos = findEnumList (enumlistlist, (char *) $3);
 
 
Line 1213... Line 1075...
        {
        {
 
 
          //Calculate the number of bits needed to represent the enumerate
          //Calculate the number of bits needed to represent the enumerate
          length = findEnumerateLength (enumlistlist, list_pos);
          length = findEnumerateLength (enumlistlist, list_pos);
 
 
          storedtype = malloc (sizeof (char) * strlen ((char *) $3));
          storedtype = (char *)malloc (sizeof (char) * strlen ((char *) $3));
 
 
          strcpy (storedtype, (char *) $3);
          strcpy (storedtype, (char *) $3);
 
 
          InsertSignal (signalslist, (char *) $5, length);
          signalslist=InsertSignal (signalslist,(char *) $5, length);
 
 
          InsertWrite (writeslist, (char *) $5);
          writeslist=InsertWrite (writeslist,(char *) $5);
 
 
          multipledec = 1;
          multipledec = 1;
 
 
        }
        }
      else
      else

powered by: WebSVN 2.1.0

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