URL
https://opencores.org/ocsvn/sc2v/sc2v/trunk
Subversion Repositories sc2v
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 32 to Rev 33
- ↔ Reverse comparison
Rev 32 → Rev 33
/trunk/ChangeLog
1,3 → 1,9
10-10-2005 Version 0.5 |
|
Added support for structures as local variables |
View dummy2.cpp file for an example |
|
|
19-09-2005 Version 0.4.6 |
|
Fix bug when closing method with }; |
/trunk/src/sc2v_step1.h
36,10 → 36,28
struct _RegNode *next; |
} RegNode; |
|
/*Each struct has a name and a list of the registers declared inside it*/ |
typedef struct _StructRegNode |
{ |
char name[MAX_NAME_LENGTH]; |
int length; |
struct _StructRegNode *next; |
} StructRegNode; |
|
typedef struct _StructNode |
{ |
char name[MAX_NAME_LENGTH]; |
StructRegNode *list; |
struct _StructNode *next; |
} StructNode; |
|
/* Global var to store Regs */ |
RegNode *regslist; |
/* Global var to store Defines */ |
DefineNode *defineslist; |
/*Global var to store Structs */ |
StructNode *structslist; |
StructRegNode *structsreglist; |
|
/* Functions for defines list*/ |
DefineNode *InsertDefine(DefineNode *list,char *name); |
49,4 → 67,10
RegNode *InsertReg(RegNode *list, char *name, char *name2); |
char *IsReg (RegNode *list,char *name); |
|
/* Functions for structs list*/ |
StructNode *InsertStruct(StructNode *list, char *name, StructRegNode *reglist); |
StructRegNode *InsertStructReg(StructRegNode *list, char *name, int length); |
void ShowStructs (StructNode * list); |
|
|
|
/trunk/src/sc2v_step1.y
23,7 → 23,7
%{ |
#include <stdio.h> |
#include <string.h> |
|
#include "sglib.h" |
#include "sc2v_step1.h" |
|
int lineno = 1; |
62,6 → 62,11
int default_break_found = 0; |
int default_found; |
|
int struct_found=0; |
int end_struct=0; |
int ignore_semicolon=0; |
char *structname; |
|
//Directives variables |
int translate; |
int verilog; |
83,10 → 88,12
|
defineslist = NULL; |
regslist = NULL; |
structslist = NULL; |
structsreglist = NULL; |
|
fprintf (stderr, "\nSystemC to Verilog Translator v0.4"); |
fprintf (stderr, |
"\nProvided by OpenSoc http://www.opensocdesign.com\n\n"); |
"\nProvided by URJC(Universidad Rey Juan Carlos)\nhttp://www.escet.urjc.es/~jmartine\n\n"); |
fprintf (stderr, "Parsing implementation file.......\n\n"); |
|
processname = (char *) malloc (256 * sizeof (char)); |
102,6 → 109,7
FILE_WRITES = fopen (file_writes, (char *) "w"); |
|
lastword = (char *) malloc (sizeof (char) * 256); |
structname = (char *) malloc (sizeof (char) * 256); |
|
for (i = 0; i < 256; i++) |
switchparenthesis[i] = 0; |
125,15 → 133,16
%token COLON SEMICOLON RANGE OPENPAR CLOSEPAR TWODOUBLEPOINTS OPENCORCH CLOSECORCH SWITCH CASE DEFAULT BREAK |
%token HEXA DEFINE READ TRANSLATEOFF TRANSLATEON VERILOGBEGIN VERILOGEND TAB DOLLAR MINEQ |
%token VOID TTRUE TFALSE ENDFUNC INC DEC INTEGER EQUALS |
%token PIFDEF PIFNDEF PENDDEF PELSE COMMENT |
%token PIFDEF PIFNDEF PENDDEF PELSE COMMENT STRUCT DOT |
|
%% commands: /* empty */ |
|commands command; |
|
|
command: |
endfunc |
struct_dec |
| |
endfunc |
| |
voidword |
| |
include |
238,8 → 247,35
| |
minorequal |
| |
comment; |
comment |
| |
struct_access |
; |
|
struct_access: |
WORD DOT WORD |
{ |
/*Struct access |
Check if it is a var acess or a reg*/ |
if (newline){ |
for (i = 0; i < openedkeys; i++) |
fprintf (file, " "); |
} |
strcpy(structname,(char *)$3); |
strcat(structname,(char *)$1); |
regname2 = IsReg (regslist, structname); |
if (regname2 == NULL) |
fprintf (file, "%s ", structname); |
else |
fprintf (file, "%s", regname2); |
|
newline = 0; |
|
free(regname2); |
|
printf("Access to struct %s.%s\n",(char *)$1,(char *)$3); |
} |
|
minorequal: |
MINEQ |
{ |
532,8 → 568,7
{ |
if(lastswitch){ |
openedcase=0; |
}else if (openedcase) |
{ |
}else if (openedcase){ |
fprintf (file, " :\n"); |
|
for (i = 0; i < openedkeys; i++) |
541,10 → 576,44
|
fprintf(file,"begin\n"); |
openedcase=0; |
} |
} |
if (end_struct){ |
end_struct=0; |
struct_found=0; |
ignore_semicolon=1; |
structslist=InsertStruct(structslist,(char *)$1,structsreglist); |
|
if (reg_found) |
{ |
//ShowStructs(structslist); |
|
/*Now we should convert all the elements of the struct into regs*/ |
StructRegNode *srll; |
SGLIB_LIST_MAP_ON_ELEMENTS (StructRegNode,structsreglist, srll,next, |
{ |
if(srll->length==0) |
fprintf (regs_file, "reg "); |
else |
fprintf (regs_file, "reg[%d:0] ", (-1 +srll->length)); |
|
regname =(char *) malloc (sizeof (char) * (strlen (srll->name) + 1)); |
regname2 = (char *) malloc (sizeof (char) * (strlen (srll->name) + strlen (processname)+strlen((char *)$1)) + 1); |
strcpy (regname, srll->name); |
strcpy (regname2, srll->name); |
strcat (regname, (char *)$1); |
strcat (regname2, (char *)$1); |
strcat (regname2, processname); |
fprintf (regs_file, "%s;\n", regname2); /*By the moment no arrays inside the struct supported*/ |
|
regslist = InsertReg (regslist, regname, regname2); |
free (regname); |
free (regname2); |
structsreglist=NULL; |
reg_found=0; /*To avoid arrays in sructs the interpretation finish here*/ |
);} |
|
}else if(struct_found && reg_found){ |
structsreglist=InsertStructReg(structsreglist,(char *)$1,reglenght); |
|
}else if (reg_found){ |
if(writelenght){ |
writelenght=0; |
if(reglenght==0) |
563,8 → 632,7
regslist = InsertReg (regslist, regname, regname2); |
free (regname); |
free (regname2); |
} |
else if(integer_found){ |
}else if(integer_found){ |
regname = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + 1)); |
regname2 = (char *) malloc (sizeof (char) * (strlen ((char *) $1) + strlen (processname)) + 1); |
strcpy (regname, (char *) $1); |
580,43 → 648,33
free (regname); |
free (regname2); |
|
}else |
{ |
if (newline) |
{ |
for (i = 0; i < openedkeys; i++) |
fprintf (file, " "); |
} |
}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) |
{ |
fprintf (file, "`%s", (char *) $1); |
defineinvocationfound = 1; |
} |
else |
{ |
fprintf (file, "%s", (char *) $1); |
ifdeffound = 0; |
} |
} |
else |
{ |
fprintf (file, "%s ", (char *) $1); |
} |
} |
else |
if (regname2 == NULL){ |
if (IsDefine (defineslist, (char *) $1)){ |
if (ifdeffound == 0){ |
fprintf (file, "`%s", (char *) $1); |
defineinvocationfound = 1; |
}else{ |
fprintf (file, "%s", (char *) $1); |
ifdeffound = 0; |
} |
}else{ |
fprintf (file, "%s ", (char *) $1); |
} |
}else |
fprintf (file, "%s", regname2); |
|
newline = 0; |
} |
newline = 0; |
} |
|
} |
else if (definefound) |
}else if (definefound) |
{ |
|
if (IsDefine (defineslist, (char *) $1)) |
751,7 → 809,7
defineparenthesis = 0; |
if (translate == 1 && verilog == 0) |
{ |
if (processfound) |
if (processfound && !struct_found && !ignore_semicolon) |
{ |
if (reg_found) |
{ |
774,6 → 832,7
|
writingvar=0; |
defineinvocationfound = 0; |
ignore_semicolon=0; |
}; |
|
|
913,37 → 972,33
CLOSEKEY |
{ |
defineparenthesis = 0; |
if (translate == 1 && verilog == 0) |
{ |
if (processfound && !definefound) |
{ |
if (openedkeys == switchparenthesis[switchfound] && switchfound > 0) |
{ |
if(struct_found){ |
end_struct=1; |
}else if (translate == 1 && verilog == 0){ |
if (processfound && !definefound){ |
if (openedkeys == switchparenthesis[switchfound] && switchfound > 0){ |
fprintf (file, "\n"); |
if (default_found & !default_break_found) |
{ |
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--; |
fprintf (file, " "); |
|
} |
else |
{ |
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) |
959,6 → 1014,8
fclose (file); |
fclose (regs_file); |
processfound = 0; |
/*Clear process struct list*/ |
structslist=NULL; |
} |
} |
else if (verilog == 1) |
1408,4 → 1465,11
} |
fprintf (file, " %s", (char *)$1); |
} |
} |
} |
|
struct_dec: |
STRUCT OPENKEY |
{ |
struct_found=1; |
} |
|
/trunk/src/sc2v_step1.l
57,6 → 57,7
"]" if(!includefound & !linecomment & !multilinecomment) return CLOSECORCH; else {yylval=(int)strdup(yytext);} return COMMENT; |
"return" if(!includefound & !linecomment & !multilinecomment) return ENDFUNC; else {yylval=(int)strdup(yytext);} return COMMENT; |
".write" if(!includefound & !linecomment & !multilinecomment) return WRITE; else {yylval=(int)strdup(yytext);} return COMMENT; |
"struct" if(!includefound & !linecomment & !multilinecomment) return STRUCT; else {yylval=(int)strdup(yytext);} return COMMENT; |
"switch" if(!includefound & !linecomment & !multilinecomment) return SWITCH; else {yylval=(int)strdup(yytext);} return COMMENT; |
"case" if(!includefound & !linecomment & !multilinecomment) return CASE; else {yylval=(int)strdup(yytext);} return COMMENT; |
"default" if(!includefound & !linecomment & !multilinecomment) return DEFAULT; else {yylval=(int)strdup(yytext);} return COMMENT; |
64,7 → 65,7
".read" if(!includefound & !linecomment & !multilinecomment) return READ; else {yylval=(int)strdup(yytext);} return COMMENT; |
".range" if(!includefound & !linecomment & !multilinecomment) return RANGE; else {yylval=(int)strdup(yytext);} return COMMENT; |
[a-zA-Z][_a-zA-Z0-9]* yylval=(int)strdup(yytext); if(!includefound & !linecomment & !multilinecomment) return WORD; else return COMMENT; |
[.:^!%/+*_"&""?""|""\\"] yylval=(int)strdup(yytext); if(!includefound & !linecomment & !multilinecomment) return SYMBOL; else return COMMENT; |
[:^!%/+*_"&""?""|""\\"] yylval=(int)strdup(yytext); if(!includefound & !linecomment & !multilinecomment) return SYMBOL; else return COMMENT; |
"<=" yylval=(int)strdup(yytext); if(!includefound & !linecomment & !multilinecomment) return MINEQ; else return COMMENT; |
"=" yylval=(int)strdup(yytext); if(!includefound & !linecomment & !multilinecomment) return EQUALS; else return COMMENT; |
"++" yylval=(int)strdup(yytext); if(!includefound & !linecomment & !multilinecomment) return INC; else return COMMENT; |
74,6 → 75,7
"@" yylval=(int)strdup(yytext); if(!includefound & !linecomment & !multilinecomment) return SYMBOL; else return COMMENT; |
"," yylval=(int)strdup(yytext); if(!includefound & !linecomment & !multilinecomment) return COLON; else return COMMENT; |
";" yylval=(int)strdup(yytext); if(!includefound & !linecomment & !multilinecomment) return SEMICOLON; else return COMMENT; |
"." yylval=(int)strdup(yytext); if(!includefound & !linecomment & !multilinecomment) return DOT; else return COMMENT; |
[" "]+ /*Ignore white spaces*/ |
"\t" return TAB; /*Ignore Tab*/ |
"\n" lineno++; if (linecomment) linecomment=0; else if(includefound) includefound=0; return NEWLINE; |
/trunk/src/sc2v_step1.c
74,3 → 74,43
); |
return NULL; |
} |
|
StructNode *InsertStruct(StructNode *list, char *name, StructRegNode *reglist){ |
|
StructNode *sl; |
|
sl=(StructNode *)malloc(sizeof(StructNode)); |
strcpy(sl->name,name); |
sl->list=reglist; |
SGLIB_LIST_ADD(StructNode,list,sl,next); |
return(list); |
|
} |
|
StructRegNode *InsertStructReg(StructRegNode *list, char *name, int length){ |
|
StructRegNode *sl; |
|
sl=(StructRegNode *)malloc(sizeof(StructRegNode)); |
strcpy(sl->name,name); |
sl->length=length; |
SGLIB_LIST_ADD(StructRegNode,list,sl,next); |
return(list); |
|
} |
|
void |
ShowStructs (StructNode * list) |
{ |
StructNode *sll; |
SGLIB_LIST_MAP_ON_ELEMENTS (StructNode, list, sll, next, |
{ |
printf ("%s\n", sll->name); |
StructRegNode *srll; |
SGLIB_LIST_MAP_ON_ELEMENTS (StructRegNode,sll->list, srll,next, |
{ |
printf ("\t%s %d\n",srll->name,srll->length); |
);} |
); |
} |
} |
/trunk/examples/dummy2.cpp
15,6 → 15,15
fsm::fsm_proc () |
{ |
|
struct { |
sc_uint<16> addr; |
sc_uint<32> data; |
} st; |
|
struct { |
sc_int<26> data1; |
} st1; |
|
sc_uint <2> c[4]; |
sc_uint <4> f; |
next_state.write (state.read ()); |
29,6 → 38,7
{ |
next_state.write (sc_uint<4>(0x1b1)); |
a.write (true); |
st1.data1=8; |
} |
else if (input2.read () < input1.read()) |
{ |
75,7 → 85,13
} |
|
void fsm::dummy_proc(){ |
struct { |
sc_int<26> data1; |
sc_uint<32> data2; |
} st2; |
|
st2.data1=6; |
st2.data2=8; |
w.write(sc_uint<1>(2)); |
|
w.write(sc_uint<1>(2)); |
|
} |
/trunk/examples/dummy2.h
29,7 → 29,6
SC_METHOD(fsm_proc); |
sensitive(state); |
sensitive << input1; |
sensitive << array; |
sensitive(input2); |
|
SC_METHOD(dummy_proc); |