[lib] now use rapidcsv as parser

This commit is contained in:
tangxifan 2022-07-27 09:04:00 -07:00
parent 27f4a174b0
commit 55f73dcdc5
5 changed files with 1823 additions and 8524 deletions

View File

@ -2,26 +2,6 @@ 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}")
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads QUIET REQUIRED)
# 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)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@
/* Headers from libopenfpga util library */ /* Headers from libopenfpga util library */
#include "openfpga_port_parser.h" #include "openfpga_port_parser.h"
#include "csv.hpp" #include "rapidcsv.h"
#include "read_csv_io_pin_table.h" #include "read_csv_io_pin_table.h"
@ -28,27 +28,26 @@ IoPinTable read_csv_io_pin_table(const char* fname) {
IoPinTable io_pin_table; IoPinTable io_pin_table;
csv::CSVFormat format; rapidcsv::Document doc(fname, rapidcsv::LabelParams(-1, 0),
format.delimiter(','); rapidcsv::SeparatorParams(','));
format.quote('~');
format.trim({'\t', ' '});
format.header_row(0);
csv::CSVReader reader(fname, format);
/* TODO: Move this to constants */ /* TODO: Move this to constants */
std::map<std::string, e_side> side_str_map { {"TOP", TOP}, {"RIGHT", RIGHT}, {"LEFT", LEFT}, {"BOTTOM", BOTTOM} }; std::map<std::string, e_side> side_str_map { {"TOP", TOP}, {"RIGHT", RIGHT}, {"LEFT", LEFT}, {"BOTTOM", BOTTOM} };
for (csv::CSVRow& row : reader) { int num_rows = doc.GetRowCount();
io_pin_table.reserve_pins(num_rows);
for (int irow = 0; irow < num_rows; 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 */
PortParser internal_pin_parser(row["port_name"].get<std::string>()); PortParser internal_pin_parser(row_vec.at(4));
io_pin_table.set_internal_pin(pin_id, internal_pin_parser.port()); io_pin_table.set_internal_pin(pin_id, internal_pin_parser.port());
PortParser external_pin_parser(row["mapped_pin"].get<std::string>()); PortParser external_pin_parser(row_vec.at(5));
io_pin_table.set_external_pin(pin_id, external_pin_parser.port()); io_pin_table.set_external_pin(pin_id, external_pin_parser.port());
std::string pin_side_str = row["orientation"].get<std::string>(); 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! Expect [TOP|RIGHT|LEFT|BOTTOM]\n");
exit(1); exit(1);

View File

@ -15,8 +15,6 @@
/* Headers from arch openfpga library */ /* Headers from arch openfpga library */
#include "write_xml_utils.h" #include "write_xml_utils.h"
#include "csv.hpp"
#include "write_csv_io_pin_table.h" #include "write_csv_io_pin_table.h"
/* Begin namespace openfpga */ /* Begin namespace openfpga */
@ -38,14 +36,17 @@ int write_csv_io_pin_table(const char* fname,
/* Open the file stream */ /* Open the file stream */
fp.open(std::string(fname), std::fstream::out | std::fstream::trunc); fp.open(std::string(fname), std::fstream::out | std::fstream::trunc);
auto writer = csv::make_csv_writer(fp);
/* TODO: Move this to constants header file */ /* TODO: Move this to constants header file */
std::array<std::string, IoPinTable::NUM_IO_DIRECTIONS> IO_DIRECTION_STRING = {"input", "output"}; std::array<std::string, IoPinTable::NUM_IO_DIRECTIONS> IO_DIRECTION_STRING = {"input", "output"};
/* Print head row */ /* Print head row */
std::vector<std::string> head_row_str({"orientation", "port_name", "mapped_pin", "direction"}); std::vector<std::string> head_row_str({"orientation", "port_name", "mapped_pin", "direction"});
writer << head_row_str; for (size_t icol = 0; icol < head_row_str.size(); icol++) {
fp << head_row_str[icol];
if (icol < head_row_str.size() - 1) {
fp << ",";
}
}
/* Print data */ /* Print data */
for (const IoPinTableId& pin_id : io_pin_table.pins()) { for (const IoPinTableId& pin_id : io_pin_table.pins()) {
@ -54,7 +55,12 @@ int write_csv_io_pin_table(const char* fname,
data_row_str.push_back(generate_xml_port_name(io_pin_table.internal_pin(pin_id))); data_row_str.push_back(generate_xml_port_name(io_pin_table.internal_pin(pin_id)));
data_row_str.push_back(generate_xml_port_name(io_pin_table.external_pin(pin_id))); data_row_str.push_back(generate_xml_port_name(io_pin_table.external_pin(pin_id)));
data_row_str.push_back(IO_DIRECTION_STRING[io_pin_table.pin_direction(pin_id)]); data_row_str.push_back(IO_DIRECTION_STRING[io_pin_table.pin_direction(pin_id)]);
writer << data_row_str; for (size_t icol = 0; icol < head_row_str.size(); icol++) {
fp << data_row_str[icol];
if (icol < data_row_str.size() - 1) {
fp << ",";
}
}
} }
return 0; return 0;