Added $sop support to BLIF back-end
authorClifford Wolf <clifford@clifford.at>
Sat, 18 Jun 2016 10:28:49 +0000 (12:28 +0200)
committerClifford Wolf <clifford@clifford.at>
Sat, 18 Jun 2016 10:28:49 +0000 (12:28 +0200)
backends/blif/blif.cc

index ede3fc90126abd60de5e2d8a5cddab9da5257cd3..4484c7584123e68a8eb33c8e04c7dc5b0513d94a 100644 (file)
@@ -338,9 +338,8 @@ struct BlifDumper
                                auto &inputs = cell->getPort("\\A");
                                auto width = cell->parameters.at("\\WIDTH").as_int();
                                log_assert(inputs.size() == width);
-                               for (int i = width-1; i >= 0; i--) {
+                               for (int i = width-1; i >= 0; i--)
                                        f << stringf(" %s", cstr(inputs.extract(i, 1)));
-                               }
                                auto &output = cell->getPort("\\Y");
                                log_assert(output.size() == 1);
                                f << stringf(" %s", cstr(output));
@@ -356,6 +355,34 @@ struct BlifDumper
                                continue;
                        }
 
+                       if (!config->icells_mode && cell->type == "$sop") {
+                               f << stringf(".names");
+                               auto &inputs = cell->getPort("\\A");
+                               auto width = cell->parameters.at("\\WIDTH").as_int();
+                               auto depth = cell->parameters.at("\\DEPTH").as_int();
+                               vector<State> table = cell->parameters.at("\\TABLE").bits;
+                               while (GetSize(table) < 2*width*depth)
+                                       table.push_back(State::S0);
+                               log_assert(inputs.size() == width);
+                               for (int i = 0; i < width; i++)
+                                       f << stringf(" %s", cstr(inputs.extract(i, 1)));
+                               auto &output = cell->getPort("\\Y");
+                               log_assert(output.size() == 1);
+                               f << stringf(" %s", cstr(output));
+                               f << stringf("\n");
+                               for (int i = 0; i < depth; i++) {
+                                       for (int j = 0; j < width; j++) {
+                                               bool pat0 = table.at(2*width*i + 2*j + 0) == State::S1;
+                                               bool pat1 = table.at(2*width*i + 2*j + 1) == State::S1;
+                                               if (pat0 && !pat1) f << "0";
+                                               else if (!pat0 && pat1) f << "1";
+                                               else f << "-";
+                                       }
+                                       f << " 1\n";
+                               }
+                               continue;
+                       }
+
                        f << stringf(".%s %s", subckt_or_gate(cell->type.str()), cstr(cell->type));
                        for (auto &conn : cell->connections())
                        for (int i = 0; i < conn.second.size(); i++) {