25 std::stringstream
function;
32 log_error(
"verilator",
"gate: {} has no state information in gate_library. you need to set one! aborting...", gt->
get_name());
40 function <<
"reg " << internal_state <<
";" << std::endl;
41 function <<
"reg " << internal_negated_state <<
";" << std::endl;
42 function << std::endl;
43 function <<
"wire clock___internal___;" << std::endl;
44 function << std::endl;
47 init_component !=
nullptr)
49 function <<
"initial begin" << std::endl;
50 function <<
"\t" << internal_state <<
" = INIT;" << std::endl;
51 function <<
"\t" << internal_negated_state <<
" = !(INIT);" << std::endl;
52 function <<
"end" << std::endl;
55 function << std::endl;
58 if (clock_pins.size() != 1)
60 log_error(
"verilator",
"unsupported reached: currently only supporting FFs with one clock! aborting...");
64 BooleanFunction async_reset_function = ff_component->get_async_reset_function();
65 BooleanFunction async_set_function = ff_component->get_async_set_function();
67 bool reset_async =
false;
68 bool set_async =
false;
72 log_error(
"verilator",
"gate: {} has no clock function in gate_library. you need to set one! aborting...", gt->
get_name());
77 function <<
"assign clock___internal___ = " << clock_function <<
";" << std::endl;
78 if (!async_reset_function.
is_empty())
81 function <<
"wire async_reset___internal___;" << std::endl;
83 function << std::endl;
88 function <<
"wire async_set___internal___;" << std::endl;
90 function << std::endl;
93 function << std::endl;
96 function <<
"always @(posedge clock___internal___";
99 function <<
" or posedge async_reset___internal___";
104 function <<
" or posedge async_set___internal___";
106 function <<
")" << std::endl;
107 function <<
"begin" << std::endl;
109 bool if_used =
false;
111 if (reset_async && set_async)
113 auto [behav_state, behave_neg_state] = ff_component->get_async_set_reset_behavior();
115 function << (if_used ?
"\telse if (" :
"\tif (") << async_reset_function.
to_string(
verilog_function_printer) <<
" & " << async_set_function <<
") begin" << std::endl;
120 function <<
"\t\t" << internal_state <<
" <= 1'b0;" << std::endl;
123 function <<
"\t\t" << internal_state <<
" <= 1'b1;" << std::endl;
126 function <<
"\t\t" << internal_state <<
" <= !(" << internal_state <<
");" << std::endl;
129 function <<
"\t\t" << internal_state <<
" <= " << internal_state <<
";" << std::endl;
132 function <<
"\t\t" << internal_state <<
" <= 1'bX;" << std::endl;
136 log_error(
"verilator",
"unimplemented reached: found weird AsyncSetResetBehaviour for gate: {}", gt->
get_name());
137 return std::string();
141 switch (behave_neg_state)
144 function <<
"\t\t" << internal_negated_state <<
" <= 1'b0;" << std::endl;
147 function <<
"\t\t" << internal_negated_state <<
" <= 1'b1;" << std::endl;
150 function <<
"\t\t" << internal_negated_state <<
" <= !(" << internal_negated_state <<
");" << std::endl;
153 function <<
"\t\t" << internal_negated_state <<
" <= " << internal_negated_state <<
";" << std::endl;
156 function <<
"\t\t" << internal_negated_state <<
" <= 1'bX;" << std::endl;
160 log_error(
"verilator",
"unimplemented reached: found weird AsyncSetResetBehaviour for gate: {}", gt->
get_name());
161 return std::string();
164 function <<
"\tend" << std::endl;
171 function <<
"\t\t" << internal_state <<
" <= 1'b0;" << std::endl;
172 function <<
"\t\t" << internal_negated_state <<
" <= 1'b1;" << std::endl;
173 function <<
"\tend" << std::endl;
179 function <<
"\t\t" << internal_state <<
" <= 1'b1;" << std::endl;
180 function <<
"\t\t" << internal_negated_state <<
" <= 1'b0;" << std::endl;
181 function <<
"\tend" << std::endl;
187 function << (if_used ?
"\telse begin\n" :
"");
188 function << (if_used ?
"\t" :
"") <<
"\t" << internal_state <<
" <= " << ff_component->get_next_state_function() <<
";" << std::endl;
189 function << (if_used ?
"\t" :
"") <<
"\t" << internal_negated_state <<
" <= !(" << ff_component->get_next_state_function() <<
");" << std::endl;
190 function << (if_used ?
"\tend\n" :
"");
191 function <<
"end" << std::endl;
194 for (
const GatePin* output_pin : output_pins)
196 function <<
"assign " << output_pin->get_name() <<
" = " << gt->
get_boolean_function(output_pin) <<
";" << std::endl;
201 log_error(
"verilator",
"cannot get FFComponent, aborting...");
202 return function.str();
205 return function.str();
static std::string to_string(Value value)
T * get_component_as(const std::function< bool(const GateTypeComponent *)> &filter=nullptr)
std::vector< GatePin * > get_output_pins() const
const std::string & get_name() const
T * get_component_as(const std::function< bool(const GateTypeComponent *)> &filter=nullptr) const
BooleanFunction get_boolean_function(const std::string &name) const
std::vector< GatePin * > get_pins(const std::function< bool(GatePin *)> &filter=nullptr) const
const std::string & get_state_identifier() const
const std::string & get_neg_state_identifier() const
#define log_error(channel,...)
std::string get_function_for_ff(const GateType *gt)
Result< std::string > verilog_function_printer(const BooleanFunction::Node &node, std::vector< std::string > &&operands)