22
33#include < stack>
44#include < vector>
5+ #include " atpg_circuit.h"
56
67Circuit CurrentCircuit::circ;
78
@@ -60,6 +61,7 @@ void CurrentCircuit::topological_sort() {
6061 topological_sort_helper (circ.elements [i].elementName , visited, stack);
6162
6263 std::vector<std::pair<std::string, int >> top_list {};
64+ std::vector<CircuitElement> top_list_circ {};
6365
6466 while (stack.empty () == false ) {
6567 int vertex = stack.top ();
@@ -93,6 +95,7 @@ void CurrentCircuit::topological_sort() {
9395
9496 // if(element.isGate()) {
9597 top_list.push_back ({element.elementName , element.arrivalTime });
98+ top_list_circ.push_back (element);
9699 // }
97100 // printf("%s(d:%d)(a:%d)\n", element.elementName.c_str(), element.delay, element.arrivalTime);
98101 stack.pop ();
@@ -104,6 +107,45 @@ void CurrentCircuit::topological_sort() {
104107 }
105108 printf (" \n " );
106109
110+ ATPGCircuit atpg_circuit;
111+ for (auto & top_element : top_list) {
112+ CircuitElement element;
113+ for (auto & pair : adj) {
114+ if (pair.first .elementName == top_element.first ) {
115+ element = pair.first ;
116+ break ;
117+ }
118+ }
119+
120+ ATPGCircuitElement atpg_element;
121+ atpg_element.name = element.elementName ;
122+ // TODO: only NAND for testing
123+ if (element.isGate ()) {
124+ atpg_element.type = ATPGCircuitElementType::NAND;
125+ } else {
126+ atpg_element.type = ATPGCircuitElementType::WIRE;
127+ }
128+
129+ // find outputs
130+ for (auto & pair : adj) {
131+ if (pair.first .elementName == top_element.first ) {
132+ for (auto & output : pair.second ) {
133+ atpg_element.outputs .push_back (output.elementName );
134+ }
135+ }
136+ }
137+
138+ // find inputs
139+ for (auto & pair : adj) {
140+ for (auto & pair_second : pair.second ) {
141+ if (pair_second.elementName == top_element.first ) {
142+ atpg_element.inputs .push_back (pair.first .elementName );
143+ }
144+ }
145+ }
146+ atpg_circuit.elements .push_back (atpg_element);
147+ }
148+
107149 printf (" Critical path:\n " );
108150 int slowest_output_index = 0 ;
109151 for (int i = 0 , current_max = 0 ; i < top_list.size (); i++) {
@@ -113,7 +155,10 @@ void CurrentCircuit::topological_sort() {
113155 slowest_output_index = i;
114156 }
115157 }
158+ std::vector<std::string> crit_path_names;
159+ crit_path_names.push_back (top_list[slowest_output_index].first );
116160 printf (" %s[%d]\n " , top_list[slowest_output_index].first .c_str (), top_list[slowest_output_index].second );
161+ std::vector<CircuitElement> crit_path_list {};
117162 while (true ) {
118163 std::vector<CircuitElement> predecessor_elements;
119164 // get pred elements
@@ -156,9 +201,36 @@ void CurrentCircuit::topological_sort() {
156201 break ;
157202 }
158203 }
159- printf (" %s[%d] \n " , slowest_pred.elementName .c_str (), slowest_pred.arrivalTime );
204+ crit_path_list.push_back (slowest_pred);
205+ // printf("%s[%d] \n", slowest_pred.elementName.c_str(), slowest_pred.arrivalTime);
160206 slowest_output_index = found_index;
161207 }
162- // printf("DEBUG slowest output index %d\n", slowest_output_index);
208+ // print critical path
209+ for (auto & element : crit_path_list) {
210+ printf (" %s[%d] \n " , element.elementName .c_str (), element.arrivalTime );
211+ crit_path_names.push_back (element.elementName );
212+ }
163213 printf (" \n " );
214+
215+ // sensitize path
216+ for (auto & name : crit_path_names) {
217+ auto & element = atpg_circuit.get_element (name);
218+ if (element.type == ATPGCircuitElementType::WIRE) {
219+ element.value = ATPGValue::CRIT_PATH;
220+ } else {
221+ // assume NAND for now..
222+ for (auto & input : element.inputs ) {
223+ if (std::find (crit_path_names.begin (), crit_path_names.end (), input) != crit_path_names.end ()) {
224+ atpg_circuit.get_element (input).value = ATPGValue::CRIT_PATH;
225+ } else {
226+ atpg_circuit.get_element (input).value = ATPGValue::ONE;
227+ }
228+ }
229+ }
230+ }
231+ printf (" ************************\n " );
232+ for (auto & element : atpg_circuit.elements ) {
233+ printf (" %s[%d]\n " , element.name .c_str (), element.value );
234+ }
235+ printf (" ************************\n " );
164236}
0 commit comments