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

Subversion Repositories sc2v

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 11 to Rev 12
    Reverse comparison

Rev 11 → Rev 12

/trunk/ChangeLog
1,3 → 1,11
26-01-2005 Version 0.2.5
 
Solved bug in nested switchs
Uses non-blocking assignments in sequential processes
Macros are correctly invoked inside and outside processes
More support for preprocessor constructions
 
23-01-2005 Version 0.2.4
 
Contribution of Harald Devos:
/trunk/src/sc2v_step1.y
29,964 → 29,1166
#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()
{
return 1;
}
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);
main ()
{
int i;
 
translate=1;
verilog=0;
writemethod=0;
yyparse();
fclose(FILE_WRITES);
fclose(FILE_DEFINES);
}
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);
}
 
%}
 
%token NUMBER WORD SC_INT SC_UINT BOOL BIGGER LOWER OPENKEY CLOSEKEY WRITE WORD SYMBOL NEWLINE ENUM INCLUDE
%token COLON SEMICOLON RANGE OPENPAR CLOSEPAR TWODOUBLEPOINTS OPENCORCH CLOSECORCH SWITCH CASE DEFAULT BREAK
%token SC_BIGINT SC_BIGUINT HEXA DEFINE READ TRANSLATEOFF TRANSLATEON VERILOGBEGIN VERILOGEND TAB DOLLAR INTCONV
%token VOID TTRUE TFALSE
%token PIFDEF PENDDEF PELSE
%token NUMBER WORD SC_INT SC_UINT BOOL BIGGER LOWER OPENKEY CLOSEKEY WRITE WORD SYMBOL NEWLINE ENUM INCLUDE
%token COLON SEMICOLON RANGE OPENPAR CLOSEPAR TWODOUBLEPOINTS OPENCORCH CLOSECORCH SWITCH CASE DEFAULT BREAK
%token SC_BIGINT SC_BIGUINT HEXA DEFINE READ TRANSLATEOFF TRANSLATEON VERILOGBEGIN VERILOGEND TAB DOLLAR INTCONV
%token VOID TTRUE TFALSE
%token PIFDEF PENDDEF PELSE
 
%%
%% commands:/* empty */
|commands command;
 
commands: /* empty */
| commands command
;
 
 
command:
voidword
|
include
|
dollar
|
intconv
|
tab
|
read
|
sc_int
|
sc_uint
|
sc_bigint
|
sc_biguint
|
number
|
bool
|
word
|
symbol
|
write
|
newline
|
openkey
|
closekey
|
colon
|
semicolon
|
range
|
openpar
|
closepar
|
void
|
opencorch
|
closecorch
|
bigger
|
lower
|
switch
|
case_only
|
case_number
|
case_word
|
case_default
|
break
|
hexa
|
define
|
translateoff
|
translateon
|
verilogbegin
|
verilogend
|
ifdef
|
endif
|
pelse
|
ttrue
|
tfalse
;
voidword
|
include
|
dollar
|
intconv
|
tab
|
read
|
sc_int
|
sc_uint
|
sc_bigint
|
sc_biguint
|
number
|
bool
|
word
|
symbol
|
write
|
newline
|
openkey
|
closekey
|
colon
|
semicolon
|
range
|
openpar
|
closepar
|
void
|
opencorch
|
closecorch
|
bigger
|
lower
|
switch
|
case_only
|
case_number
|
case_word
|
case_default
|
break
|
hexa
|
definemacro
|
defineword
|
definenumber
|
translateoff
|
translateon
|
verilogbegin
|
verilogend
|
ifdef
|
endif
|
pelse
|
ttrue
|
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
{
if(verilog==1)
fprintf(file,".read()");
}
READ OPENPAR CLOSEPAR
{
defineparenthesis = 0;
if (verilog == 1)
fprintf (file, ".read()");
 
define:
DEFINE WORD OPENPAR CLOSEPAR
{
if(translate==1 && verilog==0){
InsertDefine(defineslist, (char *)$2);
definefound = 1;
fprintf(FILE_DEFINES,"`define %s ",(char *)$2);
}else if(verilog==1)
fprintf(file,"#define %s ()",(char *)$2);
}
}
 
defineword:
DEFINE WORD WORD
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
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);
 
};
 
 
definemacro:
DEFINE WORD OPENPAR CLOSEPAR
{
defineparenthesis = 0;
//Macro found
if (translate == 1 && verilog == 0)
{
InsertDefine (defineslist, (char *) $2);
definefound = 1;
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
{
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);
}
WORD TWODOUBLEPOINTS WORD OPENPAR CLOSEPAR
{
defineparenthesis = 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");
}
else if (verilog == 1)
fprintf (file, " %s::%s()", (char *) $1, (char *) $3);
 
}
 
sc_int:
SC_INT LOWER NUMBER BIGGER
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(regs_file,"reg[%d:0] ",(-1 + $3));
reg_found = 1;
}
}else if(verilog==1)
fprintf(file,"sc_int<%d>",$3);
}
;
SC_INT LOWER NUMBER BIGGER
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (regs_file, "reg[%d:0] ", (-1 + $3));
reg_found = 1;
}
}
else if (verilog == 1)
fprintf (file, "sc_int<%d>", $3);
 
}
 
;
 
sc_uint:
SC_UINT LOWER NUMBER BIGGER
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(regs_file,"reg[%d:0] ",(-1 + $3));
reg_found = 1;
}
}else if(verilog==1)
fprintf(file,"sc_uint<%d>",$3);
}
;
SC_UINT LOWER NUMBER BIGGER
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (regs_file, "reg[%d:0] ", (-1 + $3));
reg_found = 1;
}
}
else if (verilog == 1)
fprintf (file, "sc_uint<%d>", $3);
}
 
;
 
sc_bigint:
SC_BIGINT LOWER NUMBER BIGGER
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(regs_file,"reg[%d:0] ",(-1 + $3));
reg_found = 1;
}
}else if(verilog==1)
fprintf(file,"sc_bigint<%d> ",$3);
}
;
SC_BIGINT LOWER NUMBER BIGGER
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (regs_file, "reg[%d:0] ", (-1 + $3));
reg_found = 1;
}
}
else if (verilog == 1)
fprintf (file, "sc_bigint<%d> ", $3);
}
 
;
 
sc_biguint:
SC_BIGUINT LOWER NUMBER BIGGER
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(regs_file,"reg[%d:0] ",(-1 + $3));
reg_found = 1;
}
}else if(verilog==1)
fprintf(file,"sc_biguint<%d> ",$3);
}
;
SC_BIGUINT LOWER NUMBER BIGGER
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (regs_file, "reg[%d:0] ", (-1 + $3));
reg_found = 1;
}
}
else if (verilog == 1)
fprintf (file, "sc_biguint<%d> ", $3);
}
 
;
 
bool:
BOOL
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(regs_file,"reg ");
reg_found = 1;
}
}else if(verilog==1)
fprintf(file,"bool");
}
;
BOOL
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (regs_file, "reg ");
reg_found = 1;
}
}
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 (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
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
if (reg_found)
{
if (opencorchfound)
fprintf (regs_file, "%d:0", -1 + $1);
else
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);
}
 
;
word:
WORD
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
if (openedcase)
{
fprintf (file, " :\n");
 
for (i = 0; i < openedkeys; i++)
fprintf (file, " ");
 
fprintf (file, "begin\n");
openedcase = 0;
}
 
strcpy (lastword, (char *) $1);
 
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);
}
else
{
if (newline)
{
for (i = 0; i < openedkeys; i++)
fprintf (file, " ");
}
regname2 = IsReg (regslist, (char *) $1);
if (regname2 == NULL)
{
if (IsDefine (defineslist, (char *) $1))
{
if (ifdeffound == 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);
fprintf (file, "`%s", (char *) $1);
defineinvocationfound = 1;
}
;
number:
NUMBER
else
{
if(translate==1&& verilog==0){
if(processfound)
if(reg_found)
{
if(opencorchfound)
fprintf(regs_file,"%d:0", -1 + $1);
else
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, "%s", (char *) $1);
ifdeffound = 0;
}
;
word:
WORD
{
if(translate==1&& verilog==0){
if(processfound)
{
if(openedcase)
{
fprintf(file," :\n");
for(i = 0; i < openedkeys; i++)
fprintf(file," ");
fprintf(file,"begin\n");
openedcase = 0;
}
strcpy(lastword, (char *)$1);
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);
}
else
{
if(newline)
{
for(i = 0; i < openedkeys; i++)
fprintf(file," ");
}
regname2 = IsReg(regslist, (char *)$1);
if(regname2 == NULL)
{
if(IsDefine(defineslist, (char *)$1))
{
fprintf(file,"`%s", (char *)$1);
defineinvocationfound = 1;
}
else
{
fprintf(file,"%s ",(char *)$1);
}
}
else
fprintf(file,"%s",regname2);
newline = 0;
}
}
else if(definefound)
{
if(IsDefine(defineslist, (char *)$1))
{
fprintf(FILE_DEFINES,"`%s",(char *)$1);
}
else
{
fprintf(FILE_DEFINES,"%s ",(char *)$1);
}
}
}else if(verilog==1)
fprintf(file," %s",(char *)$1);
};
}
else
{
fprintf (file, "%s ", (char *) $1);
}
}
else
fprintf (file, "%s", regname2);
 
newline = 0;
}
 
}
else if (definefound)
{
if (IsDefine (defineslist, (char *) $1))
{
 
fprintf (FILE_DEFINES, "`%s", (char *) $1);
}
else
{
fprintf (FILE_DEFINES, "%s ", (char *) $1);
}
}
}
else if (verilog == 1)
fprintf (file, " %s", (char *) $1);
};
 
symbol:
SYMBOL
{
if(translate==1&& verilog==0){
if(processfound)
{
if(reg_found)
fprintf(regs_file,"%s",(char *)$1);
else
fprintf(file,"%s",(char *)$1);
}
else if(definefound)
{
fprintf(FILE_DEFINES,"%s",(char *)$1);
}
}else if(verilog==1)
fprintf(file,"%s",(char *)$1);
};
SYMBOL
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
if (reg_found)
fprintf (regs_file, "%s", (char *) $1);
else
fprintf (file, "%s", (char *) $1);
}
else if (definefound)
{
fprintf (FILE_DEFINES, "%s", (char *) $1);
}
}
else if (verilog == 1)
fprintf (file, "%s", (char *) $1);
};
 
 
write:
WRITE
{
if(translate==1&& verilog==0){
writemethod=1;
if(processfound)
{
fprintf(file," = ");
fprintf(FILE_WRITES, "%s\n", lastword);
}
else if(definefound)
{
fprintf(FILE_DEFINES," = ");
}
}else if(verilog==1){
fprintf(file,".write");
}
};
WRITE
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
writemethod = 1;
if (processfound)
{
fprintf (file, " <= ");
fprintf (FILE_WRITES, "%s\n", lastword);
}
else if (definefound)
{
fprintf (FILE_DEFINES, " <= ");
}
 
}
else if (verilog == 1)
{
fprintf (file, ".write");
}
};
 
newline:
NEWLINE
{
if(translate==1&& verilog==0){
if(processfound & !reg_found & !openedcase)
{
fprintf(file,"\n");
newline = 1;
}
else if(definefound)
{
fprintf(FILE_DEFINES,"\n");
}
}else if(verilog==1)
fprintf(file,"\n");
};
NEWLINE
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound & !reg_found & !openedcase)
{
fprintf (file, "\n");
newline = 1;
}
else if (definefound)
{
fprintf (FILE_DEFINES, "\n");
}
 
}
else if (verilog == 1)
fprintf (file, "\n");
};
 
colon:
COLON
{
if(translate==1&& verilog==0){
if(processfound)
{
if(reg_found)
{
fprintf(regs_file,",");
}
else
fprintf(file,",");
}
else if(definefound)
{
fprintf(FILE_DEFINES,",");
}
}else if(verilog==1)
fprintf(file,",");
};
COLON
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
if (reg_found)
{
fprintf (regs_file, ",");
}
else
fprintf (file, ",");
}
else if (definefound)
{
fprintf (FILE_DEFINES, ",");
}
}
else if (verilog == 1)
fprintf (file, ",");
};
 
semicolon:
SEMICOLON
{
if(translate==1&& verilog==0){
if(processfound)
{
if(reg_found)
{
fprintf(regs_file,";\n");
reg_found = 0;
}
else if(defineinvocationfound)
{
defineinvocationfound = 0;
}
else
{
fprintf(file,";");
}
}
else if(definefound)
{
fprintf(FILE_DEFINES,";");
}
}else if(verilog==1)
fprintf(file,";");
};
SEMICOLON
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
if (reg_found)
{
fprintf (regs_file, ";\n");
reg_found = 0;
}
else
{
if (defineinvocationfound == 0)
fprintf (file, ";");
}
}
else if (definefound)
{
fprintf (FILE_DEFINES, ";");
}
}
else if (verilog == 1)
fprintf (file, ";");
 
defineinvocationfound = 0;
};
 
 
openpar:
OPENPAR
{
if(translate==1 && verilog==0){
if(processfound)
{
fprintf(file,"(");
}
else if(definefound)
{
fprintf(FILE_DEFINES,"(");
}
}else if(verilog==1)
fprintf(file,"(");
};
OPENPAR
{
defineparenthesis = 1;
if (translate == 1 && verilog == 0 && defineinvocationfound == 0)
{
if (processfound)
{
fprintf (file, "(");
}
else if (definefound)
{
fprintf (FILE_DEFINES, "(");
}
 
}
else if (verilog == 1)
{
fprintf (file, "(");
}
}
 
closepar:
CLOSEPAR
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(file,")");
}
else if(definefound)
{
fprintf(FILE_DEFINES,")");
}
}else if(verilog==1)
fprintf(file,")");
};
CLOSEPAR
{
if (translate == 1 && verilog == 0)
{
 
if (processfound)
{
if (defineparenthesis == 0)
{
fprintf (file, ")");
defineinvocationfound = 0;
}
 
}
else if (definefound)
{
fprintf (FILE_DEFINES, ")");
}
}
else if (verilog == 1)
fprintf (file, ")");
 
};
 
 
opencorch:
OPENCORCH
{
if(translate==1&& verilog==0){
if(processfound)
{
if(reg_found)
{
fprintf(regs_file,"[");
opencorchfound = 1;
}
else
fprintf(file,"[");
}
else if(definefound)
{
fprintf(FILE_DEFINES,"[");
}
}else if(verilog==1)
fprintf(file,"[");
};
OPENCORCH
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
if (reg_found)
{
fprintf (regs_file, "[");
opencorchfound = 1;
}
else
fprintf (file, "[");
}
else if (definefound)
{
fprintf (FILE_DEFINES, "[");
 
}
}
else if (verilog == 1)
fprintf (file, "[");
};
 
closecorch:
CLOSECORCH
{
if(translate==1&& verilog==0){
if(processfound)
{
if(reg_found)
{
fprintf(regs_file,"]");
opencorchfound = 0;
}
else
fprintf(file,"]");
}
else if(definefound)
{
fprintf(FILE_DEFINES,"]");
}
}else if(verilog==1)
fprintf(file,"]");
};
CLOSECORCH
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
if (reg_found)
{
fprintf (regs_file, "]");
opencorchfound = 0;
}
else
fprintf (file, "]");
}
else if (definefound)
{
fprintf (FILE_DEFINES, "]");
}
}
else if (verilog == 1)
fprintf (file, "]");
};
 
 
openkey:
OPENKEY
{
if(translate==1 && verilog==0){
openedkeys++;
if(openedkeys==1 & !definefound)
{
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");
newline = 1;
}
}else if(verilog==1)
fprintf(file,"{");
}
;
OPENKEY
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
openedkeys++;
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");
processfound = 1;
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, "{");
};
 
closekey:
CLOSEKEY
{
if(translate==1&& verilog==0){
if(processfound)
{
if(openedkeys==switchparenthesis & switchfound == 1)
{
fprintf(file,"\n");
if(default_found & !default_break_found)
{
for(i = 0; i < openedkeys; i++)
fprintf(file," ");
fprintf(file,"end\n");
default_found = 0;
}
for(i = 0; i < openedkeys; i++)
fprintf(file," ");
fprintf(file,"endcase\n");
newline = 1;
switchfound = 0;
switchparenthesis = 0;
}
else
{
fprintf(file,"\n");
for(i = 0; i < openedkeys; i++)
fprintf(file," ");
fprintf(file,"end\n");
newline = 1;
}
}
openedkeys--;
if(definefound)
{
definefound = 0;
fprintf(FILE_DEFINES,"\n//Dummy Comment\n");
}
else if(openedkeys==0)
{
fclose(file);
fclose(regs_file);
free(regslist);
/* free(regname);
free(regname2);*/
processfound = 0;
}
}else if(verilog==1)
fprintf(file,"}");
};
CLOSEKEY
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound && !definefound)
{
if (openedkeys == switchparenthesis[switchfound] && switchfound > 0)
{
fprintf (file, "\n");
if (default_found & !default_break_found)
{
for (i = 0; i < openedkeys - 1; i++)
fprintf (file, " ");
fprintf (file, "end\n");
default_found = 0;
}
for (i = 0; i < openedkeys - 1; i++)
fprintf (file, " ");
fprintf (file, "endcase\n");
newline = 1;
switchparenthesis[switchfound] = 0;
switchfound--;
 
}
else
{
fprintf (file, "\n");
for (i = 0; i < openedkeys; i++)
fprintf (file, " ");
fprintf (file, "end\n");
newline = 1;
}
}
 
openedkeys--;
if (definefound)
{
definefound = 0;
if (processfound)
fprintf (file, "\n//Dummy Comment\n");
else
fprintf (FILE_DEFINES, "\n//Dummy Comment\n");
}
else if (openedkeys == 0)
{
fclose (file);
fclose (regs_file);
free (regslist);
processfound = 0;
}
}
else if (verilog == 1)
fprintf (file, "}");
};
 
 
bigger:
BIGGER
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(file,">");
}
else if(definefound)
{
fprintf(FILE_DEFINES,">");
}
}else if(verilog==1)
fprintf(file,">");
};
BIGGER
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (file, ">");
}
else if (definefound)
{
fprintf (FILE_DEFINES, ">");
}
}
else if (verilog == 1)
fprintf (file, ">");
};
 
lower:
LOWER
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(file,"<");
}
else if(definefound)
{
fprintf(FILE_DEFINES,"<");
}
}else if(verilog==1)
fprintf(file,"<");
};
LOWER
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (file, "<");
}
else if (definefound)
{
fprintf (FILE_DEFINES, "<");
}
}
else if (verilog == 1)
fprintf (file, "<");
};
 
 
switch:
SWITCH
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(file,"\n");
for(i = 0; i < openedkeys; i++)
fprintf(file," ");
fprintf(file,"case");
switchfound = 1;
switchparenthesis = openedkeys + 1;
}
}else if(verilog==1)
fprintf(file,"switch");
};
SWITCH
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
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");
};
 
case_number:
CASE NUMBER SYMBOL
{
if(translate==1&& verilog==0){
if(processfound)
{
for(i = 0; i < openedkeys; i++)
fprintf(file," ");
if(openedcase)
fprintf(file,", %d",$2);
else
fprintf(file,"%d",$2);
CASE NUMBER SYMBOL
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
for (i = 0; i < openedkeys; i++)
fprintf (file, " ");
if (openedcase)
fprintf (file, ", %d", $2);
else
fprintf (file, "%d", $2);
 
newline = 1;
openedcase = 1;
}
}else if(verilog==1)
fprintf(file,"case %d %s",$2,(char *)$3);
};
newline = 1;
openedcase = 1;
 
}
}
else if (verilog == 1)
fprintf (file, "case %d %s", $2, (char *) $3);
};
 
case_word:
CASE WORD SYMBOL
{
if(translate==1&& verilog==0){
if(processfound)
{
for(i = 0; i < openedkeys; i++)
fprintf(file," ");
if(openedcase)
fprintf(file,", %s",(char *)$2);
else
fprintf(file,"%s",(char *)$2);
newline = 1;
openedcase = 1;
}
}else if(verilog==1)
fprintf(file,"case %s %s",(char *)$2,(char *)$3);
};
CASE WORD SYMBOL
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
for (i = 0; i < openedkeys; i++)
fprintf (file, " ");
if (openedcase)
fprintf (file, ", %s", (char *) $2);
else
fprintf (file, "%s", (char *) $2);
 
newline = 1;
openedcase = 1;
 
}
}
else if (verilog == 1)
fprintf (file, "case %s %s", (char *) $2, (char *) $3);
};
 
case_default:
DEFAULT SYMBOL
{
if(translate==1&& verilog==0){
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");
newline = 1;
default_found = 1;
}
}else if(verilog==1)
fprintf(file,"default %s",(char *)$2);
};
DEFAULT SYMBOL
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
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");
newline = 1;
default_found = 1;
}
}
else if (verilog == 1)
fprintf (file, "default %s", (char *) $2);
};
 
case_only:
CASE OPENPAR
{
//This rule occurs when in Verilog mode a case appears
if(verilog==1)
fprintf(file,"case(");
};
CASE OPENPAR
{
defineparenthesis = 0;
//This rule occurs when in Verilog mode a case appears
if (verilog == 1)
fprintf (file, "case(");
};
 
break:
BREAK SEMICOLON
{
if(translate==1&& verilog==0){
if(processfound)
{
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;");
};
BREAK SEMICOLON
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
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;");
};
 
hexa:
HEXA
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(file,"'h");
}
else if(definefound)
{
fprintf(FILE_DEFINES,"'h");
}
}else if(verilog==1)
fprintf(file,"0x");
};
HEXA
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (file, "'h");
}
else if (definefound)
{
fprintf (FILE_DEFINES, "'h");
}
}
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
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(file,"`ifdef");
}
else if(definefound)
{
fprintf(FILE_DEFINES,"`ifdef");
}
}else if(verilog==1)
fprintf(file,"#ifdef");
};
PIFDEF
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
ifdeffound = 1;
fprintf (file, "`ifdef");
}
else if (definefound)
{
fprintf (FILE_DEFINES, "`ifdef");
}
}
else if (verilog == 1)
fprintf (file, "#ifdef");
};
 
endif:
PENDDEF
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(file,"`endif");
}
else if(definefound)
{
fprintf(FILE_DEFINES,"`endif");
}
}else if(verilog==1)
fprintf(file,"#endif");
};
PENDDEF
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (file, "`endif");
}
else if (definefound)
{
fprintf (FILE_DEFINES, "`endif");
}
}
else if (verilog == 1)
fprintf (file, "#endif");
};
 
pelse:
PELSE
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(file,"`else");
}
else if(definefound)
{
fprintf(FILE_DEFINES,"`else");
}
}else if(verilog==1)
fprintf(file,"#else");
};
PELSE
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (file, "`else");
}
else if (definefound)
{
fprintf (FILE_DEFINES, "`else");
}
}
else if (verilog == 1)
fprintf (file, "#else");
};
 
ttrue:
TTRUE
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(file,"1");
}
}else if(verilog==1)
fprintf(file,"1");
};
TTRUE
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (file, "1");
}
}
else if (verilog == 1)
fprintf (file, "1");
};
 
 
tfalse:
TFALSE
{
if(translate==1&& verilog==0){
if(processfound)
{
fprintf(file,"0");
}
}else if(verilog==1)
fprintf(file,"0");
};
TFALSE
{
defineparenthesis = 0;
if (translate == 1 && verilog == 0)
{
if (processfound)
{
fprintf (file, "0");
}
}
else if (verilog == 1)
fprintf (file, "0");
};
/trunk/src/list.h
22,184 → 22,209
*/
 
 
typedef struct _define_node {
char *name;
struct _define_node *next;
typedef struct _define_node
{
char *name;
struct _define_node *next;
} DefineNode;
 
typedef struct _defines_list {
DefineNode *first;
DefineNode *last;
typedef struct _defines_list
{
DefineNode *first;
DefineNode *last;
} DefinesList;
 
typedef struct _write_node {
char *name;
struct _write_node *next;
typedef struct _write_node
{
char *name;
struct _write_node *next;
} WriteNode;
 
typedef struct _writes_list {
WriteNode *first;
WriteNode *last;
typedef struct _writes_list
{
WriteNode *first;
WriteNode *last;
} WritesList;
 
typedef struct _reg_node {
char *name;
char *name2;
struct _reg_node *next;
typedef struct _reg_node
{
char *name;
char *name2;
struct _reg_node *next;
} RegNode;
 
typedef struct _regs_list {
RegNode *first;
RegNode *last;
typedef struct _regs_list
{
RegNode *first;
RegNode *last;
} RegsList;
 
typedef struct _port_node {
char *name;
char *tipo;
int size;
struct _port_node *next;
typedef struct _port_node
{
char *name;
char *tipo;
int size;
struct _port_node *next;
} PortNode;
 
typedef struct _port_list {
PortNode *first;
PortNode *last;
typedef struct _port_list
{
PortNode *first;
PortNode *last;
} PortList;
 
typedef struct _signal_node {
char *name;
int size;
struct _signal_node *next;
typedef struct _signal_node
{
char *name;
int size;
struct _signal_node *next;
} SignalNode;
 
typedef struct _signals_list {
SignalNode *first;
SignalNode *last;
typedef struct _signals_list
{
SignalNode *first;
SignalNode *last;
} SignalsList;
 
typedef struct _bind_node {
char *nameport;
char *namebind;
struct _bind_node *next;
typedef struct _bind_node
{
char *nameport;
char *namebind;
struct _bind_node *next;
} BindNode;
 
typedef struct _binds_list {
BindNode *first;
BindNode *last;
typedef struct _binds_list
{
BindNode *first;
BindNode *last;
} BindsList;
typedef struct _instance_node {
char *nameinstance;
char *namemodulo;
BindsList *bindslist;
struct _instance_node *next;
} InstanceNode;
 
typedef struct _instances_list {
InstanceNode *first;
InstanceNode *last;
typedef struct _instance_node
{
char *nameinstance;
char *namemodulo;
BindsList *bindslist;
struct _instance_node *next;
} InstanceNode;
 
typedef struct _instances_list
{
InstanceNode *first;
InstanceNode *last;
} InstancesList;
typedef struct _sensibility_node {
char *tipo;
char *name;
struct _sensibility_node *next;
 
typedef struct _sensibility_node
{
char *tipo;
char *name;
struct _sensibility_node *next;
} SensibilityNode;
 
typedef struct _sensibility_list {
SensibilityNode *first;
SensibilityNode *last;
typedef struct _sensibility_list
{
SensibilityNode *first;
SensibilityNode *last;
} SensibilityList;
 
typedef struct _process_node {
char *name;
char *tipo; //comb or seq
SensibilityList *list;
struct _process_node *next;
typedef struct _process_node
{
char *name;
char *tipo; //comb or seq
SensibilityList *list;
struct _process_node *next;
} ProcessNode;
 
typedef struct _process_list {
ProcessNode *first;
ProcessNode *last;
typedef struct _process_list
{
ProcessNode *first;
ProcessNode *last;
} ProcessList;
 
typedef struct _enumerates_node {
char *name;
struct _enumerates_node *next;
typedef struct _enumerates_node
{
char *name;
struct _enumerates_node *next;
} EnumeratesNode;
 
typedef struct _enumerates_list {
EnumeratesNode *first;
EnumeratesNode *last;
typedef struct _enumerates_list
{
EnumeratesNode *first;
EnumeratesNode *last;
} EnumeratesList;
 
typedef struct _enumlist_node {
char *name;
int istype;
EnumeratesList *list;
struct _enumlist_node *next;
typedef struct _enumlist_node
{
char *name;
int istype;
EnumeratesList *list;
struct _enumlist_node *next;
} EnumListNode;
 
typedef struct _enumlist_list {
EnumListNode *first;
EnumListNode *last;
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);
/trunk/src/sc2v_step2.y
22,6 → 22,7
*/
 
%{
 
#include <stdio.h>
#include <string.h>
#include <math.h>
30,723 → 31,1234
 
 
/*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()
{
return 1;
}
 
main()
{
/*Initialize lists*/
writeslist = (WritesList *)malloc(sizeof(WritesList));
InitializeWritesList(writeslist);
portlist = (PortList *)malloc(sizeof(PortList));
InitializePortList(portlist);
signalslist = (SignalsList *)malloc(sizeof(SignalsList));
InitializeSignalsList(signalslist);
sensibilitylist = (SensibilityList *)malloc(sizeof(SensibilityList));
InitializeSensibilityList(sensibilitylist);
instanceslist = (InstancesList *)malloc(sizeof(InstancesList));
InitializeInstancesList(instanceslist);
int translate;
 
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");
}
 
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);
 
 
portlist = (PortList *) malloc (sizeof (PortList));
 
InitializePortList (portlist);
 
 
signalslist = (SignalsList *) malloc (sizeof (SignalsList));
 
InitializeSignalsList (signalslist);
 
 
sensibilitylist = (SensibilityList *) malloc (sizeof (SensibilityList));
 
InitializeSensibilityList (sensibilitylist);
 
 
instanceslist = (InstancesList *) malloc (sizeof (InstancesList));
 
InitializeInstancesList (instanceslist);
 
 
processlist = (ProcessList *) malloc (sizeof (ProcessList));
 
InitializeProcessList (processlist);
 
 
enumlistlist = (EnumListList *) malloc (sizeof (EnumListList));
 
InitializeEnumListList (enumlistlist);
 
 
translate = 1;
 
 
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");
 
}
 
%}
 
%token NUMBER SC_MODULE WORD OPENPAR CLOSEPAR SC_IN SC_OUT SEMICOLON BOOL ENUM
%token NUMBER SC_MODULE WORD OPENPAR CLOSEPAR SC_IN SC_OUT SEMICOLON BOOL ENUM
%token MENOR MAYOR SC_INT SC_UINT SC_METHOD SENSITIVE_POS SENSITIVE_NEG SENSITIVE
%token SENSIBLE CLOSEKEY OPENKEY SEMICOLON COLON SC_SIGNAL ARROW EQUALS NEW QUOTE
%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
|
in_bool
|
in_sc_int
|
in_sc_uint
|
out_bool
|
out_sc_int
|
out_sc_uint
|
sc_method
|
sensitive_pos
|
sensitive_neg
|
sensitive
|
sensible_word_colon
|
sensible_word_semicolon
|
sensible_par_colon
|
sensible_par_pos
|
sensible_par_neg
|
closekey
|
word_semicolon
|
word_colon
|
word_closekey
|
word_closekey_word
|
signal_bool
|
signal_uint
|
signal_int
|
instantation
|
port_binding
|
sc_ctor
|
void
|
inst_decl
|
closekey_semicolon
|
enumerates
|
enumerates_type
|
declaration
|
declaration_sc_signal
|
multiple_declaration
|
multiple_sc_signal_declaration
|
translateoff
|
translateon
;
module
|
in_bool
|
in_sc_int
|
in_sc_uint
|
out_bool
|
out_sc_int
|
out_sc_uint
|
sc_method
|
sensitive_pos
|
sensitive_neg
|
sensitive
|
sensible_word_colon
|
sensible_word_semicolon
|
sensible_par_colon
|
sensible_par_pos
|
sensible_par_neg
|
closekey
|
word_semicolon
|
word_colon
|
word_closekey
|
word_closekey_word
|
signal_bool
|
signal_uint
|
signal_int
|
instantation
|
port_binding
|
sc_ctor
|
void
|
inst_decl
|
closekey_semicolon
|
enumerates
|
enumerates_type
|
declaration
|
declaration_sc_signal
|
multiple_declaration
|
multiple_sc_signal_declaration
|
translateoff
|
translateon;
 
 
module:
SC_MODULE OPENPAR WORD CLOSEPAR OPENKEY
{
if(translate==1){
if(module_name_found)
{
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_found = 1;
}
}
}
;
SC_MODULE OPENPAR WORD CLOSEPAR OPENKEY
{
 
in_sc_uint:
SC_IN MENOR SC_UINT MENOR NUMBER MAYOR MAYOR
if (translate == 1)
{
 
if (module_name_found)
 
{
if(translate==1){
activeport = 1;
lastportsize = $5;
lastportkind = (char *)"input";
 
fprintf (stderr, "error: two or more modules found in the file\n");
 
exit (1);
 
}
};
 
in_sc_int:
SC_IN MENOR SC_INT MENOR NUMBER MAYOR MAYOR
else
 
{
if(translate==1){
activeport = 1;
lastportsize = $5;
lastportkind = (char *)"input";
 
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
{
 
if (translate == 1)
{
 
activeport = 1;
 
lastportsize = $5;
 
lastportkind = (char *) "input";
 
}
 
};
 
 
 
in_sc_int:
SC_IN MENOR SC_INT MENOR NUMBER MAYOR MAYOR
{
 
if (translate == 1)
{
 
activeport = 1;
 
lastportsize = $5;
 
lastportkind = (char *) "input";
 
}
 
};
 
 
 
 
in_bool:
SC_IN MENOR BOOL MAYOR
{
if(translate==1){
activeport = 1;
lastportsize = 0;
lastportkind = (char *)"input";
}
};
SC_IN MENOR BOOL MAYOR
{
 
if (translate == 1)
{
 
activeport = 1;
 
lastportsize = 0;
 
lastportkind = (char *) "input";
 
}
 
};
 
 
 
signal_bool:
SC_SIGNAL MENOR BOOL MAYOR
{
if(translate==1){
signalactive = 1;
lastsignalsize = 0;
}
};
SC_SIGNAL MENOR BOOL MAYOR
{
 
if (translate == 1)
{
 
signalactive = 1;
 
lastsignalsize = 0;
 
}
 
};
 
 
 
signal_uint:
SC_SIGNAL MENOR SC_UINT MENOR NUMBER MAYOR MAYOR
{
if(translate==1){
signalactive = 1;
lastsignalsize = $5;
}
};
SC_SIGNAL MENOR SC_UINT MENOR NUMBER MAYOR MAYOR
{
 
if (translate == 1)
{
 
signalactive = 1;
 
lastsignalsize = $5;
 
}
 
};
 
 
 
signal_int:
SC_SIGNAL MENOR SC_INT MENOR NUMBER MAYOR MAYOR
{
if(translate==1){
signalactive = 1;
lastsignalsize = $5;
}
};
SC_SIGNAL MENOR SC_INT MENOR NUMBER MAYOR MAYOR
{
 
if (translate == 1)
{
 
signalactive = 1;
 
lastsignalsize = $5;
 
}
 
};
 
 
 
out_bool:
SC_OUT MENOR BOOL MAYOR
{
if(translate==1){
activeport = 1;
lastportsize = 0;
lastportkind = (char *)"output";
}
};
SC_OUT MENOR BOOL MAYOR
{
 
if (translate == 1)
{
 
activeport = 1;
 
lastportsize = 0;
 
lastportkind = (char *) "output";
 
}
 
};
 
 
 
out_sc_uint:
SC_OUT MENOR SC_UINT MENOR NUMBER MAYOR MAYOR
{
if(translate==1){
activeport = 1;
lastportsize = $5;
lastportkind = (char *)"output";
}
};
SC_OUT MENOR SC_UINT MENOR NUMBER MAYOR MAYOR
{
 
if (translate == 1)
{
 
activeport = 1;
 
lastportsize = $5;
 
lastportkind = (char *) "output";
 
}
 
};
 
 
 
out_sc_int:
SC_OUT MENOR SC_INT MENOR NUMBER MAYOR MAYOR
{
if(translate==1){
activeport = 1;
lastportsize = $5;
lastportkind = (char *)"output";
}
};
SC_OUT MENOR SC_INT MENOR NUMBER MAYOR MAYOR
{
 
if (translate == 1)
{
 
activeport = 1;
 
lastportsize = $5;
 
lastportkind = (char *) "output";
 
}
 
};
 
 
 
sc_method:
SC_METHOD OPENPAR WORD CLOSEPAR SEMICOLON
SC_METHOD OPENPAR WORD CLOSEPAR SEMICOLON
{
 
if (translate == 1)
{
 
if (method_found)
 
{
if(translate==1){
if(method_found)
{
InsertProcess(processlist, active_method, sensibilitylist, active_method_type);
}
active_method = (char *)$3;
method_found = 1;
/* New sensitivity list */
sensibilitylist = (SensibilityList *)malloc(sizeof(SensibilityList));
InitializeSensibilityList(sensibilitylist);
}
};
 
InsertProcess (processlist, active_method, sensibilitylist,
active_method_type);
 
}
 
active_method = (char *) $3;
 
method_found = 1;
 
/* New sensitivity list */
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)
{
 
active_method_type = (char *) "seq"; //comb
InsertSensibility (sensibilitylist, (char *) $3, "negedge");
 
}
 
};
 
 
 
sensible_par_pos:
SENSITIVE_POS OPENPAR WORD CLOSEPAR SEMICOLON
{
 
if (translate == 1)
{
 
active_method_type = (char *) "seq"; //comb
InsertSensibility (sensibilitylist, (char *) $3, "posedge");
 
}
 
};
 
 
 
sensitive_pos:
SENSITIVE_POS
{
 
if (translate == 1)
{
 
last_sensibility = (char *) "posedge";
 
active_method_type = (char *) "seq"; //seq
sensibility_active = 1;
 
}
 
};
 
 
 
sensitive_neg:
SENSITIVE_NEG
{
 
if (translate == 1)
{
 
last_sensibility = (char *) "negedge";
 
active_method_type = (char *) "seq"; //seq
sensibility_active = 1;
 
}
 
};
 
 
 
sensitive:
SENSITIVE
{
 
if (translate == 1)
{
 
last_sensibility = (char *) " ";
 
active_method_type = (char *) "comb"; //comb
sensibility_active = 1;
 
}
 
};
 
 
 
sensible_par_colon:
SENSITIVE OPENPAR WORD CLOSEPAR SEMICOLON
{
 
if (translate == 1)
{
 
active_method_type = (char *) "comb"; //comb
InsertSensibility (sensibilitylist, (char *) $3, " ");
 
}
 
};
 
 
 
 
sensible_word_colon:
SENSIBLE WORD
{
 
if (translate == 1)
{
 
InsertSensibility (sensibilitylist, (char *) $2,
(char *) last_sensibility);
 
}
 
};
 
 
 
sensible_word_semicolon:
SENSIBLE WORD SEMICOLON
{
 
if (translate == 1)
{
 
InsertSensibility (sensibilitylist, (char *) $2,
(char *) last_sensibility);
 
if (sensibility_active)
 
{
if(translate==1){
active_method_type = (char *)"seq"; //comb
InsertSensibility(sensibilitylist, (char *)$3, "negedge");
 
sensibility_active = 0;
 
}
};
 
sensible_par_pos:
SENSITIVE_POS OPENPAR WORD CLOSEPAR SEMICOLON
}
 
};
 
 
 
closekey:
CLOSEKEY
{
 
if (translate == 1)
{
 
if (method_found)
 
{
if(translate==1){
active_method_type = (char *)"seq"; //comb
InsertSensibility(sensibilitylist, (char *)$3, "posedge");
 
method_found = 0;
 
InsertProcess (processlist, active_method, sensibilitylist,
active_method_type);
 
}
};
sensitive_pos:
SENSITIVE_POS
 
}
 
};
 
 
 
word_semicolon:
WORD SEMICOLON
{
 
if (translate == 1)
{
 
if (activeport)
 
{
if(translate==1){
last_sensibility = (char *)"posedge";
active_method_type = (char *)"seq"; //seq
sensibility_active = 1;
 
InsertPort (portlist, (char *) $1, lastportkind, lastportsize);
 
activeport = 0;
 
}
};
sensitive_neg:
SENSITIVE_NEG
 
else if (signalactive)
 
{
if(translate==1){
last_sensibility = (char *)"negedge";
active_method_type = (char *)"seq"; //seq
sensibility_active = 1;
 
InsertSignal (signalslist, (char *) $1, lastsignalsize);
 
signalactive = 0;
 
}
};
sensitive:
SENSITIVE
else if (multipledec)
{
if(translate==1){
last_sensibility = (char *)" ";
active_method_type = (char *)"comb"; //comb
sensibility_active = 1;
 
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)
{
 
//Calculate the number of bits needed to represent the enumerate
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);
 
}
 
}
};
 
sensible_par_colon:
SENSITIVE OPENPAR WORD CLOSEPAR SEMICOLON
}
 
};
 
 
 
word_colon:
WORD COLON
{
 
if (translate == 1)
{
 
if (activeport)
 
{
if(translate==1){
active_method_type = (char *)"comb"; //comb
InsertSensibility(sensibilitylist, (char *)$3, " ");
 
InsertPort (portlist, (char *) $1, lastportkind, lastportsize);
 
}
};
 
else if (signalactive)
 
sensible_word_colon:
SENSIBLE WORD
{
if(translate==1){
InsertSensibility(sensibilitylist, (char *)$2, (char *)last_sensibility);
 
InsertSignal (signalslist, (char *) $1, lastsignalsize);
 
}
};
 
sensible_word_semicolon:
SENSIBLE WORD SEMICOLON
else if (reading_enumerates)
 
{
if(translate==1){
InsertSensibility(sensibilitylist, (char *)$2, (char *)last_sensibility);
if(sensibility_active)
{
sensibility_active = 0;
}
 
InsertEnumerates (enumerateslist, (char *) $1);
 
 
}
};
else if (multipledec)
{
 
closekey:
CLOSEKEY
{
if(translate==1){
if(method_found)
{
method_found = 0;
InsertProcess(processlist, active_method, sensibilitylist, active_method_type);
}
}
};
word_semicolon:
WORD SEMICOLON
{
if(translate==1){
if(activeport)
{
InsertPort(portlist, (char *)$1, lastportkind, lastportsize);
activeport = 0;
}
else if(signalactive)
{
InsertSignal(signalslist, (char *)$1, lastsignalsize);
signalactive = 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){
//Calculate the number of bits needed to represent the enumerate
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);
}
}
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)
{
 
//Calculate the number of bits needed to represent the enumerate
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);
 
}
 
}
};
 
word_colon:
WORD COLON
{
if(translate==1){
if(activeport)
{
InsertPort(portlist, (char *)$1, lastportkind, lastportsize);
}
else if(signalactive)
{
InsertSignal(signalslist, (char *)$1, lastsignalsize);
}
else if(reading_enumerates)
{
InsertEnumerates(enumerateslist, (char *)$1);
}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){
//Calculate the number of bits needed to represent the enumerate
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);
}
}
}
};
}
 
};
 
 
 
word_closekey_word:
WORD CLOSEKEY WORD SEMICOLON
{
if(translate==1){
//Finish enumerate var declaration
if(reading_enumerates)
{
InsertEnumerates(enumerateslist, (char *)$1);
InsertEnumList(enumlistlist,enumerateslist,(char *)$4,0); //Insert also the variable name
reading_enumerates=0;
}
}
};
WORD CLOSEKEY WORD SEMICOLON
{
 
if (translate == 1)
{
 
//Finish enumerate var declaration
if (reading_enumerates)
 
{
 
InsertEnumerates (enumerateslist, (char *) $1);
 
InsertEnumList (enumlistlist, enumerateslist, (char *) $4, 0); //Insert also the variable name
reading_enumerates = 0;
 
}
 
}
 
};
 
 
 
word_closekey:
WORD CLOSEKEY SEMICOLON
{
if(translate==1){
//Finish enumerate type declaration
if(reading_enumerates)
{
InsertEnumerates(enumerateslist, (char *)$1);
InsertEnumList(enumlistlist,enumerateslist,enumname,1); //Insert also the variable name
reading_enumerates=0;
}
}
};
WORD CLOSEKEY SEMICOLON
{
 
if (translate == 1)
{
 
//Finish enumerate type declaration
if (reading_enumerates)
 
{
 
InsertEnumerates (enumerateslist, (char *) $1);
 
InsertEnumList (enumlistlist, enumerateslist, enumname, 1); //Insert also the variable name
reading_enumerates = 0;
 
}
 
}
 
};
 
 
 
 
instantation:
WORD EQUALS NEW WORD OPENPAR QUOTE WORD QUOTE CLOSEPAR SEMICOLON
WORD EQUALS NEW WORD OPENPAR QUOTE WORD QUOTE CLOSEPAR SEMICOLON
{
 
if (translate == 1)
{
 
InsertInstance (instanceslist, (char *) $1, (char *) $4);
 
}
 
};
 
 
 
port_binding:
WORD ARROW WORD OPENPAR WORD CLOSEPAR SEMICOLON
{
 
if (translate == 1)
{
 
if (instanceslist->last == NULL)
 
{
 
fprintf (stderr, "error: no instances found\n");
 
}
 
else
 
{
 
InstanceNode *aux;
 
aux = instanceslist->first;
 
while (1)
 
{
 
if (strcmp (aux->nameinstance, (char *) $1) == 0)
 
{
if(translate==1){
InsertInstance(instanceslist, (char *)$1, (char *)$4);
 
break;
 
}
};
port_binding:
WORD ARROW WORD OPENPAR WORD CLOSEPAR SEMICOLON
 
else
 
{
if(translate==1){
if(instanceslist->last == NULL)
{
fprintf(stderr,"error: no instances found\n");
}
else
{
InstanceNode *aux;
aux = instanceslist->first;
while(1)
{
if(strcmp(aux->nameinstance, (char *)$1) == 0)
{
break;
}
else
{
if(aux->next == NULL)
{
fprintf(stderr,"error: instance %s not found\n",$1);
exit(1);
}
else
{
aux = aux->next;
}
}
}
InsertBind(aux->bindslist, (char *)$3, (char *)$5);
}
 
if (aux->next == NULL)
 
{
 
fprintf (stderr, "error: instance %s not found\n", $1);
 
exit (1);
 
}
 
else
 
{
 
aux = aux->next;
 
}
 
}
};
 
}
 
InsertBind (aux->bindslist, (char *) $3, (char *) $5);
 
}
}
 
};
 
 
 
sc_ctor:
SC_CTOR OPENPAR WORD CLOSEPAR OPENKEY
{
};
void:
VOID WORD OPENPAR CLOSEPAR SEMICOLON
{
};
SC_CTOR OPENPAR WORD CLOSEPAR OPENKEY
{
 
 
};
 
 
void:VOID WORD OPENPAR CLOSEPAR SEMICOLON
{
 
 
};
 
 
inst_decl:
WORD ASTERISCO WORD SEMICOLON
{
};
closekey_semicolon: CLOSEKEY SEMICOLON
{
};
WORD ASTERISCO WORD SEMICOLON
{
 
 
};
 
 
 
closekey_semicolon:CLOSEKEY SEMICOLON
{
 
 
};
 
 
 
enumerates:
ENUM OPENKEY
{
if(translate==1){
//New enumerate list
enumerateslist = (EnumeratesList *)malloc(sizeof(EnumeratesList));
InitializeEnumeratesList(enumerateslist);
reading_enumerates=1;
}
};
ENUM OPENKEY
{
 
if (translate == 1)
{
 
//New enumerate list
enumerateslist = (EnumeratesList *) malloc (sizeof (EnumeratesList));
 
InitializeEnumeratesList (enumerateslist);
 
reading_enumerates = 1;
 
}
 
};
 
 
 
enumerates_type:
ENUM WORD OPENKEY
{
if(translate==1){
//In this case we define type e.g. enum state_t {S0,S1,S2};
enumerateslist = (EnumeratesList *)malloc(sizeof(EnumeratesList));
InitializeEnumeratesList(enumerateslist);
enumname=malloc(sizeof(char)*strlen((char *)$2));
strcpy(enumname,(char *)$2);
reading_enumerates=1;
}
};
ENUM WORD OPENKEY
{
 
if (translate == 1)
{
 
//In this case we define type e.g. enum state_t {S0,S1,S2};
enumerateslist = (EnumeratesList *) malloc (sizeof (EnumeratesList));
 
InitializeEnumeratesList (enumerateslist);
 
enumname = malloc (sizeof (char) * strlen ((char *) $2));
 
strcpy (enumname, (char *) $2);
 
reading_enumerates = 1;
 
}
 
};
 
 
 
declaration:
WORD WORD SEMICOLON
{
if(translate==1){
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, (char *)$1);
if(list_pos>-1){
//Calculate the number of bits needed to represent the enumerate
length=findEnumerateLength(enumlistlist,list_pos);
InsertSignal(signalslist, (char *)$2,length);
InsertWrite(writeslist,(char *)$2);
}else{
fprintf(stderr,"\nType %s unknow\n",(char *)$1);
return(1);
}
}
};
WORD WORD SEMICOLON
{
 
if (translate == 1)
{
 
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, (char *) $1);
 
if (list_pos > -1)
{
 
//Calculate the number of bits needed to represent the enumerate
length = findEnumerateLength (enumlistlist, list_pos);
 
 
InsertSignal (signalslist, (char *) $2, length);
 
InsertWrite (writeslist, (char *) $2);
 
}
else
{
 
fprintf (stderr, "\nType %s unknow\n", (char *) $1);
 
return (1);
 
}
 
}
 
};
 
 
 
declaration_sc_signal:
SC_SIGNAL MENOR WORD MAYOR WORD SEMICOLON
{
if(translate==1){
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, (char *)$3);
if(list_pos>-1){
//Calculate the number of bits needed to represent the enumerate
length=findEnumerateLength(enumlistlist,list_pos);
InsertSignal(signalslist, (char *)$5,length);
InsertWrite(writeslist,(char *)$5);
}else{
fprintf(stderr,"\nType %s unknow\n",(char *)$3);
return(1);
}
}
};
SC_SIGNAL MENOR WORD MAYOR WORD SEMICOLON
{
 
if (translate == 1)
{
 
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, (char *) $3);
 
if (list_pos > -1)
{
 
//Calculate the number of bits needed to represent the enumerate
length = findEnumerateLength (enumlistlist, list_pos);
 
 
InsertSignal (signalslist, (char *) $5, length);
 
InsertWrite (writeslist, (char *) $5);
 
}
else
{
 
fprintf (stderr, "\nType %s unknow\n", (char *) $3);
 
return (1);
 
}
 
}
 
};
 
 
 
multiple_declaration:
WORD WORD COLON
{
if(translate==1){
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, (char *)$1);
if(list_pos>-1){
//Calculate the number of bits needed to represent the enumerate
length=findEnumerateLength(enumlistlist,list_pos);
storedtype=malloc(sizeof(char)*strlen((char *)$1));
strcpy(storedtype,(char *)$1);
InsertSignal(signalslist, (char *)$2,length);
InsertWrite(writeslist,(char *)$2);
multipledec=1;
}else{
fprintf(stderr,"\nType %s unknow\n",(char *)$1);
return(1);
}
}
};
WORD WORD COLON
{
 
if (translate == 1)
{
 
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, (char *) $1);
 
if (list_pos > -1)
{
 
//Calculate the number of bits needed to represent the enumerate
length = findEnumerateLength (enumlistlist, list_pos);
 
storedtype = malloc (sizeof (char) * strlen ((char *) $1));
 
strcpy (storedtype, (char *) $1);
 
InsertSignal (signalslist, (char *) $2, length);
 
InsertWrite (writeslist, (char *) $2);
 
multipledec = 1;
 
}
else
{
 
fprintf (stderr, "\nType %s unknow\n", (char *) $1);
 
return (1);
 
}
 
}
 
};
 
 
 
multiple_sc_signal_declaration:
SC_SIGNAL MENOR WORD MAYOR WORD COLON
{
if(translate==1){
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, (char *)$3);
if(list_pos>-1){
//Calculate the number of bits needed to represent the enumerate
length=findEnumerateLength(enumlistlist,list_pos);
storedtype=malloc(sizeof(char)*strlen((char *)$3));
strcpy(storedtype,(char *)$3);
InsertSignal(signalslist, (char *)$5,length);
InsertWrite(writeslist,(char *)$5);
multipledec=1;
}else{
fprintf(stderr,"\nType %s unknow\n",(char *)$3);
return(1);
}
}
};
SC_SIGNAL MENOR WORD MAYOR WORD COLON
{
 
if (translate == 1)
{
 
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, (char *) $3);
 
if (list_pos > -1)
{
 
//Calculate the number of bits needed to represent the enumerate
length = findEnumerateLength (enumlistlist, list_pos);
 
storedtype = malloc (sizeof (char) * strlen ((char *) $3));
 
strcpy (storedtype, (char *) $3);
 
InsertSignal (signalslist, (char *) $5, length);
 
InsertWrite (writeslist, (char *) $5);
 
multipledec = 1;
 
}
else
{
 
fprintf (stderr, "\nType %s unknow\n", (char *) $3);
 
return (1);
 
}
 
}
 
};
 
 
 
translateoff:
TRANSLATEOFF
{
translate=0;
fprintf(stderr,"Found Translate off directive \n");
};
TRANSLATEOFF
{
 
translate = 0;
 
fprintf (stderr, "Found Translate off directive \n");
 
};
 
 
 
translateon:
TRANSLATEON
{
translate=1;
fprintf(stderr,"Found Translate on directive \n");
};
TRANSLATEON
{
 
translate = 1;
 
fprintf (stderr, "Found Translate on directive \n");
 
};
/trunk/src/sc2v_step3.y
26,108 → 26,106
#include <stdio.h>
#include <string.h>
 
int module_found = 0;
int concat_found = 0;
int opened_pars;
int *concat_par_num;
int concats_found = 0;
char *aux;
void yyerror(const char *str)
{
fprintf(stderr,"error: %s\n",str);
}
int module_found = 0;
int concat_found = 0;
int opened_pars;
int *concat_par_num;
int concats_found = 0;
char *aux;
void yyerror (const char *str)
{
fprintf (stderr, "error: %s\n", str);
}
 
int yywrap()
{
return 1;
}
int yywrap ()
{
return 1;
}
 
main()
{
concat_par_num = (int *)malloc(16*sizeof(int));
*concat_par_num = 0;
yyparse();
}
main ()
{
concat_par_num = (int *) malloc (16 * sizeof (int));
*concat_par_num = 0;
yyparse ();
 
}
 
%}
 
%token WORD
%token OPENPAR CLOSEPAR
%token MODULE
%token MODULE
 
%%
%% commands:
/* empty */
|commands command;
 
commands: /* empty */
| commands command
;
 
 
command:
module
|
closepar
|
concat
|
openpar
;
module
|
closepar
|
concat
|
openpar;
 
module:
MODULE
{
module_found = 1;
opened_pars++;
printf("%s",(char *)$1);
};
MODULE
{
module_found = 1;
opened_pars++;
printf ("%s", (char *) $1);
};
 
openpar:
OPENPAR
{
printf("(");
opened_pars++;
};
OPENPAR
{
printf ("(");
opened_pars++;
};
 
closepar:
CLOSEPAR
CLOSEPAR
{
if (module_found)
{
printf (")");
opened_pars--;
module_found = 0;
}
else if (concat_found)
{
if (opened_pars == *(concat_par_num + concats_found))
{
if(module_found)
{
printf(")");
opened_pars--;
module_found = 0;
}
else if(concat_found)
{
if(opened_pars == *(concat_par_num + concats_found))
{
printf("}");
concats_found--;
if(concats_found == 0)
{
concat_found = 0;
}
}
else
{
printf(")");
}
opened_pars--;
}
else
{
opened_pars--;
printf(")");
}
};
printf ("}");
concats_found--;
if (concats_found == 0)
{
concat_found = 0;
}
}
else
{
printf (")");
}
opened_pars--;
}
else
{
opened_pars--;
printf (")");
}
};
 
concat:
WORD
{
aux = (char *)$1;
aux++;
printf("{%s",aux);
concat_found = 1;
opened_pars++;
concats_found++;
*(concat_par_num + concats_found) = opened_pars;
};
WORD
{
aux = (char *) $1;
aux++;
printf ("{%s", aux);
concat_found = 1;
opened_pars++;
concats_found++;
*(concat_par_num + concats_found) = opened_pars;
};
/trunk/src/list.c
20,7 → 20,7
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
 
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
27,919 → 27,1743
 
#include "list.h"
 
void InitializeDefinesList(DefinesList *list)
void
InitializeDefinesList (DefinesList * list)
{
DefineNode *first;
first = (DefineNode *)malloc(sizeof(DefineNode));
list->first = first;
list->last = NULL;
 
DefineNode *first;
 
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
{
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->next = NULL;
list->last->next = nuevo;
list->last = nuevo;
}
 
if (list->last == NULL) //list empty
{
 
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->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)
 
DefineNode *auxwrite = list->first;
 
 
if (list->last == NULL)
 
{
 
return 0;
 
}
 
else
 
{
 
while (1)
 
{
return 0;
 
if ((strcmp (name, auxwrite->name) == 0))
 
{
 
return 1;
 
}
 
else if (auxwrite->next != NULL)
 
{
 
auxwrite = auxwrite->next;
 
}
 
else
 
{
 
break;
 
}
 
}
else
{
while(1)
{
if((strcmp(name, auxwrite->name)==0))
{
return 1;
}
else if(auxwrite->next != NULL)
{
auxwrite = auxwrite->next;
}
else
{
break;
}
}
}
return 0;
 
}
 
return 0;
 
}
 
void ShowDefines(char *filedefines)
 
void
ShowDefines (char *filedefines)
{
int readok;
char *auxchar;
FILE *file;
file = fopen(filedefines,(char *)"r");
while(1)
{
readok = fread((void *)&auxchar, sizeof(char), 1, file);
if(readok)
printf("%c",auxchar);
else
break;
}
 
int readok;
 
char *auxchar;
 
FILE *file;
 
 
file = fopen (filedefines, (char *) "r");
 
 
while (1)
 
{
 
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));
list->first = first;
list->last = NULL;
 
WriteNode *first;
 
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
{
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->next = NULL;
list->last->next = nuevo;
list->last = nuevo;
}
 
if (list->last == NULL) //list empty
{
 
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->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)
 
WriteNode *auxwrite = list->first;
 
 
if (list->last == NULL)
 
{
 
return 0;
 
}
 
else
 
{
 
while (1)
 
{
return 0;
 
if ((strcmp (name, auxwrite->name) == 0))
 
{
 
return 1;
 
}
 
else if (auxwrite->next != NULL)
 
{
 
auxwrite = auxwrite->next;
 
}
 
else
 
{
 
break;
 
}
 
}
else
{
while(1)
{
if((strcmp(name, auxwrite->name)==0))
{
return 1;
}
else if(auxwrite->next != NULL)
{
auxwrite = auxwrite->next;
}
else
{
break;
}
}
}
return 0;
 
}
 
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)
 
{
WriteNode *aux = list->first;
while(1)
{
printf("%s\n",aux->name);
if(aux->next==NULL)
{
break;
}
aux = aux->next;
}
 
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));
while(1)
{
ret = fscanf(file_writes,"%s",leido);
if(ret == EOF)
break;
InsertWrite(list, leido);
}
 
char *leido;
 
int ret;
 
FILE *file_writes;
 
file_writes = fopen (name, (char *) "r");
 
 
leido = (char *) malloc (256 * sizeof (char));
 
 
while (1)
 
{
 
ret = fscanf (file_writes, "%s", leido);
 
if (ret == EOF)
 
break;
 
InsertWrite (list, leido);
 
}
 
 
 
}
 
void InitializeRegsList(RegsList *list)
 
void
InitializeRegsList (RegsList * list)
{
RegNode *first;
first = (RegNode *)malloc(sizeof(RegNode));
list->first = first;
list->last = NULL;
 
RegNode *first;
 
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)
{
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->next = NULL;
list->last->next = nuevo;
list->last = nuevo;
}
 
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->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->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)
 
RegNode *auxreg = list->first;
 
 
if (list->last == NULL)
 
{
 
return NULL;
 
}
 
else
 
{
 
while (1)
 
{
return NULL;
 
if ((strcmp (name, auxreg->name) == 0))
 
{
 
return auxreg->name2;
 
}
 
else if (auxreg->next != NULL)
 
{
 
auxreg = auxreg->next;
 
}
 
else
 
{
 
break;
 
}
 
}
else
{
while(1)
{
if((strcmp(name, auxreg->name)==0))
{
return auxreg->name2;
}
else if(auxreg->next != NULL)
{
auxreg = auxreg->next;
}
else
{
break;
}
}
}
return NULL;
 
}
 
return NULL;
 
}
 
void ShowRegsList(RegsList *list)
 
void
ShowRegsList (RegsList * list)
{
if(list->last != NULL)
 
if (list->last != NULL)
 
{
 
RegNode *aux = list->first;
 
while (1)
 
{
RegNode *aux = list->first;
while(1)
{
printf("%s\t",aux->name);
printf("%s;\n",aux->name2);
if(aux->next==NULL)
{
break;
}
aux = aux->next;
}
 
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));
list->first = first;
list->last = NULL;
 
PortNode *first;
 
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)
{
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->name = name;
nuevo->tipo = tipo;
nuevo->size = size;
nuevo->next = NULL;
list->last->next = nuevo;
list->last = nuevo;
}
 
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->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)
 
{
PortNode *aux = list->first;
while(1)
{
printf("%s ",aux->tipo);
if(aux->size != 0 && aux->size !=1)
{
printf("[%d:0] ",(-1 + aux->size));
}
printf("%s;\n",aux->name);
if(aux->next==NULL)
{
break;
}
aux = aux->next;
}
 
printf ("%s ", aux->tipo);
 
if (aux->size != 0 && aux->size != 1)
 
{
 
printf ("[%d:0] ", (-1 + aux->size));
 
}
 
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)
 
{
PortNode *aux = list->first;
while(1)
 
if (strcmp (aux->tipo, (char *) "output") == 0)
 
{
 
printf ("reg ");
 
if (aux->size != 0 && aux->size != 1)
 
{
if(strcmp(aux->tipo, (char *)"output")==0)
{
printf("reg ");
if(aux->size != 0 && aux->size!=1)
{
printf("[%d:0] ",(-1 + aux->size));
}
printf("%s;\n",aux->name);
}
if(aux->next==NULL)
{
break;
}
aux = aux->next;
}
 
printf ("[%d:0] ", (-1 + aux->size));
 
}
 
printf ("%s;\n", aux->name);
 
}
 
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)
 
{
PortNode *aux = list->first;
while(1)
{
if(aux->next==NULL)
{
printf("%s",aux->name);
break;
}
else
{
printf("%s,",aux->name);
aux = aux->next;
}
}
 
if (aux->next == NULL)
 
{
 
printf ("%s", aux->name);
 
break;
 
}
 
else
 
{
 
printf ("%s,", aux->name);
 
aux = aux->next;
 
}
 
}
 
}
 
}
 
void InitializeSignalsList(SignalsList *list)
 
void
InitializeSignalsList (SignalsList * list)
{
SignalNode *first;
first = (SignalNode *)malloc(sizeof(SignalNode));
list->first = first;
list->last = NULL;
 
SignalNode *first;
 
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)
{
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->name = name;
nuevo->size = size;
nuevo->next = NULL;
list->last->next = nuevo;
list->last = nuevo;
}
 
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->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)
 
{
SignalNode *aux = list->first;
while(1)
 
if (IsWrite (WritesList, aux->name))
 
{
 
printf ("reg ");
 
if (aux->size != 0 && aux->size != 1)
 
{
if(IsWrite(WritesList, aux->name))
{
printf("reg ");
if(aux->size != 0 && aux->size!=1)
{
printf("[%d:0] ",(-1 + aux->size));
}
printf("%s;\n",aux->name);
}
else
{
printf("wire ");
if(aux->size != 0 && aux->size!=1)
{
printf("[%d:0] ",(-1 + aux->size));
}
printf("%s;\n",aux->name);
}
if(aux->next==NULL)
{
break;
}
aux = aux->next;
}
 
printf ("[%d:0] ", (-1 + aux->size));
 
}
 
printf ("%s;\n", aux->name);
 
}
 
else
 
{
 
printf ("wire ");
 
if (aux->size != 0 && aux->size != 1)
 
{
 
printf ("[%d:0] ", (-1 + aux->size));
 
}
 
printf ("%s;\n", aux->name);
 
}
 
 
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)
 
InstanceNode *auxinstance = list->first;
 
BindNode *auxbind;
 
if (list->last == NULL)
 
{
 
return 0;
 
}
 
else
 
{
 
while (1)
 
{
return 0;
}
else
{
while(1)
 
auxbind = auxinstance->bindslist->first;
 
while (1)
 
{
 
if ((strcmp (name, auxbind->namebind) == 0))
 
{
auxbind = auxinstance->bindslist->first;
while(1)
{
if((strcmp(name, auxbind->namebind)==0))
{
return 1;
}
else if(auxbind->next != NULL)
{
auxbind = auxbind->next;
}
else
{
break;
}
}
if(auxinstance->next != NULL)
{
auxinstance = auxinstance->next;
}
else
{
break;
}
 
return 1;
 
}
 
else if (auxbind->next != NULL)
 
{
 
auxbind = auxbind->next;
 
}
 
else
 
{
 
break;
 
}
 
}
 
if (auxinstance->next != NULL)
 
{
 
auxinstance = auxinstance->next;
 
}
 
else
 
{
 
break;
 
}
 
}
return 0;
 
}
 
return 0;
 
}
 
void InitializeSensibilityList(SensibilityList *list)
 
void
InitializeSensibilityList (SensibilityList * list)
{
SensibilityNode *first;
first = (SensibilityNode *)malloc(sizeof(SensibilityNode));
list->first = first;
list->last = NULL;
 
SensibilityNode *first;
 
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)
{
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->name = name;
nuevo->tipo = tipo;
nuevo->next = NULL;
list->last->next = nuevo;
list->last = nuevo;
}
 
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->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)
 
{
SensibilityNode *aux = list->first;
while(1)
{
if(!strcmp(aux->tipo,"posedge") || !strcmp(aux->tipo, "negedge"))
printf(" %s",aux->tipo);
if(aux->next==NULL)
{
printf(" %s",aux->name);
break;
}
else
{
printf(" %s or",aux->name);
}
aux = aux->next;
}
 
if (!strcmp (aux->tipo, "posedge")
|| !strcmp (aux->tipo, "negedge"))
 
printf (" %s", aux->tipo);
 
if (aux->next == NULL)
 
{
 
printf (" %s", aux->name);
 
break;
 
}
 
else
 
{
 
printf (" %s or", aux->name);
 
}
 
aux = aux->next;
 
}
 
}
 
}
 
 
void InitializeProcessList(ProcessList *list)
 
void
InitializeProcessList (ProcessList * list)
{
ProcessNode *first;
first = (ProcessNode *)malloc(sizeof(ProcessNode));
list->first = first;
list->last = NULL;
 
ProcessNode *first;
 
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)
{
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->name = name;
nuevo->tipo = tipo;
nuevo->list = SensibilityList;
nuevo->next = NULL;
list->last->next = nuevo;
list->last = nuevo;
}
 
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->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)
 
{
ProcessNode *aux = list->first;
while(1)
{
printf("%s: always @(", aux->name);
ShowSensibilityList(aux->list);
printf(")\n");
if(aux->next==NULL)
{
break;
}
aux = aux->next;
}
 
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)
{
ProcessNode *aux = list->first;
FILE *archivo;
int readok;
char *filename;
char auxchar;
char begin[10];
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");
 
while (1)
{
readok = fread ((void *) &auxchar, sizeof (char), 1, archivo);
if (readok)
printf ("%c", auxchar);
else
break;
}
 
fclose (archivo);
 
printf ("always @(");
 
ShowSensibilityList (aux->list);
 
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);
 
/*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)
{
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)
{
readok = fread((void *)&auxchar, sizeof(char), 1, archivo);
if(readok)
printf("%c",auxchar);
else
break;
}
fclose(archivo);
printf("always @(");
ShowSensibilityList(aux->list);
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);
/*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)
printf("%c",auxchar);
else
break;
}
fclose(archivo);
if(aux->next==NULL)
if (strcmp (aux->tipo, "comb") == 0 && auxchar == '<')
{
readok = fread ((void *) &lookahead, sizeof (char), 1,archivo);
 
if (readok)
{
break;
if (lookahead == '=')
{
auxchar = lookahead;
}
else
{
printf ("%c", auxchar);
}
}
aux = aux->next;
}
printf ("%c", auxchar);
}
else
{
break;
}
}
 
fclose (archivo);
 
if (aux->next == NULL)
{
break;
}
 
aux = aux->next;
 
}
 
}
 
}
 
 
void InitializeInstancesList(InstancesList *list)
 
void
InitializeInstancesList (InstancesList * list)
{
InstanceNode *first;
first = (InstanceNode *)malloc(sizeof(InstanceNode));
list->first = first;
list->last = NULL;
 
InstanceNode *first;
 
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)
{
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);
}
else
{
InstanceNode *nuevo;
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);
}
 
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);
 
}
 
else
 
{
 
InstanceNode *nuevo;
 
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);
 
}
 
}
 
void InitializeBindsList(BindsList *list)
{
BindNode *first;
first = (BindNode *)malloc(sizeof(BindNode));
list->first = first;
list->last = NULL;
 
void
InitializeBindsList (BindsList * list)
{
 
BindNode *first;
 
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->nameport = nameport;
 
nuevo->namebind = namebind;
 
nuevo->next = NULL;
 
list->last->next = nuevo;
 
list->last = nuevo;
 
}
 
}
 
 
void
ShowInstancedModules (InstancesList * list)
{
 
if (list->last != NULL)
 
{
 
InstanceNode *auxinstance;
 
auxinstance = list->first;
 
BindNode *auxbind;
 
auxbind = auxinstance->bindslist->first;
 
while (1)
 
{
list->first->nameport = nameport;
list->first->namebind = namebind;
list->first->next = NULL;
list->last = list->first;
 
printf ("%s %s (", auxinstance->namemodulo,
auxinstance->nameinstance);
 
while (1)
 
{
 
printf (".%s(%s)", auxbind->nameport, auxbind->namebind);
 
if (auxbind->next == NULL)
 
{
 
printf (");\n");
 
break;
 
}
 
else
 
{
 
printf (", ");
 
auxbind = auxbind->next;
 
}
 
}
 
if (auxinstance->next == NULL)
 
{
 
break;
 
}
 
else
 
{
 
auxinstance = auxinstance->next;
 
auxbind = auxinstance->bindslist->first;
 
}
 
}
else
{
BindNode *nuevo;
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)
 
 
//Enumerates list
void
InitializeEnumeratesList (EnumeratesList * list)
{
if(list->last != NULL)
{
InstanceNode *auxinstance;
auxinstance = list->first;
BindNode *auxbind;
auxbind = auxinstance->bindslist->first;
while(1)
{
printf("%s %s (",auxinstance->namemodulo, auxinstance->nameinstance);
while(1)
{
printf(".%s(%s)",auxbind->nameport, auxbind->namebind);
if(auxbind->next == NULL)
{
printf(");\n");
break;
}
else
{
printf(", ");
auxbind = auxbind->next;
}
}
if(auxinstance->next == NULL)
{
break;
}
else
{
auxinstance = auxinstance->next;
auxbind = auxinstance->bindslist->first;
}
}
}
 
EnumeratesNode *first;
 
first = (EnumeratesNode *) malloc (sizeof (EnumeratesNode));
 
list->first = first;
 
list->last = NULL;
 
}
 
//Enumerates list
void InitializeEnumeratesList(EnumeratesList *list)
 
void
InsertEnumerates (EnumeratesList * list, char *name)
{
EnumeratesNode *first;
first = (EnumeratesNode *)malloc(sizeof(EnumeratesNode));
list->first = first;
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->name = name;
 
nuevo->next = NULL;
 
list->last->next = nuevo;
 
list->last = nuevo;
 
}
 
}
 
void InsertEnumerates(EnumeratesList *list, char *name)
 
int
ShowEnumeratesList (EnumeratesList * list)
{
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)
{
list->first->name = name;
list->first->next = NULL;
list->last = list->first;
 
printf (",\n");
 
aux = aux->next;
 
i = 1;
 
while (1)
 
{
 
if (aux->next == NULL)
 
{
 
printf (" %s = %d;\n\n", aux->name, i);
 
return (i);
 
}
 
else
 
{
 
printf (" %s = %d,\n", aux->name, i);
 
}
 
i++;
 
aux = aux->next;
 
}
 
}
else
else
{
EnumeratesNode *nuevo;
nuevo = (EnumeratesNode *)malloc(sizeof(EnumeratesNode));
nuevo->name = name;
nuevo->next = NULL;
list->last->next = nuevo;
list->last = nuevo;
 
printf (";\n\n");
 
return (i);
 
}
 
}
 
}
 
int ShowEnumeratesList(EnumeratesList *list)
 
 
//List of enumerates list
void
InitializeEnumListList (EnumListList * list)
{
int i=0;
if(list->last != NULL)
{
EnumeratesNode *aux = list->first;
printf("parameter %s = 0",aux->name);
if(aux->next!=NULL){
printf(",\n");
aux = aux->next;
i=1;
while(1)
{
if(aux->next==NULL)
{
printf(" %s = %d;\n\n",aux->name,i);
return(i);
}
else
{
printf(" %s = %d,\n",aux->name,i);
}
i++;
aux = aux->next;
}
}else{
printf(";\n\n");
return(i);
}
}
 
EnumListNode *first;
 
first = (EnumListNode *) malloc (sizeof (EnumListNode));
 
list->first = first;
 
list->last = NULL;
 
}
 
//List of enumerates list
void InitializeEnumListList(EnumListList *list)
 
void
InsertEnumList (EnumListList * list, EnumeratesList * enumlist, char *name,
int istype)
{
EnumListNode *first;
first = (EnumListNode *)malloc(sizeof(EnumListNode));
list->first = first;
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->name = name;
 
nuevo->istype = istype;
 
nuevo->list = enumlist;
 
nuevo->next = NULL;
 
list->last->next = nuevo;
 
list->last = nuevo;
 
}
 
}
 
void InsertEnumList(EnumListList *list, EnumeratesList *enumlist, char *name, int istype)
 
void
ShowEnumListList (EnumListList * list)
{
if(list->last == NULL)
 
int items;
 
 
if (list->last != NULL)
 
{
 
EnumListNode *aux = list->first;
 
while (1)
 
{
list->first->name = name;
list->first->istype = istype;
list->first->list = enumlist;
list->first->next = NULL;
list->last = list->first;
 
items = ShowEnumeratesList (aux->list);
 
 
//Calculate the number of bits needed to represent the enumerate
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);
 
else
 
printf ("reg %s;\n\n", aux->name);
 
}
 
 
if (aux->next == NULL)
 
{
 
break;
 
}
 
aux = aux->next;
 
}
else
{
EnumListNode *nuevo;
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)
 
int
findEnumList (EnumListList * list, char *name)
{
int items;
if(list->last != NULL)
 
int i = 0;
 
if (list->last != NULL)
 
{
 
EnumListNode *aux = list->first;
 
 
while (1)
 
{
EnumListNode *aux = list->first;
while(1)
{
items=ShowEnumeratesList(aux->list);
 
//Calculate the number of bits needed to represent the enumerate
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);
else
printf("reg %s;\n\n",aux->name);
}
if(aux->next==NULL)
{
break;
}
aux = aux->next;
}
//printf("%s %s %d %d\n", aux->name,name,aux->istype,i);
if ((strcmp (aux->name, name) == 0) && ((aux->istype) == 1))
{
 
return i;
 
}
 
if (aux->next == NULL)
{
 
return -1;
 
}
 
aux = aux->next;
 
i++;
 
}
 
}
else
 
return -1;
 
}
 
int findEnumList(EnumListList *list, char *name)
 
int
findEnumerateLength (EnumListList * list, int offset)
{
int i=0;
if(list->last != NULL)
{
EnumListNode *aux = list->first;
 
while(1)
int i = 0;
 
double bits, bits_round;
 
int bits_i;
 
 
if (list->last != NULL)
 
{
//printf("%s %s %d %d\n", aux->name,name,aux->istype,i);
if((strcmp(aux->name,name)==0) && ((aux->istype)==1)){
return i;
}
if(aux->next==NULL){
return -1;
}
aux = aux->next;
i++;
 
i = 0;
 
EnumListNode *aux = list->first;
 
EnumeratesNode *aux2;
 
 
for (i = 0; i < offset; i++)
 
aux = aux->next;
 
 
aux2 = aux->list->first;
 
 
i = 0;
 
while (1)
 
{
 
i++;
 
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;
 
return bits_i;
 
}
 
aux2 = aux2->next;
 
 
}
 
}
} else
return -1;
}
 
int findEnumerateLength(EnumListList *list, int offset){
int i=0;
double bits,bits_round;
int bits_i;
if(list->last != NULL)
{
i=0;
EnumListNode *aux = list->first;
EnumeratesNode *aux2;
for(i=0;i< offset; i++)
aux = aux->next;
aux2=aux->list->first;
i=0;
while(1)
{
i++;
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;
return bits_i;
}
aux2 = aux2->next;
}
}
}
/trunk/examples/fsm.cpp
1,5 → 1,8
#include "systemc.h"
 
#define HOLA 1
#define CONCAT 1
 
void fsm::regs(){
if(rst.read()){
state.write(S0);
15,7 → 18,7
sc_uint<2> c;
next_state.write(state.read());
a.write(0);
b.write(0);
b.write(HOLA);
#ifdef CONCAT
c.write((a.range(1,0),b.range(1,0)));
24,7 → 27,7
#endif
switch((int)state.read()){
case S0 :
case S0 : //Case 0
if(input1.read()){
next_state.write(S1);
a.write(true);

powered by: WebSVN 2.1.0

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