[lib] now use rapidcsv as parser
This commit is contained in:
parent
27f4a174b0
commit
55f73dcdc5
|
@ -2,26 +2,6 @@ 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}")
|
||||
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 LIB_SOURCES src/*/*.cpp)
|
||||
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
|
@ -13,7 +13,7 @@
|
|||
/* Headers from libopenfpga util library */
|
||||
#include "openfpga_port_parser.h"
|
||||
|
||||
#include "csv.hpp"
|
||||
#include "rapidcsv.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;
|
||||
|
||||
csv::CSVFormat format;
|
||||
format.delimiter(',');
|
||||
format.quote('~');
|
||||
format.trim({'\t', ' '});
|
||||
format.header_row(0);
|
||||
|
||||
csv::CSVReader reader(fname, format);
|
||||
rapidcsv::Document doc(fname, rapidcsv::LabelParams(-1, 0),
|
||||
rapidcsv::SeparatorParams(','));
|
||||
|
||||
/* 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) {
|
||||
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();
|
||||
/* 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());
|
||||
|
||||
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());
|
||||
|
||||
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)) {
|
||||
VTR_LOG("Invalid side defintion! Expect [TOP|RIGHT|LEFT|BOTTOM]\n");
|
||||
exit(1);
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
/* Headers from arch openfpga library */
|
||||
#include "write_xml_utils.h"
|
||||
|
||||
#include "csv.hpp"
|
||||
|
||||
#include "write_csv_io_pin_table.h"
|
||||
|
||||
/* Begin namespace openfpga */
|
||||
|
@ -38,14 +36,17 @@ int write_csv_io_pin_table(const char* fname,
|
|||
/* Open the file stream */
|
||||
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 */
|
||||
std::array<std::string, IoPinTable::NUM_IO_DIRECTIONS> IO_DIRECTION_STRING = {"input", "output"};
|
||||
|
||||
/* Print head row */
|
||||
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 */
|
||||
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.external_pin(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;
|
||||
|
|
Loading…
Reference in New Issue