[lib] fixed a few bugs; now csv reader and writer is working

This commit is contained in:
tangxifan 2022-07-27 09:11:24 -07:00
parent 55f73dcdc5
commit d197010ba3
2 changed files with 5 additions and 3 deletions

View File

@ -28,7 +28,7 @@ IoPinTable read_csv_io_pin_table(const char* fname) {
IoPinTable io_pin_table; IoPinTable io_pin_table;
rapidcsv::Document doc(fname, rapidcsv::LabelParams(-1, 0), rapidcsv::Document doc(fname, rapidcsv::LabelParams(-1, -1),
rapidcsv::SeparatorParams(',')); rapidcsv::SeparatorParams(','));
/* TODO: Move this to constants */ /* TODO: Move this to constants */
@ -37,7 +37,7 @@ IoPinTable read_csv_io_pin_table(const char* fname) {
int num_rows = doc.GetRowCount(); int num_rows = doc.GetRowCount();
io_pin_table.reserve_pins(num_rows); io_pin_table.reserve_pins(num_rows);
for (int irow = 0; irow < num_rows; irow++) { for (int irow = 1; irow < num_rows; irow++) {
std::vector<std::string> row_vec = doc.GetRow<std::string>(irow); std::vector<std::string> row_vec = doc.GetRow<std::string>(irow);
IoPinTableId pin_id = io_pin_table.create_pin(); IoPinTableId pin_id = io_pin_table.create_pin();
/* Fill pin-level information */ /* Fill pin-level information */
@ -49,7 +49,7 @@ IoPinTable read_csv_io_pin_table(const char* fname) {
std::string pin_side_str = row_vec.at(0); std::string pin_side_str = row_vec.at(0);
if (side_str_map.end() == side_str_map.find(pin_side_str)) { if (side_str_map.end() == side_str_map.find(pin_side_str)) {
VTR_LOG("Invalid side defintion! Expect [TOP|RIGHT|LEFT|BOTTOM]\n"); VTR_LOG("Invalid side defintion (='%s')! Expect [TOP|RIGHT|LEFT|BOTTOM]\n", pin_side_str.c_str());
exit(1); exit(1);
} else { } else {
io_pin_table.set_pin_side(pin_id, side_str_map[pin_side_str]); io_pin_table.set_pin_side(pin_id, side_str_map[pin_side_str]);

View File

@ -47,6 +47,7 @@ int write_csv_io_pin_table(const char* fname,
fp << ","; fp << ",";
} }
} }
fp << "\n";
/* Print data */ /* Print data */
for (const IoPinTableId& pin_id : io_pin_table.pins()) { for (const IoPinTableId& pin_id : io_pin_table.pins()) {
@ -61,6 +62,7 @@ int write_csv_io_pin_table(const char* fname,
fp << ","; fp << ",";
} }
} }
fp << "\n";
} }
return 0; return 0;