atpg-ls/main.cpp

52 lines
1.4 KiB
C++
Raw Normal View History

#include <cstdio>
#include <cstdlib>
2023-02-12 16:22:32 +08:00
#include <assert.h>
#include "circuit.h"
int main(int args, char* argv[]) {
if(args != 2) {
printf("usage: ./atpg <XXX.bench>\n");
exit(1);
}
2023-02-16 18:51:31 +08:00
srand(19260817);
2023-02-20 13:08:25 +08:00
Circuit* circuit = new Circuit();
2023-02-16 18:51:31 +08:00
printf("parsing file %s ...", argv[1]);
2023-02-20 13:08:25 +08:00
circuit->parse_from_file(argv[1]);
circuit->init_stems();
circuit->init_topo_index();
2023-02-16 18:51:31 +08:00
printf(" Done.\n");
printf("====== Circuit Statistics ====== \n");
2023-02-20 13:08:25 +08:00
printf("PI:\t%ld\n", circuit->PIs.size());
printf("PO:\t%ld\n", circuit->POs.size());
printf("Gate:\t%ld\n", circuit->name2gate.size());
printf("Stem:\t%ld\n", circuit->stems.size());
2023-02-16 18:51:31 +08:00
printf("================================ \n");
2023-02-12 16:22:32 +08:00
2023-02-23 11:00:24 +08:00
std::unordered_set<Fault*> faults;
2023-02-12 18:14:12 +08:00
2023-02-16 18:51:31 +08:00
// init faults
2023-02-23 11:00:24 +08:00
for(auto g : circuit->gates) {
faults.insert(new Fault(g, Fault::SA0));
faults.insert(new Fault(g, Fault::SA1));
2023-02-12 16:22:32 +08:00
}
2023-02-23 11:00:24 +08:00
while(true) {
bool ls = circuit->local_search(faults);
2023-02-26 03:47:26 +00:00
bool is_valid = circuit->is_valid_circuit();
2023-02-23 11:00:24 +08:00
printf("checking valid circuit ...");
2023-02-26 03:47:26 +00:00
printf(" result: %d.\n", is_valid);
2023-02-23 11:00:24 +08:00
if(!ls) break;
2023-02-26 03:47:26 +00:00
if(!is_valid) break;
2023-02-23 11:00:24 +08:00
if(faults.size() == 0) break;
}
2023-02-19 19:42:50 +08:00
2023-02-23 11:00:24 +08:00
//printf("[final] flip: %d, stem: %d, fault:%d\n", circuit->flip_total_weight, circuit->stem_total_weight, circuit->fault_total_weight);
2023-02-21 19:07:40 +08:00
return 0;
}