aboutsummaryrefslogtreecommitdiffstats
path: root/backends/cxxrtl/cxxrtl.h
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2020-04-18 09:21:14 +0000
committerGitHub <noreply@github.com>2020-04-18 09:21:14 +0000
commitc98cde88427aedacbcaf66d915912377ccb0cb01 (patch)
tree527c3cf1d1eedaba94d56f16cbea2c7bf7fab77e /backends/cxxrtl/cxxrtl.h
parentd42530b7bba58d2f4c0b435b7c2d6ece5941e0e3 (diff)
parent63d2a308572aaa5abe0ab4591067a013a953d684 (diff)
downloadyosys-c98cde88427aedacbcaf66d915912377ccb0cb01.tar.gz
yosys-c98cde88427aedacbcaf66d915912377ccb0cb01.tar.bz2
yosys-c98cde88427aedacbcaf66d915912377ccb0cb01.zip
Merge pull request #1963 from whitequark/cxxrtl-blackboxes
cxxrtl: add support for simple and templated C++ black boxes
Diffstat (limited to 'backends/cxxrtl/cxxrtl.h')
-rw-r--r--backends/cxxrtl/cxxrtl.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/backends/cxxrtl/cxxrtl.h b/backends/cxxrtl/cxxrtl.h
index fd390db79..0b330fa8f 100644
--- a/backends/cxxrtl/cxxrtl.h
+++ b/backends/cxxrtl/cxxrtl.h
@@ -28,7 +28,9 @@
#include <type_traits>
#include <tuple>
#include <vector>
+#include <map>
#include <algorithm>
+#include <memory>
#include <sstream>
// The cxxrtl support library implements compile time specialized arbitrary width arithmetics, as well as provides
@@ -657,6 +659,57 @@ struct memory {
}
};
+struct parameter {
+ const enum {
+ MISSING = 0,
+ UINT = 1,
+ SINT = 2,
+ STRING = 3,
+ DOUBLE = 4,
+ } value_type;
+
+ // In debug mode, using the wrong .as_*() function will assert.
+ // In release mode, using the wrong .as_*() function will safely return a default value.
+ union {
+ const unsigned uint_value = 0;
+ const signed sint_value;
+ };
+ const std::string string_value = "";
+ const double double_value = 0.0;
+
+ parameter() : value_type(MISSING) {}
+ parameter(unsigned value) : value_type(UINT), uint_value(value) {}
+ parameter(signed value) : value_type(SINT), sint_value(value) {}
+ parameter(const std::string &value) : value_type(STRING), string_value(value) {}
+ parameter(const char *value) : value_type(STRING), string_value(value) {}
+ parameter(double value) : value_type(DOUBLE), double_value(value) {}
+
+ parameter(const parameter &) = default;
+ parameter &operator=(const parameter &) = delete;
+
+ unsigned as_uint() const {
+ assert(value_type == UINT);
+ return uint_value;
+ }
+
+ signed as_sint() const {
+ assert(value_type == SINT);
+ return sint_value;
+ }
+
+ const std::string &as_string() const {
+ assert(value_type == STRING);
+ return string_value;
+ }
+
+ double as_double() const {
+ assert(value_type == DOUBLE);
+ return double_value;
+ }
+};
+
+typedef std::map<std::string, parameter> parameter_map;
+
struct module {
module() {}
virtual ~module() {}