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

Subversion Repositories sc2v

[/] [sc2v/] [trunk/] [src/] [sc2v_step2.c] - Diff between revs 35 and 36

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 35 Rev 36
/* -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
 *
 *
 *  SystemC to Verilog Translator v0.4
 *  SystemC to Verilog Translator v0.4
 *  Provided by Universidad Rey Juan Carlos
 *  Provided by Universidad Rey Juan Carlos
 *
 *
 * -----------------------------------------------------------------------------
 * -----------------------------------------------------------------------------
 *  This program is free software; you can redistribute it and/or modify
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  (at your option) any later version.
 *
 *
 *  This program is distributed in the hope that it will be useful,
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *  GNU Library General Public License for more details.
 *
 *
 *  You should have received a copy of the GNU General Public License
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 */
 
 
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <math.h>
#include <math.h>
 
 
#include "sc2v_step2.h"
#include "sc2v_step2.h"
 
 
void
void
ShowDefines (char *filedefines)
ShowDefines (char *filedefines)
{
{
 
 
  int readok;
  int readok;
 
 
  char *auxchar;
  char *auxchar;
  FILE *file;
  FILE *file;
 
 
  file = fopen (filedefines, (char *) "r");
  file = fopen (filedefines, (char *) "r");
 
 
  while (1){
  while (1){
    readok = fread ((void *) &auxchar, sizeof (char), 1, file);
    readok = fread ((void *) &auxchar, sizeof (char), 1, file);
    if (readok){
    if (readok){
          printf ("%c", auxchar);
          printf ("%c", auxchar);
        }else{
        }else{
          break;
          break;
        }
        }
  }
  }
}
}
 
 
WriteNode *
WriteNode *
InsertWrite (WriteNode * list, char *name)
InsertWrite (WriteNode * list, char *name)
{
{
  WriteNode *wl;
  WriteNode *wl;
 
 
  wl = (WriteNode *) malloc (sizeof (WriteNode));
  wl = (WriteNode *) malloc (sizeof (WriteNode));
  strcpy (wl->name, name);
  strcpy (wl->name, name);
  SGLIB_LIST_ADD (WriteNode, list, wl, next);
  SGLIB_LIST_ADD (WriteNode, list, wl, next);
  return (list);
  return (list);
}
}
 
 
int
int
IsWrite (WriteNode * list, char *name)
IsWrite (WriteNode * list, char *name)
{
{
  WriteNode *wll;
  WriteNode *wll;
  SGLIB_LIST_MAP_ON_ELEMENTS (WriteNode, list, wll, next,
  SGLIB_LIST_MAP_ON_ELEMENTS (WriteNode, list, wll, next,
  {
  {
        if ((strcmp (name, (char *) wll->name) == 0)) return (1);
        if ((strcmp (name, (char *) wll->name) == 0)) return (1);
    }
    }
  );
  );
  return (0);
  return (0);
}
}
 
 
void
void
ShowWritesList (WriteNode * list)
ShowWritesList (WriteNode * list)
{
{
  WriteNode *wll;
  WriteNode *wll;
  SGLIB_LIST_MAP_ON_ELEMENTS (WriteNode, list, wll, next,{
  SGLIB_LIST_MAP_ON_ELEMENTS (WriteNode, list, wll, next,{
        printf ("%s\n", wll->name);
        printf ("%s\n", wll->name);
    }
    }
  );
  );
  return;
  return;
}
}
 
 
 
 
 
 
WriteNode *
WriteNode *
ReadWritesFile (WriteNode *list,char *name)
ReadWritesFile (WriteNode *list,char *name)
{
{
 
 
  char *leido;
  char *leido;
  int ret;
  int ret;
  FILE *file_writes;
  FILE *file_writes;
  file_writes = fopen (name, (char *) "r");
  file_writes = fopen (name, (char *) "r");
 
 
  leido = (char *) malloc (256 * sizeof (char));
  leido = (char *) malloc (256 * sizeof (char));
 
 
  while (1){
  while (1){
      ret = fscanf (file_writes, "%s", leido);
      ret = fscanf (file_writes, "%s", leido);
      if (ret == EOF)
      if (ret == EOF)
        break;
        break;
      list = InsertWrite (list, leido);
      list = InsertWrite (list, leido);
  }
  }
  return(list);
  return(list);
}
}
 
 
PortNode *
PortNode *
InsertPort (PortNode * list, char *name, char *tipo, int size, int pflag)
InsertPort (PortNode * list, char *name, char *tipo, int size, int pflag)
{
{
  PortNode *pl;
  PortNode *pl;
  pl = (PortNode *) malloc (sizeof (PortNode));
  pl = (PortNode *) malloc (sizeof (PortNode));
  strcpy (pl->name, name);
  strcpy (pl->name, name);
  strcpy (pl->tipo, tipo);
  strcpy (pl->tipo, tipo);
  pl->size = size;
  pl->size = size;
  pl->pflag = pflag;
  pl->pflag = pflag;
  SGLIB_LIST_ADD (PortNode, list, pl, next);
  SGLIB_LIST_ADD (PortNode, list, pl, next);
  return (list);
  return (list);
}
}
 
 
void
void
ShowPortList (PortNode * list)
ShowPortList (PortNode * list)
{
{
 
 
  PortNode *pll;
  PortNode *pll;
 
 
  SGLIB_LIST_MAP_ON_ELEMENTS (PortNode, list, pll, next,
  SGLIB_LIST_MAP_ON_ELEMENTS (PortNode, list, pll, next,
  {
  {
        printf ("%s ", pll->tipo);
        printf ("%s ", pll->tipo);
        if (pll->pflag == 1) printf("signed ");
        if (pll->pflag == 1) printf("signed ");
        if (pll->size != 0 && pll->size != 1)
        if (pll->size != 0 && pll->size != 1)
        {
        {
          printf ("[%d:0] ", (-1 + pll->size));}
          printf ("[%d:0] ", (-1 + pll->size));}
        printf ("%s;\n", pll->name);
        printf ("%s;\n", pll->name);
        }
        }
  );
  );
  return;
  return;
}
}
 
 
void
void
RegOutputs (PortNode * list, InstanceNode *instances)
RegOutputs (PortNode * list, InstanceNode *instances)
{
{
 
 
  PortNode *pll;
  PortNode *pll;
  SGLIB_LIST_MAP_ON_ELEMENTS (PortNode, list, pll, next,
  SGLIB_LIST_MAP_ON_ELEMENTS (PortNode, list, pll, next,
  {
  {
        if (strcmp (pll->tipo, "output") == 0)
        if (strcmp (pll->tipo, "output") == 0)
        {
        {
         if(!IsWire(pll->name,instances)){
         if(!IsWire(pll->name,instances)){
           if (pll->pflag == 1) printf("reg signed "); else printf ("reg ");
           if (pll->pflag == 1) printf("reg signed "); else printf ("reg ");
          if (pll->size != 0 && pll->size != 1)
          if (pll->size != 0 && pll->size != 1)
          {
          {
            printf ("[%d:0] ", (-1 + pll->size));}
            printf ("[%d:0] ", (-1 + pll->size));}
            printf ("%s;\n", pll->name);}
            printf ("%s;\n", pll->name);}
          }
          }
         }
         }
  );
  );
  return;
  return;
}
}
 
 
void
void
EnumeratePorts (PortNode *list)
EnumeratePorts (PortNode *list)
{
{
  PortNode *pll;
  PortNode *pll;
 
 
  SGLIB_LIST_MAP_ON_ELEMENTS (PortNode, list, pll, next,
  SGLIB_LIST_MAP_ON_ELEMENTS (PortNode, list, pll, next,
  {
  {
        if (pll->next == NULL)
        if (pll->next == NULL)
        {
        {
          printf ("%s", pll->name); break;
          printf ("%s", pll->name); break;
        }
        }
        else
        else
        {
        {
          printf ("%s,", pll->name);}
          printf ("%s,", pll->name);}
        }
        }
  );
  );
  return;
  return;
}
}
 
 
SignalNode *
SignalNode *
InsertSignal (SignalNode * list, char *name, int size, int arraysize,int sflag)
InsertSignal (SignalNode * list, char *name, int size, int arraysize,int sflag)
{
{
  SignalNode *sl;
  SignalNode *sl;
 
 
  sl = (SignalNode *) malloc (sizeof (SignalNode));
  sl = (SignalNode *) malloc (sizeof (SignalNode));
  strcpy (sl->name, name);
  strcpy (sl->name, name);
  sl->size = size;
  sl->size = size;
  sl->arraysize=arraysize;
  sl->arraysize=arraysize;
  sl->sflag=sflag;
  sl->sflag=sflag;
  SGLIB_LIST_ADD (SignalNode, list, sl, next);
  SGLIB_LIST_ADD (SignalNode, list, sl, next);
  return (list);
  return (list);
 
 
}
}
 
 
 
 
void
void
ShowSignalsList (SignalNode * list, WriteNode * writeslist)
ShowSignalsList (SignalNode * list, WriteNode * writeslist)
{
{
  SignalNode *sll;
  SignalNode *sll;
  SGLIB_LIST_MAP_ON_ELEMENTS (SignalNode, list, sll, next,
  SGLIB_LIST_MAP_ON_ELEMENTS (SignalNode, list, sll, next,
  {
  {
        if (IsWrite (writeslist, sll->name))
        if (IsWrite (writeslist, sll->name))
        {
        {
          if (sll->sflag==1) printf("reg signed "); else printf ("reg ");
          if (sll->sflag==1) printf("reg signed "); else printf ("reg ");
          if (sll->size != 0 && sll->size != 1)
          if (sll->size != 0 && sll->size != 1)
          {
          {
            printf ("[%d:0] ", (-1 + sll->size));
            printf ("[%d:0] ", (-1 + sll->size));
          }
          }
          printf ("%s", sll->name);
          printf ("%s", sll->name);
        }
        }
        else
        else
        {
        {
          if (sll->sflag==1) printf("wire signed "); else printf ("wire ");
          if (sll->sflag==1) printf("wire signed "); else printf ("wire ");
          if (sll->size != 0 && sll->size != 1)
          if (sll->size != 0 && sll->size != 1)
          {
          {
                printf ("[%d:0] ", (-1 + sll->size));
                printf ("[%d:0] ", (-1 + sll->size));
          }
          }
          printf ("%s", sll->name);
          printf ("%s", sll->name);
        }
        }
        if(sll->arraysize !=0)
        if(sll->arraysize !=0)
          printf("[%d:0]", (-1 + sll->arraysize));
          printf("[%d:0]", (-1 + sll->arraysize));
        printf(";\n");
        printf(";\n");
  }
  }
  );
  );
  return;
  return;
}
}
 
 
 
 
/* Decides if a signal is a wire or a reg*/
/* Decides if a signal is a wire or a reg*/
int
int
IsWire (char *name, InstanceNode * list)
IsWire (char *name, InstanceNode * list)
{
{
 
 
  InstanceNode *ill;
  InstanceNode *ill;
  SGLIB_LIST_MAP_ON_ELEMENTS (InstanceNode, list, ill, next,
  SGLIB_LIST_MAP_ON_ELEMENTS (InstanceNode, list, ill, next,
  {
  {
    BindNode * bll;
    BindNode * bll;
        SGLIB_LIST_MAP_ON_ELEMENTS (BindNode,ill->bindslist, bll, next,
        SGLIB_LIST_MAP_ON_ELEMENTS (BindNode,ill->bindslist, bll, next,
        {
        {
        if ((strcmp(name,bll->namebind)==0))
        if ((strcmp(name,bll->namebind)==0))
        {
        {
         return 1;
         return 1;
        }
        }
        }
        }
        );}
        );}
  );
  );
  return 0;
  return 0;
}
}
 
 
 
 
 
 
SensibilityNode *
SensibilityNode *
InsertSensibility (SensibilityNode * list, char *name, char *tipo)
InsertSensibility (SensibilityNode * list, char *name, char *tipo)
{
{
  SensibilityNode *sl;
  SensibilityNode *sl;
  sl = (SensibilityNode *) malloc (sizeof (SensibilityNode));
  sl = (SensibilityNode *) malloc (sizeof (SensibilityNode));
  strcpy (sl->name, name);
  strcpy (sl->name, name);
  strcpy (sl->tipo, tipo);
  strcpy (sl->tipo, tipo);
  SGLIB_LIST_ADD (SensibilityNode, list, sl, next);
  SGLIB_LIST_ADD (SensibilityNode, list, sl, next);
  return (list);
  return (list);
}
}
 
 
void
void
ShowSensibilityList (SensibilityNode * list)
ShowSensibilityList (SensibilityNode * list)
{
{
  SensibilityNode *sll;
  SensibilityNode *sll;
  SGLIB_LIST_MAP_ON_ELEMENTS (SensibilityNode, list, sll, next,
  SGLIB_LIST_MAP_ON_ELEMENTS (SensibilityNode, list, sll, next,
  {
  {
        if (!strcmp (sll->tipo, "posedge")|| !strcmp (sll->tipo,"negedge"))
        if (!strcmp (sll->tipo, "posedge")|| !strcmp (sll->tipo,"negedge"))
          printf (" %s",sll->tipo);
          printf (" %s",sll->tipo);
        if (sll->next == NULL)
        if (sll->next == NULL)
        {
        {
          printf (" %s", sll->name); break;
          printf (" %s", sll->name); break;
        }
        }
        else
        else
        {
        {
          printf (" %s or", sll->name);}
          printf (" %s or", sll->name);}
    }
    }
  );
  );
  return;
  return;
}
}
 
 
 
 
ProcessNode *
ProcessNode *
InsertProcess (ProcessNode * list, char *name,
InsertProcess (ProcessNode * list, char *name,
               SensibilityNode * SensibilityList, char *tipo)
               SensibilityNode * SensibilityList, char *tipo)
{
{
  ProcessNode *pl;
  ProcessNode *pl;
  pl = (ProcessNode *) malloc (sizeof (ProcessNode));
  pl = (ProcessNode *) malloc (sizeof (ProcessNode));
  strcpy (pl->name, name);
  strcpy (pl->name, name);
  strcpy (pl->tipo, tipo);
  strcpy (pl->tipo, tipo);
  pl->list = SensibilityList;
  pl->list = SensibilityList;
  SGLIB_LIST_ADD (ProcessNode, list, pl, next);
  SGLIB_LIST_ADD (ProcessNode, list, pl, next);
  return (list);
  return (list);
}
}
 
 
 
 
void
void
ShowProcessList (ProcessNode * list)
ShowProcessList (ProcessNode * list)
{
{
  ProcessNode *pll;
  ProcessNode *pll;
  SGLIB_LIST_MAP_ON_ELEMENTS (ProcessNode, list, pll, next,
  SGLIB_LIST_MAP_ON_ELEMENTS (ProcessNode, list, pll, next,
  {
  {
        printf ("%s: always @(", pll->name);
        printf ("%s: always @(", pll->name);
        ShowSensibilityList (pll->list); printf (")\n");
        ShowSensibilityList (pll->list); printf (")\n");
  }
  }
  );
  );
  return;
  return;
}
}
 
 
 
 
void
void
ShowProcessCode (ProcessNode * list)
ShowProcessCode (ProcessNode * list)
{
{
  FILE *archivo;
  FILE *archivo;
  int readok;
  int readok;
  char lookahead;
  char lookahead;
  char *filename;
  char *filename;
  char auxchar;
  char auxchar;
  char begin[10];
  char begin[10];
 
 
  ProcessNode *pll;
  ProcessNode *pll;
  SGLIB_LIST_MAP_ON_ELEMENTS (ProcessNode, list, pll, next,
  SGLIB_LIST_MAP_ON_ELEMENTS (ProcessNode, list, pll, next,
  {
  {
    fprintf(stderr,"Writing process code => %s\n",pll->name);
    fprintf(stderr,"Writing process code => %s\n",pll->name);
        printf ("//%s:\n", pll->name);
        printf ("//%s:\n", pll->name);
        filename =(char *) malloc (256 * sizeof (char));
        filename =(char *) malloc (256 * sizeof (char));
        strcpy (filename, pll->name);
        strcpy (filename, pll->name);
        strcat (filename, (char *) "_regs.sc2v");
        strcat (filename, (char *) "_regs.sc2v");
        archivo = fopen (filename, (char *) "r");
        archivo = fopen (filename, (char *) "r");
        while (1)
        while (1)
        {
        {
          readok =fread ((void *) &auxchar, sizeof (char), 1,archivo);
          readok =fread ((void *) &auxchar, sizeof (char), 1,archivo);
          if (readok) printf ("%c", auxchar);
          if (readok) printf ("%c", auxchar);
          else
          else
            break;
            break;
        }
        }
    fclose (archivo);
    fclose (archivo);
    printf ("always @(");
    printf ("always @(");
 
 
    ShowSensibilityList (pll->list);
    ShowSensibilityList (pll->list);
    printf (" )\n");
    printf (" )\n");
    printf ("   begin\n");
    printf ("   begin\n");
    strcpy (filename, pll->name);
    strcpy (filename, pll->name);
    strcat (filename, (char *) ".sc2v");
    strcat (filename, (char *) ".sc2v");
    archivo = fopen (filename, (char *) "r");
    archivo = fopen (filename, (char *) "r");
 
 
        /*Read the initial begin of the file */
        /*Read the initial begin of the file */
    fscanf (archivo, "%s", begin);
    fscanf (archivo, "%s", begin);
    readok =fread ((void *) &auxchar, sizeof (char), 1,archivo);
    readok =fread ((void *) &auxchar, sizeof (char), 1,archivo);
 
 
        /*Trim the beggining of the file */
        /*Trim the beggining of the file */
        while (auxchar == '\n' || auxchar == ' ' || auxchar == '\t')
        while (auxchar == '\n' || auxchar == ' ' || auxchar == '\t')
            readok =fread ((void *) &auxchar, sizeof (char), 1,archivo); printf ("\n   %c", auxchar);
            readok =fread ((void *) &auxchar, sizeof (char), 1,archivo); printf ("\n   %c", auxchar);
 
 
        while (1){
        while (1){
          readok = fread ((void *) &auxchar, sizeof (char), 1,archivo);
          readok = fread ((void *) &auxchar, sizeof (char), 1,archivo);
          if (readok){
          if (readok){
             if (strcmp (pll->tipo, "comb") == 0 && auxchar == '<')
             if (strcmp (pll->tipo, "comb") == 0 && auxchar == '<')
                 {
                 {
                   readok = fread ((void *) &lookahead, sizeof (char), 1, archivo);
                   readok = fread ((void *) &lookahead, sizeof (char), 1, archivo);
                   if (readok){
                   if (readok){
                          if (lookahead == '='){
                          if (lookahead == '='){
                              auxchar = lookahead;
                              auxchar = lookahead;
                          }else{
                          }else{
                              printf ("%c", auxchar);
                              printf ("%c", auxchar);
                              auxchar = lookahead;
                              auxchar = lookahead;
                          }
                          }
                   }
                   }
             }
             }
                 printf ("%c", auxchar);
                 printf ("%c", auxchar);
          }
          }
      else
      else
      {
      {
        break;
        break;
          }
          }
    }
    }
 
 
    fclose (archivo);
    fclose (archivo);
    }
    }
  );
  );
 
 
}
}
 
 
InstanceNode *
InstanceNode *
InsertInstance (InstanceNode * list, char *nameinstance, char *namemodulo)
InsertInstance (InstanceNode * list, char *nameinstance, char *namemodulo)
{
{
  InstanceNode *il;
  InstanceNode *il;
  il = (InstanceNode *) malloc (sizeof (InstanceNode));
  il = (InstanceNode *) malloc (sizeof (InstanceNode));
  strcpy (il->nameinstance, nameinstance);
  strcpy (il->nameinstance, nameinstance);
  strcpy (il->namemodulo, namemodulo);
  strcpy (il->namemodulo, namemodulo);
  il->bindslist = NULL;
  il->bindslist = NULL;
  SGLIB_LIST_ADD (InstanceNode, list, il, next);
  SGLIB_LIST_ADD (InstanceNode, list, il, next);
  return (list);
  return (list);
}
}
 
 
BindNode *
BindNode *
InsertBind (BindNode * list, char *nameport, char *namebind)
InsertBind (BindNode * list, char *nameport, char *namebind)
{
{
  BindNode *bl;
  BindNode *bl;
  bl = (BindNode *) malloc (sizeof (BindNode));
  bl = (BindNode *) malloc (sizeof (BindNode));
  strcpy (bl->nameport, nameport);
  strcpy (bl->nameport, nameport);
  strcpy (bl->namebind, namebind);
  strcpy (bl->namebind, namebind);
  SGLIB_LIST_ADD (BindNode, list, bl, next);
  SGLIB_LIST_ADD (BindNode, list, bl, next);
  return (list);
  return (list);
 
 
}
}
 
 
 
 
void
void
ShowInstancedModules (InstanceNode * list)
ShowInstancedModules (InstanceNode * list)
{
{
  InstanceNode *ill;
  InstanceNode *ill;
  SGLIB_LIST_MAP_ON_ELEMENTS (InstanceNode, list, ill, next,
  SGLIB_LIST_MAP_ON_ELEMENTS (InstanceNode, list, ill, next,
  {
  {
        printf ("%s %s (", ill->namemodulo,ill->nameinstance);
        printf ("%s %s (", ill->namemodulo,ill->nameinstance);
        BindNode * bll;
        BindNode * bll;
        SGLIB_LIST_MAP_ON_ELEMENTS (BindNode,ill->bindslist, bll,next,
        SGLIB_LIST_MAP_ON_ELEMENTS (BindNode,ill->bindslist, bll,next,
        {
        {
          printf (".%s(%s)",bll->nameport,bll->namebind);
          printf (".%s(%s)",bll->nameport,bll->namebind);
          if (bll->next == NULL)
          if (bll->next == NULL)
            printf (");\n");
            printf (");\n");
          else
          else
            printf (", ");}
            printf (", ");}
    );}
    );}
  );
  );
}
}
 
 
 
 
EnumeratesNode *InsertEnumerates (EnumeratesNode * list, char *name)
EnumeratesNode *InsertEnumerates (EnumeratesNode * list, char *name)
{
{
 
 
  EnumeratesNode *el;
  EnumeratesNode *el;
  el = (EnumeratesNode *) malloc (sizeof (EnumeratesNode));
  el = (EnumeratesNode *) malloc (sizeof (EnumeratesNode));
  strcpy (el->name, name);
  strcpy (el->name, name);
  SGLIB_LIST_ADD (EnumeratesNode, list, el, next);
  SGLIB_LIST_ADD (EnumeratesNode, list, el, next);
  return (list);
  return (list);
}
}
 
 
 
 
int
int
ShowEnumeratesList (EnumeratesNode *list)
ShowEnumeratesList (EnumeratesNode *list)
{
{
 
 
  EnumeratesNode *ell;
  EnumeratesNode *ell;
  int i = 0;
  int i = 0;
 
 
  printf ("parameter  %s = 0", list->name);
  printf ("parameter  %s = 0", list->name);
 
 
  if(list->next!=NULL){
  if(list->next!=NULL){
    list=list->next;
    list=list->next;
    printf(",\n");
    printf(",\n");
    i=1;
    i=1;
    SGLIB_LIST_MAP_ON_ELEMENTS (EnumeratesNode,list, ell,next,
    SGLIB_LIST_MAP_ON_ELEMENTS (EnumeratesNode,list, ell,next,
    {
    {
      if(ell->next==NULL)
      if(ell->next==NULL)
          {
          {
                printf("           %s = %d;\n\n",ell->name,i);
                printf("           %s = %d;\n\n",ell->name,i);
                return(i);
                return(i);
          }
          }
          else
          else
          {
          {
            printf("           %s = %d,\n",ell->name,i);
            printf("           %s = %d,\n",ell->name,i);
          }
          }
          i++;
          i++;
        }
        }
        );
        );
  }else{
  }else{
    printf(";\n\n");
    printf(";\n\n");
        return(i);
        return(i);
  }
  }
}
}
 
 
EnumListNode *
EnumListNode *
InsertEnumList (EnumListNode * list, EnumeratesNode * enumlist, char *name,int istype)
InsertEnumList (EnumListNode * list, EnumeratesNode * enumlist, char *name,int istype)
{
{
  EnumListNode *el;
  EnumListNode *el;
  el = (EnumListNode *) malloc (sizeof (EnumListNode));
  el = (EnumListNode *) malloc (sizeof (EnumListNode));
  strcpy (el->name, name);
  strcpy (el->name, name);
  el->istype=istype;
  el->istype=istype;
  el->list=enumlist;
  el->list=enumlist;
  SGLIB_LIST_ADD (EnumListNode, list, el, next);
  SGLIB_LIST_ADD (EnumListNode, list, el, next);
  return (list);
  return (list);
}
}
 
 
void
void
ShowEnumListList (EnumListNode * list)
ShowEnumListList (EnumListNode * list)
{
{
 
 
  int items;
  int items;
  EnumListNode *ell;
  EnumListNode *ell;
  double bits, bits_round;
  double bits, bits_round;
  int bits_i;
  int bits_i;
 
 
  SGLIB_LIST_MAP_ON_ELEMENTS(EnumListNode,list, ell,next,
  SGLIB_LIST_MAP_ON_ELEMENTS(EnumListNode,list, ell,next,
  {
  {
 
 
          items = ShowEnumeratesList (ell->list);
          items = ShowEnumeratesList (ell->list);
 
 
          //Calculate the number of bits needed to represent the enumerate
          //Calculate the number of bits needed to represent the enumerate
          bits = log ((double) (items + 1)) / log (2.0);
          bits = log ((double) (items + 1)) / log (2.0);
          bits_i = bits;
          bits_i = bits;
          bits_round = bits_i;
          bits_round = bits_i;
          if (bits_round != bits)
          if (bits_round != bits)
            bits_i++;
            bits_i++;
          if (bits_i == 0)
          if (bits_i == 0)
            bits_i = 1;
            bits_i = 1;
 
 
          if (!(ell->istype))
          if (!(ell->istype))
            {
            {
            if ((bits_i - 1) != 0)
            if ((bits_i - 1) != 0)
                  printf ("reg [%d:0] %s;\n\n", bits_i - 1, ell->name);
                  printf ("reg [%d:0] %s;\n\n", bits_i - 1, ell->name);
            else
            else
                  printf ("reg %s;\n\n", ell->name);
                  printf ("reg %s;\n\n", ell->name);
            }
            }
 
 
  }
  }
  );
  );
}
}
 
 
 
 
int
int
findEnumList (EnumListNode * list, char *name)
findEnumList (EnumListNode * list, char *name)
{
{
 
 
  int i = 0;
  int i = 0;
  EnumListNode *ell;
  EnumListNode *ell;
 
 
  SGLIB_LIST_MAP_ON_ELEMENTS (EnumListNode,list, ell,next,
  SGLIB_LIST_MAP_ON_ELEMENTS (EnumListNode,list, ell,next,
  {
  {
          //printf("%s %s %d %d\n", aux->name,name,aux->istype,i);
          //printf("%s %s %d %d\n", aux->name,name,aux->istype,i);
          if ((strcmp (ell->name, name) == 0) && ((ell->istype) == 1))
          if ((strcmp (ell->name, name) == 0) && ((ell->istype) == 1))
          {
          {
         return i;
         return i;
      }
      }
 
 
          i++;
          i++;
   }
   }
   );
   );
   return -1;
   return -1;
}
}
 
 
 
 
int
int
findEnumerateLength (EnumListNode * list, int offset)
findEnumerateLength (EnumListNode * list, int offset)
{
{
 
 
  int i,j = 0;
  int i,j = 0;
  double bits, bits_round;
  double bits, bits_round;
  int bits_i;
  int bits_i;
 
 
  EnumListNode *ell;
  EnumListNode *ell;
  EnumeratesNode *enumll;
  EnumeratesNode *enumll;
 
 
  j=0;
  j=0;
  i=0;
  i=0;
 
 
  SGLIB_LIST_MAP_ON_ELEMENTS (EnumListNode,list, ell,next,
  SGLIB_LIST_MAP_ON_ELEMENTS (EnumListNode,list, ell,next,
  {
  {
    i++;
    i++;
    if(i==offset+1){
    if(i==offset+1){
      SGLIB_LIST_MAP_ON_ELEMENTS (EnumeratesNode,ell->list, enumll,next,
      SGLIB_LIST_MAP_ON_ELEMENTS (EnumeratesNode,ell->list, enumll,next,
      {
      {
            j++;
            j++;
          });
          });
        }
        }
  });
  });
 
 
   //Calculate the number of bits needed to represent the enumerate
   //Calculate the number of bits needed to represent the enumerate
   bits = log ((double) (j)) / log (2.0);
   bits = log ((double) (j)) / log (2.0);
   bits_i = bits;
   bits_i = bits;
   bits_round = bits_i;
   bits_round = bits_i;
 
 
   if (bits_round != bits)
   if (bits_round != bits)
    bits_i++;
    bits_i++;
   if (bits_i == 0)
   if (bits_i == 0)
        bits_i = 1;
        bits_i = 1;
 
 
   return bits_i;
   return bits_i;
 
 
 }
 }
 
 
 /* Functions for functions inputs list*/
 /* Functions for functions inputs list*/
FunctionInputNode *InsertFunctionInput (FunctionInputNode * list, char *name, int lenght, int flag){
FunctionInputNode *InsertFunctionInput (FunctionInputNode * list, char *name, int lenght, int flag){
  FunctionInputNode *fl;
  FunctionInputNode *fl;
  fl = (FunctionInputNode *) malloc (sizeof (FunctionInputNode));
  fl = (FunctionInputNode *) malloc (sizeof (FunctionInputNode));
  strcpy (fl->name, name);
  strcpy (fl->name, name);
  fl->lenght=lenght;
  fl->lenght=lenght;
  fl->sgnflag=flag;
  fl->sgnflag=flag;
  SGLIB_LIST_ADD (FunctionInputNode, list, fl, next);
  SGLIB_LIST_ADD (FunctionInputNode, list, fl, next);
  return (list);
  return (list);
}
}
 
 
void ShowFunctionInputs (FunctionInputNode * list){
void ShowFunctionInputs (FunctionInputNode * list){
 
 
  FunctionInputNode *fll;
  FunctionInputNode *fll;
 
 
  SGLIB_LIST_REVERSE(FunctionInputNode,list, next);
  SGLIB_LIST_REVERSE(FunctionInputNode,list, next);
 
 
  SGLIB_LIST_MAP_ON_ELEMENTS (FunctionInputNode,list, fll,next,
  SGLIB_LIST_MAP_ON_ELEMENTS (FunctionInputNode,list, fll,next,
  {
  {
    if(fll->sgnflag==0)
    if(fll->sgnflag==0)
    {
    {
    if(fll->lenght!=1)
    if(fll->lenght!=1)
     printf("input [%d:0] %s;\n",(fll->lenght)-1,fll->name);
     printf("input [%d:0] %s;\n",(fll->lenght)-1,fll->name);
    else
    else
     printf("input %s;\n",fll->name);
     printf("input %s;\n",fll->name);
     } else {
     } else {
     if(fll->lenght!=1)
     if(fll->lenght!=1)
     printf("input signed [%d:0] %s;\n",(fll->lenght)-1,fll->name);
     printf("input signed [%d:0] %s;\n",(fll->lenght)-1,fll->name);
    else
    else
     printf("input signed %s;\n",fll->name);
     printf("input signed %s;\n",fll->name);
     }
     }
  });
  });
}
}
 
 
/* Functions for functions list*/
/* Functions for functions list*/
FunctionNode *InsertFunction (FunctionNode *list, char *name,FunctionInputNode *InputsList,int outputlenght,int flag){
FunctionNode *InsertFunction (FunctionNode *list, char *name,FunctionInputNode *InputsList,int outputlenght,int flag){
  FunctionNode *fl;
  FunctionNode *fl;
  fl = (FunctionNode *) malloc (sizeof (FunctionNode));
  fl = (FunctionNode *) malloc (sizeof (FunctionNode));
  strcpy (fl->name, name);
  strcpy (fl->name, name);
  fl->outputlenght=outputlenght;
  fl->outputlenght=outputlenght;
  fl->list = InputsList;
  fl->list = InputsList;
  fl->sgnflag=flag;
  fl->sgnflag=flag;
  SGLIB_LIST_ADD (FunctionNode, list, fl, next);
  SGLIB_LIST_ADD (FunctionNode, list, fl, next);
  return (list);
  return (list);
}
}
 
 
void ShowFunctionCode (FunctionNode *list){
void ShowFunctionCode (FunctionNode *list){
 
 
  FILE *archivo;
  FILE *archivo;
  int readok;
  int readok;
  char *filename;
  char *filename;
  char auxchar;
  char auxchar;
  char begin[10];
  char begin[10];
 
 
  FunctionNode *fll;
  FunctionNode *fll;
 
 
  SGLIB_LIST_MAP_ON_ELEMENTS (FunctionNode,list, fll,next,
  SGLIB_LIST_MAP_ON_ELEMENTS (FunctionNode,list, fll,next,
  {
  {
   if(fll->sgnflag==0)
   if(fll->sgnflag==0)
   {
   {
        if(fll->outputlenght!=1)
        if(fll->outputlenght!=1)
     printf("function [%d:0] %s;\n\n",(fll->outputlenght)-1,fll->name);
     printf("function [%d:0] %s;\n\n",(fll->outputlenght)-1,fll->name);
    else
    else
         printf("function %s;\n\n",fll->name);
         printf("function %s;\n\n",fll->name);
        } else {
        } else {
   if(fll->outputlenght!=1)
   if(fll->outputlenght!=1)
     printf("function signed [%d:0] %s;\n\n",(fll->outputlenght)-1,fll->name);
     printf("function signed [%d:0] %s;\n\n",(fll->outputlenght)-1,fll->name);
    else
    else
         printf("function signed %s;\n\n",fll->name);
         printf("function signed %s;\n\n",fll->name);
   }
   }
 
 
        ShowFunctionInputs(fll->list);
        ShowFunctionInputs(fll->list);
 
 
        //Show Registers
        //Show Registers
        filename =(char *) malloc (256 * sizeof (char));
        filename =(char *) malloc (256 * sizeof (char));
        strcpy (filename, fll->name);
        strcpy (filename, fll->name);
        strcat (filename, (char *) "_regs.sc2v");
        strcat (filename, (char *) "_regs.sc2v");
        archivo = fopen (filename, (char *) "r");
        archivo = fopen (filename, (char *) "r");
        if(archivo==NULL){
        if(archivo==NULL){
                fprintf(stderr,"Error opening file %s\n",filename);
                fprintf(stderr,"Error opening file %s\n",filename);
                exit(1);
                exit(1);
        }
        }
        printf("\n");
        printf("\n");
        while (1)
        while (1)
        {
        {
          readok =fread ((void *) &auxchar, sizeof (char), 1,archivo);
          readok =fread ((void *) &auxchar, sizeof (char), 1,archivo);
          if (readok) printf ("%c", auxchar);
          if (readok) printf ("%c", auxchar);
          else{
          else{
                break;
                break;
          }
          }
        }
        }
    fclose (archivo);
    fclose (archivo);
 
 
        printf ("\n   begin\n");
        printf ("\n   begin\n");
    strcpy (filename, fll->name);
    strcpy (filename, fll->name);
    strcat (filename, (char *) ".sc2v");
    strcat (filename, (char *) ".sc2v");
    archivo = fopen (filename, (char *) "r");
    archivo = fopen (filename, (char *) "r");
 
 
        /*Read the initial begin of the file */
        /*Read the initial begin of the file */
    fscanf (archivo, "%s", begin);
    fscanf (archivo, "%s", begin);
    readok =fread ((void *) &auxchar, sizeof (char), 1,archivo);
    readok =fread ((void *) &auxchar, sizeof (char), 1,archivo);
 
 
        /*Trim the beggining of the file */
        /*Trim the beggining of the file */
        while (auxchar == '\n' || auxchar == ' ' || auxchar == '\t')
        while (auxchar == '\n' || auxchar == ' ' || auxchar == '\t')
            readok =fread ((void *) &auxchar, sizeof (char), 1,archivo); printf ("\n   %c", auxchar);
            readok =fread ((void *) &auxchar, sizeof (char), 1,archivo); printf ("\n   %c", auxchar);
 
 
        while (1){
        while (1){
          readok = fread ((void *) &auxchar, sizeof (char), 1,archivo);
          readok = fread ((void *) &auxchar, sizeof (char), 1,archivo);
          if (readok)
          if (readok)
             printf ("%c", auxchar);
             printf ("%c", auxchar);
          else
          else
         break;
         break;
        }
        }
    printf("endfunction\n\n");
    printf("endfunction\n\n");
 
 
    fclose (archivo);
    fclose (archivo);
 
 
  });
  });
 
 
}
}
 
 

powered by: WebSVN 2.1.0

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