diff --git a/libs/libpcf/src/io/read_csv_io_pin_table.cpp b/libs/libpcf/src/io/read_csv_io_pin_table.cpp index 18bc0499c..0a1e90d9c 100644 --- a/libs/libpcf/src/io/read_csv_io_pin_table.cpp +++ b/libs/libpcf/src/io/read_csv_io_pin_table.cpp @@ -18,6 +18,14 @@ /* Begin namespace openfpga */ namespace openfpga { +/* Constants for io pin table csv parser */ +constexpr const int ROW_INDEX_INTERNAL_PIN = 4; +constexpr const int ROW_INDEX_EXTERNAL_PIN = 5; +constexpr const int ROW_INDEX_DIRECTION = 6; +constexpr const int ROW_INDEX_SIDE = 0; +constexpr const char* DIRECTION_INPUT = "in"; +constexpr const char* DIRECTION_OUTPUT = "out"; + /******************************************************************** * Parse XML codes about to an object of PinConstraints *******************************************************************/ @@ -40,13 +48,13 @@ IoPinTable read_csv_io_pin_table(const char* fname) { std::vector row_vec = doc.GetRow(irow); IoPinTableId pin_id = io_pin_table.create_pin(); /* Fill pin-level information */ - PortParser internal_pin_parser(row_vec.at(4)); + PortParser internal_pin_parser(row_vec.at(ROW_INDEX_INTERNAL_PIN)); io_pin_table.set_internal_pin(pin_id, internal_pin_parser.port()); - PortParser external_pin_parser(row_vec.at(5)); + PortParser external_pin_parser(row_vec.at(ROW_INDEX_EXTERNAL_PIN)); io_pin_table.set_external_pin(pin_id, external_pin_parser.port()); - std::string pin_side_str = row_vec.at(0); + std::string pin_side_str = row_vec.at(ROW_INDEX_SIDE); if (side_str_map.end() == side_str_map.find(pin_side_str)) { VTR_LOG( "Invalid side defintion (='%s')! Expect [TOP|RIGHT|LEFT|BOTTOM]\n", @@ -69,6 +77,18 @@ IoPinTable read_csv_io_pin_table(const char* fname) { "Invalid direction defintion! Expect [A2F|F2A] in the pin name\n"); exit(1); } + + /* Parse pin direction from a specific column, this has a higher priority than inferring from pin names */ + std::string port_dir_str = row_vec.at(ROW_INDEX_DIRECTION); + if (port_dir_str == std::string(DIRECTION_INPUT)) { + io_pin_table.set_pin_direction(pin_id, IoPinTable::INPUT); + } else if (port_dir_str == std::string(DIRECTION_OUTPUT)) { + io_pin_table.set_pin_direction(pin_id, IoPinTable::OUTPUT); + } else { + VTR_LOG( + "Invalid direction defintion! Expect [%s|%s] in the GPIO direction\n", DIRECTION_INPUT, DIRECTION_OUTPUT); + exit(1); + } } return io_pin_table;