11 m_control_mapping = control_mapping;
14 std::string VerilogConverter::build_operand(
const std::string& operand)
const
16 if (operand.find(
"?") != std::string::npos)
18 return operand.substr(1);
24 std::string VerilogConverter::build_operation(
const Converter::Operation& operation,
const std::vector<std::string>& operands)
const
31 for (
const auto& o : operands)
33 op += (build_operand(o) +
" & ");
35 op.erase(op.size() - 3);
38 if (operands.size() > 1)
40 log_error(
"z3_utils",
"unhandled amount of operands for operation");
41 return "NOT IMPLEMENTED REACHED";
43 op =
"~" + build_operand(operands.front());
46 for (
const auto& o : operands)
48 op += (build_operand(o) +
" | ");
50 op.erase(op.size() - 3);
53 for (
const auto& o : operands)
55 op += (build_operand(o) +
" ^ ");
57 op.erase(op.size() - 3);
61 return "NOT IMPLEMENTED REACHED";
68 std::string VerilogConverter::generate_assignment(
const std::string& l)
const
73 auto sub_expressions_start = l.find(lhs) + lhs.size() + 1;
74 auto sub_expressions_size = l.size() - sub_expressions_start - 2;
75 auto sub_expressions_string = l.substr(sub_expressions_start, sub_expressions_size);
79 log_debug(
"z3_utils",
"Found {} sub_expressions.", sub_expressions.size());
83 log_debug(
"z3_utils",
"Translated {} sub_expressions.", translated_sub_expressions.size());
87 return "\twire " + lhs +
";\n" +
"\tassign " + lhs +
" = " + rhs +
";\n";
90 std::string VerilogConverter::generate_initialization(
const std::vector<std::string>& input_vars)
const
92 std::string init =
"module func ( ";
94 for (
const auto& in : input_vars)
97 if (m_control_mapping.find(in) == m_control_mapping.end())
99 init = init + in +
", ";
104 for (
const auto& in : input_vars)
106 if (m_control_mapping.find(in) == m_control_mapping.end())
108 init +=
"\tinput " + in +
";\n";
112 init +=
"\toutput out;\n";
116 for (
const auto& [control_var, value] : m_control_mapping)
118 init +=
"\twire " + control_var +
";\n";
119 init +=
"\tassign " + control_var +
" = " + std::to_string(value) +
"; // control bit\n";
126 std::string VerilogConverter::construct_function(
const std::string& assignments,
const std::string& initialization,
const std::vector<std::string>& input_vars)
const
130 std::string return_var;
131 if (assignments.empty())
133 const auto begin = initialization.find(
"i");
134 const auto end = initialization.find(
",");
135 return_var = initialization.substr(begin, end - begin);
139 const auto last_assigment_pos = assignments.rfind(
"assign") + 7;
140 const auto last_line = assignments.substr(last_assigment_pos);
144 std::string final_words =
"\tassign out = " + return_var +
";\n";
145 final_words +=
"endmodule";
146 return (initialization + assignments + final_words);
std::map< std::string, std::string > extract_sub_exrepssions(const std::string &l) const
std::string extract_lhs(const std::string &l) const
std::map< std::string, std::string > translate_sub_expressions(const std::map< std::string, std::string > &se) const
std::string merge_sub_expressions(const std::map< std::string, std::string > &translated_sub_expressions) const
std::string operation_to_string(const Operation &op) const
void set_control_mapping(const std::map< std::string, bool > &control_mapping)
#define log_error(channel,...)
#define log_debug(channel,...)
@ counter
Counter operation.