20
20
#include < sstream>
21
21
#include < cctype> // std::isdigit
22
22
#include < regex> // std::regex
23
+ #include < optional>
23
24
24
25
#include " blifparse.hpp"
25
26
#include " atom_netlist.h"
@@ -407,13 +408,14 @@ struct BlifAllocCallback : public blifparse::Callback {
407
408
// Look through all the models loaded, to find the one which is non-blackbox (i.e. has real blocks
408
409
// and is not a blackbox). To check for errors we look at all models, even if we've already
409
410
// found a non-blackbox model.
410
- int top_model_idx = -1 ; // Not valid
411
411
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) {
413
415
if (!blif_models_black_box_[i]) {
414
416
// 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
417
419
top_model_idx = i;
418
420
} else {
419
421
// We already have a top model
@@ -427,14 +429,13 @@ struct BlifAllocCallback : public blifparse::Callback {
427
429
}
428
430
}
429
431
430
- if (top_model_idx == - 1 ) {
432
+ if (! top_model_idx. has_value () ) {
431
433
vpr_throw (VPR_ERROR_BLIF_F, filename_.c_str (), lineno_,
432
434
" No non-blackbox models found. The main model must not be a blackbox." );
433
435
}
434
436
435
437
// 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 ();
438
439
}
439
440
440
441
private:
@@ -536,11 +537,17 @@ struct BlifAllocCallback : public blifparse::Callback {
536
537
537
538
bool verify_blackbox_model (AtomNetlist& blif_model) {
538
539
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
+
539
546
const t_model& arch_model = models_.get_model (arch_model_id);
540
547
541
548
// Verify each port on the model
542
549
//
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
544
551
// get converted to blocks
545
552
for (auto blk_id : blif_model.blocks ()) {
546
553
// Check that the port directions match
0 commit comments