Commit a3bf3593 authored by Adam P. Goucher's avatar Adam P. Goucher

Depth order

parent 913e9407
Pipeline #56206487 passed with stages
in 7 minutes and 44 seconds
......@@ -54,20 +54,62 @@ struct zeropres {
};
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Usage: ./pres0 infile.aag" << std::endl;
return 1;
std::vector<zeropres> depth_sort(std::vector<zeropres> &orig) {
std::vector<uint32_t> depths(orig.size() + 1, orig.size() + 1);
depths[0] = 0;
int opts = 0;
int maxdepth = 0;
do {
opts = 0;
maxdepth = 0;
for (int i = 0; i < orig.size(); i++) {
uint32_t x = 0;
for (auto it = orig[i].inputs.begin(); it != orig[i].inputs.end(); ++it) {
uint32_t y = *it;
if (y > x) { x = y; }
}
x += 1;
if (x < depths[i+1]) {depths[i+1] = x; opts += 1; }
if (x > maxdepth) { maxdepth = x; }
}
} while (opts != 0);
std::vector<uint32_t> newmap(depths.size());
uint32_t used = 0;
std::vector<zeropres> news;
for (uint32_t d = 0; d <= maxdepth; d++) {
for (uint32_t i = 0; i < depths.size(); i++) {
if (depths[i] == d) {
newmap[i] = (used++);
if (i > 0) {
auto thing = orig[i-1];
for (auto it = thing.inputs.begin(); it != thing.inputs.end(); ++it) {
(*it) = newmap[*it];
}
news.push_back(thing);
}
}
}
}
return news;
}
std::vector<zeropres> load_aag(std::string filename) {
std::unordered_map<uint32_t, uint32_t> x2i;
x2i[0] = 0;
x2i[1] = 1;
int m = 0; int i = 0; int l = 0; int o = 0; int a = 0;
std::ifstream instream(argv[1]);
std::ifstream instream(filename);
std::string line;
while (std::getline(instream, line)) {
......@@ -83,7 +125,7 @@ int main(int argc, char* argv[]) {
if (i == 0) {
std::cerr << "Error: no inputs specified" << std::endl;
return 1;
exit(1);
}
std::vector<zeropres> gates;
......@@ -152,6 +194,22 @@ int main(int argc, char* argv[]) {
for (int j = 0; j < o; j++) { outputs[j] = x2i[outputs[j]] >> 1; }
gates.emplace_back(LGATE_OUT, outputs);
return gates;
}
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Usage: ./pres0 infile.aag" << std::endl;
return 1;
}
auto gates = load_aag(argv[1]);
gates = depth_sort(gates);
for (auto it = gates.begin(); it != gates.end(); ++it) {
it->to_stream(std::cout);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment