From 3ace7f8ef73e24a38d55b2bf55516ad234fa6305 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Thu, 16 Jan 2020 13:26:55 -0700 Subject: [PATCH] move generic data structures to openfpgautil library --- .../libarchopenfpga/src/circuit_library.cpp | 47 ++-------- .../src/read_xml_circuit_library.cpp | 6 +- .../libarchopenfpga/src/string_token.h | 88 ------------------- .../libopenfpgautil/src/openfpga_digest.cpp | 2 +- .../src/openfpga_port.cpp} | 47 +++++++--- .../src/openfpga_port.h} | 16 ++-- .../src/openfpga_port_parser.cpp} | 52 ++--------- .../src/openfpga_port_parser.h} | 30 +++---- .../src/openfpga_tokenizer.cpp} | 53 ++--------- .../libopenfpgautil/src/openfpga_tokenizer.h | 44 ++++++++++ 10 files changed, 126 insertions(+), 259 deletions(-) delete mode 100644 libopenfpga/libarchopenfpga/src/string_token.h rename libopenfpga/{libarchopenfpga/src/device_port.cpp => libopenfpgautil/src/openfpga_port.cpp} (84%) rename libopenfpga/{libarchopenfpga/src/device_port.h => libopenfpgautil/src/openfpga_port.h} (91%) rename libopenfpga/{libarchopenfpga/src/port_parser.cpp => libopenfpgautil/src/openfpga_port_parser.cpp} (81%) rename libopenfpga/{libarchopenfpga/src/port_parser.h => libopenfpgautil/src/openfpga_port_parser.h} (84%) rename libopenfpga/{libarchopenfpga/src/string_token.cpp => libopenfpgautil/src/openfpga_tokenizer.cpp} (63%) create mode 100644 libopenfpga/libopenfpgautil/src/openfpga_tokenizer.h diff --git a/libopenfpga/libarchopenfpga/src/circuit_library.cpp b/libopenfpga/libarchopenfpga/src/circuit_library.cpp index 3c68583a5..9dcfa62c8 100644 --- a/libopenfpga/libarchopenfpga/src/circuit_library.cpp +++ b/libopenfpga/libarchopenfpga/src/circuit_library.cpp @@ -1,44 +1,9 @@ -/********************************************************** - * MIT License - * - * Copyright (c) 2018 LNIS - The University of Utah - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - ***********************************************************************/ - -/************************************************************************ - * Filename: circuit_library.cpp - * Created by: Xifan Tang - * Change history: - * +-------------------------------------+ - * | Date | Author | Notes - * +-------------------------------------+ - * | 2019/08/07 | Xifan Tang | Created - * +-------------------------------------+ - ***********************************************************************/ - #include #include #include "vtr_assert.h" -#include "port_parser.h" +#include "openfpga_port_parser.h" #include "circuit_library.h" /************************************************************************ @@ -2015,8 +1980,8 @@ void CircuitLibrary::set_timing_graph_delays(const CircuitModelId& model_id) { */ /* Parse the string for inputs */ - MultiPortParser input_port_parser(delay_in_port_names_[model_id][size_t(delay_type)]); - std::vector input_ports = input_port_parser.ports(); + openfpga::MultiPortParser input_port_parser(delay_in_port_names_[model_id][size_t(delay_type)]); + std::vector input_ports = input_port_parser.ports(); std::vector input_port_ids; std::vector input_pin_ids; /* Check each element */ @@ -2044,8 +2009,8 @@ void CircuitLibrary::set_timing_graph_delays(const CircuitModelId& model_id) { } /* Parse the string for outputs */ - MultiPortParser output_port_parser(delay_out_port_names_[model_id][size_t(delay_type)]); - std::vector output_ports = output_port_parser.ports(); + openfpga::MultiPortParser output_port_parser(delay_out_port_names_[model_id][size_t(delay_type)]); + std::vector output_ports = output_port_parser.ports(); std::vector output_port_ids; std::vector output_pin_ids; /* Check each element */ @@ -2073,7 +2038,7 @@ void CircuitLibrary::set_timing_graph_delays(const CircuitModelId& model_id) { } /* Parse the delay matrix */ - PortDelayParser port_delay_parser(delay_values_[model_id][size_t(delay_type)]); + openfpga::PortDelayParser port_delay_parser(delay_values_[model_id][size_t(delay_type)]); /* Make sure the delay matrix size matches */ VTR_ASSERT(port_delay_parser.height() == output_port_ids.size()); diff --git a/libopenfpga/libarchopenfpga/src/read_xml_circuit_library.cpp b/libopenfpga/libarchopenfpga/src/read_xml_circuit_library.cpp index ef9e4e809..fb26c49bc 100644 --- a/libopenfpga/libarchopenfpga/src/read_xml_circuit_library.cpp +++ b/libopenfpga/libarchopenfpga/src/read_xml_circuit_library.cpp @@ -16,8 +16,8 @@ #include "arch_error.h" #include "read_xml_util.h" -/* Headers from openfpga_utils*/ -#include "string_token.h" +/* Headers from openfpgautil library */ +#include "openfpga_tokenizer.h" #include "read_xml_circuit_library.h" @@ -423,7 +423,7 @@ void read_xml_output_mask(pugi::xml_node& xml_port, std::vector mask_vector; if (nullptr != output_mask_attr) { /* Split the string with token ',' */ - StringToken string_tokenizer(get_attribute(xml_port, "lut_output_mask", loc_data, pugiutil::ReqOpt::OPTIONAL).as_string(nullptr)); + openfpga::StringToken string_tokenizer(get_attribute(xml_port, "lut_output_mask", loc_data, pugiutil::ReqOpt::OPTIONAL).as_string(nullptr)); for (const std::string& mask_token : string_tokenizer.split(',')) { mask_vector.push_back(std::atoi(mask_token.c_str())); } diff --git a/libopenfpga/libarchopenfpga/src/string_token.h b/libopenfpga/libarchopenfpga/src/string_token.h deleted file mode 100644 index c0a4c1614..000000000 --- a/libopenfpga/libarchopenfpga/src/string_token.h +++ /dev/null @@ -1,88 +0,0 @@ -/********************************************************** - * MIT License - * - * Copyright (c) 2018 LNIS - The University of Utah - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - ***********************************************************************/ - -/************************************************************************ - * Filename: string_token.h - * Created by: Xifan Tang - * Change history: - * +-------------------------------------+ - * | Date | Author | Notes - * +-------------------------------------+ - * | 2019/08/09 | Xifan Tang | Created - * +-------------------------------------+ - ***********************************************************************/ - -/* IMPORTANT: - * The following preprocessing flags are added to - * avoid compilation error when this headers are included in more than 1 times - */ -#ifndef STRING_TOKEN_H -#define STRING_TOKEN_H - -/* - * Notes in include header files in a head file - * Only include the neccessary header files - * that is required by the data types in the function/class declarations! - */ -/* Header files should be included in a sequence */ -/* Standard header files required go first */ -#include -#include - - -/************************************************************************ - * This file includes a tokenizer for string objects - * It splits a string with given delima and return a vector of tokens - * It can accept different delima in splitting strings - ***********************************************************************/ - -class StringToken { - public : /* Constructors*/ - StringToken (const std::string& data); - public : /* Public Accessors */ - std::string data() const; - std::vector split(const std::string& delims) const; - std::vector split(const char& delim) const; - std::vector split(const char* delim) const; - std::vector split(const std::vector& delim) const; - std::vector split(); - public : /* Public Mutators */ - void set_data(const std::string& data); - void add_delim(const char& delim); - void ltrim(const std::string& sensitive_word); - void rtrim(const std::string& sensitive_word); - void trim(); - private : /* Private Mutators */ - void add_default_delim(); - private: /* Internal data */ - std::string data_; /* Lines to be splited */ - std::vector delims_; -}; - -#endif - -/************************************************************************ - * End of file : string_token.h - ***********************************************************************/ - diff --git a/libopenfpga/libopenfpgautil/src/openfpga_digest.cpp b/libopenfpga/libopenfpgautil/src/openfpga_digest.cpp index 69e8447e2..f1b44d788 100644 --- a/libopenfpga/libopenfpgautil/src/openfpga_digest.cpp +++ b/libopenfpga/libopenfpgautil/src/openfpga_digest.cpp @@ -2,7 +2,7 @@ * This file includes functions that handles the file outputting * in OpenFPGA framework *******************************************************************/ -/* Headers from vtr util library */ +/* Headers from vtrutil library */ #include "vtr_log.h" /* Headers from openfpgautil library */ diff --git a/libopenfpga/libarchopenfpga/src/device_port.cpp b/libopenfpga/libopenfpgautil/src/openfpga_port.cpp similarity index 84% rename from libopenfpga/libarchopenfpga/src/device_port.cpp rename to libopenfpga/libopenfpgautil/src/openfpga_port.cpp index d02229970..7e7cc4007 100644 --- a/libopenfpga/libarchopenfpga/src/device_port.cpp +++ b/libopenfpga/libopenfpgautil/src/openfpga_port.cpp @@ -2,12 +2,21 @@ #include #include +/* Headers from vtrutil library */ #include "vtr_assert.h" -#include "device_port.h" +#include "openfpga_port.h" -/* Basic Port member functions */ -/* Constructor */ +/* namespace openfpga begins */ +namespace openfpga { + +/************************************************************************ + * Member functions for BasicPort class + ***********************************************************************/ + +/************************************************************************ + * Constructors + ***********************************************************************/ /* Default constructor */ BasicPort::BasicPort() { /* By default we set an invalid port, which size is 0 */ @@ -41,7 +50,9 @@ BasicPort::BasicPort(const BasicPort& basic_port) { set(basic_port); } -/* Accessors */ +/************************************************************************ + * Accessors + ***********************************************************************/ /* get the port width */ size_t BasicPort::get_width() const { if (true == is_valid()) { @@ -96,7 +107,9 @@ bool BasicPort::contained(const BasicPort& portA) const { return ( lsb_ <= portA.get_lsb() && portA.get_msb() <= msb_ ); } -/* Overloaded operators */ +/************************************************************************ + * Overloaded operators + ***********************************************************************/ /* Two ports are the same only when: * 1. port names are the same * 2. LSBs are the same @@ -111,7 +124,9 @@ bool BasicPort::operator== (const BasicPort& portA) const { return false; } -/* Mutators */ +/************************************************************************ + * Mutators + ***********************************************************************/ /* copy */ void BasicPort::set(const BasicPort& basic_port) { name_ = basic_port.get_name(); @@ -287,8 +302,13 @@ bool BasicPort::is_valid() const { return true; } -/* ConfPorts member functions */ -/* Constructor */ +/************************************************************************ + * ConfPorts member functions + ***********************************************************************/ + +/************************************************************************ + * Constructor + ***********************************************************************/ /* Default constructor */ ConfPorts::ConfPorts() { /* default port */ @@ -301,7 +321,9 @@ ConfPorts::ConfPorts(const ConfPorts& conf_ports) { set(conf_ports); } -/* Accessors */ +/************************************************************************ + * Accessors + ***********************************************************************/ size_t ConfPorts::get_reserved_port_width() const { return reserved_.get_width(); } @@ -326,7 +348,9 @@ size_t ConfPorts::get_regular_port_msb() const { return regular_.get_msb(); } -/* Mutators */ +/************************************************************************ + * Mutators + ***********************************************************************/ void ConfPorts::set(const ConfPorts& conf_ports) { set_reserved_port(conf_ports.get_reserved_port_width()); set_regular_port(conf_ports.get_regular_port_lsb(), conf_ports.get_regular_port_msb()); @@ -393,5 +417,4 @@ void ConfPorts::reset() { return; } - - +} /* namespace openfpga ends */ diff --git a/libopenfpga/libarchopenfpga/src/device_port.h b/libopenfpga/libopenfpgautil/src/openfpga_port.h similarity index 91% rename from libopenfpga/libarchopenfpga/src/device_port.h rename to libopenfpga/libopenfpgautil/src/openfpga_port.h index 149a7f78b..d870e94fc 100644 --- a/libopenfpga/libarchopenfpga/src/device_port.h +++ b/libopenfpga/libopenfpgautil/src/openfpga_port.h @@ -1,13 +1,15 @@ -/* IMPORTANT: - * The following preprocessing flags are added to - * avoid compilation error when this headers are included in more than 1 times - */ -#ifndef DEVICE_PORT_H -#define DEVICE_PORT_H +#ifndef OPENFPGA_PORT_H +#define OPENFPGA_PORT_H +/******************************************************************** + * Include header files that are required by data structure declaration + *******************************************************************/ #include #include +/* namespace openfpga begins */ +namespace openfpga { + /* A basic port */ class BasicPort { public: /* Constructors */ @@ -85,5 +87,7 @@ class ConfPorts { /* TODO: create a class for BL and WL ports */ +} /* namespace openfpga ends */ + #endif diff --git a/libopenfpga/libarchopenfpga/src/port_parser.cpp b/libopenfpga/libopenfpgautil/src/openfpga_port_parser.cpp similarity index 81% rename from libopenfpga/libarchopenfpga/src/port_parser.cpp rename to libopenfpga/libopenfpgautil/src/openfpga_port_parser.cpp index 9453787e3..78f357b82 100644 --- a/libopenfpga/libarchopenfpga/src/port_parser.cpp +++ b/libopenfpga/libopenfpgautil/src/openfpga_port_parser.cpp @@ -1,50 +1,17 @@ -/********************************************************** - * MIT License - * - * Copyright (c) 2018 LNIS - The University of Utah - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - ***********************************************************************/ - -/************************************************************************ - * Filename: port_parser.cpp - * Created by: Xifan Tang - * Change history: - * +-------------------------------------+ - * | Date | Author | Notes - * +-------------------------------------+ - * | 2019/08/09 | Xifan Tang | Created - * +-------------------------------------+ - ***********************************************************************/ - /************************************************************************ * Member functions for Port parsers ***********************************************************************/ - -#include "string.h" +#include #include "vtr_assert.h" #include "vtr_geometry.h" -#include "string_token.h" +#include "openfpga_tokenizer.h" -#include "port_parser.h" +#include "openfpga_port_parser.h" + +/* namespace openfpga begins */ +namespace openfpga { /************************************************************************ * Member functions for PortParser class @@ -323,9 +290,4 @@ void PortDelayParser::clear() { return; } - - -/************************************************************************ - * End of file : port_parser.cpp - ***********************************************************************/ - +} /* namespace openfpga ends */ diff --git a/libopenfpga/libarchopenfpga/src/port_parser.h b/libopenfpga/libopenfpgautil/src/openfpga_port_parser.h similarity index 84% rename from libopenfpga/libarchopenfpga/src/port_parser.h rename to libopenfpga/libopenfpgautil/src/openfpga_port_parser.h index 32e7f4f19..dfa4ca466 100644 --- a/libopenfpga/libarchopenfpga/src/port_parser.h +++ b/libopenfpga/libopenfpgautil/src/openfpga_port_parser.h @@ -1,25 +1,17 @@ -/* IMPORTANT: - * The following preprocessing flags are added to - * avoid compilation error when this headers are included in more than 1 times - */ -#ifndef PORT_PARSER_H -#define PORT_PARSER_H +#ifndef OPENFPGA_PORT_PARSER_H +#define OPENFPGA_PORT_PARSER_H -/* - * Notes in include header files in a head file - * Only include the neccessary header files - * that is required by the data types in the function/class declarations! - */ -/* Header files should be included in a sequence */ -/* Standard header files required go first */ +/******************************************************************** + * Include header files that are required by data structure declaration + *******************************************************************/ #include #include #include "vtr_ndmatrix.h" #include "vtr_geometry.h" -#include "device_port.h" -#include "string_token.h" +#include "openfpga_port.h" +#include "openfpga_tokenizer.h" /************************************************************************ * This file includes parsers for port definition in the architecture XML @@ -27,6 +19,9 @@ * It means we may reuse this for constructing a structural Verilog parser ***********************************************************************/ +/* namespace openfpga begins */ +namespace openfpga { + /************************************************************************ * Class PortParser: single port parser * Supported port definition: @@ -103,10 +98,7 @@ class PortDelayParser { vtr::Matrix delay_matrix_; }; +} /* namespace openfpga ends */ #endif -/************************************************************************ - * End of file : port_parser.h - ***********************************************************************/ - diff --git a/libopenfpga/libarchopenfpga/src/string_token.cpp b/libopenfpga/libopenfpgautil/src/openfpga_tokenizer.cpp similarity index 63% rename from libopenfpga/libarchopenfpga/src/string_token.cpp rename to libopenfpga/libopenfpgautil/src/openfpga_tokenizer.cpp index 2f6dab90c..6ce121ee0 100644 --- a/libopenfpga/libarchopenfpga/src/string_token.cpp +++ b/libopenfpga/libopenfpgautil/src/openfpga_tokenizer.cpp @@ -1,47 +1,15 @@ -/********************************************************** - * MIT License - * - * Copyright (c) 2018 LNIS - The University of Utah - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - ***********************************************************************/ - -/************************************************************************ - * Filename: string_token.cpp - * Created by: Xifan Tang - * Change history: - * +-------------------------------------+ - * | Date | Author | Notes - * +-------------------------------------+ - * | 2019/08/09 | Xifan Tang | Created - * +-------------------------------------+ - ***********************************************************************/ - /************************************************************************ * Member functions for StringToken class ***********************************************************************/ +#include -#include "string.h" - +/* Headers from vtrutil library */ #include "vtr_assert.h" -#include "string_token.h" +#include "openfpga_tokenizer.h" + +/* namespace openfpga begins */ +namespace openfpga { /************************************************************************ * Constructors @@ -68,13 +36,13 @@ std::vector StringToken::split(const std::string& delims) const { std::copy(data_.begin(), data_.end(), tmp); tmp[data_.size()] = '\0'; /* Split using strtok */ - char* result = strtok(tmp, delims.c_str()); + char* result = std::strtok(tmp, delims.c_str()); while (NULL != result) { std::string result_str(result); /* Store the token */ ret.push_back(result_str); /* Got to next */ - result = strtok(NULL, delims.c_str()); + result = std::strtok(NULL, delims.c_str()); } /* Free the tmp */ @@ -168,7 +136,4 @@ void StringToken::add_default_delim() { return; } -/************************************************************************ - * End of file : string_token.cpp - ***********************************************************************/ - +} /* namespace openfpga ends */ diff --git a/libopenfpga/libopenfpgautil/src/openfpga_tokenizer.h b/libopenfpga/libopenfpgautil/src/openfpga_tokenizer.h new file mode 100644 index 000000000..d57403d55 --- /dev/null +++ b/libopenfpga/libopenfpgautil/src/openfpga_tokenizer.h @@ -0,0 +1,44 @@ +#ifndef OPENFPGA_TOKENIZER_H +#define OPENFPGA_TOKENIZER_H + +/******************************************************************** + * Include header files that are required by data structure declaration + *******************************************************************/ +#include +#include + +/* namespace openfpga begins */ +namespace openfpga { + +/************************************************************************ + * This file includes a tokenizer for string objects + * It splits a string with given delima and return a vector of tokens + * It can accept different delima in splitting strings + ***********************************************************************/ + +class StringToken { + public : /* Constructors*/ + StringToken (const std::string& data); + public : /* Public Accessors */ + std::string data() const; + std::vector split(const std::string& delims) const; + std::vector split(const char& delim) const; + std::vector split(const char* delim) const; + std::vector split(const std::vector& delim) const; + std::vector split(); + public : /* Public Mutators */ + void set_data(const std::string& data); + void add_delim(const char& delim); + void ltrim(const std::string& sensitive_word); + void rtrim(const std::string& sensitive_word); + void trim(); + private : /* Private Mutators */ + void add_default_delim(); + private: /* Internal data */ + std::string data_; /* Lines to be splited */ + std::vector delims_; +}; + +} /* namespace openfpga ends */ + +#endif