[lib] developing csv reader for pin table file

This commit is contained in:
tangxifan 2022-07-26 21:46:44 -07:00
parent 1d1c2d7e8c
commit e860706363
3 changed files with 58 additions and 1 deletions

View File

@ -2,6 +2,24 @@ cmake_minimum_required(VERSION 3.9)
project("libpcf") 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 EXEC_SOURCES test/*.cpp)
file(GLOB_RECURSE LIB_SOURCES src/*/*.cpp) file(GLOB_RECURSE LIB_SOURCES src/*/*.cpp)
file(GLOB_RECURSE LIB_HEADERS src/*/*.h) file(GLOB_RECURSE LIB_HEADERS src/*/*.h)

View File

@ -8,6 +8,7 @@
/* Headers from vtr util library */ /* Headers from vtr util library */
#include "vtr_assert.h" #include "vtr_assert.h"
#include "vtr_time.h" #include "vtr_time.h"
#include "vtr_log.h"
/* Headers from libopenfpga util library */ /* Headers from libopenfpga util library */
#include "openfpga_port_parser.h" #include "openfpga_port_parser.h"
@ -27,6 +28,44 @@ IoPinTable read_csv_io_pin_table(const char* fname) {
IoPinTable io_pin_table; 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; return io_pin_table;
} }

View File

@ -14,4 +14,4 @@ RIGHT,,,,gfpga_pad_IO_F2A[40],pad_fpga_io[5],,,
BOTTOM,,,,gfpga_pad_IO_A2F[64],pad_fpga_io[6],,, BOTTOM,,,,gfpga_pad_IO_A2F[64],pad_fpga_io[6],,,
BOTTOM,,,,gfpga_pad_IO_F2A[64],pad_fpga_io[6],,, BOTTOM,,,,gfpga_pad_IO_F2A[64],pad_fpga_io[6],,,
LEFT,,,,gfpga_pad_IO_F2A[127],pad_fpga_io[7],,, LEFT,,,,gfpga_pad_IO_F2A[127],pad_fpga_io[7],,,
LEFT,,,,gfpga_pad_IO_A2F[127],pad_fpga_io[7],,, LEFT,,,,gfpga_pad_IO_A2F[127],pad_fpga_io[7],,,

1 orientation row col pin_num_in_cell port_name mapped_pin GPIO_type Associated Clock Clock Edge
14 BOTTOM gfpga_pad_IO_A2F[64] pad_fpga_io[6]
15 BOTTOM gfpga_pad_IO_F2A[64] pad_fpga_io[6]
16 LEFT gfpga_pad_IO_F2A[127] pad_fpga_io[7]
17 LEFT gfpga_pad_IO_A2F[127] pad_fpga_io[7]