mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-06 14:13:23 +00:00
cxxrtl: add simple black box support.
This commit adds support for replacing RTLIL modules with CXXRTL black boxes. Black box port widths may not depend on the parameters with which it is instantiated (yet); the parameters may only be used to change the behavior of the black box.
This commit is contained in:
parent
8bc3cd30dc
commit
2b88d9a3fe
2 changed files with 311 additions and 70 deletions
|
@ -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() {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue