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
|
int main ()
{
vector<string> node(11);
Graph G(11, node);
int** edge = new int*[12];
ifstream fin("bench/c17.bench");
string line , word, token , gate , parents, child;
vector<string> PIs, POs, GATEs, FANINs;
int nodes =0; int edges =0; int pi=0, po=0;
int node_counter = 0;
map <vector<string>, string> cells;
while (getline(fin, line))
{
int child_indx = 0, parent_indx = 0;
//-----------------------------------------------------------
if (line.find("INPUT") != string::npos)
{
string Pin = line.substr(line.find("(") + 1, line.find(")") - line.find("(") - 1);
PIs.push_back(Pin);
//---------------------------------------------------
if (verify(Pin, node, node_counter) == -1)
{
node[node_counter] = Pin;
G.nodes[node_counter] = node[node_counter];
node_counter++;
}
//---------------------------------------------------
}
if (line.find("OUTPUT") != string::npos)
{
string Pout = line.substr(line.find("(") + 1, line.find(")") - line.find("(") - 1);
POs.push_back(Pout);
//---------------------------------------------------
if (verify(Pout, node, node_counter) == -1)
{
node[node_counter] = Pout;
G.nodes[node_counter] = node[node_counter];
node_counter++;
}
//---------------------------------------------------
}
if (line.find("=") != string::npos)
{
cout << edges++ << endl;
child = line.substr(0, line.find("=") - 1);
child.erase(remove_if(child.begin(), child.end(), isspace), child.end());
//---------------------------------------------------
if (verify(child, node, node_counter) == -1)
{
node[node_counter] = child;
G.nodes[node_counter] = node[node_counter];
node_counter++;
}
//---------------------------------------------------
gate = line.substr(line.find("=") + 1, line.find("(") - line.find("=") - 1);
//---------------------------------------------------
string Ginputs = line.substr(line.find("(") + 1, line.find(")") - line.find("(") - 1); // gate inputs
//---------------------------------------------------
int inputs = (int)(count(begin(Ginputs), end(Ginputs), ',' ) + 1);
vector<string> parent(inputs);
//--------------------------------------------------
child_indx = verify(child, node, node_counter);
edge[child_indx] = new int[inputs];
//---------------------------------------------------
if (inputs == 1)
{
parent[0] = Ginputs;
parent[0].erase(remove_if(parent[0].begin(), parent[0].end(), isspace), parent[0].end());
cells.insert(make_pair(parent, child));
//-------------------------------------------
for (int i = 0; i < parent.size(); i++)
{
if (verify(parent[i], node, node_counter) == -1)
{
node[node_counter] = parent[i];
G.nodes[node_counter] = node[node_counter];
node_counter++;
}
inputs--;
edge[child_indx][inputs] = verify(parent[i], node, node_counter + 1);
G.Add_Edge(edge[child_indx][inputs], child_indx, 1.5);
}
//-------------------------------------------
}
if (inputs == 2)
{
parent[0] = Ginputs.substr(0, Ginputs.find(","));
parent[0].erase(remove_if(parent[0].begin(), parent[0].end(), isspace), parent[0].end());
Ginputs = Ginputs.substr(Ginputs.find(",") + 2, Ginputs.length());
parent[1] = Ginputs.substr(0, Ginputs.length());
parent[1].erase(remove_if(parent[1].begin(), parent[1].end(), isspace), parent[1].end());
cells.insert(make_pair(parent, child));
//-------------------------------------------
for (int i = 0; i < parent.size(); i++) {
if (verify(parent[i], node, node_counter) == -1)
{
node[node_counter] = parent[i];
G.nodes[node_counter] = node[node_counter];
node_counter++;
}
inputs--;
edge[child_indx][inputs] = verify(parent[i], node, node_counter + 1);
G.Add_Edge(edge[child_indx][inputs], child_indx, 1.5);
}
//-------------------------------------------
}
}
}
G.Draw_Graph();
char z;
cin >> z;
return 0;
}
//--------------------------------------------------------------------
int verify(string node_name, vector<string> arr, int num)
{
for (int i = 0; i < num; i++)
{
if (arr[i] == node_name)
return i;
}
return -1;
}
//--------------------------------------------------------------------
|