[lib] developing pcf data structure

This commit is contained in:
tangxifan 2022-07-27 11:12:18 -07:00
parent 079a502153
commit 73c0349832
4 changed files with 204 additions and 1 deletions

View File

@ -0,0 +1,91 @@
#include <algorithm>
#include "vtr_assert.h"
#include "vtr_log.h"
#include "openfpga_port_parser.h"
#include "pcf_data.h"
/* Begin namespace openfpga */
namespace openfpga {
/************************************************************************
* Member functions for class PcfData
***********************************************************************/
/************************************************************************
* Constructors
***********************************************************************/
PcfData::PcfData() {
return;
}
/************************************************************************
* Public Accessors : aggregates
***********************************************************************/
PcfData::pcf_io_constraint_range PcfData::io_constraints() const {
return vtr::make_range(io_constraint_ids_.begin(), io_constraint_ids_.end());
}
/************************************************************************
* Public Accessors : Basic data query
***********************************************************************/
openfpga::BasicPort PcfData::io_pin(const PcfIoConstraintId& io_id) const {
/* validate the io_id */
VTR_ASSERT(valid_io_constraint_id(io_id));
return io_constraint_pins_[io_id];
}
std::string PcfData::io_net(const PcfIoConstraintId& io_id) const {
/* validate the io_id */
VTR_ASSERT(valid_io_constraint_id(io_id));
return io_constraint_nets_[io_id];
}
bool PcfData::empty() const {
return 0 == io_constraint_ids_.size();
}
/************************************************************************
* Public Mutators
***********************************************************************/
void PcfData::reserve_io_constraints(const size_t& num_io_constraints) {
io_constraint_ids_.reserve(num_io_constraints);
io_constraint_pins_.reserve(num_io_constraints);
io_constraint_nets_.reserve(num_io_constraints);
}
PcfIoConstraintId PcfData::create_io_constraint() {
/* Create a new id */
PcfIoConstraintId io_id = PcfIoConstraintId(io_constraint_ids_.size());
io_constraint_ids_.push_back(io_id);
io_constraint_pins_.emplace_back();
io_constraint_nets_.emplace_back();
return io_id;
}
void PcfData::set_io_net(const PcfIoConstraintId& io_id,
const std::string& net) {
VTR_ASSERT(valid_io_constraint_id(io_id));
io_constraint_nets_[io_id] = net;
}
void PcfData::set_io_pin(const PcfIoConstraintId& io_id,
const std::string& pin) {
VTR_ASSERT(valid_io_constraint_id(io_id));
PortParser port_parser(pin);
io_constraint_pins_[io_id] = port_parser.port();
}
/************************************************************************
* Internal invalidators/validators
***********************************************************************/
/* Validators */
bool PcfData::valid_io_constraint_id(const PcfIoConstraintId& io_id) const {
return ( size_t(io_id) < io_constraint_ids_.size() ) && ( io_id == io_constraint_ids_[io_id] );
}
} /* End namespace openfpga*/

View File

@ -0,0 +1,89 @@
#ifndef PCF_DATA_H
#define PCF_DATA_H
/********************************************************************
* This file include the declaration of pcf data
*******************************************************************/
#include <string>
#include <map>
#include <array>
/* Headers from vtrutil library */
#include "vtr_vector.h"
#include "vtr_geometry.h"
/* Headers from openfpgautil library */
#include "openfpga_port.h"
#include "pcf_data_fwd.h"
/* Begin namespace openfpga */
namespace openfpga {
/********************************************************************
* A data structure to constain PCF data
* This data structure may include a number of design constraints
* - I/O constraint, for instance, force a net to be mapped to specific pin
*
* Typical usage:
* --------------
* // Create an object
* PcfData pcf_data;
* // Add a constraint
* PcfIoConstraintId io_id = pcf_data.create_io_constraint();
* pcf_data.set_io_net(io_id, net_name);
* pcf_data.set_io_pin(io_id, pin_name);
*
*******************************************************************/
class PcfData {
public: /* Types */
typedef vtr::vector<PcfIoConstraintId, PcfIoConstraintId>::const_iterator pcf_io_constraint_iterator;
/* Create range */
typedef vtr::Range<pcf_io_constraint_iterator> pcf_io_constraint_range;
public: /* Constructors */
PcfData();
public: /* Accessors: aggregates */
pcf_io_constraint_range io_constraints() const;
public: /* Public Accessors: Basic data query */
/* Get the pin to be constrained */
openfpga::BasicPort io_pin(const PcfIoConstraintId& io_id) const;
/* Get the net to be constrained */
std::string io_net(const PcfIoConstraintId& io_id) const;
/* Check if there are any io constraints */
bool empty() const;
public: /* Public Mutators */
/* Reserve a number of design constraints to be memory efficent */
void reserve_io_constraints(const size_t& num_io_constraints);
/* Add a pin constraint to storage */
PcfIoConstraintId create_io_constraint();
/* Set the net for an io constraint */
void set_io_net(const PcfIoConstraintId& io_id,
const std::string& net);
/* Set the net for an io constraint */
void set_io_pin(const PcfIoConstraintId& io_id,
const std::string& pin);
public: /* Public invalidators/validators */
/* Show if the constraint id is a valid for data queries */
bool valid_io_constraint_id(const PcfIoConstraintId& io_id) const;
private: /* Internal data */
/* Unique ids for each design constraint */
vtr::vector<PcfIoConstraintId, PcfIoConstraintId> io_constraint_ids_;
/* Pins to constraint */
vtr::vector<PcfIoConstraintId, openfpga::BasicPort> io_constraint_pins_;
/* Nets to constraint */
vtr::vector<PcfIoConstraintId, std::string> io_constraint_nets_;
};
} /* End namespace openfpga*/
#endif

View File

@ -0,0 +1,22 @@
/************************************************************************
* A header file for PinConstraints class, including critical data declaration
* Please include this file only for using any PinConstraints data structure
* Refer to pin_constraints.h for more details
***********************************************************************/
/************************************************************************
* Create strong id for PinConstraints to avoid illegal type casting
***********************************************************************/
#ifndef PCF_DATA_FWD_H
#define PCF_DATA_FWD_H
#include "vtr_strong_id.h"
struct pcf_io_constraint_id_tag;
typedef vtr::StrongId<pcf_io_constraint_id_tag> PcfIoConstraintId;
/* Short declaration of class */
class PcfData;
#endif

View File

@ -13,7 +13,8 @@
namespace openfpga { namespace openfpga {
/* Parse a .pcf file through a stream, return an object which contains all the data */ /* Parse a .pcf file through a stream, return an object which contains all the data */
PcfData read_pcf(const char* fname); int read_pcf(const char* fname,
PcfData& pcf_data);
} /* End namespace openfpga*/ } /* End namespace openfpga*/