move generic data structures to openfpgautil library

This commit is contained in:
tangxifan 2020-01-16 13:26:55 -07:00
parent d232391250
commit 3ace7f8ef7
10 changed files with 126 additions and 259 deletions

View File

@ -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 <numeric> #include <numeric>
#include <algorithm> #include <algorithm>
#include "vtr_assert.h" #include "vtr_assert.h"
#include "port_parser.h" #include "openfpga_port_parser.h"
#include "circuit_library.h" #include "circuit_library.h"
/************************************************************************ /************************************************************************
@ -2015,8 +1980,8 @@ void CircuitLibrary::set_timing_graph_delays(const CircuitModelId& model_id) {
*/ */
/* Parse the string for inputs */ /* Parse the string for inputs */
MultiPortParser input_port_parser(delay_in_port_names_[model_id][size_t(delay_type)]); openfpga::MultiPortParser input_port_parser(delay_in_port_names_[model_id][size_t(delay_type)]);
std::vector<BasicPort> input_ports = input_port_parser.ports(); std::vector<openfpga::BasicPort> input_ports = input_port_parser.ports();
std::vector<CircuitPortId> input_port_ids; std::vector<CircuitPortId> input_port_ids;
std::vector<size_t> input_pin_ids; std::vector<size_t> input_pin_ids;
/* Check each element */ /* Check each element */
@ -2044,8 +2009,8 @@ void CircuitLibrary::set_timing_graph_delays(const CircuitModelId& model_id) {
} }
/* Parse the string for outputs */ /* Parse the string for outputs */
MultiPortParser output_port_parser(delay_out_port_names_[model_id][size_t(delay_type)]); openfpga::MultiPortParser output_port_parser(delay_out_port_names_[model_id][size_t(delay_type)]);
std::vector<BasicPort> output_ports = output_port_parser.ports(); std::vector<openfpga::BasicPort> output_ports = output_port_parser.ports();
std::vector<CircuitPortId> output_port_ids; std::vector<CircuitPortId> output_port_ids;
std::vector<size_t> output_pin_ids; std::vector<size_t> output_pin_ids;
/* Check each element */ /* Check each element */
@ -2073,7 +2038,7 @@ void CircuitLibrary::set_timing_graph_delays(const CircuitModelId& model_id) {
} }
/* Parse the delay matrix */ /* 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 */ /* Make sure the delay matrix size matches */
VTR_ASSERT(port_delay_parser.height() == output_port_ids.size()); VTR_ASSERT(port_delay_parser.height() == output_port_ids.size());

View File

@ -16,8 +16,8 @@
#include "arch_error.h" #include "arch_error.h"
#include "read_xml_util.h" #include "read_xml_util.h"
/* Headers from openfpga_utils*/ /* Headers from openfpgautil library */
#include "string_token.h" #include "openfpga_tokenizer.h"
#include "read_xml_circuit_library.h" #include "read_xml_circuit_library.h"
@ -423,7 +423,7 @@ void read_xml_output_mask(pugi::xml_node& xml_port,
std::vector<size_t> mask_vector; std::vector<size_t> mask_vector;
if (nullptr != output_mask_attr) { if (nullptr != output_mask_attr) {
/* Split the string with token ',' */ /* 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(',')) { for (const std::string& mask_token : string_tokenizer.split(',')) {
mask_vector.push_back(std::atoi(mask_token.c_str())); mask_vector.push_back(std::atoi(mask_token.c_str()));
} }

View File

@ -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 <string>
#include <vector>
/************************************************************************
* 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<std::string> split(const std::string& delims) const;
std::vector<std::string> split(const char& delim) const;
std::vector<std::string> split(const char* delim) const;
std::vector<std::string> split(const std::vector<char>& delim) const;
std::vector<std::string> 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<char> delims_;
};
#endif
/************************************************************************
* End of file : string_token.h
***********************************************************************/

View File

@ -2,7 +2,7 @@
* This file includes functions that handles the file outputting * This file includes functions that handles the file outputting
* in OpenFPGA framework * in OpenFPGA framework
*******************************************************************/ *******************************************************************/
/* Headers from vtr util library */ /* Headers from vtrutil library */
#include "vtr_log.h" #include "vtr_log.h"
/* Headers from openfpgautil library */ /* Headers from openfpgautil library */

View File

@ -2,12 +2,21 @@
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
/* Headers from vtrutil library */
#include "vtr_assert.h" #include "vtr_assert.h"
#include "device_port.h" #include "openfpga_port.h"
/* Basic Port member functions */ /* namespace openfpga begins */
/* Constructor */ namespace openfpga {
/************************************************************************
* Member functions for BasicPort class
***********************************************************************/
/************************************************************************
* Constructors
***********************************************************************/
/* Default constructor */ /* Default constructor */
BasicPort::BasicPort() { BasicPort::BasicPort() {
/* By default we set an invalid port, which size is 0 */ /* By default we set an invalid port, which size is 0 */
@ -41,7 +50,9 @@ BasicPort::BasicPort(const BasicPort& basic_port) {
set(basic_port); set(basic_port);
} }
/* Accessors */ /************************************************************************
* Accessors
***********************************************************************/
/* get the port width */ /* get the port width */
size_t BasicPort::get_width() const { size_t BasicPort::get_width() const {
if (true == is_valid()) { if (true == is_valid()) {
@ -96,7 +107,9 @@ bool BasicPort::contained(const BasicPort& portA) const {
return ( lsb_ <= portA.get_lsb() && portA.get_msb() <= msb_ ); return ( lsb_ <= portA.get_lsb() && portA.get_msb() <= msb_ );
} }
/* Overloaded operators */ /************************************************************************
* Overloaded operators
***********************************************************************/
/* Two ports are the same only when: /* Two ports are the same only when:
* 1. port names are the same * 1. port names are the same
* 2. LSBs are the same * 2. LSBs are the same
@ -111,7 +124,9 @@ bool BasicPort::operator== (const BasicPort& portA) const {
return false; return false;
} }
/* Mutators */ /************************************************************************
* Mutators
***********************************************************************/
/* copy */ /* copy */
void BasicPort::set(const BasicPort& basic_port) { void BasicPort::set(const BasicPort& basic_port) {
name_ = basic_port.get_name(); name_ = basic_port.get_name();
@ -287,8 +302,13 @@ bool BasicPort::is_valid() const {
return true; return true;
} }
/* ConfPorts member functions */ /************************************************************************
/* Constructor */ * ConfPorts member functions
***********************************************************************/
/************************************************************************
* Constructor
***********************************************************************/
/* Default constructor */ /* Default constructor */
ConfPorts::ConfPorts() { ConfPorts::ConfPorts() {
/* default port */ /* default port */
@ -301,7 +321,9 @@ ConfPorts::ConfPorts(const ConfPorts& conf_ports) {
set(conf_ports); set(conf_ports);
} }
/* Accessors */ /************************************************************************
* Accessors
***********************************************************************/
size_t ConfPorts::get_reserved_port_width() const { size_t ConfPorts::get_reserved_port_width() const {
return reserved_.get_width(); return reserved_.get_width();
} }
@ -326,7 +348,9 @@ size_t ConfPorts::get_regular_port_msb() const {
return regular_.get_msb(); return regular_.get_msb();
} }
/* Mutators */ /************************************************************************
* Mutators
***********************************************************************/
void ConfPorts::set(const ConfPorts& conf_ports) { void ConfPorts::set(const ConfPorts& conf_ports) {
set_reserved_port(conf_ports.get_reserved_port_width()); set_reserved_port(conf_ports.get_reserved_port_width());
set_regular_port(conf_ports.get_regular_port_lsb(), conf_ports.get_regular_port_msb()); set_regular_port(conf_ports.get_regular_port_lsb(), conf_ports.get_regular_port_msb());
@ -393,5 +417,4 @@ void ConfPorts::reset() {
return; return;
} }
} /* namespace openfpga ends */

View File

@ -1,13 +1,15 @@
/* IMPORTANT: #ifndef OPENFPGA_PORT_H
* The following preprocessing flags are added to #define OPENFPGA_PORT_H
* avoid compilation error when this headers are included in more than 1 times
*/
#ifndef DEVICE_PORT_H
#define DEVICE_PORT_H
/********************************************************************
* Include header files that are required by data structure declaration
*******************************************************************/
#include <string> #include <string>
#include <vector> #include <vector>
/* namespace openfpga begins */
namespace openfpga {
/* A basic port */ /* A basic port */
class BasicPort { class BasicPort {
public: /* Constructors */ public: /* Constructors */
@ -85,5 +87,7 @@ class ConfPorts {
/* TODO: create a class for BL and WL ports */ /* TODO: create a class for BL and WL ports */
} /* namespace openfpga ends */
#endif #endif

View File

@ -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 * Member functions for Port parsers
***********************************************************************/ ***********************************************************************/
#include <cstring>
#include "string.h"
#include "vtr_assert.h" #include "vtr_assert.h"
#include "vtr_geometry.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 * Member functions for PortParser class
@ -323,9 +290,4 @@ void PortDelayParser::clear() {
return; return;
} }
} /* namespace openfpga ends */
/************************************************************************
* End of file : port_parser.cpp
***********************************************************************/

View File

@ -1,25 +1,17 @@
/* IMPORTANT: #ifndef OPENFPGA_PORT_PARSER_H
* The following preprocessing flags are added to #define OPENFPGA_PORT_PARSER_H
* avoid compilation error when this headers are included in more than 1 times
*/
#ifndef PORT_PARSER_H
#define PORT_PARSER_H
/* /********************************************************************
* Notes in include header files in a head file * Include header files that are required by data structure declaration
* 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 <string> #include <string>
#include <vector> #include <vector>
#include "vtr_ndmatrix.h" #include "vtr_ndmatrix.h"
#include "vtr_geometry.h" #include "vtr_geometry.h"
#include "device_port.h" #include "openfpga_port.h"
#include "string_token.h" #include "openfpga_tokenizer.h"
/************************************************************************ /************************************************************************
* This file includes parsers for port definition in the architecture XML * 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 * It means we may reuse this for constructing a structural Verilog parser
***********************************************************************/ ***********************************************************************/
/* namespace openfpga begins */
namespace openfpga {
/************************************************************************ /************************************************************************
* Class PortParser: single port parser * Class PortParser: single port parser
* Supported port definition: * Supported port definition:
@ -103,10 +98,7 @@ class PortDelayParser {
vtr::Matrix<float> delay_matrix_; vtr::Matrix<float> delay_matrix_;
}; };
} /* namespace openfpga ends */
#endif #endif
/************************************************************************
* End of file : port_parser.h
***********************************************************************/

View File

@ -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 * Member functions for StringToken class
***********************************************************************/ ***********************************************************************/
#include <cstring>
#include "string.h" /* Headers from vtrutil library */
#include "vtr_assert.h" #include "vtr_assert.h"
#include "string_token.h" #include "openfpga_tokenizer.h"
/* namespace openfpga begins */
namespace openfpga {
/************************************************************************ /************************************************************************
* Constructors * Constructors
@ -68,13 +36,13 @@ std::vector<std::string> StringToken::split(const std::string& delims) const {
std::copy(data_.begin(), data_.end(), tmp); std::copy(data_.begin(), data_.end(), tmp);
tmp[data_.size()] = '\0'; tmp[data_.size()] = '\0';
/* Split using strtok */ /* Split using strtok */
char* result = strtok(tmp, delims.c_str()); char* result = std::strtok(tmp, delims.c_str());
while (NULL != result) { while (NULL != result) {
std::string result_str(result); std::string result_str(result);
/* Store the token */ /* Store the token */
ret.push_back(result_str); ret.push_back(result_str);
/* Got to next */ /* Got to next */
result = strtok(NULL, delims.c_str()); result = std::strtok(NULL, delims.c_str());
} }
/* Free the tmp */ /* Free the tmp */
@ -168,7 +136,4 @@ void StringToken::add_default_delim() {
return; return;
} }
/************************************************************************ } /* namespace openfpga ends */
* End of file : string_token.cpp
***********************************************************************/

View File

@ -0,0 +1,44 @@
#ifndef OPENFPGA_TOKENIZER_H
#define OPENFPGA_TOKENIZER_H
/********************************************************************
* Include header files that are required by data structure declaration
*******************************************************************/
#include <string>
#include <vector>
/* 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<std::string> split(const std::string& delims) const;
std::vector<std::string> split(const char& delim) const;
std::vector<std::string> split(const char* delim) const;
std::vector<std::string> split(const std::vector<char>& delim) const;
std::vector<std::string> 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<char> delims_;
};
} /* namespace openfpga ends */
#endif