aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2020-03-17 10:07:29 +0000
committerDavid Shah <dave@ds0.me>2020-03-17 10:07:29 +0000
commitd20ce45c1b59ad1485c2299234c4dd8d1dec35f3 (patch)
tree07b6cecfdbd926beb41292e7bfe0e56615bda471 /common
parent564f40f6dbda8726fe1abd1f5e66fdc6fd74035c (diff)
parent54b15ed20100523199885685c4557f160fbf56a0 (diff)
downloadnextpnr-d20ce45c1b59ad1485c2299234c4dd8d1dec35f3.tar.gz
nextpnr-d20ce45c1b59ad1485c2299234c4dd8d1dec35f3.tar.bz2
nextpnr-d20ce45c1b59ad1485c2299234c4dd8d1dec35f3.zip
Merge branch 'master' of ssh.github.com:YosysHQ/nextpnr
Diffstat (limited to 'common')
-rw-r--r--common/util.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/common/util.h b/common/util.h
index 2ccfe5d2..9512bd40 100644
--- a/common/util.h
+++ b/common/util.h
@@ -25,6 +25,8 @@
#include <string>
#include "nextpnr.h"
+#include "log.h"
+
NEXTPNR_NAMESPACE_BEGIN
// Get a value from a map-style container, returning default if value is not
@@ -47,8 +49,9 @@ std::string str_or_default(const Container &ct, const KeyType &key, std::string
auto found = ct.find(key);
if (found == ct.end())
return def;
- else
+ else {
return found->second;
+ }
};
template <typename KeyType>
@@ -57,8 +60,11 @@ std::string str_or_default(const std::unordered_map<KeyType, Property> &ct, cons
auto found = ct.find(key);
if (found == ct.end())
return def;
- else
+ else {
+ if (!found->second.is_string)
+ log_error("Expecting string value but got integer %d.\n", int(found->second.intval));
return found->second.as_string();
+ }
};
// Get a value from a map-style container, converting to int, and returning
@@ -79,9 +85,13 @@ int int_or_default(const std::unordered_map<KeyType, Property> &ct, const KeyTyp
if (found == ct.end())
return def;
else {
- if (found->second.is_string)
- return std::stoi(found->second.as_string());
- else
+ if (found->second.is_string) {
+ try {
+ return std::stoi(found->second.as_string());
+ } catch (std::invalid_argument &e) {
+ log_error("Expecting numeric value but got '%s'.\n", found->second.as_string().c_str());
+ }
+ } else
return found->second.as_int64();
}
};