[lib] developing csv reader for pin table file
This commit is contained in:
parent
1d1c2d7e8c
commit
e860706363
|
@ -2,6 +2,24 @@ cmake_minimum_required(VERSION 3.9)
|
|||
|
||||
project("libpcf")
|
||||
|
||||
# For CSV reader
|
||||
if(CSV_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD ${CSV_CXX_STANDARD})
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
endif(CSV_CXX_STANDARD)
|
||||
|
||||
option(BUILD_PYTHON "Build Python Binding" OFF)
|
||||
|
||||
message("Building CSV library using C++${CMAKE_CXX_STANDARD}")
|
||||
|
||||
# Defines CSV_HAS_CXX17 in compatibility.hpp
|
||||
if (CMAKE_VERSION VERSION_LESS "3.12.0")
|
||||
add_definitions(-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD})
|
||||
else()
|
||||
add_compile_definitions(CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD})
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE EXEC_SOURCES test/*.cpp)
|
||||
file(GLOB_RECURSE LIB_SOURCES src/*/*.cpp)
|
||||
file(GLOB_RECURSE LIB_HEADERS src/*/*.h)
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
/* Headers from vtr util library */
|
||||
#include "vtr_assert.h"
|
||||
#include "vtr_time.h"
|
||||
#include "vtr_log.h"
|
||||
|
||||
/* Headers from libopenfpga util library */
|
||||
#include "openfpga_port_parser.h"
|
||||
|
@ -27,6 +28,44 @@ IoPinTable read_csv_io_pin_table(const char* fname) {
|
|||
|
||||
IoPinTable io_pin_table;
|
||||
|
||||
csv::CSVFormat format;
|
||||
format.delimiter(',');
|
||||
format.quote('~');
|
||||
format.trim({'\t', ' '});
|
||||
format.header_row(0);
|
||||
|
||||
csv::CSVReader reader(fname, format);
|
||||
|
||||
/* TODO: Move this to constants */
|
||||
std::map<std::string, e_side> side_str_map { {"TOP", TOP}, {"RIGHT", RIGHT}, {"LEFT", LEFT}, {"BOTTOM", BOTTOM} };
|
||||
|
||||
for (csv::CSVRow& row : reader) {
|
||||
IoPinTableId pin_id = io_pin_table.create_pin();
|
||||
/* Fill pin-level information */
|
||||
PortParser internal_pin_parser(row["port_name"].get<std::string>());
|
||||
io_pin_table.set_internal_pin(pin_id, internal_pin_parser.port());
|
||||
|
||||
PortParser external_pin_parser(row["mapped_pin"].get<std::string>());
|
||||
io_pin_table.set_external_pin(pin_id, external_pin_parser.port());
|
||||
|
||||
std::string pin_side_str = row["orientation"].get<std::string>();
|
||||
if (side_str_map.end() == side_str_map.find(pin_side_str)) {
|
||||
VTR_LOG("Invalid side defintion! Expect [TOP|RIGHT|LEFT|BOTTOM]\n");
|
||||
exit(1);
|
||||
} else {
|
||||
io_pin_table.set_pin_side(pin_id, side_str_map[pin_side_str]);
|
||||
}
|
||||
|
||||
/*This is not general purpose: we should have an explicit attribute in the csv file to decalare direction */
|
||||
if (internal_pin_parser.port().get_name().find("A2F") != std::string::npos) {
|
||||
io_pin_table.set_pin_direction(pin_id, IoPinTable::INPUT);
|
||||
} else if (internal_pin_parser.port().get_name().find("F2A") != std::string::npos) {
|
||||
io_pin_table.set_pin_direction(pin_id, IoPinTable::OUTPUT);
|
||||
} else {
|
||||
VTR_LOG("Invalid direction defintion! Expect [A2F|F2A] in the pin name\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
return io_pin_table;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue