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

Subversion Repositories mips789

[/] [mips789/] [branches/] [avendor/] [CTool/] [gensim.c] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 mcupro
 
2
#include "stdio.h"
3
#include "stdlib.h"
4
 
5
 
6
 
7
/*the two functions listed between are added by Liwei 2007-8-29*/
8
 char HEX[]="0123456789ABCDEF" ;
9
 char hex[]="0123456789abcdef" ;
10
 
11
unsigned char hex2byte( char hex_char)
12
{
13
    unsigned char i ;
14
    for(i=0;i<16;++i)if(HEX[i]==hex_char)return i ;
15
    for(i=0;i<16;++i)if(hex[i]==hex_char)return i ;
16
    return 0 ;
17
}
18
unsigned int par2u32(char*par)
19
{
20
    unsigned int i,ret=0 ;
21
    if(par==NULL)return ;
22
    if((0==strncmp(par,"0x",2))||(0==strncmp(par,"0X",2)))
23
    for(i=2;;++i)    {if(par[i]=='\0')return ret ; ret=ret*16+hex2byte(par[i]);}
24
    else
25
    for(i=0;;++i)    {if(par[i]=='\0')return ret ; ret=ret*10+hex2byte(par[i]);}
26
    return 0 ;
27
}
28
 
29
main(int argc,char*argv[])
30
{
31
    int j=4,i=0,ii=0 ;
32
    int cntr=0,base=0 ;
33
 
34
    char str1[100],str2[111];
35
    /*
36
        FILE*ff=fopen(file_name[1],"r");
37
        FILE*ft=fopen(file_name[2],"w");
38
        */
39
    FILE*ff=fopen("code.txt","r");
40
    FILE*ft=fopen("sim_ram.v","w");
41
 
42
    if(NULL!=argv[1])
43
    base=par2u32(argv[1])/4;
44
    for(j=0;j<4;++j)
45
    {
46
        cntr=-10 ;
47
        fprintf(ft,"module sim_syn_ram%d(\n",j);
48
        fprintf(ft,"        data,\n");
49
        fprintf(ft,"        wraddress,\n");
50
        fprintf(ft,"        rdaddress_a,\n");
51
        fprintf(ft,"        rdaddress_b,\n");
52
        fprintf(ft,"        wren,\n");
53
        fprintf(ft,"        clock,\n");
54
        fprintf(ft,"        qa,\n");
55
        fprintf(ft,"        qb);\n\n");
56
        fprintf(ft,"    input   [7:0]  data;\n");
57
        fprintf(ft,"    input   [10:0]  wraddress;\n");
58
        fprintf(ft,"    input   [10:0]  rdaddress_a;\n");
59
        fprintf(ft,"    input   [10:0]  rdaddress_b;\n");
60
        fprintf(ft,"    input     wren;\n");
61
        fprintf(ft,"    reg [7:0]  r_data;\n");
62
        fprintf(ft,"    reg [10:0]  r_wraddress;\n");
63
        fprintf(ft,"    reg [10:0]  r_rdaddress_a;\n");
64
        fprintf(ft,"    reg [10:0]  r_rdaddress_b;\n");
65
        fprintf(ft,"    reg   r_wren;\n");
66
        fprintf(ft,"    input     clock;\n");
67
        fprintf(ft,"    output  [7:0]  qa;\n");
68
        fprintf(ft,"    output  [7:0]  qb;\n");
69
        fprintf(ft,"    reg [7:0] mem_bank  [0:2047]  ;\n");
70
        if(base!=0)
71
        fprintf(ft,"    integer i;\n    initial begin\n        for(i=0;i<%d;i=1+i)\n         mem_bank[i] = 'h00;\n       ",base);
72
        else
73
        fprintf(ft,"    initial begin   \n       ");
74
 
75
        rewind(ff);
76
        cntr=-10 ;
77
        i=-1 ;
78
 
79
        while(fgets(str2,100,ff))
80
        {
81
            ++i ;
82
            if(3==j)
83
            {
84
                str2[2]=0 ;
85
                fprintf(ft,"mem_bank[%d] = 'h%s ; ",base+i,&str2[0]);
86
                ++cntr ;
87
                if(!(cntr%10))
88
                {
89
                    cntr=0 ;
90
                    fprintf(ft,"\n       ");
91
                }
92
            }
93
            else
94
            if(2==j)
95
            {
96
                str2[4]=0 ;
97
 
98
                fprintf(ft,"mem_bank[%d] = 'h%s ; ",base+i,&str2[2]);
99
 
100
                ++cntr ;
101
                if(!(cntr%10))
102
                {
103
                    cntr=0 ;
104
                    fprintf(ft,"\n       ");
105
                }
106
            }
107
            else
108
            if(1==j)
109
            {
110
                str2[6]=0 ;
111
                fprintf(ft,"mem_bank[%d] = 'h%s ; ",base+i,&str2[4]);
112
 
113
                ++cntr ;
114
                if(!(cntr%10))
115
                {
116
                    cntr=0 ;
117
                    fprintf(ft,"\n       ");
118
                }
119
            }
120
            else
121
            if(0==j)
122
            {
123
                str2[8]=0 ;
124
                fprintf(ft,"mem_bank[%d] = 'h%s ; ",base+i,&str2[6]);
125
 
126
                ++cntr ;
127
                if(!(cntr%10))
128
                {
129
                    cntr=0 ;
130
                    fprintf(ft,"\n       ");
131
                }
132
            }
133
        }
134
        fprintf(ft,"    \n       end\n");
135
        fprintf(ft,"    always @ (posedge clock) if (r_wren) mem_bank[r_wraddress]<=r_data;\n");
136
        fprintf(ft,"    always @ (posedge clock)\n");
137
        fprintf(ft,"    begin\n");
138
        fprintf(ft,"        r_data<=data;\n");
139
        fprintf(ft,"        r_wraddress<=wraddress;\n");
140
        fprintf(ft,"        r_rdaddress_a<=rdaddress_a;\n");
141
        fprintf(ft,"        r_rdaddress_b<=rdaddress_b;\n");
142
        fprintf(ft,"        r_wren<=wren;\n");
143
        fprintf(ft,"    end\n");
144
        fprintf(ft,"    assign qa =mem_bank[r_rdaddress_a];\n");
145
        fprintf(ft,"    assign qb =mem_bank[r_rdaddress_b];\n");
146
        fprintf(ft,"endmodule\n\n\n\n");
147
    }
148
}

powered by: WebSVN 2.1.0

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