Skip to content

Commit

Permalink
Avoid strcpy inside of atom netlist.
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
  • Loading branch information
litghost committed Aug 13, 2020
1 parent 4a48908 commit 45939ec
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
19 changes: 16 additions & 3 deletions vpr/src/base/atom_netlist.cpp
Expand Up @@ -17,20 +17,33 @@
*
*/
AtomNetlist::AtomNetlist(std::string name, std::string id)
: Netlist<AtomBlockId, AtomPortId, AtomPinId, AtomNetId>(name, id) {}
: Netlist<AtomBlockId, AtomPortId, AtomPinId, AtomNetId>(name, id)
, inpad_model_(nullptr)
, outpad_model_(nullptr) {}

/*
*
* Blocks
*
*/
void AtomNetlist::set_block_types(const t_model* inpad, const t_model* outpad) {
VTR_ASSERT(inpad != nullptr);
VTR_ASSERT(outpad != nullptr);

inpad_model_ = inpad;
outpad_model_ = outpad;
}

AtomBlockType AtomNetlist::block_type(const AtomBlockId id) const {
VTR_ASSERT(inpad_model_ != nullptr);
VTR_ASSERT(outpad_model_ != nullptr);

const t_model* blk_model = block_model(id);

AtomBlockType type = AtomBlockType::BLOCK;
if (blk_model->name == std::string(MODEL_INPUT)) {
if (blk_model == inpad_model_) {
type = AtomBlockType::INPAD;
} else if (blk_model->name == std::string(MODEL_OUTPUT)) {
} else if (blk_model == outpad_model_) {
type = AtomBlockType::OUTPAD;
} else {
type = AtomBlockType::BLOCK;
Expand Down
12 changes: 12 additions & 0 deletions vpr/src/base/atom_netlist.h
Expand Up @@ -87,13 +87,17 @@ class AtomNetlist : public Netlist<AtomBlockId, AtomPortId, AtomPinId, AtomNetId
*/
AtomNetlist(std::string name = "", std::string id = "");

AtomNetlist(const AtomNetlist& rhs) = default;
AtomNetlist& operator=(const AtomNetlist& rhs) = default;

public: //Public types
typedef std::vector<std::vector<vtr::LogicValue>> TruthTable;

public: //Public Accessors
/*
* Blocks
*/
void set_block_types(const t_model* inpad, const t_model* outpad);

///@brief Returns the type of the specified block
AtomBlockType block_type(const AtomBlockId id) const;
Expand Down Expand Up @@ -257,6 +261,14 @@ class AtomNetlist : public Netlist<AtomBlockId, AtomPortId, AtomPinId, AtomNetId
vtr::vector_map<AtomBlockId, const t_model*> block_models_; //Architecture model of each block
vtr::vector_map<AtomBlockId, TruthTable> block_truth_tables_; //Truth tables of each block

// Input IOs and output IOs always exist and have their own architecture
// models. While their models are already included in block_models_, we
// also store direct pointers to them to make checks of whether a block is
// an INPAD or OUTPAD fast, as such checks are common in some netlist
// operations (e.g. clean-up of an input netlist).
const t_model* inpad_model_;
const t_model* outpad_model_;

//Port data
vtr::vector_map<AtomPortId, const t_model_ports*> port_models_; //Architecture port models of each port

Expand Down
7 changes: 7 additions & 0 deletions vpr/src/base/read_blif.cpp
Expand Up @@ -51,6 +51,10 @@ struct BlifAllocCallback : public blifparse::Callback {
, blif_format_(blif_format) {
VTR_ASSERT(blif_format_ == e_circuit_format::BLIF
|| blif_format_ == e_circuit_format::EBLIF);
inpad_model_ = find_model(MODEL_INPUT);
outpad_model_ = find_model(MODEL_OUTPUT);

main_netlist_.set_block_types(inpad_model_, outpad_model_);
}

static constexpr const char* OUTPAD_NAME_PREFIX = "out:";
Expand All @@ -70,6 +74,7 @@ struct BlifAllocCallback : public blifparse::Callback {
//Create a new model, and set it's name

blif_models_.emplace_back(model_name, netlist_id_);
blif_models_.back().set_block_types(inpad_model_, outpad_model_);
blif_models_black_box_.emplace_back(false);
ended_ = false;
set_curr_block(AtomBlockId::INVALID()); //This statement doesn't define a block, so mark invalid
Expand Down Expand Up @@ -629,6 +634,8 @@ struct BlifAllocCallback : public blifparse::Callback {
const std::string netlist_id_; ///<Unique identifier based on the contents of the blif file
const t_model* user_arch_models_ = nullptr;
const t_model* library_arch_models_ = nullptr;
const t_model* inpad_model_;
const t_model* outpad_model_;

size_t unique_subckt_name_counter_ = 0;

Expand Down

0 comments on commit 45939ec

Please sign in to comment.