/
STprint.cpp
183 lines (153 loc) · 4.87 KB
/
STprint.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <iostream>
#include <fstream>
#include <math.h>
#include <vector>
#include <string>
//#include <cstdio>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;
enum port {N,E,S,W,L,D};
// N E S W L D
// 0 1 2 3 4 5
class STslot{
public:
port ports[5];
int x_dest;
int y_dest;
int x_src;
int y_src;
STslot(){
for(int i = 0; i < 5; i++){
ports[i] = D;
}
x_dest = 0;
y_dest = 0;
x_src = 0;
y_src = 0;
}
};
class STprint{
ofstream niST;
ofstream routerST;
char niST_name[20];
char routerST_name[20];
const int numOfNodes;
string bin(int val, int bits) {
int max = (int)pow(2.0,bits-1);
string s = "";
for(int i = 0; i < bits; i++){
if(val/max >= 1){
val -= max;
s += "1";
} else {
s += "0";
}
max = max / 2;
}
return s;
}
public:
STprint(int _numOfNodes): numOfNodes(_numOfNodes){
sprintf(niST_name,"ni_ST_%i.vhd",numOfNodes);
sprintf(routerST_name,"router_ST_%i.vhd",numOfNodes);
niST.open(niST_name, ios::trunc);
routerST.open(routerST_name, ios::trunc);
}
~STprint(){
niST.close();
routerST.close();
}
char p2c(port p){
char c;
if (p == N) c = 'N';
if (p == E) c = 'E';
if (p == S) c = 'S';
if (p == W) c = 'W';
if (p == L) c = 'L';
if (p == D) c = 'D';
return c;
}
void writeHeaderRouter(int countWidth){
routerST << "-------------------------------------------------------------\n";
routerST << "-- " << routerST_name << "\n";
routerST << "-- This is an auto generated file, do not edit by hand.\n";
routerST << "-------------------------------------------------------------\n";
routerST << "library ieee;\n";
routerST << "use ieee.std_logic_1164.all;\n";
routerST << "use ieee.numeric_std.all;\n\n";
routerST << "use work.noc_types.all;\n\n";
routerST << "entity router_ST_" << numOfNodes << " is\n";
routerST << "\tgeneric (\n";
routerST << "\t\tNI_NUM\t: natural\n";
routerST << "\t\t);\n";
routerST << "\tport (\n";
routerST << "\t\tcount\t: in unsigned(" << countWidth-1 << " downto 0);\n";
routerST << "\t\tsels\t: out select_signals\n";
routerST << "\t\t);\n";
routerST << "end router_ST_" << numOfNodes << ";\n\n";
routerST << "architecture data of router_ST_" << numOfNodes << " is\n";
routerST << "begin -- data\n\n";
routerST << "process(count) begin\n\n";
routerST << "\tcase count is\n\n";
}
void endArchRouter(){
routerST << "\t\twhen others => sels <= (others => D);\n\n";
routerST << "\tend case;\n";
routerST << "end process;\n\n";
routerST << "end data;\n";
}
void writeSlotRouter(int slotNum, int countWidth, port* ports){
routerST << "\t\twhen \"" << bin(slotNum,countWidth) << "\" =>\n";
routerST << "\t\t\tsels(N) <= " << p2c(ports[N]) << ";\n";
routerST << "\t\t\tsels(E) <= " << p2c(ports[E]) << ";\n";
routerST << "\t\t\tsels(S) <= " << p2c(ports[S]) << ";\n";
routerST << "\t\t\tsels(W) <= " << p2c(ports[W]) << ";\n";
routerST << "\t\t\tsels(L) <= " << p2c(ports[L]) << ";\n";
}
void writeHeaderNI(int countWidth, int numOfNodes){
niST << "-------------------------------------------------------------\n";
niST << "-- " << niST_name << "\n";
niST << "-- This is an auto generated file, do not edit by hand.\n";
niST << "-------------------------------------------------------------\n";
niST << "library ieee;\n";
niST << "use ieee.std_logic_1164.all;\n";
niST << "use ieee.numeric_std.all;\n\n";
niST << "use work.noc_types.all;\n\n";
niST << "entity ni_ST_" << numOfNodes << " is\n";
niST << "\tgeneric (\n";
niST << "\t\tNI_NUM\t: natural);\n";
niST << "\tport (\n";
niST << "\t\tcount\t: in unsigned(" << countWidth-1 << " downto 0);\n";
niST << "\t\tdest\t: out integer range 0 to " << numOfNodes-1 << ";\n";
niST << "\t\tsrc\t: out integer range 0 to " << numOfNodes-1 << "\n";
niST << "\t\t);\n";
niST << "end ni_ST_" << numOfNodes << ";\n\n";
niST << "architecture data of ni_ST_" << numOfNodes << " is\n";
niST << "begin -- data\n\n";
}
void startST(int num){
niST << "\tNI_NUM" << num << " : if NI_NUM = " << num << " generate\n";
niST << "\tprocess(count) begin\n\n";
niST << "\t\tcase count is\n\n";
}
void writeSlotNIDest(int slotNum, int countWidth, int dest){
niST << "\t\t\twhen \"" << bin(slotNum,countWidth) << "\" =>\n";
niST << "\t\t\t\tdest <= " << dest << ";\n";
}
void writeSlotNISrc(int src){
niST << "\t\t\t\tsrc <= " << src << ";\n";
}
void endST(int num){
niST << "\t\t\twhen others =>\n";
niST << "\t\t\t\tdest <= " << num << ";\n";
niST << "\t\t\t\tsrc <= " << num << ";\n\n";
niST << "\t\tend case;\n";
niST << "\tend process;\n\n";
niST << "\tend generate NI_NUM" << num << ";\n\n";
}
void endArchNI(){
niST << "end data;\n";
}
};