-
Notifications
You must be signed in to change notification settings - Fork 0
/
rewire_c.cpp
106 lines (83 loc) · 2.59 KB
/
rewire_c.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
#include "array.h"
#include "rewire.h"
#undef array_fetch
#undef foreach_fanin
#undef foreach_fanout
#undef foreach_node
#include "sis_header/sis.h"
#include "sis_interface.h"
#include "rewire_c.h"
BNetwork *sisnet2BNetwork(network_t *net);
static network_t *currentNetwork = NULL;
static BNetwork *currentBNetwork = NULL;
static IGNetwork *currentIGNetwork = NULL;
extern "C" int rewire_find_aw(node_t *twsrc, node_t *twdst, int rlevel, array_t *aw) {
Array<RewireAW> awArray;
int ret;
int i;
BNode *src, *dst;
BNode *currentInternal, *nextInternal;
BNode *fanin;
BNode *dstFound;
rewire_aw_t aw_found;
src = currentBNetwork->findNode(twsrc->name);
dst = currentBNetwork->findNode(twdst->name);
currentInternal = dst;
nextInternal = NULL;
dstFound = NULL;
//trace("starting %s->%s\n", twsrc->name, twdst->name);
while (!dstFound) {
// check each fanin to see if src connect to it
// else go to next internal node
for (i = 0; i < currentInternal->in.size && ((fanin = currentInternal->in.space[i]) != NULL); i++) {
if (fanin == src){
dstFound = currentInternal;
}
//if (fanin->p.linkedNode != NULL) {
// cout << fanin->p.linkedNode->name->c_str() << endl;
//}
//cout << fanin->name->c_str() << endl;
if (fanin->p.linkedNode == dst) {
nextInternal = fanin;
}
}
if ((!dstFound && nextInternal == currentInternal) || currentInternal == NULL) {
trace("failed to find interal node for %s->%s\n", twsrc->name, twdst->name);
return REDUNDANT;
}
currentInternal = nextInternal;
}
ret = rewireFindAW(src, dstFound, rlevel, awArray);
for (i = 0; i < awArray.size; i++) {
aw_found.src = network_find_node(currentNetwork, (char *) awArray.space[i].src->name->c_str());
aw_found.dst = network_find_node(currentNetwork, (char *) awArray.space[i].dst->name->c_str());
aw_found.polarity = awArray.space[i].polarity;
aw_found.dst_function = awArray.space[i].dstFunction == BNODE_AND ? NODE_AND : NODE_OR;
array_insert_last(rewire_aw_t, aw, aw_found);
}
return ret;
}
extern "C" void rewire_network_change(network_t *network) {
if (currentIGNetwork != NULL) {
delete currentIGNetwork;
}
if (currentBNetwork != NULL) {
delete currentBNetwork;
}
currentNetwork = network;
currentBNetwork = sisnet2BNetwork(network);
currentBNetwork->assignDominator();
currentIGNetwork = new IGNetwork(currentBNetwork);
}
extern "C" void rewire_end() {
if (currentIGNetwork != NULL) {
delete currentIGNetwork;
}
if (currentBNetwork != NULL) {
delete currentBNetwork;
}
currentNetwork = NULL;
currentIGNetwork = NULL;
currentBNetwork = NULL;
rewireEndImply();
}