| 9 | #include <fstream> |
| 10 | |
| 11 | DREAMPLACE_BEGIN_NAMESPACE |
| 12 | |
| 13 | bool DefWriter::write(std::string const& outFile, std::string const& inFile, |
| 14 | std::vector<Node> const& vNode, std::vector<PlaceDB::index_type> const& vNodeIndex, |
| 15 | PlaceDB::coordinate_type const* x, PlaceDB::coordinate_type const* y) const |
| 16 | { |
| 17 | std::ifstream in (inFile.c_str()); |
| 18 | FILE* out = fopen(outFile.c_str(), "w"); |
| 19 | std::string line; |
| 20 | std::string nodeName; |
| 21 | std::size_t pos1, pos2; |
| 22 | bool flag = false; // whether in COMPONENTS block |
| 23 | std::size_t rowCount = 0; |
| 24 | |
| 25 | dreamplacePrint(kINFO, "writing placement to %s\n", outFile.c_str()); |
| 26 | |
| 27 | if (!in.good()) |
| 28 | { |
| 29 | dreamplacePrint(kERROR, "unable to open %s for read\n", inFile.c_str()); |
| 30 | return false; |
| 31 | } |
| 32 | if (out == NULL) |
| 33 | { |
| 34 | dreamplacePrint(kERROR, "unable to open %s for write\n", outFile.c_str()); |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | while (getline(in, line)) |
| 39 | { |
| 40 | line = trim(line); |
| 41 | pos1 = line.find("END"); |
| 42 | pos2 = line.find("COMPONENTS"); |
| 43 | if (pos1 != std::string::npos && |
| 44 | pos2 != std::string::npos) // match "END COMPONENTS" |
| 45 | { |
| 46 | // found "END COMPONENTS" |
| 47 | // dump positions here |
| 48 | writeCompBlock(out, vNode, vNodeIndex, x, y); |
| 49 | |
| 50 | flag = false; |
| 51 | continue; |
| 52 | } |
| 53 | else if (pos2 != std::string::npos) // match "COMPONENTS" |
| 54 | { |
| 55 | flag = true; |
| 56 | continue; |
| 57 | } |
| 58 | |
| 59 | if (flag) {/* skip everything in a COMPONENTS block */} |
| 60 | else |
| 61 | { |
| 62 | if (line.substr(0, 3) == "ROW") // match "ROW" entry, it does not hurt even if not matched; mainly for modification of benchmarks |
| 63 | { |
| 64 | Row const& row = m_db.row(rowCount); |
| 65 | fprintf(out, "ROW %s %s %d %d %s DO %u BY %u STEP %d %d ", |
| 66 | row.name().c_str(), row.macroName().c_str(), |
| 67 | row.xl(), row.yl(), std::string(row.orient()).c_str(), |
| 68 | row.numSites(kX), (row.step(kY) == 0)? 1 : row.numSites(kY), row.step(kX), row.step(kY)); |
nothing calls this directly
no test coverage detected