Skip to content

Commit 0b243a1

Browse files
authored
Merge pull request #3214 from verilog-to-routing/fredt_check_blif_model_is_in_arch
Throw if BLIF model doesn't exist in the arch xml
2 parents 6a1fe64 + 1f842d5 commit 0b243a1

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

vpr/src/base/read_blif.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <sstream>
2121
#include <cctype> //std::isdigit
2222
#include <regex> //std::regex
23+
#include <optional>
2324

2425
#include "blifparse.hpp"
2526
#include "atom_netlist.h"
@@ -407,13 +408,14 @@ struct BlifAllocCallback : public blifparse::Callback {
407408
//Look through all the models loaded, to find the one which is non-blackbox (i.e. has real blocks
408409
//and is not a blackbox). To check for errors we look at all models, even if we've already
409410
//found a non-blackbox model.
410-
int top_model_idx = -1; //Not valid
411411

412-
for (int i = 0; i < static_cast<int>(blif_models_.size()); ++i) {
412+
std::optional<size_t> top_model_idx; //Not valid yet
413+
414+
for (size_t i = 0; i < blif_models_.size(); ++i) {
413415
if (!blif_models_black_box_[i]) {
414416
//A non-blackbox model
415-
if (top_model_idx == -1) {
416-
//This is the top model
417+
if (!top_model_idx.has_value()) {
418+
// Top model is first non-blackbox model found
417419
top_model_idx = i;
418420
} else {
419421
//We already have a top model
@@ -427,14 +429,13 @@ struct BlifAllocCallback : public blifparse::Callback {
427429
}
428430
}
429431

430-
if (top_model_idx == -1) {
432+
if (!top_model_idx.has_value()) {
431433
vpr_throw(VPR_ERROR_BLIF_F, filename_.c_str(), lineno_,
432434
"No non-blackbox models found. The main model must not be a blackbox.");
433435
}
434436

435437
//Return the main model
436-
VTR_ASSERT(top_model_idx >= 0);
437-
return static_cast<size_t>(top_model_idx);
438+
return top_model_idx.value();
438439
}
439440

440441
private:
@@ -536,11 +537,17 @@ struct BlifAllocCallback : public blifparse::Callback {
536537

537538
bool verify_blackbox_model(AtomNetlist& blif_model) {
538539
LogicalModelId arch_model_id = models_.get_model_by_name(blif_model.netlist_name());
540+
541+
if(!arch_model_id.is_valid()) {
542+
vpr_throw(VPR_ERROR_BLIF_F, filename_.c_str(), lineno_, "BLIF model '%s' has no equivalent architecture model.",
543+
blif_model.netlist_name().c_str());
544+
}
545+
539546
const t_model& arch_model = models_.get_model(arch_model_id);
540547

541548
//Verify each port on the model
542549
//
543-
// We parse each .model as it's own netlist so the IOs
550+
// We parse each .model as its own netlist so the IOs
544551
// get converted to blocks
545552
for (auto blk_id : blif_model.blocks()) {
546553
//Check that the port directions match

0 commit comments

Comments
 (0)