LOGIN   :::   RECOVER PASS   :::   GET ACCOUNT    
Browse
  • Projects
  • Code (CVS)
  • Forums
  • News
  • Articles
  • Polls
  •  
    OpenCores
  • FAQ
  • CVS HowTo
  • Mission
  • Media
  • Tools
  • Sponsors
  • Mirrors
  • Logos
  • Contact us
  •  
    Tools
  • Search
      
  • Download Cores (CVSGet)
  •  
    More
  • Wishbone
  • Perlilog
  • EDA tools
  • OpenTech CD
  •  
    Navigation: All forums > Cvs-checkins > Message List > Message Post

    Message

    Reply | Reply all
    Date Prev | Date Next | Thread Prev | Thread Next Date Index | Thread Index

    From: OpenCores CVS Agent<cvs@o...>
    Date: Wed Jan 26 17:50:18 CET 2005
    Subject: [cvs-checkins] MODIFIED: sc2v ...
    Top
    Date: 00/05/01 26:17:50

    Modified: sc2v/src list.c list.h sc2v_step1.y sc2v_step2.y
    sc2v_step3.y
    Log:
    Version 0.2.5. View ChangeLog




    Revision Changes Path
    1.4 +1683 -859 sc2v/src/list.c

    http://www.opencores.org/cvsweb.shtml/sc2v/src/list.c.diff?r1=1.3&r2=1.4

    (In the diff below, changes in quantity of whitespace are not shown.)

    Index: list.c
    ===================================================================
    RCS file: /cvsroot/jcastillo/sc2v/src/list.c,v
    retrieving revision 1.3
    retrieving revision 1.4
    diff -u -b -r1.3 -r1.4
    --- list.c 23 Jan 2005 13:19:43 -0000 1.3
    +++ list.c 26 Jan 2005 16:50:16 -0000 1.4
    @@ -27,919 +27,1743 @@

    #include "list.h"

    -void InitializeDefinesList(DefinesList *list)
    +void
    +InitializeDefinesList (DefinesList * list)
    {
    +
    DefineNode *first;
    - first = (DefineNode *)malloc(sizeof(DefineNode));
    +
    + first = (DefineNode *) malloc (sizeof (DefineNode));
    +
    list->first = first;
    +
    list->last = NULL;
    +
    }

    -void InsertDefine(DefinesList *list, char *name)
    +
    +void
    +InsertDefine (DefinesList * list, char *name)
    {
    - if(list->last == NULL) //list empty
    +
    + if (list->last == NULL) //list empty
    {
    - list->first->name = (char *)malloc(256*sizeof(char));
    - strcpy(list->first->name ,name);
    +
    + list->first->name = (char *) malloc (256 * sizeof (char));
    +
    + strcpy (list->first->name, name);
    +
    list->first->next = NULL;
    +
    list->last = list->first;
    +
    }
    +
    else
    +
    {
    +
    DefineNode *nuevo;
    - nuevo = (DefineNode *)malloc(sizeof(DefineNode));
    - nuevo->name = (char *)malloc(256*sizeof(char));
    - strcpy(nuevo->name ,name);
    +
    + nuevo = (DefineNode *) malloc (sizeof (DefineNode));
    +
    + nuevo->name = (char *) malloc (256 * sizeof (char));
    +
    + strcpy (nuevo->name, name);
    +
    nuevo->next = NULL;
    +
    list->last->next = nuevo;
    +
    list->last = nuevo;
    +
    }
    }

    -int IsDefine(DefinesList *list, char *name)
    +int
    +IsDefine (DefinesList * list, char *name)
    {
    +
    DefineNode *auxwrite = list->first;

    - if(list->last == NULL)
    +
    + if (list->last == NULL)
    +
    { + return 0; + } + else + { - while(1) + + while (1) + { - if((strcmp(name, auxwrite->name)==0)) + + if ((strcmp (name, auxwrite->name) == 0)) + { + return 1; + } - else if(auxwrite->next != NULL) + + else if (auxwrite->next != NULL) + { + auxwrite = auxwrite->next; + } + else + { + break; + } + } + } + return 0; + } -void ShowDefines(char *filedefines) + +void +ShowDefines (char *filedefines) { + int readok; + char *auxchar; + FILE *file; - file = fopen(filedefines,(char *)"r"); - while(1) + file = fopen (filedefines, (char *) "r"); + + + while (1) + { - readok = fread((void *)&auxchar, sizeof(char), 1, file); - if(readok) - printf("%c",auxchar); + + readok = fread ((void *) &auxchar, sizeof (char), 1, file); + + if (readok) + + printf ("%c", auxchar); + else + break; + } + } -void InitializeWritesList(WritesList *list) + +void +InitializeWritesList (WritesList * list) { + WriteNode *first; - first = (WriteNode *)malloc(sizeof(WriteNode)); + + first = (WriteNode *) malloc (sizeof (WriteNode)); + list->first = first; + list->last = NULL; + } -void InsertWrite(WritesList *list, char *name) + +void +InsertWrite (WritesList * list, char *name) { - if(list->last == NULL) //list empty + + if (list->last == NULL) //list empty { - list->first->name = (char *)malloc(256*sizeof(char)); - strcpy(list->first->name ,name); + + list->first->name = (char *) malloc (256 * sizeof (char)); + + strcpy (list->first->name, name); + list->first->next = NULL; + list->last = list->first; + } + else + { + WriteNode *nuevo; - nuevo = (WriteNode *)malloc(sizeof(WriteNode)); - nuevo->name = (char *)malloc(256*sizeof(char)); - strcpy(nuevo->name ,name); + + nuevo = (WriteNode *) malloc (sizeof (WriteNode)); + + nuevo->name = (char *) malloc (256 * sizeof (char)); + + strcpy (nuevo->name, name); + nuevo->next = NULL; + list->last->next = nuevo; + list->last = nuevo; + } } -int IsWrite(WritesList *list, char *name) +int +IsWrite (WritesList * list, char *name) { + WriteNode *auxwrite = list->first; - if(list->last == NULL) + + if (list->last == NULL) + { + return 0; + } + else + { - while(1) + + while (1) + { - if((strcmp(name, auxwrite->name)==0)) + + if ((strcmp (name, auxwrite->name) == 0)) + { + return 1; + } - else if(auxwrite->next != NULL) + + else if (auxwrite->next != NULL) + { + auxwrite = auxwrite->next; + } + else + { + break; + } + } + } + return 0; + } -void ShowWritesList(WritesList *list) + +void +ShowWritesList (WritesList * list) { - if(list->last != NULL) //list not empty + + if (list->last != NULL) //list not empty { + WriteNode *aux = list->first; - while(1) + + while (1) + { - printf("%s\n",aux->name); - if(aux->next==NULL) + + printf ("%s\n", aux->name); + + if (aux->next == NULL) + { + break; + } + aux = aux->next; + } + } + } -void ReadWritesFile(WritesList *list, char *name) + +void +ReadWritesFile (WritesList * list, char *name) { + char *leido; + int ret; + FILE *file_writes; - file_writes = fopen(name, (char *)"r"); - leido = (char *)malloc(256*sizeof(char)); + file_writes = fopen (name, (char *) "r"); + + + leido = (char *) malloc (256 * sizeof (char)); + + + while (1) - while(1) { - ret = fscanf(file_writes,"%s",leido); - if(ret == EOF) + + ret = fscanf (file_writes, "%s", leido); + + if (ret == EOF) + break; - InsertWrite(list, leido); + + InsertWrite (list, leido); + } + } -void InitializeRegsList(RegsList *list) + +void +InitializeRegsList (RegsList * list) { + RegNode *first; - first = (RegNode *)malloc(sizeof(RegNode)); + + first = (RegNode *) malloc (sizeof (RegNode)); + list->first = first; + list->last = NULL; + } -void InsertReg(RegsList *list, char *name, char *name2) + +void +InsertReg (RegsList * list, char *name, char *name2) { - if(list->last == NULL) + + if (list->last == NULL) + { - list->first->name = (char *)malloc(256*sizeof(char)); - list->first->name2 = (char *)malloc(256*sizeof(char)); - strcpy(list->first->name ,name); - strcpy(list->first->name2 ,name2); + + list->first->name = (char *) malloc (256 * sizeof (char)); + + list->first->name2 = (char *) malloc (256 * sizeof (char)); + + strcpy (list->first->name, name); + + strcpy (list->first->name2, name2); + list->first->next = NULL; + list->last = list->first; + } + else + { + RegNode *nuevo; - nuevo = (RegNode *)malloc(sizeof(RegNode)); - nuevo->name = (char *)malloc(256*sizeof(char)); - nuevo->name2 = (char *)malloc(256*sizeof(char)); - strcpy(nuevo->name ,name); - strcpy(nuevo->name2 ,name2); + + nuevo = (RegNode *) malloc (sizeof (RegNode)); + + nuevo->name = (char *) malloc (256 * sizeof (char)); + + nuevo->name2 = (char *) malloc (256 * sizeof (char)); + + strcpy (nuevo->name, name); + + strcpy (nuevo->name2, name2); + nuevo->next = NULL; + list->last->next = nuevo; + list->last = nuevo; + } } + /* Looks if a WORD of func.y file is a register of the process*/ -char *IsReg(RegsList *list, char *name) +char * +IsReg (RegsList * list, char *name) { + RegNode *auxreg = list->first; - if(list->last == NULL) + + if (list->last == NULL) + { + return NULL; + } + else + { - while(1) + + while (1) + { - if((strcmp(name, auxreg->name)==0)) + + if ((strcmp (name, auxreg->name) == 0)) + { + return auxreg->name2; + } - else if(auxreg->next != NULL) + + else if (auxreg->next != NULL) + { + auxreg = auxreg->next; + } + else + { + break; + } + } + } + return NULL; + } -void ShowRegsList(RegsList *list) + +void +ShowRegsList (RegsList * list) { - if(list->last != NULL) + + if (list->last != NULL) + { + RegNode *aux = list->first; - while(1) + + while (1) + { - printf("%s\t",aux->name); - printf("%s;\n",aux->name2); - if(aux->next==NULL) + + printf ("%s\t", aux->name); + + printf ("%s;\n", aux->name2); + + if (aux->next == NULL) + { + break; + } + aux = aux->next; + } + } + } -void InitializePortList(PortList *list) + +void +InitializePortList (PortList * list) { + PortNode *first; - first = (PortNode *)malloc(sizeof(PortNode)); + + first = (PortNode *) malloc (sizeof (PortNode)); + list->first = first; + list->last = NULL; + } -void InsertPort(PortList *list, char *name, char *tipo, int size) + +void +InsertPort (PortList * list, char *name, char *tipo, int size) { - if(list->last == NULL) + + if (list->last == NULL) + { + list->first->name = name; + list->first->tipo = tipo; + list->first->size = size; + list->first->next = NULL; + list->last = list->first; + } + else + { + PortNode *nuevo; - nuevo = (PortNode *)malloc(sizeof(PortNode)); + + nuevo = (PortNode *) malloc (sizeof (PortNode)); + nuevo->name = name; + nuevo->tipo = tipo; + nuevo->size = size; + nuevo->next = NULL; + list->last->next = nuevo; + list->last = nuevo; + } + } -void ShowPortList(PortList *list) + +void +ShowPortList (PortList * list) { - if(list->last != NULL) + + if (list->last != NULL) + { + PortNode *aux = list->first; - while(1) + + while (1) + { - printf("%s ",aux->tipo); - if(aux->size != 0 && aux->size !=1) + + printf ("%s ", aux->tipo); + + if (aux->size != 0 && aux->size != 1) + { - printf("[%d:0] ",(-1 + aux->size)); + + printf ("[%d:0] ", (-1 + aux->size)); + } - printf("%s;\n",aux->name); - if(aux->next==NULL) + + printf ("%s;\n", aux->name); + + if (aux->next == NULL) + { + break; + } + aux = aux->next; + } + } + } -void RegOutputs(PortList *list) + +void +RegOutputs (PortList * list) { - if(list->last != NULL) - { + + if (list->last != NULL) + + { + PortNode *aux = list->first; - while(1) + + while (1) + { - if(strcmp(aux->tipo, (char *)"output")==0) + + if (strcmp (aux->tipo, (char *) "output") == 0) + { - printf("reg "); - if(aux->size != 0 && aux->size!=1) + + printf ("reg "); + + if (aux->size != 0 && aux->size != 1) + { - printf("[%d:0] ",(-1 + aux->size)); + + printf ("[%d:0] ", (-1 + aux->size)); + } - printf("%s;\n",aux->name); + + printf ("%s;\n", aux->name); + } - if(aux->next==NULL) + + if (aux->next == NULL) + { + break; + } + aux = aux->next; + } + } + } -void EnumeratePorts(PortList *list) + +void +EnumeratePorts (PortList * list) { - if(list->last != NULL) + + if (list->last != NULL) + { + PortNode *aux = list->first; - while(1) + + while (1) + { - if(aux->next==NULL) + + if (aux->next == NULL) + { - printf("%s",aux->name); + + printf ("%s", aux->name); + break; + } + else + { - printf("%s,",aux->name); + + printf ("%s,", aux->name); + aux = aux->next; + } + } + } + } -void InitializeSignalsList(SignalsList *list) + +void +InitializeSignalsList (SignalsList * list) { + SignalNode *first; - first = (SignalNode *)malloc(sizeof(SignalNode)); + + first = (SignalNode *) malloc (sizeof (SignalNode)); + list->first = first; + list->last = NULL; + } -void InsertSignal(SignalsList *list, char *name, int size) + +void +InsertSignal (SignalsList * list, char *name, int size) { - if(list->last == NULL) + + if (list->last == NULL) + { + list->first->name = name; + list->first->size = size; + list->first->next = NULL; + list->last = list->first; + } + else + { + SignalNode *nuevo; - nuevo = (SignalNode *)malloc(sizeof(SignalNode)); + + nuevo = (SignalNode *) malloc (sizeof (SignalNode)); + nuevo->name = name; + nuevo->size = size; + nuevo->next = NULL; + list->last->next = nuevo; + list->last = nuevo; + } + } -void ShowSignalsList(SignalsList *list, WritesList *WritesList) + +void +ShowSignalsList (SignalsList * list, WritesList * WritesList) { - if(list->last != NULL) + + if (list->last != NULL) + { + SignalNode *aux = list->first; - while(1) + + while (1) + { - if(IsWrite(WritesList, aux->name)) + + if (IsWrite (WritesList, aux->name)) + { - printf("reg "); - if(aux->size != 0 && aux->size!=1) + + printf ("reg "); + + if (aux->size != 0 && aux->size != 1) + { - printf("[%d:0] ",(-1 + aux->size)); + + printf ("[%d:0] ", (-1 + aux->size)); + } - printf("%s;\n",aux->name); + + printf ("%s;\n", aux->name); + } + else + { - printf("wire "); - if(aux->size != 0 && aux->size!=1) + + printf ("wire "); + + if (aux->size != 0 && aux->size != 1) + { - printf("[%d:0] ",(-1 + aux->size)); + + printf ("[%d:0] ", (-1 + aux->size)); + } - printf("%s;\n",aux->name); + + printf ("%s;\n", aux->name); + } - if(aux->next==NULL) + + if (aux->next == NULL) + { + break; + } + aux = aux->next; + } + } + } + + /* Decides if a signal is a wire or a reg*/ -int IsWire(char *name, InstancesList *list) +int +IsWire (char *name, InstancesList * list) { + InstanceNode *auxinstance = list->first; + BindNode *auxbind; - if(list->last == NULL) + + if (list->last == NULL) + { + return 0; + } + else + { - while(1) + + while (1) + { + auxbind = auxinstance->bindslist->first; - while(1) + + while (1) + { - if((strcmp(name, auxbind->namebind)==0)) + + if ((strcmp (name, auxbind->namebind) == 0)) + { + return 1; + } - else if(auxbind->next != NULL) + + else if (auxbind->next != NULL) + { + auxbind = auxbind->next; + } + else + { + break; + } + } - if(auxinstance->next != NULL) + + if (auxinstance->next != NULL) + { + auxinstance = auxinstance->next; + } + else + { + break; + } + } + } + return 0; + } -void InitializeSensibilityList(SensibilityList *list) + +void +InitializeSensibilityList (SensibilityList * list) { + SensibilityNode *first; - first = (SensibilityNode *)malloc(sizeof(SensibilityNode)); + + first = (SensibilityNode *) malloc (sizeof (SensibilityNode)); + list->first = first; + list->last = NULL; + } -void InsertSensibility(SensibilityList *list, char *name, char *tipo) + +void +InsertSensibility (SensibilityList * list, char *name, char *tipo) { - if(list->last == NULL) + + if (list->last == NULL) + { + list->first->name = name; + list->first->tipo = tipo; + list->first->next = NULL; + list->last = list->first; + } + else + { + SensibilityNode *nuevo; - nuevo = (SensibilityNode *)malloc(sizeof(SensibilityNode)); + + nuevo = (SensibilityNode *) malloc (sizeof (SensibilityNode)); + nuevo->name = name; + nuevo->tipo = tipo; + nuevo->next = NULL; + list->last->next = nuevo; + list->last = nuevo; + } + } -void ShowSensibilityList(SensibilityList *list) + +void +ShowSensibilityList (SensibilityList * list) { - if(list->last != NULL) + + if (list->last != NULL) + { + SensibilityNode *aux = list->first; - while(1) + + while (1) + { - if(!strcmp(aux->tipo,"posedge") || !strcmp(aux->tipo, "negedge")) - printf(" %s",aux->tipo); - if(aux->next==NULL) + + if (!strcmp (aux->tipo, "posedge") + || !strcmp (aux->tipo, "negedge")) + + printf (" %s", aux->tipo); + + if (aux->next == NULL) + { - printf(" %s",aux->name); + + printf (" %s", aux->name); + break; + } + else + { - printf(" %s or",aux->name); + + printf (" %s or", aux->name); + } + aux = aux->next; + } + } + } -void InitializeProcessList(ProcessList *list) + +void +InitializeProcessList (ProcessList * list) { + ProcessNode *first; - first = (ProcessNode *)malloc(sizeof(ProcessNode)); + + first = (ProcessNode *) malloc (sizeof (ProcessNode)); + list->first = first; + list->last = NULL; + } -void InsertProcess(ProcessList *list, char *name, SensibilityList *SensibilityList, char *tipo) + +void +InsertProcess (ProcessList * list, char *name, + SensibilityList * SensibilityList, char *tipo) { - if(list->last == NULL) + + if (list->last == NULL) + { + list->first->name = name; + list->first->tipo = tipo; + list->first->list = SensibilityList; + list->first->next = NULL; + list->last = list->first; + } + else + { + ProcessNode *nuevo; - nuevo = (ProcessNode *)malloc(sizeof(ProcessNode)); + + nuevo = (ProcessNode *) malloc (sizeof (ProcessNode)); + nuevo->name = name; + nuevo->tipo = tipo; + nuevo->list = SensibilityList; + nuevo->next = NULL; + list->last->next = nuevo; + list->last = nuevo; + } + } -void ShowProcessList(ProcessList *list) + +void +ShowProcessList (ProcessList * list) { - if(list->last != NULL) + + if (list->last != NULL) + { + ProcessNode *aux = list->first; - while(1) + + while (1) + { - printf("%s: always @(", aux->name); - ShowSensibilityList(aux->list); - printf(")\n"); - if(aux->next==NULL) + + printf ("%s: always @(", aux->name); + + ShowSensibilityList (aux->list); + + printf (")\n"); + + if (aux->next == NULL) + { + break; + } + aux = aux->next; + } + } + } -void ShowProcessCode(ProcessList *list) + +void +ShowProcessCode (ProcessList * list) { - if(list->last != NULL) + + if (list->last != NULL) + { + ProcessNode *aux = list->first; FILE *archivo; int readok; + char lookahead; char *filename; char auxchar; char begin[10]; - while(1) + + while (1) { - printf("//%s:\n", aux->name); - filename = (char *)malloc(256*sizeof(char)); - strcpy(filename,aux->name); - strcat(filename,(char *)"_regs.sc2v"); - archivo = fopen(filename,(char *)"r"); + printf ("//%s:\n", aux->name); + filename = (char *) malloc (256 * sizeof (char)); + strcpy (filename, aux->name); + strcat (filename, (char *) "_regs.sc2v"); + archivo = fopen (filename, (char *) "r"); - while(1) + while (1) { - readok = fread((void *)&auxchar, sizeof(char), 1, archivo); - if(readok) - printf("%c",auxchar); + readok = fread ((void *) &auxchar, sizeof (char), 1, archivo); + if (readok) + printf ("%c", auxchar); else break; } - fclose(archivo); + fclose (archivo); + + printf ("always @("); + + ShowSensibilityList (aux->list); - printf("always @("); - ShowSensibilityList(aux->list); - printf(" )\n"); - printf(" begin\n"); - strcpy(filename,aux->name); - strcat(filename,(char *)".sc2v"); - archivo = fopen(filename,(char *)"r"); + printf (" )\n"); + printf (" begin\n"); + strcpy (filename, aux->name); + strcat (filename, (char *) ".sc2v"); + archivo = fopen (filename, (char *) "r"); - /*Read the initial begin of the file*/ - fscanf(archivo,"%s",begin); - readok=fread((void *)&auxchar, sizeof(char), 1, archivo); + /*Read the initial begin of the file */ + fscanf (archivo, "%s", begin); - /*Trim the beggining of the file*/ - while(auxchar=='\n' || auxchar==' ' || auxchar=='\t') - readok=fread((void *)&auxchar, sizeof(char), 1, archivo); + readok = fread ((void *) &auxchar, sizeof (char), 1, archivo); - printf("\n %c",auxchar); + /*Trim the beggining of the file */ + while (auxchar == '\n' || auxchar == ' ' || auxchar == '\t') + readok = fread ((void *) &auxchar, sizeof (char), 1, archivo); + + printf ("\n %c", auxchar); + + while (1) + { + readok = fread ((void *) &auxchar, sizeof (char), 1, archivo); + if (readok) + { + if (strcmp (aux->tipo, "comb") == 0 && auxchar == '<') + { + readok = fread ((void *) &lookahead, sizeof (char), 1,archivo); - while(1) + if (readok) + { + if (lookahead == '=') + { + auxchar = lookahead; + } + else { - readok = fread((void *)&auxchar, sizeof(char), 1, archivo); - if(readok) - printf("%c",auxchar); + printf ("%c", auxchar); + } + } + } + printf ("%c", auxchar); + } else + { break; } + } - fclose(archivo); + fclose (archivo); - if(aux->next==NULL) + if (aux->next == NULL) { break; } + aux = aux->next; + } + } + } -void InitializeInstancesList(InstancesList *list) + +void +InitializeInstancesList (InstancesList * list) { + InstanceNode *first; - first = (InstanceNode *)malloc(sizeof(InstanceNode)); + + first = (InstanceNode *) malloc (sizeof (InstanceNode)); + list->first = first; + list->last = NULL; + } -void InsertInstance(InstancesList *list, char *nameinstance, char *namemodulo) + +void +InsertInstance (InstancesList * list, char *nameinstance, char *namemodulo) { - if(list->last == NULL) + + if (list->last == NULL) + { + list->first->nameinstance = nameinstance; + list->first->namemodulo = namemodulo; + list->first->next = NULL; + list->last = list->first; - list->last->bindslist = (BindsList *)malloc(sizeof(BindsList)); - list->last->bindslist = (BindsList *)malloc(sizeof(BindsList)); - InitializeBindsList(list->last->bindslist); + + list->last->bindslist = (BindsList *) malloc (sizeof (BindsList)); + + list->last->bindslist = (BindsList *) malloc (sizeof (BindsList)); + + InitializeBindsList (list->last->bindslist); + } + else + { + InstanceNode *nuevo; - nuevo = (InstanceNode *)malloc(sizeof(InstanceNode)); + + nuevo = (InstanceNode *) malloc (sizeof (InstanceNode)); + nuevo->nameinstance = nameinstance; + nuevo->namemodulo = namemodulo; + nuevo->next = NULL; + list->last->next = nuevo; + list->last = nuevo; - list->last->bindslist = (BindsList *)malloc(sizeof(BindsList)); - InitializeBindsList(list->last->bindslist); + + list->last->bindslist = (BindsList *) malloc (sizeof (BindsList)); + + InitializeBindsList (list->last->bindslist); + } + } -void InitializeBindsList(BindsList *list) + +void +InitializeBindsList (BindsList * list) { + BindNode *first; - first = (BindNode *)malloc(sizeof(BindNode)); + + first = (BindNode *) malloc (sizeof (BindNode)); + list->first = first; + list->last = NULL; + } -void InsertBind(BindsList *list, char *nameport, char *namebind) + +void +InsertBind (BindsList * list, char *nameport, char *namebind) { - if(list->last == NULL) + + if (list->last == NULL) + { + list->first->nameport = nameport; + list->first->namebind = namebind; + list->first->next = NULL; + list->last = list->first; + } + else + { + BindNode *nuevo; - nuevo = (BindNode *)malloc(sizeof(BindNode)); + + nuevo = (BindNode *) malloc (sizeof (BindNode)); + nuevo->nameport = nameport; + nuevo->namebind = namebind; + nuevo->next = NULL; + list->last->next = nuevo; + list->last = nuevo; + } + } -void ShowInstancedModules(InstancesList *list) + +void +ShowInstancedModules (InstancesList * list) { - if(list->last != NULL) + + if (list->last != NULL) + { + InstanceNode *auxinstance; + auxinstance = list->first; + BindNode *auxbind; + auxbind = auxinstance->bindslist->first; - while(1) + + while (1) + { - printf("%s %s (",auxinstance->namemodulo, auxinstance->nameinstance); - while(1) + + printf ("%s %s (", auxinstance->namemodulo, + auxinstance->nameinstance); + + while (1) + { - printf(".%s(%s)",auxbind->nameport, auxbind->namebind); - if(auxbind->next == NULL) + + printf (".%s(%s)", auxbind->nameport, auxbind->namebind); + + if (auxbind->next == NULL) + { - printf(");\n"); + + printf (");\n"); + break; + } + else + { - printf(", "); + + printf (", "); + auxbind = auxbind->next; + } + } - if(auxinstance->next == NULL) + + if (auxinstance->next == NULL) + { + break; + } + else + { + auxinstance = auxinstance->next; + auxbind = auxinstance->bindslist->first; + } + } + } + } + + //Enumerates list -void InitializeEnumeratesList(EnumeratesList *list) +void +InitializeEnumeratesList (EnumeratesList * list) { + EnumeratesNode *first; - first = (EnumeratesNode *)malloc(sizeof(EnumeratesNode)); + + first = (EnumeratesNode *) malloc (sizeof (EnumeratesNode)); + list->first = first; + list->last = NULL; + } -void InsertEnumerates(EnumeratesList *list, char *name) + +void +InsertEnumerates (EnumeratesList * list, char *name) { - if(list->last == NULL) + + if (list->last == NULL) + { + list->first->name = name; + list->first->next = NULL; + list->last = list->first; + } + else + { + EnumeratesNode *nuevo; - nuevo = (EnumeratesNode *)malloc(sizeof(EnumeratesNode)); + + nuevo = (EnumeratesNode *) malloc (sizeof (EnumeratesNode)); + nuevo->name = name; + nuevo->next = NULL; + list->last->next = nuevo; + list->last = nuevo; + } + } -int ShowEnumeratesList(EnumeratesList *list) + +int +ShowEnumeratesList (EnumeratesList * list) { - int i=0; - if(list->last != NULL) + + int i = 0; + + if (list->last != NULL) + { + EnumeratesNode *aux = list->first; - printf("parameter %s = 0",aux->name); - if(aux->next!=NULL){ - printf(",\n"); + printf ("parameter %s = 0", aux->name); + + + if (aux->next != NULL) + { + + printf (",\n"); + aux = aux->next; - i=1; - while(1) + + i = 1; + + while (1) + { - if(aux->next==NULL) + + if (aux->next == NULL) + { - printf(" %s = %d;\n\n",aux->name,i); - return(i); + + printf (" %s = %d;\n\n", aux->name, i); + + return (i); + } + else + { - printf(" %s = %d,\n",aux->name,i); + + printf (" %s = %d,\n", aux->name, i); + } + i++; + aux = aux->next; + } - }else{ - printf(";\n\n"); - return(i); + + } + else + { + + printf (";\n\n"); + + return (i); + } + } + } + + //List of enumerates list -void InitializeEnumListList(EnumListList *list) +void +InitializeEnumListList (EnumListList * list) { + EnumListNode *first; - first = (EnumListNode *)malloc(sizeof(EnumListNode)); + + first = (EnumListNode *) malloc (sizeof (EnumListNode)); + list->first = first; + list->last = NULL; + } -void InsertEnumList(EnumListList *list, EnumeratesList *enumlist, char *name, int istype) + +void +InsertEnumList (EnumListList * list, EnumeratesList * enumlist, char *name, + int istype) { - if(list->last == NULL) + + if (list->last == NULL) + { + list->first->name = name; + list->first->istype = istype; + list->first->list = enumlist; + list->first->next = NULL; + list->last = list->first; + } + else + { + EnumListNode *nuevo; - nuevo = (EnumListNode *)malloc(sizeof(EnumListNode)); + + nuevo = (EnumListNode *) malloc (sizeof (EnumListNode)); + nuevo->name = name; + nuevo->istype = istype; + nuevo->list = enumlist; + nuevo->next = NULL; + list->last->next = nuevo; + list->last = nuevo; + } + } -void ShowEnumListList(EnumListList *list) + +void +ShowEnumListList (EnumListList * list) { + int items; - if(list->last != NULL) + + if (list->last != NULL) + { + EnumListNode *aux = list->first; - while(1) + + while (1) + { - items=ShowEnumeratesList(aux->list); + + items = ShowEnumeratesList (aux->list); + //Calculate the number of bits needed to represent the enumerate - double bits,bits_round; + double bits, bits_round; + int bits_i; - bits=log((double)(items+1))/log(2.0); - bits_i=bits; - bits_round=bits_i; - if(bits_round!=bits) bits_i++; - if(bits_i==0) bits_i=1; - if(!(aux->istype)){ - if((bits_i-1)!=0) - printf("reg [%d:0] %s;\n\n",bits_i-1,aux->name); + bits = log ((double) (items + 1)) / log (2.0); + + bits_i = bits; + + bits_round = bits_i; + + if (bits_round != bits) + bits_i++; + + if (bits_i == 0) + bits_i = 1; + + + if (!(aux->istype)) + { + + if ((bits_i - 1) != 0) + + printf ("reg [%d:0] %s;\n\n", bits_i - 1, aux->name); + else - printf("reg %s;\n\n",aux->name); + + printf ("reg %s;\n\n", aux->name); + } - if(aux->next==NULL) + + if (aux->next == NULL) + { + break; + } + aux = aux->next; + } + } + } -int findEnumList(EnumListList *list, char *name) + +int +findEnumList (EnumListList * list, char *name) { - int i=0; - if(list->last != NULL) + + int i = 0; + + if (list->last != NULL) + { + EnumListNode *aux = list->first; - while(1) + + while (1) + { + //printf("%s %s %d %d\n", aux->name,name,aux->istype,i); - if((strcmp(aux->name,name)==0) && ((aux->istype)==1)){ + if ((strcmp (aux->name, name) == 0) && ((aux->istype) == 1)) + { + return i; + } - if(aux->next==NULL){ + + if (aux->next == NULL) + { + return -1; + } + aux = aux->next; + i++; + + } + } - } else + else + return -1; + } -int findEnumerateLength(EnumListList *list, int offset){ - int i=0; - double bits,bits_round; + +int +findEnumerateLength (EnumListList * list, int offset) +{ + + int i = 0; + + double bits, bits_round; + int bits_i; - if(list->last != NULL) + + if (list->last != NULL) + { - i=0; + + i = 0; + EnumListNode *aux = list->first; + EnumeratesNode *aux2; - for(i=0;i< offset; i++) + + for (i = 0; i < offset; i++) + aux = aux->next; - aux2=aux->list->first; - i=0; - while(1) + aux2 = aux->list->first; + + + i = 0; + + while (1) + { + i++; - if(aux2->next==NULL){ + + if (aux2->next == NULL) + { + //Calculate the number of bits needed to represent the enumerate - bits=log((double)(i))/log(2.0); - bits_i=bits; - bits_round=bits_i; - if(bits_round!=bits) bits_i++; - if(bits_i==0) bits_i=1; + bits = log ((double) (i)) / log (2.0); + + bits_i = bits; + + bits_round = bits_i; + + if (bits_round != bits) + bits_i++; + + if (bits_i == 0) + bits_i = 1; + return bits_i; + } + aux2 = aux2->next; + } + } + } 1.3 +147 -122 sc2v/src/list.h http://www.opencores.org/cvsweb.shtml/sc2v/src/list.h.diff?r1=1.2&r2=1.3 (In the diff below, changes in quantity of whitespace are not shown.) Index: list.h =================================================================== RCS file: /cvsroot/jcastillo/sc2v/src/list.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- list.h 20 Dec 2004 17:49:07 -0000 1.2 +++ list.h 26 Jan 2005 16:50:16 -0000 1.3 @@ -22,184 +22,209 @@ */ -typedef struct _define_node { +typedef struct _define_node +{ char *name; struct _define_node *next; } DefineNode; -typedef struct _defines_list { +typedef struct _defines_list +{ DefineNode *first; DefineNode *last; } DefinesList; -typedef struct _write_node { +typedef struct _write_node +{ char *name; struct _write_node *next; } WriteNode; -typedef struct _writes_list { +typedef struct _writes_list +{ WriteNode *first; WriteNode *last; } WritesList; -typedef struct _reg_node { +typedef struct _reg_node +{ char *name; char *name2; struct _reg_node *next; } RegNode; -typedef struct _regs_list { +typedef struct _regs_list +{ RegNode *first; RegNode *last; } RegsList; -typedef struct _port_node { +typedef struct _port_node +{ char *name; char *tipo; int size; struct _port_node *next; } PortNode; -typedef struct _port_list { +typedef struct _port_list +{ PortNode *first; PortNode *last; } PortList; -typedef struct _signal_node { +typedef struct _signal_node +{ char *name; int size; struct _signal_node *next; } SignalNode; -typedef struct _signals_list { +typedef struct _signals_list +{ SignalNode *first; SignalNode *last; } SignalsList; -typedef struct _bind_node { +typedef struct _bind_node +{ char *nameport; char *namebind; struct _bind_node *next; } BindNode; -typedef struct _binds_list { +typedef struct _binds_list +{ BindNode *first; BindNode *last; } BindsList; -typedef struct _instance_node { +typedef struct _instance_node +{ char *nameinstance; char *namemodulo; BindsList *bindslist; struct _instance_node *next; - } InstanceNode; +} InstanceNode; -typedef struct _instances_list { +typedef struct _instances_list +{ InstanceNode *first; InstanceNode *last; } InstancesList; -typedef struct _sensibility_node { +typedef struct _sensibility_node +{ char *tipo; char *name; struct _sensibility_node *next; } SensibilityNode; -typedef struct _sensibility_list { +typedef struct _sensibility_list +{ SensibilityNode *first; SensibilityNode *last; } SensibilityList; -typedef struct _process_node { +typedef struct _process_node +{ char *name; char *tipo; //comb or seq SensibilityList *list; struct _process_node *next; } ProcessNode; -typedef struct _process_list { +typedef struct _process_list +{ ProcessNode *first; ProcessNode *last; } ProcessList; -typedef struct _enumerates_node { +typedef struct _enumerates_node +{ char *name; struct _enumerates_node *next; } EnumeratesNode; -typedef struct _enumerates_list { +typedef struct _enumerates_list +{ EnumeratesNode *first; EnumeratesNode *last; } EnumeratesList; -typedef struct _enumlist_node { +typedef struct _enumlist_node +{ char *name; int istype; EnumeratesList *list; struct _enumlist_node *next; } EnumListNode; -typedef struct _enumlist_list { +typedef struct _enumlist_list +{ EnumListNode *first; EnumListNode *last; } EnumListList; /* Functions for DEFINES list*/ -void InitializeDefinesList(DefinesList *list); -void InsertDefine(DefinesList *list, char *name); -int IsDefine(DefinesList *list, char *name); -void ShowDefines(char *filedefines); +void InitializeDefinesList (DefinesList * list); +void InsertDefine (DefinesList * list, char *name); +int IsDefine (DefinesList * list, char *name); +void ShowDefines (char *filedefines); /* Functions for WRITES list*/ -void InitializeWritesList(WritesList *list); -void InsertWrite(WritesList *list, char *name); -int IsWrite(WritesList *list, char *name); -void ShowRegsList(RegsList *list); -void ReadWritesFile(WritesList *list, char *name); +void InitializeWritesList (WritesList * list); +void InsertWrite (WritesList * list, char *name); +int IsWrite (WritesList * list, char *name); +void ShowRegsList (RegsList * list); +void ReadWritesFile (WritesList * list, char *name); /* Functions for registers list*/ -void InitializeRegsList(RegsList *list); -void InsertReg(RegsList *list, char *name, char *name2); -char *IsReg(RegsList *list, char *name); -void ShowRegsList(RegsList *list); +void InitializeRegsList (RegsList * list); +void InsertReg (RegsList * list, char *name, char *name2); +char *IsReg (RegsList * list, char *name); +void ShowRegsList (RegsList * list); /* Functions for ports list*/ -void InitializePortList(PortList *list); -void InsertPort(PortList *list, char *name, char *tipo, int size); -void ShowPortList(PortList *list); -void EnumeratePorts(PortList *list); +void InitializePortList (PortList * list); +void InsertPort (PortList * list, char *name, char *tipo, int size); +void ShowPortList (PortList * list); +void EnumeratePorts (PortList * list); /* Functions for signals list*/ -void InitializeSignalsList(SignalsList *list); -void InsertSignal(SignalsList *list, char *name, int size); -void ShowSignalsList(SignalsList *list, WritesList *WritesList); -int IsWire(char *name, InstancesList *list); +void InitializeSignalsList (SignalsList * list); +void InsertSignal (SignalsList * list, char *name, int size); +void ShowSignalsList (SignalsList * list, WritesList * WritesList); +int IsWire (char *name, InstancesList * list); /* Functions for sensitivity list*/ -void InitializeSensibilityList(SensibilityList *list); -void InsertSensibility(SensibilityList *list, char *name, char *tipo); -void ShowSensibilityList(SensibilityList *list); +void InitializeSensibilityList (SensibilityList * list); +void InsertSensibility (SensibilityList * list, char *name, char *tipo); +void ShowSensibilityList (SensibilityList * list); /* Functions for process list*/ -void InsertProcess(ProcessList *list, char *name, SensibilityList *SensibilityList, char *tipo); -void ShowProcessList(ProcessList *list); -void ShowProcessCode(ProcessList *list); +void InsertProcess (ProcessList * list, char *name, + SensibilityList * SensibilityList, char *tipo); +void ShowProcessList (ProcessList * list); +void ShowProcessCode (ProcessList * list); /* Functions for instances and binds list*/ -void InitializeInstancesList(InstancesList *list); -void InsertInstance(InstancesList *list, char *nameInstance, char *namemodulo); -void InitializeBindsList(BindsList *list); -void InsertBind(BindsList *list, char *namePort, char *namebind); -void ShowInstancedModules(InstancesList *list); +void InitializeInstancesList (InstancesList * list); +void InsertInstance (InstancesList * list, char *nameInstance, + char *namemodulo); +void InitializeBindsList (BindsList * list); +void InsertBind (BindsList * list, char *namePort, char *namebind); +void ShowInstancedModules (InstancesList * list); /* Functions for enumerates list*/ -void InitializeEnumeratesList(EnumeratesList *list); -void InsertEnumerates(EnumeratesList *list, char *name); -int ShowEnumeratesList(EnumeratesList *list); +void InitializeEnumeratesList (EnumeratesList * list); +void InsertEnumerates (EnumeratesList * list, char *name); +int ShowEnumeratesList (EnumeratesList * list); /*Functions of list of enumerates list*/ -void InitializeEnumListList(EnumListList *list); -void InsertEnumList(EnumListList *list, EnumeratesList *enumlist, char *name, int istype); -void ShowEnumListList(EnumListList *list); -int findEnumList(EnumListList *list, char *name); -int findEnumerateLength(EnumListList *list, int offset); +void InitializeEnumListList (EnumListList * list); +void InsertEnumList (EnumListList * list, EnumeratesList * enumlist, + char *name, int istype); +void ShowEnumListList (EnumListList * list); +int findEnumList (EnumListList * list, char *name); +int findEnumerateLength (EnumListList * list, int offset); 1.6 +1072 -870 sc2v/src/sc2v_step1.y http://www.opencores.org/cvsweb.shtml/sc2v/src/sc2v_step1.y.diff?r1=1.5&r2=1.6 (In the diff below, changes in quantity of whitespace are not shown.) Index: sc2v_step1.y =================================================================== RCS file: /cvsroot/jcastillo/sc2v/src/sc2v_step1.y,v retrieving revision 1.5 retrieving revision 1.6 diff -u -b -r1.5 -r1.6 --- sc2v_step1.y 23 Jan 2005 13:19:44 -0000 1.5 +++ sc2v_step1.y 26 Jan 2005 16:50:16 -0000 1.6 @@ -29,85 +29,92 @@ #include "list.h" /* Global var to store Regs */ -RegsList *regslist; + RegsList *regslist; /* Global var to store Defines */ -DefinesList *defineslist; + DefinesList *defineslist; -int processfound = 0; -int switchfound = 0; -int switchparenthesis = 0; -char *processname, *processname2; -char *fileregs; -char *filename ; -int openedkeys = 0; -int newline = 0; -int reg_found = 0; -int regs_end; -int i = 0; //for loops counter -FILE *file; -FILE *regs_file; -char *regname, *regname2; -char *lastword; // Stores last WORD for use it in WRITE -char *file_defines; -FILE *FILE_DEFINES; -char *file_writes; -FILE *FILE_WRITES; //FILE to store .write to know if it is a wire or reg -int definefound = 0; -int defineinvocationfound = 0; -int opencorchfound = 0; + int processfound = 0; + int switchfound = 0; + int switchparenthesis[256]; + int ifdeffound = 0; + char *processname, *processname2; + char *fileregs; + char *filename; + int openedkeys = 0; + int newline = 0; + int reg_found = 0; + int regs_end; + int i = 0; //for loops counter + FILE *file; + FILE *regs_file; + char *regname, *regname2; + char *lastword; // Stores last WORD for use it in WRITE + char *file_defines; + FILE *FILE_DEFINES; + char *file_writes; + FILE *FILE_WRITES; //FILE to store .write to know if it is a wire or reg + int definefound = 0; + int defineinvocationfound = 0; + int opencorchfound = 0; + int defineparenthesis = 0; -int openedcase = 0; + int openedcase = 0; -int default_break_found = 0; -int default_found; + int default_break_found = 0; + int default_found; //Directives variables -int translate; -int verilog; -int writemethod; + int translate; + int verilog; + int writemethod; -void yyerror(const char *str) -{ - fprintf(stderr,"error: %s\n",str); -} + void yyerror (const char *str) + { + fprintf (stderr, "error: %s\n", str); + } -int yywrap() -{ + int yywrap () + { return 1; -} + } -main() -{ - regslist = (RegsList *)malloc(sizeof(RegsList)); - InitializeRegsList(regslist); - defineslist = (DefinesList *)malloc(sizeof(DefinesList)); - InitializeDefinesList(defineslist); - - processname = (char *)malloc(256*sizeof(int)); - processname2 = (char *)malloc(256*sizeof(int)); - fileregs = (char *)malloc(256*sizeof(int)); - - file_defines = (char *)malloc(256*sizeof(int)); - strcpy(file_defines, (char *)"file_defines.sc2v"); - FILE_DEFINES = fopen(file_defines,(char *)"w"); - - file_writes = (char *)malloc(256*sizeof(int)); - strcpy(file_writes, (char *)"file_writes.sc2v"); - FILE_WRITES = fopen(file_writes,(char *)"w"); - if(FILE_WRITES!=NULL) - printf("\nopening file => filename = %s\n",file_writes); - - lastword=malloc(sizeof(char)*256); - - translate=1; - verilog=0; - writemethod=0; - - yyparse(); - fclose(FILE_WRITES); - fclose(FILE_DEFINES); -} + main () + { + int i; + + regslist = (RegsList *) malloc (sizeof (RegsList)); + InitializeRegsList (regslist); + defineslist = (DefinesList *) malloc (sizeof (DefinesList)); + InitializeDefinesList (defineslist); + + processname = (char *) malloc (256 * sizeof (int)); + processname2 = (char *) malloc (256 * sizeof (int)); + fileregs = (char *) malloc (256 * sizeof (int)); + + file_defines = (char *) malloc (256 * sizeof (int)); + strcpy (file_defines, (char *) "file_defines.sc2v"); + FILE_DEFINES = fopen (file_defines, (char *) "w"); + + file_writes = (char *) malloc (256 * sizeof (int)); + strcpy (file_writes, (char *) "file_writes.sc2v"); + FILE_WRITES = fopen (file_writes, (char *) "w"); + if (FILE_WRITES != NULL) + printf ("\nopening file => filename = %s\n", file_writes); + + lastword = malloc (sizeof (char) * 256); + + for (i = 0; i < 256; i++) + switchparenthesis[i] = 0; + + translate = 1; + verilog = 0; + writemethod = 0; + + yyparse (); + fclose (FILE_WRITES); + fclose (FILE_DEFINES); + } %} @@ -117,11 +124,8 @@ %token VOID TTRUE TFALSE %token PIFDEF PENDDEF PELSE -%% - -commands: /* empty */ - | commands command - ; +%% commands:/* empty */ +|commands command; command: @@ -195,7 +199,11 @@ | hexa | - define + definemacro + | + defineword + | + definenumber | translateoff | @@ -213,780 +221,974 @@ | ttrue | - tfalse - ; + tfalse; voidword: - VOID - { - if(verilog==1) - fprintf(file," void"); - }; +VOID +{ + defineparenthesis = 0; + if (verilog == 1) + fprintf (file, " void"); +}; include: - INCLUDE - { - if(verilog==1) - fprintf(file," #include"); - }; +INCLUDE +{ + defineparenthesis = 0; + if (verilog == 1) + fprintf (file, " #include"); +}; dollar: - DOLLAR - { - if(verilog==1) - fprintf(file," $"); - }; +DOLLAR +{ + defineparenthesis = 0; + if (verilog == 1) + fprintf (file, " $"); +}; intconv: - INTCONV - { - if(verilog==1) - fprintf(file," (int)"); - }; +INTCONV +{ + defineparenthesis = 0; + if (verilog == 1) + fprintf (file, " (int)"); +}; tab: - TAB - { - if(verilog==1) - fprintf(file," \t"); - }; +TAB +{ + defineparenthesis = 0; + if (verilog == 1) + fprintf (file, " \t"); +}; read: - READ OPENPAR CLOSEPAR +READ OPENPAR CLOSEPAR +{ + defineparenthesis = 0; + if (verilog == 1) + fprintf (file, ".read()"); + +} + +defineword: +DEFINE WORD WORD +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(verilog==1) - fprintf(file,".read()"); + if (processfound) + { + fprintf (file, "`define %s %s\n", (char *) $2, (char *) $3); + InsertDefine (defineslist, (char *) $2); + } + else + { + fprintf (FILE_DEFINES, "`define %s %s\n", (char *) $2, (char *) $3); + InsertDefine (defineslist, (char *) $2); + } + } + else if (verilog == 1) + fprintf (file, "#define %s %s\n", (char *) $2, (char *) $3); + +}; +definenumber: +DEFINE WORD NUMBER +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) + { + if (processfound) + { + fprintf (file, "`define %s %d\n", (char *) $2, (int) $3); + InsertDefine (defineslist, (char *) $2); } + else + { + fprintf (FILE_DEFINES, "`define %s %d\n", (char *) $2, (int) $3); + InsertDefine (defineslist, (char *) $2); + } + } + else if (verilog == 1) + fprintf (file, "#define %s %d\n", (char *) $2, (int) $3); + +}; -define: - DEFINE WORD OPENPAR CLOSEPAR + +definemacro: +DEFINE WORD OPENPAR CLOSEPAR +{ + defineparenthesis = 0; + //Macro found + if (translate == 1 && verilog == 0) { - if(translate==1 && verilog==0){ - InsertDefine(defineslist, (char *)$2); + InsertDefine (defineslist, (char *) $2); definefound = 1; - fprintf(FILE_DEFINES,"`define %s ",(char *)$2); - }else if(verilog==1) - fprintf(file,"#define %s ()",(char *)$2); + if (processfound) + fprintf (file, "`define %s ", (char *) $2); + else + fprintf (FILE_DEFINES, "`define %s ", (char *) $2); } + else if (verilog == 1) + fprintf (file, "#define %s ()", (char *) $2); +} + void: - WORD TWODOUBLEPOINTS WORD OPENPAR CLOSEPAR +WORD TWODOUBLEPOINTS WORD OPENPAR CLOSEPAR +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - strcpy(processname ,(char *)$4); - strcpy(processname2 ,(char *)$4); - strcat(processname2, (char *)".sc2v"); - strcpy(fileregs ,(char *)$4); - strcat(fileregs, (char *)"_regs.sc2v"); - /* - strcpy(file_writes, (char *)$4); - strcat(file_writes, (char *)"_writes.sc2v"); - */ - }else if(verilog==1) - fprintf(file," %s::%s()",(char *)$1,(char *)$3); - + strcpy (processname, (char *) $4); + strcpy (processname2, (char *) $4); + strcat (processname2, (char *) ".sc2v"); + strcpy (fileregs, (char *) $4); + strcat (fileregs, (char *) "_regs.sc2v"); } + else if (verilog == 1) + fprintf (file, " %s::%s()", (char *) $1, (char *) $3); + +} + sc_int: - SC_INT LOWER NUMBER BIGGER +SC_INT LOWER NUMBER BIGGER +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(regs_file,"reg[%d:0] ",(-1 + $3)); + fprintf (regs_file, "reg[%d:0] ", (-1 + $3)); reg_found = 1; } - }else if(verilog==1) - fprintf(file,"sc_int<%d>",$3); - } - ; + else if (verilog == 1) + fprintf (file, "sc_int<%d>", $3); + +} + +; sc_uint: - SC_UINT LOWER NUMBER BIGGER +SC_UINT LOWER NUMBER BIGGER +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(regs_file,"reg[%d:0] ",(-1 + $3)); + fprintf (regs_file, "reg[%d:0] ", (-1 + $3)); reg_found = 1; } - }else if(verilog==1) - fprintf(file,"sc_uint<%d>",$3); } - ; + else if (verilog == 1) + fprintf (file, "sc_uint<%d>", $3); +} + +; sc_bigint: - SC_BIGINT LOWER NUMBER BIGGER +SC_BIGINT LOWER NUMBER BIGGER +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(regs_file,"reg[%d:0] ",(-1 + $3)); + fprintf (regs_file, "reg[%d:0] ", (-1 + $3)); reg_found = 1; } - }else if(verilog==1) - fprintf(file,"sc_bigint<%d> ",$3); } - ; + else if (verilog == 1) + fprintf (file, "sc_bigint<%d> ", $3); +} + +; sc_biguint: - SC_BIGUINT LOWER NUMBER BIGGER +SC_BIGUINT LOWER NUMBER BIGGER +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(regs_file,"reg[%d:0] ",(-1 + $3)); + fprintf (regs_file, "reg[%d:0] ", (-1 + $3)); reg_found = 1; } - }else if(verilog==1) - fprintf(file,"sc_biguint<%d> ",$3); } - ; + else if (verilog == 1) + fprintf (file, "sc_biguint<%d> ", $3); +} + +; bool: - BOOL +BOOL +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(regs_file,"reg "); + fprintf (regs_file, "reg "); reg_found = 1; } - }else if(verilog==1) - fprintf(file,"bool"); } - ; + else if (verilog == 1) + fprintf (file, "bool"); +} + +; range: - RANGE OPENPAR NUMBER COLON NUMBER CLOSEPAR +RANGE OPENPAR NUMBER COLON NUMBER CLOSEPAR +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) - fprintf(file,"[%d:%d]",$3,$5); - else if(definefound) - fprintf(FILE_DEFINES,"[%d:%d]",$3,$5); - }else if(verilog==1) - fprintf(file,".range(%d,%d)",$3,$5); + if (processfound) + fprintf (file, "[%d:%d]", $3, $5); + else if (definefound) + fprintf (FILE_DEFINES, "[%d:%d]", $3, $5); } - ; + else if (verilog == 1) + fprintf (file, ".range(%d,%d)", $3, $5); +} + +; number: - NUMBER +NUMBER +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) - if(reg_found) + if (processfound) + if (reg_found) { - if(opencorchfound) - fprintf(regs_file,"%d:0", -1 + $1); + if (opencorchfound) + fprintf (regs_file, "%d:0", -1 + $1); else - fprintf(regs_file,"%d",$1); + fprintf (regs_file, "%d", $1); } else - fprintf(file,"%d",$1); - else if(definefound) - fprintf(FILE_DEFINES,"%d",$1); - }else if(verilog==1) - fprintf(file,"%d",$1); + fprintf (file, "%d", $1); + else if (definefound) + fprintf (FILE_DEFINES, "%d", $1); } - ; + else if (verilog == 1) + fprintf (file, "%d", $1); +} + +; word: - WORD +WORD +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - if(openedcase) + if (openedcase) { - fprintf(file," :\n"); + fprintf (file, " :\n"); - for(i = 0; i < openedkeys; i++) - fprintf(file," "); + for (i = 0; i < openedkeys; i++) + fprintf (file, " "); - fprintf(file,"begin\n"); + fprintf (file, "begin\n"); openedcase = 0; } - strcpy(lastword, (char *)$1); + strcpy (lastword, (char *) $1); - if(reg_found) + if (reg_found) { - regname=malloc(sizeof(char)*(strlen((char *)$1)+1)); - regname2=malloc(sizeof(char)*(strlen((char *)$1)+strlen(processname))+1); - - strcpy(regname ,(char *)$1); - strcpy(regname2 ,(char *)$1); - strcat(regname2, processname); - fprintf(regs_file,"%s",regname2); - InsertReg(regslist, regname, regname2); - free(regname); - free(regname2); + regname = malloc (sizeof (char) * (strlen ((char *) $1) + 1)); + regname2 = + malloc (sizeof (char) * + (strlen ((char *) $1) + strlen (processname)) + 1); + + strcpy (regname, (char *) $1); + strcpy (regname2, (char *) $1); + strcat (regname2, processname); + fprintf (regs_file, "%s", regname2); + InsertReg (regslist, regname, regname2); + free (regname); + free (regname2); } else { - if(newline) + if (newline) { - for(i = 0; i < openedkeys; i++) - fprintf(file," "); + for (i = 0; i < openedkeys; i++) + fprintf (file, " "); } - regname2 = IsReg(regslist, (char *)$1); - if(regname2 == NULL) + regname2 = IsReg (regslist, (char *) $1); + if (regname2 == NULL) + { + if (IsDefine (defineslist, (char *) $1)) { - if(IsDefine(defineslist, (char *)$1)) + if (ifdeffound == 0) { - fprintf(file,"`%s", (char *)$1); + fprintf (file, "`%s", (char *) $1); defineinvocationfound = 1; } else { - fprintf(file,"%s ",(char *)$1); + fprintf (file, "%s", (char *) $1); + ifdeffound = 0; } } else - fprintf(file,"%s",regname2); + { + fprintf (file, "%s ", (char *) $1); + } + } + else + fprintf (file, "%s", regname2); newline = 0; } } - else if(definefound) + else if (definefound) { - if(IsDefine(defineslist, (char *)$1)) + if (IsDefine (defineslist, (char *) $1)) { - fprintf(FILE_DEFINES,"`%s",(char *)$1); + + fprintf (FILE_DEFINES, "`%s", (char *) $1); } else { - fprintf(FILE_DEFINES,"%s ",(char *)$1); + fprintf (FILE_DEFINES, "%s ", (char *) $1); } } - }else if(verilog==1) - fprintf(file," %s",(char *)$1); - }; + } + else if (verilog == 1) + fprintf (file, " %s", (char *) $1); +}; symbol: - SYMBOL +SYMBOL +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - if(reg_found) - fprintf(regs_file,"%s",(char *)$1); + if (reg_found) + fprintf (regs_file, "%s", (char *) $1); else - fprintf(file,"%s",(char *)$1); + fprintf (file, "%s", (char *) $1); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,"%s",(char *)$1); + fprintf (FILE_DEFINES, "%s", (char *) $1); } - }else if(verilog==1) - fprintf(file,"%s",(char *)$1); - }; + } + else if (verilog == 1) + fprintf (file, "%s", (char *) $1); +}; write: - WRITE +WRITE +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - writemethod=1; - if(processfound) + writemethod = 1; + if (processfound) { - fprintf(file," = "); - fprintf(FILE_WRITES, "%s\n", lastword); + fprintf (file, " <= "); + fprintf (FILE_WRITES, "%s\n", lastword); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES," = "); + fprintf (FILE_DEFINES, " <= "); } - }else if(verilog==1){ - fprintf(file,".write"); } - }; + else if (verilog == 1) + { + fprintf (file, ".write"); + } +}; newline: - NEWLINE +NEWLINE +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound & !reg_found & !openedcase) + if (processfound & !reg_found & !openedcase) { - fprintf(file,"\n"); + fprintf (file, "\n"); newline = 1; } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,"\n"); + fprintf (FILE_DEFINES, "\n"); } - }else if(verilog==1) - fprintf(file,"\n"); - }; + } + else if (verilog == 1) + fprintf (file, "\n"); +}; colon: - COLON +COLON +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - if(reg_found) + if (reg_found) { - fprintf(regs_file,","); + fprintf (regs_file, ","); } else - fprintf(file,","); + fprintf (file, ","); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,","); + fprintf (FILE_DEFINES, ","); } - }else if(verilog==1) - fprintf(file,","); - }; + } + else if (verilog == 1) + fprintf (file, ","); +}; semicolon: - SEMICOLON +SEMICOLON +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - if(reg_found) + if (reg_found) { - fprintf(regs_file,";\n"); + fprintf (regs_file, ";\n"); reg_found = 0; } - else if(defineinvocationfound) - { - defineinvocationfound = 0; - } else { - fprintf(file,";"); + if (defineinvocationfound == 0) + fprintf (file, ";"); } } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,";"); + fprintf (FILE_DEFINES, ";"); } - }else if(verilog==1) - fprintf(file,";"); - }; + } + else if (verilog == 1) + fprintf (file, ";"); + + defineinvocationfound = 0; +}; + openpar: - OPENPAR +OPENPAR +{ + defineparenthesis = 1; + if (translate == 1 && verilog == 0 && defineinvocationfound == 0) { - if(translate==1 && verilog==0){ - if(processfound) + if (processfound) { - fprintf(file,"("); + fprintf (file, "("); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,"("); + fprintf (FILE_DEFINES, "("); } - }else if(verilog==1) - fprintf(file,"("); - }; + + } + else if (verilog == 1) + { + fprintf (file, "("); + } +} closepar: - CLOSEPAR +CLOSEPAR +{ + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + + if (processfound) + { + if (defineparenthesis == 0) { - fprintf(file,")"); + fprintf (file, ")"); + defineinvocationfound = 0; } - else if(definefound) + + } + else if (definefound) { - fprintf(FILE_DEFINES,")"); + fprintf (FILE_DEFINES, ")"); } - }else if(verilog==1) - fprintf(file,")"); - }; + } + else if (verilog == 1) + fprintf (file, ")"); + +}; + opencorch: - OPENCORCH +OPENCORCH +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - if(reg_found) + if (reg_found) { - fprintf(regs_file,"["); + fprintf (regs_file, "["); opencorchfound = 1; } else - fprintf(file,"["); + fprintf (file, "["); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,"["); + fprintf (FILE_DEFINES, "["); } - }else if(verilog==1) - fprintf(file,"["); - }; + } + else if (verilog == 1) + fprintf (file, "["); +}; closecorch: - CLOSECORCH +CLOSECORCH +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - if(reg_found) + if (reg_found) { - fprintf(regs_file,"]"); + fprintf (regs_file, "]"); opencorchfound = 0; } else - fprintf(file,"]"); + fprintf (file, "]"); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,"]"); + fprintf (FILE_DEFINES, "]"); } - }else if(verilog==1) - fprintf(file,"]"); - }; + } + else if (verilog == 1) + fprintf (file, "]"); +}; openkey: - OPENKEY +OPENKEY +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1 && verilog==0){ openedkeys++; - if(openedkeys==1 & !definefound) + if (!definefound) + { + if (openedkeys == 1) { - printf("opening file => filename = %s\n",processname2); - file = fopen(processname2,(char *)"w"); - printf("opening file => filename = %s\n",fileregs); - regs_file = fopen(fileregs,(char *)"w"); + printf ("opening file => filename = %s\n", processname2); + file = fopen (processname2, (char *) "w"); + printf ("opening file => filename = %s\n", fileregs); + regs_file = fopen (fileregs, (char *) "w"); processfound = 1; - regslist = (RegsList *)malloc(sizeof(RegsList)); - InitializeRegsList(regslist); - /* regname = (char *)malloc(256*sizeof(int)); - regname2 = (char *)malloc(256*sizeof(int));*/ - } - if(processfound) - if(openedkeys != switchparenthesis) - { - fprintf(file,"\n"); - for(i = 0; i < openedkeys; i++) - fprintf(file," "); - fprintf(file,"begin\n"); + regslist = (RegsList *) malloc (sizeof (RegsList)); + InitializeRegsList (regslist); + } + if (processfound) + if (openedkeys != switchparenthesis[switchfound]) + { + fprintf (file, "\n"); + for (i = 0; i < openedkeys; i++) + fprintf (file, " "); + fprintf (file, "begin\n"); newline = 1; } - - }else if(verilog==1) - fprintf(file,"{"); } - ; + } + else if (verilog == 1) + fprintf (file, "{"); +}; closekey: - CLOSEKEY +CLOSEKEY +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound && !definefound) { - if(openedkeys==switchparenthesis & switchfound == 1) + if (openedkeys == switchparenthesis[switchfound] && switchfound > 0) { - fprintf(file,"\n"); - if(default_found & !default_break_found) + fprintf (file, "\n"); + if (default_found & !default_break_found) { - for(i = 0; i < openedkeys; i++) - fprintf(file," "); - fprintf(file,"end\n"); + for (i = 0; i < openedkeys - 1; i++) + fprintf (file, " "); + fprintf (file, "end\n"); default_found = 0; } - for(i = 0; i < openedkeys; i++) - fprintf(file," "); - fprintf(file,"endcase\n"); + for (i = 0; i < openedkeys - 1; i++) + fprintf (file, " "); + fprintf (file, "endcase\n"); newline = 1; - switchfound = 0; - switchparenthesis = 0; + switchparenthesis[switchfound] = 0; + switchfound--; + } else { - fprintf(file,"\n"); - for(i = 0; i < openedkeys; i++) - fprintf(file," "); - fprintf(file,"end\n"); + fprintf (file, "\n"); + for (i = 0; i < openedkeys; i++) + fprintf (file, " "); + fprintf (file, "end\n"); newline = 1; } } openedkeys--; - if(definefound) + if (definefound) { definefound = 0; - fprintf(FILE_DEFINES,"\n//Dummy Comment\n"); + if (processfound) + fprintf (file, "\n//Dummy Comment\n"); + else + fprintf (FILE_DEFINES, "\n//Dummy Comment\n"); } - else if(openedkeys==0) + else if (openedkeys == 0) { - fclose(file); - fclose(regs_file); - free(regslist); -/* free(regname); - free(regname2);*/ + fclose (file); + fclose (regs_file); + free (regslist); processfound = 0; } - }else if(verilog==1) - fprintf(file,"}"); - }; + } + else if (verilog == 1) + fprintf (file, "}"); +}; bigger: - BIGGER +BIGGER +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(file,">"); + fprintf (file, ">"); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,">"); + fprintf (FILE_DEFINES, ">"); } - }else if(verilog==1) - fprintf(file,">"); - }; + } + else if (verilog == 1) + fprintf (file, ">"); +}; lower: - LOWER +LOWER +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(file,"<"); + fprintf (file, "<"); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,"<"); + fprintf (FILE_DEFINES, "<"); } - }else if(verilog==1) - fprintf(file,"<"); - }; + } + else if (verilog == 1) + fprintf (file, "<"); +}; switch: - SWITCH +SWITCH { - if(translate==1&& verilog==0){ - if(processfound) + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - fprintf(file,"\n"); - for(i = 0; i < openedkeys; i++) - fprintf(file," "); - fprintf(file,"case"); - switchfound = 1; - switchparenthesis = openedkeys + 1; + if (processfound) + { + fprintf (file, "\n"); + for (i = 0; i < openedkeys; i++) + fprintf (file, " "); + fprintf (file, "case"); + switchfound++; + switchparenthesis[switchfound] = openedkeys + 1; + } } - }else if(verilog==1) - fprintf(file,"switch"); + else if (verilog == 1) + fprintf (file, "switch"); }; case_number: - CASE NUMBER SYMBOL +CASE NUMBER SYMBOL +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - for(i = 0; i < openedkeys; i++) - fprintf(file," "); - if(openedcase) - fprintf(file,", %d",$2); + for (i = 0; i < openedkeys; i++) + fprintf (file, " "); + if (openedcase) + fprintf (file, ", %d", $2); else - fprintf(file,"%d",$2); + fprintf (file, "%d", $2); newline = 1; openedcase = 1; } - }else if(verilog==1) - fprintf(file,"case %d %s",$2,(char *)$3); - }; + } + else if (verilog == 1) + fprintf (file, "case %d %s", $2, (char *) $3); +}; + case_word: - CASE WORD SYMBOL +CASE WORD SYMBOL +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - for(i = 0; i < openedkeys; i++) - fprintf(file," "); - if(openedcase) - fprintf(file,", %s",(char *)$2); + for (i = 0; i < openedkeys; i++) + fprintf (file, " "); + if (openedcase) + fprintf (file, ", %s", (char *) $2); else - fprintf(file,"%s",(char *)$2); + fprintf (file, "%s", (char *) $2); newline = 1; openedcase = 1; } - }else if(verilog==1) - fprintf(file,"case %s %s",(char *)$2,(char *)$3); - }; + } + else if (verilog == 1) + fprintf (file, "case %s %s", (char *) $2, (char *) $3); +}; case_default: - DEFAULT SYMBOL +DEFAULT SYMBOL +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - for(i = 0; i < openedkeys; i++) - fprintf(file," "); - fprintf(file,"default:\n"); - for(i = 0; i < openedkeys; i++) - fprintf(file," "); - fprintf(file,"begin\n"); + for (i = 0; i < openedkeys; i++) + fprintf (file, " "); + fprintf (file, "default:\n"); + for (i = 0; i < openedkeys; i++) + fprintf (file, " "); + fprintf (file, "begin\n"); newline = 1; default_found = 1; } - }else if(verilog==1) - fprintf(file,"default %s",(char *)$2); - }; + } + else if (verilog == 1) + fprintf (file, "default %s", (char *) $2); +}; case_only: - CASE OPENPAR - { +CASE OPENPAR +{ + defineparenthesis = 0; //This rule occurs when in Verilog mode a case appears - if(verilog==1) - fprintf(file,"case("); - }; + if (verilog == 1) + fprintf (file, "case("); +}; break: - BREAK SEMICOLON +BREAK SEMICOLON +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - if(newline == 0) - fprintf(file,"\n"); - for(i = 0; i < openedkeys; i++) - fprintf(file," "); - fprintf(file,"end\n"); - if(default_found) + if (newline == 0) + fprintf (file, "\n"); + for (i = 0; i < openedkeys; i++) + fprintf (file, " "); + fprintf (file, "end\n"); + if (default_found) { default_break_found = 1; } } - }else if(verilog==1) - fprintf(file,"break;"); - }; + } + else if (verilog == 1) + fprintf (file, "break;"); +}; hexa: - HEXA +HEXA +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(file,"'h"); + fprintf (file, "'h"); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,"'h"); + fprintf (FILE_DEFINES, "'h"); } - }else if(verilog==1) - fprintf(file,"0x"); - }; + } + else if (verilog == 1) + fprintf (file, "0x"); +}; translateoff: - TRANSLATEOFF - { - translate=0; - fprintf(stderr,"Found Translate off directive \n"); - }; +TRANSLATEOFF +{ + defineparenthesis = 0; + translate = 0; + fprintf (stderr, "Found Translate off directive \n"); +}; translateon: - TRANSLATEON - { - translate=1; - fprintf(stderr,"Found Translate on directive \n"); - }; +TRANSLATEON +{ + defineparenthesis = 0; + translate = 1; + fprintf (stderr, "Found Translate on directive \n"); +}; verilogbegin: - VERILOGBEGIN - { - verilog=1; - fprintf(stderr,"Found Verilog Begin directive \n"); - }; +VERILOGBEGIN +{ + defineparenthesis = 0; + verilog = 1; + fprintf (stderr, "Found Verilog Begin directive \n"); +}; verilogend: - VERILOGEND - { - verilog=0; - fprintf(stderr,"Found Verilog End directive \n"); - }; +VERILOGEND +{ + defineparenthesis = 0; + verilog = 0; + fprintf (stderr, "Found Verilog End directive \n"); +}; ifdef: - PIFDEF +PIFDEF +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(file,"`ifdef"); + ifdeffound = 1; + fprintf (file, "`ifdef"); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,"`ifdef"); + fprintf (FILE_DEFINES, "`ifdef"); } - }else if(verilog==1) - fprintf(file,"#ifdef"); - }; + } + else if (verilog == 1) + fprintf (file, "#ifdef"); +}; + endif: - PENDDEF +PENDDEF +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(file,"`endif"); + fprintf (file, "`endif"); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,"`endif"); + fprintf (FILE_DEFINES, "`endif"); } - }else if(verilog==1) - fprintf(file,"#endif"); - }; + } + else if (verilog == 1) + fprintf (file, "#endif"); +}; + pelse: - PELSE +PELSE +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(file,"`else"); + fprintf (file, "`else"); } - else if(definefound) + else if (definefound) { - fprintf(FILE_DEFINES,"`else"); + fprintf (FILE_DEFINES, "`else"); } - }else if(verilog==1) - fprintf(file,"#else"); - }; + } + else if (verilog == 1) + fprintf (file, "#else"); +}; + ttrue: - TTRUE +TTRUE +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(file,"1"); + fprintf (file, "1"); } - }else if(verilog==1) - fprintf(file,"1"); - }; + } + else if (verilog == 1) + fprintf (file, "1"); +}; tfalse: - TFALSE +TFALSE +{ + defineparenthesis = 0; + if (translate == 1 && verilog == 0) { - if(translate==1&& verilog==0){ - if(processfound) + if (processfound) { - fprintf(file,"0"); + fprintf (file, "0"); } - }else if(verilog==1) - fprintf(file,"0"); - }; + } + else if (verilog == 1) + fprintf (file, "0"); +}; 1.4 +1155 -643 sc2v/src/sc2v_step2.y http://www.opencores.org/cvsweb.shtml/sc2v/src/sc2v_step2.y.diff?r1=1.3&r2=1.4 (In the diff below, changes in quantity of whitespace are not shown.) Index: sc2v_step2.y =================================================================== RCS file: /cvsroot/jcastillo/sc2v/src/sc2v_step2.y,v retrieving revision 1.3 retrieving revision 1.4 diff -u -b -r1.3 -r1.4 --- sc2v_step2.y 23 Jan 2005 13:19:44 -0000 1.3 +++ sc2v_step2.y 26 Jan 2005 16:50:16 -0000 1.4 @@ -22,6 +22,7 @@ */ %{ + #include <stdio.h> #include <string.h> #include <math.h> @@ -30,123 +31,186 @@ /*Global var to read from file_writes.sc2v*/ -WritesList *writeslist; + WritesList *writeslist; + /*Global var to store ports*/ -PortList *portlist; + PortList *portlist; + /* Global var to store signals*/ -SignalsList *signalslist; + SignalsList *signalslist; + /* Global var to store sensitivity list*/ -SensibilityList *sensibilitylist; + SensibilityList *sensibilitylist; + /* Global var to store instantiated modules*/ -InstancesList *instanceslist; + InstancesList *instanceslist; + /* Global var to store process list*/ -ProcessList *processlist; + ProcessList *processlist; + /*List of enumerates*/ -EnumeratesList *enumerateslist; -EnumListList *enumlistlist; -char *enumname; -int reading_enumerates=0; + EnumeratesList *enumerateslist; + + EnumListList *enumlistlist; + + char *enumname; + + int reading_enumerates = 0; + /*Multiple Declarations*/ -int multipledec; -char *storedtype; + int multipledec; + + char *storedtype; + /* Global var to store process module name*/ -char *module_name; -int module_name_found = 0; + char *module_name; + + int module_name_found = 0; + /* Global var to store last port type*/ -char *lastportkind; -int lastportsize; -int activeport = 0; // 1 -> reading port list + char *lastportkind; + + int lastportsize; + + int activeport = 0; // 1 -> reading port list /* Global var to store last signal type*/ -int lastsignalsize; -int signalactive = 0; + int lastsignalsize; + + int signalactive = 0; + /* Global var to store last SC_METHOD found*/ -char *active_method; -char *active_method_type; -int method_found; + char *active_method; + + char *active_method_type; + + int method_found; + /* Global var to store last sensitivity found*/ -char *last_sensibility; -int sensibility_active = 0; + char *last_sensibility; + int sensibility_active = 0; -int translate; -void yyerror(const char *str) -{ - fprintf(stderr,"error: %s\n",str); -} -int yywrap() -{ + int translate; + + + void yyerror (const char *str) + { + + fprintf (stderr, "error: %s\n", str); + + } + + int yywrap () + { + return 1; -} -main() -{ - /*Initialize lists*/ + } + - writeslist = (WritesList *)malloc(sizeof(WritesList)); - InitializeWritesList(writeslist); + main () + { - portlist = (PortList *)malloc(sizeof(PortList)); - InitializePortList(portlist); + /*Initialize lists */ - signalslist = (SignalsList *)malloc(sizeof(SignalsList)); - InitializeSignalsList(signalslist); + writeslist = (WritesList *) malloc (sizeof (WritesList)); - sensibilitylist = (SensibilityList *)malloc(sizeof(SensibilityList)); - InitializeSensibilityList(sensibilitylist); + InitializeWritesList (writeslist); - instanceslist = (InstancesList *)malloc(sizeof(InstancesList)); - InitializeInstancesList(instanceslist); - processlist = (ProcessList *)malloc(sizeof(ProcessList)); - InitializeProcessList(processlist); + portlist = (PortList *) malloc (sizeof (PortList)); - enumlistlist = (EnumListList *)malloc(sizeof(EnumListList)); - InitializeEnumListList(enumlistlist); + InitializePortList (portlist); - translate=1; - yyparse(); + signalslist = (SignalsList *) malloc (sizeof (SignalsList)); - printf("module %s(",module_name); - EnumeratePorts(portlist); - printf(");\n"); + InitializeSignalsList (signalslist); - ShowPortList(portlist); - printf("\n"); - RegOutputs(portlist); - printf("\n"); - ShowEnumListList(enumlistlist); + sensibilitylist = (SensibilityList *) malloc (sizeof (SensibilityList)); - ReadWritesFile(writeslist, (char *)"file_writes.sc2v"); + InitializeSensibilityList (sensibilitylist); - ShowSignalsList(signalslist, writeslist); - printf("\n"); - ShowInstancedModules(instanceslist); - printf("\n"); + instanceslist = (InstancesList *) malloc (sizeof (InstancesList)); - ShowDefines((char *)"file_defines.sc2v"); + InitializeInstancesList (instanceslist); - ShowProcessCode(processlist); - printf("\n"); - printf("endmodule\n"); -} + processlist = (ProcessList *) malloc (sizeof (ProcessList)); + + InitializeProcessList (processlist); + + + enumlistlist = (EnumListList *) malloc (sizeof (EnumListList)); + + InitializeEnumListList (enumlistlist); + + + translate = 1; + + + yyparse (); + + + printf ("module %s(", module_name); + + EnumeratePorts (portlist); + + printf (");\n"); + + + ShowPortList (portlist); + + printf ("\n"); + + RegOutputs (portlist); + + printf ("\n"); + + + ShowEnumListList (enumlistlist); + + + ReadWritesFile (writeslist, (char *) "file_writes.sc2v"); + + + ShowSignalsList (signalslist, writeslist); + + printf ("\n"); + + + ShowInstancedModules (instanceslist); + + printf ("\n"); + + + ShowDefines ((char *) "file_defines.sc2v"); + + + ShowProcessCode (processlist); + + printf ("\n"); + + + printf ("endmodule\n"); + + } %} @@ -155,15 +219,13 @@ %token SENSIBLE CLOSEKEY OPENKEY SEMICOLON COLON SC_SIGNAL ARROW EQUALS NEW QUOTE %token SC_CTOR VOID ASTERISCO TRANSLATEON TRANSLATEOFF -%% +%% commands: /* empty */ +|commands command; -commands: /* empty */ - | commands command - ; command: - module +module | in_bool | @@ -237,516 +299,966 @@ | translateoff | - translateon - ; + translateon; + module: - SC_MODULE OPENPAR WORD CLOSEPAR OPENKEY +SC_MODULE OPENPAR WORD CLOSEPAR OPENKEY +{ + + if (translate == 1) { - if(translate==1){ - if(module_name_found) + + if (module_name_found) + { - fprintf(stderr,"error: two or more modules found in the file\n"); - exit(1); + + fprintf (stderr, "error: two or more modules found in the file\n"); + + exit (1); + } + else + { - module_name = (char *)malloc(256*sizeof(char)); - strcpy(module_name, (char *)$3); + + module_name = (char *) malloc (256 * sizeof (char)); + + strcpy (module_name, (char *) $3); + module_name_found = 1; + } } - } - ; + +} + +; + + in_sc_uint: - SC_IN MENOR SC_UINT MENOR NUMBER MAYOR MAYOR +SC_IN MENOR SC_UINT MENOR NUMBER MAYOR MAYOR +{ + + if (translate == 1) { - if(translate==1){ + activeport = 1; + lastportsize = $5; - lastportkind = (char *)"input"; + + lastportkind = (char *) "input"; + } - }; + +}; + + in_sc_int: - SC_IN MENOR SC_INT MENOR NUMBER MAYOR MAYOR +SC_IN MENOR SC_INT MENOR NUMBER MAYOR MAYOR +{ + + if (translate == 1) { - if(translate==1){ + activeport = 1; + lastportsize = $5; - lastportkind = (char *)"input"; + + lastportkind = (char *) "input"; + } - }; + +}; + + in_bool: - SC_IN MENOR BOOL MAYOR +SC_IN MENOR BOOL MAYOR +{ + + if (translate == 1) { - if(translate==1){ + activeport = 1; + lastportsize = 0; - lastportkind = (char *)"input"; + + lastportkind = (char *) "input"; + } - }; + +}; + + signal_bool: - SC_SIGNAL MENOR BOOL MAYOR +SC_SIGNAL MENOR BOOL MAYOR +{ + + if (translate == 1) { - if(translate==1){ + signalactive = 1; + lastsignalsize = 0; + } - }; + +}; + + signal_uint: - SC_SIGNAL MENOR SC_UINT MENOR NUMBER MAYOR MAYOR +SC_SIGNAL MENOR SC_UINT MENOR NUMBER MAYOR MAYOR +{ + + if (translate == 1) { - if(translate==1){ + signalactive = 1; + lastsignalsize = $5; + } - }; + +}; + + signal_int: - SC_SIGNAL MENOR SC_INT MENOR NUMBER MAYOR MAYOR +SC_SIGNAL MENOR SC_INT MENOR NUMBER MAYOR MAYOR +{ + + if (translate == 1) { - if(translate==1){ + signalactive = 1; + lastsignalsize = $5; + } - }; + +}; + + out_bool: - SC_OUT MENOR BOOL MAYOR +SC_OUT MENOR BOOL MAYOR +{ + + if (translate == 1) { - if(translate==1){ + activeport = 1; + lastportsize = 0; - lastportkind = (char *)"output"; + + lastportkind = (char *) "output"; + } - }; + +}; + + out_sc_uint: - SC_OUT MENOR SC_UINT MENOR NUMBER MAYOR MAYOR +SC_OUT MENOR SC_UINT MENOR NUMBER MAYOR MAYOR +{ + + if (translate == 1) { - if(translate==1){ + activeport = 1; + lastportsize = $5; - lastportkind = (char *)"output"; + + lastportkind = (char *) "output"; + } - }; + +}; + + out_sc_int: - SC_OUT MENOR SC_INT MENOR NUMBER MAYOR MAYOR +SC_OUT MENOR SC_INT MENOR NUMBER MAYOR MAYOR +{ + + if (translate == 1) { - if(translate==1){ + activeport = 1; + lastportsize = $5; - lastportkind = (char *)"output"; + + lastportkind = (char *) "output"; + } - }; + +}; + + sc_method: - SC_METHOD OPENPAR WORD CLOSEPAR SEMICOLON +SC_METHOD OPENPAR WORD CLOSEPAR SEMICOLON +{ + + if (translate == 1) { - if(translate==1){ - if(method_found) + + if (method_found) + { - InsertProcess(processlist, active_method, sensibilitylist, active_method_type); + + InsertProcess (processlist, active_method, sensibilitylist, + active_method_type); + } - active_method = (char *)$3; + + active_method = (char *) $3; + method_found = 1; + /* New sensitivity list */ - sensibilitylist = (SensibilityList *)malloc(sizeof(SensibilityList)); - InitializeSensibilityList(sensibilitylist); + sensibilitylist = (SensibilityList *) malloc (sizeof (SensibilityList)); + + InitializeSensibilityList (sensibilitylist); + } - }; + +}; + + sensible_par_neg: - SENSITIVE_NEG OPENPAR WORD CLOSEPAR SEMICOLON +SENSITIVE_NEG OPENPAR WORD CLOSEPAR SEMICOLON +{ + + if (translate == 1) { - if(translate==1){ - active_method_type = (char *)"seq"; //comb - InsertSensibility(sensibilitylist, (char *)$3, "negedge"); + + active_method_type = (char *) "seq"; //comb + InsertSensibility (sensibilitylist, (char *) $3, "negedge"); + } - }; + +}; + + sensible_par_pos: - SENSITIVE_POS OPENPAR WORD CLOSEPAR SEMICOLON +SENSITIVE_POS OPENPAR WORD CLOSEPAR SEMICOLON +{ + + if (translate == 1) { - if(translate==1){ - active_method_type = (char *)"seq"; //comb - InsertSensibility(sensibilitylist, (char *)$3, "posedge"); + + active_method_type = (char *) "seq"; //comb + InsertSensibility (sensibilitylist, (char *) $3, "posedge"); + } - }; + +}; + + sensitive_pos: - SENSITIVE_POS +SENSITIVE_POS +{ + + if (translate == 1) { - if(translate==1){ - last_sensibility = (char *)"posedge"; - active_method_type = (char *)"seq"; //seq + + last_sensibility = (char *) "posedge"; + + active_method_type = (char *) "seq"; //seq sensibility_active = 1; + } - }; + +}; + + sensitive_neg: - SENSITIVE_NEG +SENSITIVE_NEG +{ + + if (translate == 1) { - if(translate==1){ - last_sensibility = (char *)"negedge"; - active_method_type = (char *)"seq"; //seq + + last_sensibility = (char *) "negedge"; + + active_method_type = (char *) "seq"; //seq sensibility_active = 1; + } - }; + +}; + + sensitive: - SENSITIVE +SENSITIVE +{ + + if (translate == 1) { - if(translate==1){ - last_sensibility = (char *)" "; - active_method_type = (char *)"comb"; //comb + + last_sensibility = (char *) " "; + + active_method_type = (char *) "comb"; //comb sensibility_active = 1; + } - }; + +}; + + sensible_par_colon: - SENSITIVE OPENPAR WORD CLOSEPAR SEMICOLON +SENSITIVE OPENPAR WORD CLOSEPAR SEMICOLON +{ + + if (translate == 1) { - if(translate==1){ - active_method_type = (char *)"comb"; //comb - InsertSensibility(sensibilitylist, (char *)$3, " "); + + active_method_type = (char *) "comb"; //comb + InsertSensibility (sensibilitylist, (char *) $3, " "); + } - }; + +}; + + sensible_word_colon: - SENSIBLE WORD +SENSIBLE WORD +{ + + if (translate == 1) { - if(translate==1){ - InsertSensibility(sensibilitylist, (char *)$2, (char *)last_sensibility); + + InsertSensibility (sensibilitylist, (char *) $2, + (char *) last_sensibility); + } - }; + +}; + + sensible_word_semicolon: - SENSIBLE WORD SEMICOLON +SENSIBLE WORD SEMICOLON +{ + + if (translate == 1) { - if(translate==1){ - InsertSensibility(sensibilitylist, (char *)$2, (char *)last_sensibility); - if(sensibility_active) + + InsertSensibility (sensibilitylist, (char *) $2, + (char *) last_sensibility); + + if (sensibility_active) + { + sensibility_active = 0; + } + } - }; + +}; + + closekey: - CLOSEKEY +CLOSEKEY +{ + + if (translate == 1) { - if(translate==1){ - if(method_found) + + if (method_found) + { + method_found = 0; - InsertProcess(processlist, active_method, sensibilitylist, active_method_type); + + InsertProcess (processlist, active_method, sensibilitylist, + active_method_type); + } + } - }; + +}; + + word_semicolon: - WORD SEMICOLON +WORD SEMICOLON +{ + + if (translate == 1) { - if(translate==1){ - if(activeport) + + if (activeport) + { - InsertPort(portlist, (char *)$1, lastportkind, lastportsize); + + InsertPort (portlist, (char *) $1, lastportkind, lastportsize); + activeport = 0; + } - else if(signalactive) + + else if (signalactive) + { - InsertSignal(signalslist, (char *)$1, lastsignalsize); + + InsertSignal (signalslist, (char *) $1, lastsignalsize); + signalactive = 0; - }else if(multipledec){ - int length,list_pos; - length=0; - list_pos=0; + + } + else if (multipledec) + { + + int length, list_pos; + + length = 0; + + list_pos = 0; + //Look in the enumerated list if it was declared e.j state_t state; - list_pos=findEnumList(enumlistlist, storedtype); - if(list_pos>-1){ + list_pos = findEnumList (enumlistlist, storedtype); + + if (list_pos > -1) + { + //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); + + InsertWrite (writeslist, (char *) $1); + + free (storedtype); + + multipledec = 0; + + } + else + { + + fprintf (stderr, "\nType %s unknow\n", (char *) $1); + + return (1); - InsertSignal(signalslist, (char *)$1,length); - InsertWrite(writeslist,(char *)$1); - free(storedtype); - multipledec=0; - }else{ - fprintf(stderr,"\nType %s unknow\n",(char *)$1); - return(1); } + } + } - }; + +}; + + word_colon: - WORD COLON +WORD COLON +{ + + if (translate == 1) { - if(translate==1){ - if(activeport) + + if (activeport) + { - InsertPort(portlist, (char *)$1, lastportkind, lastportsize); + + InsertPort (portlist, (char *) $1, lastportkind, lastportsize); + + } + + else if (signalactive) + + { + + InsertSignal (signalslist, (char *) $1, lastsignalsize); + } - else if(signalactive) + + else if (reading_enumerates) + { - InsertSignal(signalslist, (char *)$1, lastsignalsize); + + InsertEnumerates (enumerateslist, (char *) $1); + + } - else if(reading_enumerates) + else if (multipledec) { - InsertEnumerates(enumerateslist, (char *)$1); - }else if(multipledec){ - int length,list_pos; - length=0; - list_pos=0; + int length, list_pos; + + length = 0; + + list_pos = 0; + //Look in the enumerated list if it was declared e.j state_t state; - list_pos=findEnumList(enumlistlist, storedtype); - if(list_pos>-1){ + list_pos = findEnumList (enumlistlist, storedtype); + + if (list_pos > -1) + { + //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); + + InsertWrite (writeslist, (char *) $1); + + multipledec = 1; + + } + else + { + + fprintf (stderr, "\nType %s unknow\n", (char *) $1); + + return (1); - InsertSignal(signalslist, (char *)$1,length); - InsertWrite(writeslist,(char *)$1); - multipledec=1; - }else{ - fprintf(stderr,"\nType %s unknow\n",(char *)$1); - return(1); } + } + } - }; + +}; + + word_closekey_word: - WORD CLOSEKEY WORD SEMICOLON +WORD CLOSEKEY WORD SEMICOLON +{ + + if (translate == 1) { - if(translate==1){ + //Finish enumerate var declaration - if(reading_enumerates) + if (reading_enumerates) + { - InsertEnumerates(enumerateslist, (char *)$1); - InsertEnumList(enumlistlist,enumerateslist,(char *)$4,0); //Insert also the variable name - reading_enumerates=0; + + InsertEnumerates (enumerateslist, (char *) $1); + + InsertEnumList (enumlistlist, enumerateslist, (char *) $4, 0); //Insert also the variable name + reading_enumerates = 0; + } + } - }; + +}; + + word_closekey: - WORD CLOSEKEY SEMICOLON +WORD CLOSEKEY SEMICOLON +{ + + if (translate == 1) { - if(translate==1){ + //Finish enumerate type declaration - if(reading_enumerates) + if (reading_enumerates) + { - InsertEnumerates(enumerateslist, (char *)$1); - InsertEnumList(enumlistlist,enumerateslist,enumname,1); //Insert also the variable name - reading_enumerates=0; + + InsertEnumerates (enumerateslist, (char *) $1); + + InsertEnumList (enumlistlist, enumerateslist, enumname, 1); //Insert also the variable name + reading_enumerates = 0; + } + } - }; + +}; + + instan