URL
https://opencores.org/ocsvn/sc2v/sc2v/trunk
Subversion Repositories sc2v
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 3 to Rev 4
- ↔ Reverse comparison
Rev 3 → Rev 4
/trunk/sc2v.pdf
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/src/sc2v_step1.y
1,6 → 1,6
/* ----------------------------------------------------------------------------- |
* |
* SystemC to Verilog Translator v0.1 |
* SystemC to Verilog Translator v0.2 |
* Provided by OpenSoc Design |
* |
* www.opensocdesign.com |
62,7 → 62,11
int default_break_found = 0; |
int default_found; |
|
|
//Directives variables |
int translate; |
int verilog; |
int writemethod; |
|
void yyerror(const char *str) |
{ |
fprintf(stderr,"error: %s\n",str); |
80,7 → 84,6
defineslist = (DefinesList *)malloc(sizeof(DefinesList)); |
InitializeDefinesList(defineslist); |
|
lastword = (char *)malloc(256*sizeof(int)); |
processname = (char *)malloc(256*sizeof(int)); |
processname2 = (char *)malloc(256*sizeof(int)); |
fileregs = (char *)malloc(256*sizeof(int)); |
95,6 → 98,10
if(FILE_WRITES!=NULL) |
printf("\nopening file => filename = %s\n",file_writes); |
|
translate=1; |
verilog=0; |
writemethod=0; |
|
yyparse(); |
fclose(FILE_WRITES); |
fclose(FILE_DEFINES); |
102,9 → 109,11
|
%} |
|
%token NUMBER WORD SC_INT SC_UINT BOOL MAYOR MENOR OPENKEY CLOSEKEY WRITE WORD SYMBOL NEWLINE |
%token COLON SEMICOLON RANGE OPENPAR CLOSEPAR DOSPUNTOSDOBLE OPENCORCH CLOSECORCH SWITCH CASE DEFAULT BREAK |
%token SC_BIGINT SC_BIGUINT HEXA DEFINE READ |
%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 |
%token PIFDEF PENDDEF PELSE |
|
%% |
|
114,6 → 123,16
|
|
command: |
voidword |
| |
include |
| |
dollar |
| |
intconv |
| |
tab |
| |
read |
| |
sc_int |
156,14 → 175,18
| |
closecorch |
| |
mayor |
bigger |
| |
menor |
lower |
| |
switch |
| |
case_number |
case_only |
| |
case_number |
| |
case_word |
| |
case_default |
| |
break |
171,23 → 194,83
hexa |
| |
define |
| |
translateoff |
| |
translateon |
| |
verilogbegin |
| |
verilogend |
| |
ifdef |
| |
endif |
| |
else |
; |
|
|
|
voidword: |
VOID |
{ |
if(verilog==1) |
fprintf(file," void"); |
}; |
|
|
include: |
INCLUDE |
{ |
if(verilog==1) |
fprintf(file," #include"); |
}; |
|
|
dollar: |
DOLLAR |
{ |
if(verilog==1) |
fprintf(file," $"); |
}; |
|
intconv: |
INTCONV |
{ |
if(verilog==1) |
fprintf(file," (int)"); |
}; |
|
tab: |
TAB |
{ |
if(verilog==1) |
fprintf(file," \t"); |
}; |
|
read: |
READ OPENPAR CLOSEPAR |
{ |
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); |
} |
void: |
WORD DOSPUNTOSDOBLE WORD OPENPAR CLOSEPAR |
WORD TWODOUBLEPOINTS WORD OPENPAR CLOSEPAR |
{ |
if(translate==1&& verilog==0){ |
strcpy(processname ,(char *)$4); |
strcpy(processname2 ,(char *)$4); |
strcat(processname2, (char *)".sc2v"); |
197,48 → 280,64
strcpy(file_writes, (char *)$4); |
strcat(file_writes, (char *)"_writes.sc2v"); |
*/ |
}else if(verilog==1) |
fprintf(file," %s::%s()",(char *)$1,(char *)$3); |
|
} |
sc_int: |
SC_INT MENOR NUMBER MAYOR |
{ |
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_uint: |
SC_UINT MENOR NUMBER MAYOR |
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_bigint: |
SC_BIGINT MENOR NUMBER MAYOR |
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_biguint: |
SC_BIGUINT MENOR NUMBER MAYOR |
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); |
} |
; |
|
245,11 → 344,14
bool: |
BOOL |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
fprintf(regs_file,"reg "); |
reg_found = 1; |
} |
}else if(verilog==1) |
fprintf(file,"bool"); |
} |
; |
|
256,10 → 358,13
range: |
RANGE OPENPAR NUMBER COLON NUMBER CLOSEPAR |
{ |
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); |
} |
; |
|
266,6 → 371,7
number: |
NUMBER |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
if(reg_found) |
{ |
278,21 → 384,28
fprintf(file,"%d",$1); |
else if(definefound) |
fprintf(FILE_DEFINES,"%d",$1); |
}else if(verilog==1) |
fprintf(file,"%d",$1); |
} |
; |
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; |
|
for(i = 0; i < openedkeys; i++) |
fprintf(file," "); |
|
fprintf(file,"begin\n"); |
openedcase = 0; |
} |
|
lastword=malloc(sizeof(char)*strlen((char *)$1)); |
strcpy(lastword, (char *)$1); |
|
if(reg_found) |
305,27 → 418,28
} |
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; |
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) |
332,7 → 446,7
{ |
if(IsDefine(defineslist, (char *)$1)) |
{ |
fprintf(FILE_DEFINES,"`%s ",(char *)$1); |
fprintf(FILE_DEFINES,"`%s",(char *)$1); |
} |
else |
{ |
339,12 → 453,14
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) |
356,30 → 472,16
{ |
fprintf(FILE_DEFINES,"%s",(char *)$1); |
} |
} |
; |
}else if(verilog==1) |
fprintf(file,"%s",(char *)$1); |
}; |
|
/*espace: |
ESPACE |
{ |
if(processfound) |
fprintf(file," "); |
} |
; |
*/ |
|
/* |
tab: |
TAB |
{ |
if(processfound) |
fprintf(file,"\t"); |
} |
; |
*/ |
write: |
WRITE |
{ |
if(translate==1&& verilog==0){ |
writemethod=1; |
if(processfound) |
{ |
fprintf(file," = "); |
389,12 → 491,17
{ |
fprintf(FILE_DEFINES," = "); |
} |
} |
; |
free(lastword); |
|
}else if(verilog==1){ |
fprintf(file,".write"); |
} |
}; |
|
newline: |
NEWLINE |
{ |
if(translate==1&& verilog==0){ |
if(processfound & !reg_found & !openedcase) |
{ |
fprintf(file,"\n"); |
404,12 → 511,15
{ |
fprintf(FILE_DEFINES,"\n"); |
} |
} |
; |
|
}else if(verilog==1) |
fprintf(file,"\n"); |
}; |
|
colon: |
COLON |
COLON |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
if(reg_found) |
423,12 → 533,14
{ |
fprintf(FILE_DEFINES,","); |
} |
} |
; |
}else if(verilog==1) |
fprintf(file,","); |
}; |
|
semicolon: |
SEMICOLON |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
if(reg_found) |
449,12 → 561,14
{ |
fprintf(FILE_DEFINES,";"); |
} |
} |
; |
}else if(verilog==1) |
fprintf(file,";"); |
}; |
|
openpar: |
OPENPAR |
OPENPAR |
{ |
if(translate==1 && verilog==0){ |
if(processfound) |
{ |
fprintf(file,"("); |
463,12 → 577,14
{ |
fprintf(FILE_DEFINES,"("); |
} |
} |
; |
}else if(verilog==1) |
fprintf(file,"("); |
}; |
|
closepar: |
CLOSEPAR |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
fprintf(file,")"); |
477,12 → 593,14
{ |
fprintf(FILE_DEFINES,")"); |
} |
} |
; |
}else if(verilog==1) |
fprintf(file,")"); |
}; |
|
opencorch: |
OPENCORCH |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
if(reg_found) |
498,12 → 616,14
fprintf(FILE_DEFINES,"["); |
|
} |
} |
; |
}else if(verilog==1) |
fprintf(file,"["); |
}; |
|
closecorch: |
CLOSECORCH |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
if(reg_found) |
518,13 → 638,15
{ |
fprintf(FILE_DEFINES,"]"); |
} |
} |
; |
}else if(verilog==1) |
fprintf(file,"]"); |
}; |
|
|
openkey: |
OPENKEY |
{ |
if(translate==1 && verilog==0){ |
openedkeys++; |
if(openedkeys==1 & !definefound) |
{ |
541,16 → 663,14
if(processfound) |
if(openedkeys != switchparenthesis) |
{ |
fprintf(file,"\n"); |
for(i = 0; i < openedkeys; i++) |
fprintf(file," "); |
fprintf(file,"begin\n"); |
newline = 1; |
} |
/*if(definefound) |
{ |
|
}*/ |
|
}else if(verilog==1) |
fprintf(file,"{"); |
} |
; |
|
557,6 → 677,7
closekey: |
CLOSEKEY |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
if(openedkeys==switchparenthesis & switchfound == 1) |
601,13 → 722,15
free(regname2); |
processfound = 0; |
} |
} |
; |
}else if(verilog==1) |
fprintf(file,"}"); |
}; |
|
|
mayor: |
MAYOR |
bigger: |
BIGGER |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
fprintf(file,">"); |
616,12 → 739,14
{ |
fprintf(FILE_DEFINES,">"); |
} |
} |
; |
}else if(verilog==1) |
fprintf(file,">"); |
}; |
|
menor: |
MENOR |
lower: |
LOWER |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
fprintf(file,"<"); |
630,14 → 755,16
{ |
fprintf(FILE_DEFINES,"<"); |
} |
} |
; |
}else if(verilog==1) |
fprintf(file,"<"); |
}; |
|
|
switch: |
SWITCH |
{ |
if(processfound) |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
fprintf(file,"\n"); |
for(i = 0; i < openedkeys; i++) |
646,14 → 773,15
switchfound = 1; |
switchparenthesis = openedkeys + 1; |
} |
}else if(verilog==1) |
fprintf(file,"switch"); |
}; |
|
|
|
|
case_number: |
CASE NUMBER SYMBOL |
{ |
if(processfound) |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
for(i = 0; i < openedkeys; i++) |
fprintf(file," "); |
661,20 → 789,40
fprintf(file,", %d",$2); |
else |
fprintf(file,"%d",$2); |
//for(i = 0; i < openedkeys; i++) |
// fprintf(file," "); |
//fprintf(file,"begin\n"); |
|
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_default: |
DEFAULT SYMBOL |
{ |
if(processfound) |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
for(i = 0; i < openedkeys; i++) |
fprintf(file," "); |
685,11 → 833,22
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("); |
}; |
|
break: |
BREAK SEMICOLON |
{ |
if(translate==1&& verilog==0){ |
if(processfound) |
{ |
if(newline == 0) |
696,17 → 855,20
fprintf(file,"\n"); |
for(i = 0; i < openedkeys; i++) |
fprintf(file," "); |
fprintf(file,"end"); |
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"); |
715,5 → 877,80
{ |
fprintf(FILE_DEFINES,"'h"); |
} |
}else if(verilog==1) |
fprintf(file,"0x"); |
}; |
|
translateoff: |
TRANSLATEOFF |
{ |
translate=0; |
fprintf(stderr,"Found Translate off directive \n"); |
}; |
|
translateon: |
TRANSLATEON |
{ |
translate=1; |
fprintf(stderr,"Found Translate on directive \n"); |
}; |
|
verilogbegin: |
VERILOGBEGIN |
{ |
verilog=1; |
fprintf(stderr,"Found Verilog Begin directive \n"); |
}; |
|
verilogend: |
VERILOGEND |
{ |
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"); |
}; |
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"); |
}; |
else: |
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"); |
}; |
/trunk/src/list.h
122,6 → 122,28
ProcessNode *last; |
} ProcessList; |
|
typedef struct _enumerates_node { |
char *name; |
struct _enumerates_node *next; |
} EnumeratesNode; |
|
typedef struct _enumerates_list { |
EnumeratesNode *first; |
EnumeratesNode *last; |
} EnumeratesList; |
|
typedef struct _enumlist_node { |
char *name; |
int istype; |
EnumeratesList *list; |
struct _enumlist_node *next; |
} EnumListNode; |
|
typedef struct _enumlist_list { |
EnumListNode *first; |
EnumListNode *last; |
} EnumListList; |
|
/* Functions for DEFINES list*/ |
void InitializeDefinesList(DefinesList *list); |
void InsertDefine(DefinesList *list, char *name); |
169,3 → 191,15
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); |
|
/*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); |
/trunk/src/sc2v_step2.y
1,6 → 1,6
/* ----------------------------------------------------------------------------- |
* |
* SystemC to Verilog Translator v0.1 |
* SystemC to Verilog Translator v0.2 |
* Provided by OpenSoc Design |
* |
* www.opensocdesign.com |
24,6 → 24,7
%{ |
#include <stdio.h> |
#include <string.h> |
#include <math.h> |
|
#include "list.h" |
|
46,7 → 47,16
/* Global var to store process list*/ |
ProcessList *processlist; |
|
/*List of enumerates*/ |
EnumeratesList *enumerateslist; |
EnumListList *enumlistlist; |
char *enumname; |
int reading_enumerates=0; |
|
/*Multiple Declarations*/ |
int multipledec; |
char *storedtype; |
|
/* Global var to store process module name*/ |
char *module_name; |
int module_name_found = 0; |
70,8 → 80,7
int sensibility_active = 0; |
|
|
|
|
int translate; |
|
void yyerror(const char *str) |
{ |
85,21 → 94,33
|
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)); |
|
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"); |
108,7 → 129,9
printf("\n"); |
RegOutputs(portlist); |
printf("\n"); |
|
|
ShowEnumListList(enumlistlist); |
|
ReadWritesFile(writeslist, (char *)"file_writes.sc2v"); |
|
ShowSignalsList(signalslist, writeslist); |
127,10 → 150,10
|
%} |
|
%token NUMBER SC_MODULE WORD OPENPAR CLOSEPAR SC_IN SC_OUT SEMICOLON BOOL |
%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 SC_CTOR VOID ASTERISCO |
%token SC_CTOR VOID ASTERISCO TRANSLATEON TRANSLATEOFF |
|
%% |
|
166,6 → 189,12
| |
sensible_word_semicolon |
| |
sensible_par_colon |
| |
sensible_par_pos |
| |
sensible_par_neg |
| |
closekey |
| |
word_semicolon |
172,6 → 201,10
| |
word_colon |
| |
word_closekey |
| |
word_closekey_word |
| |
signal_bool |
| |
signal_uint |
189,11 → 222,28
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"); |
206,88 → 256,101
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"; |
} |
; |
}; |
|
signal_bool: |
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; |
} |
; |
}; |
|
signal_int: |
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"; |
} |
; |
}; |
|
out_sc_uint: |
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_method: |
SC_METHOD OPENPAR WORD CLOSEPAR SEMICOLON |
{ |
if(translate==1){ |
if(method_found) |
{ |
InsertProcess(processlist, active_method, sensibilitylist, active_method_type); |
298,44 → 361,78
sensibilitylist = (SensibilityList *)malloc(sizeof(SensibilityList)); |
InitializeSensibilityList(sensibilitylist); |
} |
; |
}; |
|
sensible_par_neg: |
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) |
{ |
342,21 → 439,24
sensibility_active = 0; |
} |
} |
; |
}; |
|
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); |
366,13 → 466,32
{ |
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); |
} |
} |
} |
; |
}; |
|
word_colon: |
WORD COLON |
{ |
if(translate==1){ |
if(activeport) |
{ |
InsertPort(portlist, (char *)$1, lastportkind, lastportsize); |
381,19 → 500,73
{ |
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 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 |
free(enumname); |
reading_enumerates=0; |
} |
} |
}; |
|
|
instantation: |
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"); |
424,31 → 597,157
InsertBind(aux->bindslist, (char *)$3, (char *)$5); |
} |
} |
; |
}; |
|
sc_ctor: |
SC_CTOR OPENPAR WORD CLOSEPAR OPENKEY |
{ |
|
}; |
|
} |
; |
|
void: |
VOID WORD OPENPAR CLOSEPAR SEMICOLON |
{ |
|
} |
; |
}; |
|
inst_decl: |
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; |
} |
}; |
|
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; |
} |
}; |
|
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); |
} |
} |
}; |
|
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); |
} |
} |
}; |
|
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); |
} |
} |
}; |
|
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); |
} |
} |
}; |
|
translateoff: |
TRANSLATEOFF |
{ |
translate=0; |
fprintf(stderr,"Found Translate off directive \n"); |
}; |
|
translateon: |
TRANSLATEON |
{ |
translate=1; |
fprintf(stderr,"Found Translate on directive \n"); |
}; |
/trunk/src/sc2v_step3.y
0,0 → 1,133
/* ----------------------------------------------------------------------------- |
* |
* SystemC to Verilog Translator v0.2 |
* Provided by OpenSoc Design |
* |
* www.opensocdesign.com |
* |
* ----------------------------------------------------------------------------- |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU Library General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
*/ |
|
|
%{ |
#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 yywrap() |
{ |
return 1; |
} |
|
main() |
{ |
concat_par_num = (int *)malloc(16*sizeof(int)); |
*concat_par_num = 0; |
yyparse(); |
|
} |
|
%} |
|
%token WORD |
%token OPENPAR CLOSEPAR |
%token MODULE |
|
%% |
|
commands: /* empty */ |
| commands command |
; |
|
|
command: |
module |
| |
closepar |
| |
concat |
| |
openpar |
; |
|
module: |
MODULE |
{ |
module_found = 1; |
opened_pars++; |
printf("%s",(char *)$1); |
}; |
openpar: |
OPENPAR |
{ |
printf("("); |
opened_pars++; |
}; |
|
closepar: |
CLOSEPAR |
{ |
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(")"); |
} |
}; |
|
concat: |
WORD |
{ |
aux = (char *)$1; |
aux++; |
printf("{%s",aux); |
concat_found = 1; |
opened_pars++; |
concats_found++; |
*(concat_par_num + concats_found) = opened_pars; |
}; |
/trunk/src/sc2v_step1.l
1,6 → 1,6
/* ----------------------------------------------------------------------------- |
* |
* SystemC to Verilog Translator v0.1 |
* SystemC to Verilog Translator v0.2 |
* Provided by OpenSoc Design |
* |
* www.opensocdesign.com |
31,16 → 31,16
%} |
|
%% |
"void" return VOID; |
[0-9]+ yylval=atoi(yytext); return NUMBER; |
void /* Ignore void */ |
"::" return DOSPUNTOSDOBLE; |
"::" return TWODOUBLEPOINTS; |
sc_int return SC_INT; |
sc_uint return SC_UINT; |
sc_bigint return SC_BIGINT; |
sc_biguint return SC_BIGUINT; |
bool return BOOL; |
">" return MAYOR; |
"<" return MENOR; |
">" return BIGGER; |
"<" return LOWER; |
"{" return OPENKEY; |
"}" return CLOSEKEY; |
"(" return OPENPAR; |
54,20 → 54,30
"break" return BREAK; |
".read" return READ; |
".range" return RANGE; |
"#define" return DEFINE; |
"#include" /* Ignore #include */ |
[a-zA-Z][_a-zA-Z0-9]* yylval=(int)strdup(yytext); return WORD; |
[.:"^"!%()=/+*_"&""?""|""\\"] yylval=(int)strdup(yytext); return SYMBOL; |
"-" yylval=(int)strdup(yytext); return SYMBOL; |
"~" yylval=(int)strdup(yytext); return SYMBOL; |
"@" yylval=(int)strdup(yytext); return SYMBOL; |
"#" yylval=(int)strdup(yytext); return SYMBOL; |
"," return COLON; |
";" return SEMICOLON; |
[" "]+ /* Ignore white spaces*/ |
"\t" /* Ignore TAB; */ |
[" "]+ /*Ignore white spaces*/ |
"\t" return TAB; /*Ignore Tab*/ |
"\n" return NEWLINE; |
"0x" return HEXA; |
"$" /* Ignore $ */ |
"(int)" /* Ignore int type conversions*/ |
"$" return DOLLAR; /* Ignore $ */ |
"(int)" return INTCONV; /* Ignore int type conversions*/ |
|
"#define" return DEFINE; |
"#include" |
"#ifdef" return PIFDEF; |
"#else" return PELSE; |
"#endif" return PENDDEF; |
|
|
"//"[ ]*[tT][rR][aA][nN][sS][lL][aA][tT][eE][ ]*[oO][fF][fF] return TRANSLATEOFF; /*Translate directive*/ |
"//"[ ]*[tT][rR][aA][nN][sS][lL][aA][tT][eE][ ]*[oO][nN] return TRANSLATEON; /*Translate directive*/ |
"/*"[ ]*[vV][eE][rR][iI][lL][oO][gG][ ]*[bB][eE][gG][iI][nN] return VERILOGBEGIN; |
[vV][eE][rR][iI][lL][oO][gG][ ]*[eE][nN][dD]"*/" return VERILOGEND; |
|
%% |
/trunk/src/sc2v_step2.l
1,6 → 1,6
/* ----------------------------------------------------------------------------- |
* |
* SystemC to Verilog Translator v0.1 |
* SystemC to Verilog Translator v0.2 |
* Provided by OpenSoc Design |
* |
* www.opensocdesign.com |
60,6 → 60,7
\( if(!includefound & !linecomment & !multilinecomment) return OPENPAR; |
\) if(!includefound & !linecomment & !multilinecomment) return CLOSEPAR; |
; if(!includefound & !linecomment & !multilinecomment) return SEMICOLON; |
"enum" if(!includefound & !linecomment & !multilinecomment) return ENUM; |
"," if(!includefound & !linecomment & !multilinecomment) return COLON; |
"{" if(!includefound & !linecomment & !multilinecomment) return OPENKEY; |
"}" if(!includefound & !linecomment & !multilinecomment) return CLOSEKEY; |
82,9 → 83,11
"*/" multilinecomment = 0; |
"/" /* ignore */ |
"-" |
"#" |
"#" |
"@" |
"|" |
"~" |
|
"//"[ ]*[tT][rR][aA][nN][sS][lL][aA][tT][eE][ ]*[oO][fF][fF] return TRANSLATEOFF; /*Translate directive*/ |
"//"[ ]*[tT][rR][aA][nN][sS][lL][aA][tT][eE][ ]*[oO][nN] return TRANSLATEON; /*Translate directive*/ |
%% |
/trunk/src/sc2v_step3.l
0,0 → 1,42
/* ----------------------------------------------------------------------------- |
* |
* SystemC to Verilog Translator v0.2 |
* Provided by OpenSoc Design |
* |
* www.opensocdesign.com |
* |
* ----------------------------------------------------------------------------- |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU Library General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
*/ |
|
|
%{ |
#include <stdio.h> |
#include "y.tab.h" |
|
extern int yylval; |
|
%} |
|
%% |
"module"[" "]*[a-zA-Z][_a-zA-Z0-9]*[" "]*["("] yylval=(int)strdup(yytext); return MODULE; |
"("[" "]*[a-zA-Z][_a-zA-Z0-9" "\[\]:]*[,] yylval=(int)strdup(yytext); return WORD; |
"(" return OPENPAR; |
")" return CLOSEPAR; |
|
|
|
|
%% |
/trunk/src/list.c
23,6 → 23,7
|
#include <stdlib.h> |
#include <stdio.h> |
#include <math.h> |
|
#include "list.h" |
|
317,9 → 318,9
while(1) |
{ |
printf("%s ",aux->tipo); |
if(aux->size != 0) |
if(aux->size != 0 && aux->size !=1) |
{ |
printf("[%d:0] ",(-1 + aux->size)); |
printf("[%d:0] ",(-1 + aux->size)); |
} |
printf("%s;\n",aux->name); |
if(aux->next==NULL) |
341,9 → 342,9
if(strcmp(aux->tipo, (char *)"output")==0) |
{ |
printf("reg "); |
if(aux->size != 0) |
if(aux->size != 0 && aux->size!=1) |
{ |
printf("[%d:0] ",(-1 + aux->size)); |
printf("[%d:0] ",(-1 + aux->size)); |
} |
printf("%s;\n",aux->name); |
} |
416,9 → 417,9
if(IsWrite(WritesList, aux->name)) |
{ |
printf("reg "); |
if(aux->size != 0) |
if(aux->size != 0 && aux->size!=1) |
{ |
printf("[%d:0] ",(-1 + aux->size)); |
printf("[%d:0] ",(-1 + aux->size)); |
} |
printf("%s;\n",aux->name); |
} |
425,9 → 426,9
else |
{ |
printf("wire "); |
if(aux->size != 0) |
if(aux->size != 0 && aux->size!=1) |
{ |
printf("[%d:0] ",(-1 + aux->size)); |
printf("[%d:0] ",(-1 + aux->size)); |
} |
printf("%s;\n",aux->name); |
} |
519,15 → 520,16
SensibilityNode *aux = list->first; |
while(1) |
{ |
printf("%s ",aux->tipo); |
if(!strcmp(aux->tipo,"posedge") || !strcmp(aux->tipo, "negedge")) |
printf(" %s",aux->tipo); |
if(aux->next==NULL) |
{ |
printf("%s",aux->name); |
printf(" %s",aux->name); |
break; |
} |
else |
{ |
printf("%s or ",aux->name); |
printf(" %s or",aux->name); |
} |
aux = aux->next; |
} |
594,6 → 596,7
int readok; |
char *filename; |
char auxchar; |
char begin[10]; |
|
while(1) |
{ |
616,11 → 619,22
|
printf("always @("); |
ShowSensibilityList(aux->list); |
printf(")\n"); |
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); |
742,3 → 756,189
} |
} |
} |
|
//Enumerates list |
void InitializeEnumeratesList(EnumeratesList *list) |
{ |
EnumeratesNode *first; |
first = (EnumeratesNode *)malloc(sizeof(EnumeratesNode)); |
list->first = first; |
list->last = NULL; |
} |
|
void InsertEnumerates(EnumeratesList *list, char *name) |
{ |
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; |
} |
} |
|
int ShowEnumeratesList(EnumeratesList *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); |
} |
} |
} |
|
//List of enumerates list |
void InitializeEnumListList(EnumListList *list) |
{ |
EnumListNode *first; |
first = (EnumListNode *)malloc(sizeof(EnumListNode)); |
list->first = first; |
list->last = NULL; |
} |
|
void InsertEnumList(EnumListList *list, EnumeratesList *enumlist, char *name, int istype) |
{ |
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 ShowEnumListList(EnumListList *list) |
{ |
int items; |
|
if(list->last != NULL) |
{ |
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; |
} |
} |
} |
|
int findEnumList(EnumListList *list, char *name) |
{ |
int i=0; |
if(list->last != NULL) |
{ |
EnumListNode *aux = list->first; |
|
while(1) |
{ |
//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++; |
} |
} |
} |
|
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/src/Makefile
27,10 → 27,13
|
$(LEX) sc2v_step2.l |
$(YACC) -d sc2v_step2.y |
gcc lex.yy.c y.tab.c list.c -Isrc -o ../bin/sc2v_step2 |
gcc lex.yy.c y.tab.c list.c -Isrc -o ../bin/sc2v_step2 -lm |
$(LEX) sc2v_step1.l |
$(YACC) -d sc2v_step1.y |
gcc lex.yy.c y.tab.c list.c -Isrc -o ../bin/sc2v_step1 |
gcc lex.yy.c y.tab.c list.c -Isrc -o ../bin/sc2v_step1 -lm |
$(LEX) sc2v_step3.l |
$(YACC) -d sc2v_step3.y |
gcc lex.yy.c y.tab.c list.c -Isrc -o ../bin/sc2v_step3 -lm |
|
clean: |
|
/trunk/bin/sc2v.sh
6,5 → 6,6
# usage: sc2v <filename_without_extension> |
# |
../bin/sc2v_step1 < $1.cpp |
../bin/sc2v_step2 < $1.h > $1.v |
../bin/sc2v_step2 < $1.h > $1.sc2v |
../bin/sc2v_step3 < $1.sc2v > $1.v |
\rm *.sc2v |
/trunk/Makefile
18,7 → 18,7
|
test: |
cd src; make all |
cd examples; ../bin/sc2v.sh rng; ../bin/sc2v.sh md5; echo ""; echo "sc2v translated the following files successfully"; echo ""; ls -l *.v |
cd examples; ../bin/sc2v.sh rng; ../bin/sc2v.sh md5; ../bin/sc2v.sh fsm; echo ""; echo "sc2v translated the following files successfully"; echo ""; ls -l *.v |
|
docs: |
cd src; doxygen doxygen.cfg |
/trunk/README
33,7 → 33,7
installed before trying to compile sc2v. |
|
For compiling the sources just type "make" under the directory you unzipped the |
fonts. It will generate two executables: sc2v_step1 and sc2v_step2. |
fonts. It will generate three executables: sc2v_step1 and sc2v_step2 sc2v_step3. |
|
|
2- Translating an SystemC module: |
59,16 → 59,10
-Only data types: bool, sc_int, sc_bigint, sc_uint and sc_biguint are |
supported. |
|
-No enumerated types supported. |
|
-No global variables supported. |
|
4- Known bugs |
|
-Concatenation is not yet supported. If you use concatenations like: |
(var1, var2), in the verilog file will appear identically, so you must |
replace the "(" and ")" by "{" and "}" manually. |
|
-The usage of macros and defines may cause some errors. |
|
-Using comments in switch case structures may cause errors. Specially |
/trunk/examples/md5.cpp
11,7 → 11,7
//// - done //// |
//// //// |
//// Author(s): //// |
//// - Javier Castillo, jcastilo@opencores.org //// |
//// - Javier Castillo, jcastillo@opencores.org //// |
//// //// |
////////////////////////////////////////////////////////////////////// |
//// //// |
43,6 → 43,9
// CVS Revision History |
// |
// $Log: not supported by cvs2svn $ |
// Revision 1.1.1.1 2004/10/08 14:04:10 jcastillo |
// First import |
// |
// Revision 1.1.1.1 2004/09/08 16:24:49 jcastillo |
// Initial release |
// |
/trunk/examples/fsm.cpp
0,0 → 1,45
#include "systemc.h" |
|
void fsm::regs(){ |
if(rst.read()){ |
state.write(S0); |
}else |
state.write(next_state); |
} |
|
void fsm::fsm_proc(){ |
/*Verilog begin |
cfsm_proc={a[1:0],b[1:0]}; |
verilog end*/ |
|
sc_uint<2> c; |
next_state.write(state.read()); |
a.write(0); |
b.write(0); |
|
#ifdef CONCAT |
c.write((a.range(1,0),b.range(1,0))); |
#else |
c.write((a,a)); |
#endif |
|
switch((int)state.read()){ |
case S0 : |
if(input1.read()){ |
next_state.write(S1); |
a.write(1); |
} |
break; |
// tRaNsLaTe oFF |
case S1: |
if(input2.read()){ |
next_state.write(S2); |
b.write(1); |
} |
break; |
// tRaNsLaTe oN |
case S2: |
next_state.write(S0); |
break; |
} |
} |
/trunk/examples/md5.h
43,6 → 43,9
// CVS Revision History |
// |
// $Log: not supported by cvs2svn $ |
// Revision 1.1.1.1 2004/10/08 14:04:10 jcastillo |
// First import |
// |
// Revision 1.1.1.1 2004/09/08 16:24:49 jcastillo |
// Initial release |
// |
91,13 → 94,13
void round64FSM (); |
void md5_rom (); |
void funcs (); |
|
|
SC_CTOR (md5) |
{ |
|
SC_METHOD (reg_signal); |
sensitive_pos << clk; |
sensitive_neg << reset; |
sensitive_pos (clk); |
sensitive_neg (reset); |
|
SC_METHOD (md5_getdata); |
sensitive << newtext_i << data_i << load_i << getdata_state << |
/trunk/examples/fsm.h
0,0 → 1,35
/* This is a example code with the new constructions supported |
by sc2v 0.2 */ |
|
|
#include "systemc.h" |
|
SC_MODULE(fsm){ |
|
sc_in<bool> clk; |
sc_in<bool> rst,input1, input2; |
sc_out< sc_uint<2> > a,b; |
|
enum state_t {S0,S1,S2}; |
sc_signal<state_t> state,next_state; |
|
//translate off |
sc_signal<sc_uint<4> > temp; |
//translate on |
|
void regs(); |
void fsm_proc(); |
|
SC_CTOR(fsm){ |
|
SC_METHOD(regs); |
sensitive_pos(clk); |
sensitive_neg(rst); |
|
SC_METHOD(fsm_proc); |
sensitive(state); |
sensitive << input1; |
sensitive(input2); |
|
} |
}; |