Skip to content

Commit 37eaf71

Browse files
committed
Added EBLIF parameter validation and fixed post-route verilog output
Signed-off-by: Maciej Kurc <[email protected]>
1 parent b3becd3 commit 37eaf71

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

vpr/src/base/netlist_writer.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "vpr_error.h"
2121

22+
#include "read_blif.h"
23+
2224
#include "netlist_walker.h"
2325
#include "netlist_writer.h"
2426

@@ -619,7 +621,13 @@ class BlackBoxInst : public Instance {
619621

620622
//Verilog parameters
621623
for (auto iter = params_.begin(); iter != params_.end(); ++iter) {
622-
os << indent(depth + 1) << "." << iter->first << "(" << iter->second << ")";
624+
/* Prepend a prefix if needed */
625+
std::stringstream prefix;
626+
if (is_binary_param(iter->second)) {
627+
prefix << iter->second.length() << "'b";
628+
}
629+
630+
os << indent(depth + 1) << "." << iter->first << "(" << prefix.str() << iter->second << ")";
623631
if (iter != --params_.end()) {
624632
os << ",";
625633
}

vpr/src/base/read_blif.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@ struct BlifAllocCallback : public blifparse::Callback {
386386
parse_error(lineno_, ".param", "Supported only in extended BLIF format");
387387
}
388388

389+
// Validate the parameter value
390+
bool is_valid = is_string_param(value) || is_binary_param(value) || is_real_param(value);
391+
392+
if (!is_valid) {
393+
parse_error(lineno_, ".param", "Incorrect parameter value specification");
394+
}
395+
389396
curr_model().set_block_param(curr_block(), name, value);
390397
}
391398

@@ -666,6 +673,70 @@ vtr::LogicValue to_vtr_logic_value(blifparse::LogicValue val) {
666673
return new_val;
667674
}
668675

676+
bool is_string_param(const std::string& param) {
677+
/* Empty param is considered a string */
678+
if (param.empty()) {
679+
return true;
680+
}
681+
682+
/* There have to be at least 2 characters (the quotes) */
683+
if (param.length() < 2) {
684+
return false;
685+
}
686+
687+
/* The first and the last characters must be quotes */
688+
size_t len = param.length();
689+
if (param[0] != '"' || param[len - 1] != '"') {
690+
return false;
691+
}
692+
693+
/* There mustn't be any other quotes except for escaped ones */
694+
for (size_t i = 1; i < (len - 1); ++i) {
695+
if (param[i] == '"' && param[i - 1] != '\\') {
696+
return false;
697+
}
698+
}
699+
700+
/* This is a string param */
701+
return true;
702+
}
703+
704+
bool is_binary_param(const std::string& param) {
705+
/* Must be non-empty */
706+
if (param.empty()) {
707+
return false;
708+
}
709+
710+
/* The string must contain only '0' and '1' */
711+
for (size_t i = 0; i < param.length(); ++i) {
712+
if (param[i] != '0' && param[i] != '1') {
713+
return false;
714+
}
715+
}
716+
717+
/* This is a binary word param */
718+
return true;
719+
}
720+
721+
bool is_real_param(const std::string& param) {
722+
const std::string chars = "012345678.";
723+
724+
/* Must be non-empty */
725+
if (param.empty()) {
726+
return false;
727+
}
728+
729+
/* The string mustn't contain any other chars that the expected ones */
730+
for (size_t i = 0; i < param.length(); ++i) {
731+
if (chars.find(param[i]) == std::string::npos) {
732+
return false;
733+
}
734+
}
735+
736+
/* This is a real number param */
737+
return true;
738+
}
739+
669740
AtomNetlist read_blif(e_circuit_format circuit_format,
670741
const char* blif_file,
671742
const t_model* user_models,

vpr/src/base/read_blif.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include "atom_netlist_fwd.h"
55
#include "read_circuit.h"
66

7+
bool is_string_param(const std::string& param);
8+
bool is_binary_param(const std::string& param);
9+
bool is_real_param(const std::string& param);
10+
711
AtomNetlist read_blif(e_circuit_format circuit_format,
812
const char* blif_file,
913
const t_model* user_models,

0 commit comments

Comments
 (0)