24 std::stringstream
function;
27 if (lut_component ==
nullptr)
29 log_error(
"verilator",
"cannot get LUTComponent for gate type '{}', aborting...", gt->
get_name());
36 log_error(
"verilator",
"LUT gate type '{}' has no output pin configs, aborting...", gt->
get_name());
40 for (
const auto& [pin_name, cfg] : pin_cfgs)
42 if (cfg.input_pins.empty())
44 log_error(
"verilator",
"LUT gate type '{}': output pin '{}' has no input pins configured, aborting...", gt->
get_name(), pin_name);
49 std::string safe_name = pin_name;
50 for (
char& c : safe_name)
52 if (!std::isalnum(
static_cast<unsigned char>(c)))
57 const std::string lookup_wire =
"lut_lookup_" + safe_name;
61 std::vector<std::string> inputs = cfg.input_pins;
62 std::reverse(inputs.begin(), inputs.end());
64 function <<
"wire [" << inputs.size() - 1 <<
":0] " << lookup_wire <<
" = {";
65 for (
const auto& ipin : inputs)
67 function << ipin <<
", ";
69 function.seekp(-2,
function.cur);
72 function <<
"assign " << pin_name <<
" = " << cfg.init_identifier <<
"[" << lookup_wire;
73 if (cfg.bit_offset > 0)
75 function <<
" + " << cfg.bit_offset;
80 return function.str();
const std::string & get_name() const
T * get_component_as(const std::function< bool(const GateTypeComponent *)> &filter=nullptr) const
const std::unordered_map< std::string, LUTOutputConfig > & get_output_pin_configs() const
static bool is_class_of(const GateTypeComponent *component)
#define log_error(channel,...)
std::string get_function_for_lut(const GateType *gt)