55 #include <boost/algorithm/string.hpp> 56 #include <boost/range/adaptor/reversed.hpp> 57 #include <boost/tokenizer.hpp> 64 "ABS",
"ACCESS",
"AFTER",
"ALIAS",
"ALL",
"AND",
65 "ARCHITECTURE",
"ARRAY",
"ASSERT",
"ATTRIBUTE",
"BEGIN",
"BLOCK",
66 "BODY",
"BUFFER",
"BUS",
"CASE",
"COMPONENT",
"CONFIGURATION",
67 "CONSTANT",
"DISCONNECT",
"DOWNTO",
"ELSE",
"ELSIF",
"END",
68 "ENTITY",
"EXIT",
"FILE",
"FOR",
"FUNCTION",
"GENERATE",
69 "GENERIC",
"GROUP",
"GUARDED",
"IF",
"IMPURE",
"IN",
70 "INERTIAL",
"INOUT",
"IS",
"LABEL",
"LIBRARY",
"LINKAGE",
71 "LITERAL",
"LOOP",
"MAP",
"MOD",
"NAND",
"NEW",
72 "NEXT",
"NOR",
"NOT",
"NULL",
"OF",
"ON",
73 "OPEN",
"OR",
"OTHERS",
"OUT",
"PACKAGE",
"PORT",
74 "POSTPONED",
"PROCEDURE",
"PROCESS",
"PURE",
"RANGE",
"RECORD",
75 "REGISTER",
"REJECT",
"REM",
"RETURN",
"ROL",
"ROR",
76 "SELECT",
"SEVERITY",
"SIGNAL",
"SHARED",
"SLA",
"SLI",
77 "SRA",
"SRL",
"SUBTYPE",
"THEN",
"TO",
"TRANSPORT",
78 "TYPE",
"UNAFFECTED",
"UNITS",
"UNTIL",
"USE",
"VARIABLE",
79 "WAIT",
"WHEN",
"WHILE",
"WITH",
"XNOR",
"XOR"};
112 return "std_logic_vector";
121 return "std_logic_vector";
127 return "std_logic_vector";
150 auto*
mod = GetPointer<module>(Owner);
151 std::string port_name = cir->
get_id();
152 bool specialization_string =
false;
160 std::vector<std::pair<std::string, structural_objectRef>> library_parameters;
161 mod->get_NP_library_parameters(Owner, library_parameters);
162 for(
const auto& library_parameter : library_parameters)
164 if(port_name == library_parameter.first)
166 specialization_string =
true;
177 if(specialization_string)
183 const auto& port_vector = GetPointer<port_o>(cir);
184 return " (" +
STR(port_vector->get_ports_size() - 1) +
" downto 0)";
196 if(!GetPointer<port_o>(cir) or !GetPointer<port_o>(cir)->get_reverse())
198 if(GetPointer<port_o>(cir) && GetPointer<port_o>(cir)->size_parameter.size())
200 return " (" + (GetPointer<port_o>(cir)->size_parameter) +
"-1 downto 0)";
202 else if(specialization_string)
208 return " (" + std::to_string(Type->size - 1) +
" downto 0)";
213 if(GetPointer<port_o>(cir) && GetPointer<port_o>(cir)->size_parameter.size())
215 return " (0 to " + (GetPointer<port_o>(cir)->size_parameter) +
"-1)";
217 else if(specialization_string)
223 return " (0 to " + std::to_string(Type->size - 1) +
")";
234 if(specialization_string)
238 auto lsb = GetPointer<port_o>(cir)->get_lsb();
240 std::to_string(static_cast<int>(lsb) - 1) +
") downto " + std::to_string(lsb) +
") ";
253 auto n_sign = GetPointer<signal_o>(cir)->get_signals_size();
255 auto lsb = GetPointer<signal_o>(cir)->get_lsb();
256 auto msb = size_fs * n_sign + lsb;
258 return "(" + std::to_string(static_cast<int>(msb) - 1) +
" downto " + std::to_string(lsb) +
") ";
262 auto lsb = GetPointer<port_o>(cir)->get_lsb();
263 auto n_ports = GetPointer<port_o>(cir)->get_ports_size();
266 auto size_fp = Type_fp->
vector_size > 0 ? Type_fp->size * Type_fp->vector_size : Type_fp->size;
267 auto msb = size_fp * n_ports + lsb;
268 return "(" + std::to_string(static_cast<int>(msb) - 1) +
" downto " + std::to_string(lsb) +
") ";
270 if(Type->vector_size > 1 && Type->size == 1)
272 return "(" + std::to_string(static_cast<int>(Type->vector_size) - 1) +
" downto 0) ";
274 else if(Type->vector_size == 1 && Type->size == 1)
276 return "(0 downto 0)";
278 else if(Type->vector_size == 0 && Type->size != 0)
280 return "(" + std::to_string(static_cast<int>(Type->size) - 1) +
" downto 0) ";
284 THROW_ERROR(
"Not completely specified: " + port_name);
293 if(GetPointer<port_o>(cir) and specialization_string)
310 return Type->id_type;
323 auto*
mod = GetPointer<module>(Owner);
324 std::string port_name = cir->
get_id();
325 bool specialization_string =
false;
331 std::vector<std::pair<std::string, structural_objectRef>> library_parameters;
332 mod->get_NP_library_parameters(Owner, library_parameters);
333 for(
const auto& library_parameter : library_parameters)
335 if(port_name == library_parameter.first)
337 specialization_string =
true;
348 return "(" + GetPointer<port_o>(cir)->get_id() +
")";
357 Type->
print(std::cerr);
366 if(specialization_string)
370 auto lsb = GetPointer<port_o>(Owner)->get_lsb();
371 return "(((" + GetPointer<port_o>(cir)->get_id() +
"+1)*" + (
BITSIZE_PREFIX + port_name) +
")+(" +
372 std::to_string(static_cast<int>(lsb) - 1) +
") downto (" + GetPointer<port_o>(cir)->get_id() +
373 "*" + (
BITSIZE_PREFIX + port_name) +
")+" + std::to_string(lsb) +
")";
386 auto lsb = GetPointer<port_o>(Owner)->get_lsb();
388 std::to_string((1 + std::stoi(GetPointer<port_o>(cir)->get_id())) * static_cast<int>(size_fp) +
389 static_cast<int>(lsb) - 1) +
391 std::to_string((std::stoi(GetPointer<port_o>(cir)->get_id())) * static_cast<int>(size_fp) +
392 static_cast<int>(lsb)) +
406 if(specialization_string)
410 auto lsb = GetPointer<port_o>(Owner)->get_lsb();
411 return "(((" + GetPointer<port_o>(cir)->get_id() +
"+1)*" + (
BITSIZE_PREFIX + port_name) +
"*" +
412 (
NUM_ELEM_PREFIX + port_name) +
")+(" + std::to_string(static_cast<int>(lsb) - 1) +
") downto (" +
413 GetPointer<port_o>(cir)->get_id() +
"*" + (
BITSIZE_PREFIX + port_name) +
"*" +
427 auto lsb = GetPointer<port_o>(Owner)->get_lsb();
429 std::to_string((1 + std::stoi(GetPointer<port_o>(cir)->get_id())) * static_cast<int>(size_fp) +
430 static_cast<int>(lsb) - 1) +
432 std::to_string((std::stoi(GetPointer<port_o>(cir)->get_id())) * static_cast<int>(size_fp) +
433 static_cast<int>(lsb)) +
459 "Expected a component or a channel got something of different");
476 std::vector<std::string> library_list = string_to_container<std::vector<std::string>>(library,
";");
477 for(
const auto& l : library_list)
486 "Expected a component or a channel got something of different");
494 "Expected a component or a channel got something of different");
505 "Expected a port got something of different " + cir->
get_id());
507 dir = GetPointer<port_o>(cir)->get_port_direction();
528 case port_o::TLM_INOUT:
529 case port_o::TLM_OUT:
530 case port_o::UNKNOWN:
537 if(not last_port_to_analyze)
546 auto*
mod = GetPointer<module>(cir);
564 if(
mod->get_in_port_size())
567 for(
unsigned int i = 0; i <
mod->get_in_port_size(); i++)
569 if(i ==
mod->get_in_port_size() - 1 && !
mod->get_out_port_size() && !
mod->get_in_out_port_size() &&
570 !
mod->get_gen_port_size())
580 if(
mod->get_out_port_size())
583 for(
unsigned int i = 0; i <
mod->get_out_port_size(); i++)
585 if(i ==
mod->get_out_port_size() - 1 && !
mod->get_in_out_port_size() && !
mod->get_gen_port_size())
595 if(
mod->get_in_out_port_size())
598 for(
unsigned int i = 0; i <
mod->get_in_out_port_size(); i++)
600 if(i ==
mod->get_in_out_port_size() - 1 && !
mod->get_gen_port_size())
610 if(
mod->get_gen_port_size())
613 for(
unsigned int i = 0; i <
mod->get_gen_port_size(); i++)
615 if(i ==
mod->get_gen_port_size() - 1)
643 auto n_sign = GetPointer<signal_o>(cir)->get_signals_size();
645 auto lsb = GetPointer<signal_o>(cir)->get_lsb();
646 auto msb = size_fs * n_sign + lsb;
648 " : std_logic_vector (" +
STR(msb - 1) +
" downto " +
STR(lsb) +
");\n");
664 bool write_parametrization)
667 "Expected a component or a channel got something of different");
670 if(write_parametrization)
687 "Expected a component or a channel got something of different");
698 if(first_port_analyzed)
722 const auto port_vector = GetPointer<port_o>(port);
723 const auto vector_port_size =
GET_TYPE_SIZE(port) * port_vector->get_ports_size();
725 auto msb = vector_port_size - 1;
727 for(
unsigned int local_port_index = 0; local_port_index < port_vector->get_ports_size(); local_port_index++)
729 if(GetPointer<port_o>(port_vector->get_port(local_port_index))->find_bounded_object())
742 for(
unsigned int local_port_index = 0; local_port_index < port_vector->get_ports_size(); local_port_index++)
745 if(local_port_index != 0)
750 auto reverse_port_index = port_vector->get_ports_size() - local_port_index - 1;
751 const auto object_bounded =
752 GetPointer<port_o>(port_vector->get_port(reverse_port_index))->find_bounded_object();
753 THROW_ASSERT(object_bounded, port_vector->get_port(reverse_port_index)->get_path());
763 msb = msb - single_port_size;
782 auto* con = GetPointer<constant_o>(object_bounded);
783 std::string trimmed_value =
"";
784 auto long_value = std::stoull(con->get_value());
787 trimmed_value = trimmed_value + (((1LLU << (
GET_TYPE_SIZE(con) - ind - 1)) & long_value) ?
'1' :
'0');
810 bool first_port_analyzed)
819 if(first_port_analyzed)
849 if(!object_bounded and GetPointer<port_o>(port)->get_port_direction() == port_o::IN)
859 for(
unsigned int s = 0; s < size; s++)
866 "<--Written port binding " + port->
get_id() +
" => " +
867 (object_bounded ? object_bounded->
get_path() :
""));
870 THROW_ASSERT(object_bounded,
"NULL object_bounded received");
872 "A port has to have always an owner");
875 auto* con = GetPointer<constant_o>(object_bounded);
876 std::string trimmed_value =
"";
877 auto long_value = std::stoull(con->get_value());
880 trimmed_value = trimmed_value + (((1LLU << (
GET_TYPE_SIZE(con) - ind - 1)) & long_value) ?
'1' :
'0');
926 THROW_ASSERT(GetPointer<port_o>(port)->get_port_direction() == port_o::IN or
935 "Needed a conversion on output port binding " + port->
get_path() +
" => " +
991 "<--Written port binding " + port->
get_id() +
" => " +
992 (object_bounded ? object_bounded->
get_id() :
""));
1000 "Expected a signal or a constant, got something of different");
1001 std::string port_string;
1002 std::string signal_string;
1005 auto* con = GetPointer<constant_o>(sig);
1006 std::string trimmed_value =
"";
1007 auto long_value = std::stoull(con->get_value());
1010 trimmed_value = trimmed_value + (((1LLU << (
GET_TYPE_SIZE(con) - ind - 1)) & long_value) ?
'1' :
'0');
1012 signal_string =
"\"" + trimmed_value +
"\"";
1034 if(GetPointer<port_o>(port)->get_port_direction() == port_o::IN)
1036 std::swap(port_string, signal_string);
1039 if(port_string != signal_string)
1041 const auto left = GetPointer<port_o>(port)->get_port_direction() == port_o::IN ? sig : port;
1042 const auto right = GetPointer<port_o>(port)->get_port_direction() == port_o::IN ? port : sig;
1046 signal_string =
"unsigned(" + signal_string +
")";
1051 signal_string =
"signed(" + signal_string +
")";
1056 signal_string =
"std_logic_vector(" + signal_string +
")";
1061 signal_string =
"" + signal_string +
"(0)";
1066 signal_string = std::string(
"'") + signal_string.at(1) +
"'";
1123 std::string port_string;
1124 std::string signal_string;
1128 if(GetPointer<port_o>(port)->get_port_direction() == port_o::IN)
1130 std::swap(port_string, signal_string);
1133 if(port_string != signal_string)
1135 const auto left = GetPointer<port_o>(port)->get_port_direction() == port_o::IN ? sig : port;
1136 const auto right = GetPointer<port_o>(port)->get_port_direction() == port_o::IN ? port : sig;
1140 signal_string =
"unsigned(" + signal_string +
")";
1145 signal_string =
"signed(" + signal_string +
")";
1150 signal_string =
"std_logic_vector(" + signal_string +
")";
1155 signal_string =
"" + signal_string +
"(0)";
1165 "Expected a component or a channel got something of different");
1166 auto*
mod = GetPointer<module>(cir);
1169 bool first_it =
true;
1174 std::vector<std::string> mem_tag = string_to_container<std::vector<std::string>>(memory_str,
";");
1176 for(
const auto& i : mem_tag)
1178 std::vector<std::string> mem_add = string_to_container<std::vector<std::string>>(i,
"=");
1179 THROW_ASSERT(mem_add.size() == 2,
"malformed address");
1190 std::string name = mem_add[0];
1192 if(mod->get_owner() && GetPointer<module>(mod->get_owner()) &&
1208 std::vector<std::pair<std::string, structural_objectRef>> library_parameters;
1209 mod->get_NP_library_parameters(cir, library_parameters);
1211 for(
const auto& library_parameter : library_parameters)
1223 const std::string& name = library_parameter.first;
1244 "=>" +
STR(GetPointer<port_o>(obj)->get_ports_size()));
1250 const auto parameter = mod->GetParameter(name);
1251 const auto parameter_type = mod->get_parameter_type(
TM, name);
1253 switch(parameter_type)
1257 if(parameter.substr(0, 2) ==
"\"\"")
1269 if(parameter.front() ==
'\"' and parameter.back() ==
'\"')
1274 else if(mod->get_owner())
1276 if(GetPointer<const module>(mod->get_owner()))
1278 if(mod->get_owner()->ExistsParameter(parameter))
1281 const auto actual_parameter_type =
1282 GetPointer<const module>(mod->get_owner())->get_parameter_type(
TM, parameter);
1284 THROW_ASSERT(actual_parameter_type == parameter_type,
"");
1292 std::vector<std::string> mem_tag =
1293 string_to_container<std::vector<std::string>>(memory_str,
";");
1294 for(
const auto& i : mem_tag)
1296 std::vector<std::string> mem_add = string_to_container<std::vector<std::string>>(i,
"=");
1297 THROW_ASSERT(mem_add.size() == 2,
"malformed address");
1299 "---Checking owner memory parameter " + mem_add[0]);
1300 if(mem_add[0] == parameter)
1308 THROW_ASSERT(mod->get_typeRef()->id_type ==
"constant_value",
1309 mod->get_typeRef()->id_type);
1310 THROW_ASSERT(mod->get_out_port_size() == 1,
STR(mod->get_out_port_size()));
1312 name +
"=> std_logic_vector(to_unsigned(" + parameter +
", " +
1342 if(parameter.front() ==
'\"' and parameter.back() ==
'\"')
1344 long long int value = 0;
1345 long long int mult = 1;
1346 for(
const auto digit : boost::adaptors::reverse(parameter.substr(1, parameter.size() - 2)))
1352 else if(digit ==
'0')
1378 THROW_UNREACHABLE(
"Type of parameter " + parameter +
" (" +
STR(parameter_type) +
") not supported");
1396 const std::string&,
const std::string& reset_state,
bool one_hot)
1398 auto it_end = list_of_states.end();
1399 size_t n_states = list_of_states.size();
1402 unsigned max_value = 0;
1403 for(
auto it = list_of_states.begin(); it != it_end; ++it)
1407 if(max_value != n_states - 1)
1413 if(one_hot or ((
parameters->isOption(OPT_generate_vcd) and
parameters->getOption<
bool>(OPT_generate_vcd)) or
1416 for(
const auto& state : list_of_states)
1421 "constant " + state +
": std_logic_vector(" +
STR(max_value) +
" downto 0) := \"" +
1429 "constant " + state +
": std_logic_vector(" +
STR(bitsnumber - 1) +
" downto 0) := \"" +
1436 " downto 0) := " + reset_state +
";\n");
1442 " downto 0) := " + reset_state +
";\n");
1450 unsigned int count = 0;
1451 for(
auto it = list_of_states.begin(); it != it_end; ++it)
1455 if(count != n_states)
1466 const std::string& reset_port,
const std::string& clock_port,
1467 const std::string& reset_type,
bool)
1470 if(reset_type ==
"no" || reset_type ==
"sync")
1477 if(!
parameters->getOption<
bool>(OPT_reset_level))
1499 if(!
parameters->getOption<
bool>(OPT_reset_level))
1521 bool single_proc,
unsigned int output_index,
const structural_objectRef& cir,
const std::string& reset_state,
1522 const std::string& reset_port,
const std::string& start_port,
const std::string& clock_port,
1523 std::vector<std::string>::const_iterator& first, std::vector<std::string>::const_iterator& end,
bool,
1524 const std::map<
unsigned int,
std::map<std::string, std::set<unsigned int>>>& bypass_signals)
1527 auto*
mod = GetPointer<module>(cir);
1528 boost::char_separator<char> state_sep(
":",
nullptr);
1529 boost::char_separator<char> sep(
" ",
nullptr);
1530 using tokenizer = boost::tokenizer<boost::char_separator<char>>;
1534 write_comment(
"concurrent process#" +
STR(output_index) +
": combinational logic\n");
1536 for(
unsigned int i = 0; i <
mod->get_in_port_size(); i++)
1539 if(port_name != clock_port and port_name != reset_port)
1550 std::string default_output;
1551 for(
unsigned int i = 0; i <
mod->get_out_port_size(); i++)
1561 default_output +=
"0";
1562 if(!single_proc && output_index != i)
1569 if(single_proc || output_index ==
mod->get_out_port_size())
1577 for(
auto first_it = first; first_it != end; ++first_it)
1580 tokenizer state_tokens_first(*first_it, state_sep);
1582 tokenizer::const_iterator its = state_tokens_first.begin();
1584 std::string state_description = *its;
1587 std::vector<std::string> state_transitions;
1588 for(; its != state_tokens_first.end(); ++its)
1590 state_transitions.push_back(*its);
1593 tokenizer tokens_curr(state_description, sep);
1595 its = tokens_curr.begin();
1599 std::string current_output = *its;
1602 bool skip_state = !single_proc && output_index !=
mod->get_out_port_size() &&
1603 default_output[output_index] == current_output[output_index];
1604 bool skip_state_transition = !single_proc && output_index !=
mod->get_out_port_size();
1605 if(!single_proc && output_index !=
mod->get_out_port_size())
1607 for(
const auto& current_transition : state_transitions)
1609 tokenizer transition_tokens(current_transition, sep);
1610 tokenizer::const_iterator itt = transition_tokens.begin();
1613 tokenizer::const_iterator current_input_it;
1614 std::string input_string = *itt;
1615 if(
mod->get_in_port_size() - 3)
1617 boost::char_separator<char> comma_sep(
",",
nullptr);
1618 tokenizer current_input_tokens(input_string, comma_sep);
1619 current_input_it = current_input_tokens.begin();
1623 std::string transition_outputs = *itt;
1625 THROW_ASSERT(itt == transition_tokens.end(),
"Bad transition format");
1626 if(transition_outputs[output_index] !=
'-')
1629 skip_state_transition =
false;
1641 if(reset_state == present_state)
1644 for(
unsigned int i = 0; i <
mod->get_out_port_size(); i++)
1654 if(
starts_with(
mod->get_out_port(i)->get_id(),
"selector_MUX") ||
1658 if(single_proc || output_index == i)
1664 if(single_proc || output_index ==
mod->get_out_port_size())
1672 bool unique_transition = (state_transitions.size() == 1);
1673 if(current_output != default_output && (single_proc || !unique_transition || skip_state_transition))
1675 for(
unsigned int i = 0; i <
mod->get_out_port_size(); i++)
1686 if(default_output[i] != current_output[i])
1688 if(single_proc || output_index == i)
1690 switch(current_output[i])
1694 if(bypass_signals.find(i) == bypass_signals.end() ||
1695 bypass_signals.find(i)->second.find(present_state) == bypass_signals.find(i)->second.end())
1702 for(
const auto& stateIns : bypass_signals.find(i)->second)
1704 if(stateIns.first != present_state)
1708 bool first_i =
true;
1709 for(
const auto& in : stateIns.second)
1733 THROW_ERROR(
"Unsupported value in current output");
1741 if(!skip_state_transition)
1743 for(
unsigned int i = 0; i < state_transitions.size(); i++)
1747 tokenizer transition_tokens(state_transitions[i], sep);
1748 tokenizer::const_iterator itt = transition_tokens.begin();
1752 tokenizer::const_iterator current_input_it;
1753 std::string input_string = *itt;
1754 if(
mod->get_in_port_size() - 3)
1756 boost::char_separator<char> comma_sep(
",",
nullptr);
1757 tokenizer current_input_tokens(input_string, comma_sep);
1758 current_input_it = current_input_tokens.begin();
1765 std::string transition_outputs = *itt;
1767 THROW_ASSERT(itt == transition_tokens.end(),
"Bad transition format");
1769 if(!unique_transition)
1776 else if((i + 1) == state_transitions.size())
1784 if((i + 1) < state_transitions.size())
1786 bool first_test =
true;
1787 for(
unsigned int ind = 0; ind <
mod->get_in_port_size(); ind++)
1791 auto port_size =
mod->get_in_port(ind)->get_typeRef()->size;
1792 auto vec_size =
mod->get_in_port(ind)->get_typeRef()->vector_size;
1793 if(port_name != reset_port && port_name != clock_port && port_name != start_port)
1795 std::string in_or_conditions = *current_input_it;
1796 boost::char_separator<char> pipe_sep(
"|",
nullptr);
1797 tokenizer in_or_conditions_tokens(in_or_conditions, pipe_sep);
1798 THROW_ASSERT(in_or_conditions_tokens.begin() != in_or_conditions_tokens.end(),
"");
1800 if((*in_or_conditions_tokens.begin()) !=
"-")
1810 bool first_test_or =
true;
1811 bool need_parenthesis =
false;
1812 std::string res_or_conditions;
1813 for(tokenizer::const_iterator in_or_conditions_tokens_it = in_or_conditions_tokens.begin();
1814 in_or_conditions_tokens_it != in_or_conditions_tokens.end();
1815 ++in_or_conditions_tokens_it)
1817 THROW_ASSERT((*in_or_conditions_tokens_it) !=
"-",
"wrong conditions structure");
1820 res_or_conditions +=
" or ";
1821 need_parenthesis =
true;
1825 first_test_or =
false;
1828 res_or_conditions += port_name;
1829 if((*in_or_conditions_tokens_it)[0] ==
'&')
1831 auto pos = std::stoull((*in_or_conditions_tokens_it).substr(1));
1832 res_or_conditions += std::string(
"(") +
STR(pos) +
") = '1'";
1836 res_or_conditions +=
1837 std::string(
" = ") + ((*in_or_conditions_tokens_it)[0] ==
'-' ?
"-" :
"");
1838 if(port_size > 1 || (port_size == 1 && vec_size > 0))
1840 res_or_conditions +=
1848 res_or_conditions +=
"'" + *in_or_conditions_tokens_it +
"'";
1852 if(need_parenthesis)
1854 res_or_conditions =
"(" + res_or_conditions +
")";
1866 if(single_proc || output_index ==
mod->get_out_port_size())
1870 for(
unsigned int i2 = 0; i2 <
mod->get_out_port_size(); i2++)
1880 if(transition_outputs[i2] !=
'-')
1883 if(single_proc || output_index == i2)
1885 if(transition_outputs[i2] ==
'2')
1889 else if(transition_outputs[i2] ==
'1')
1891 if(bypass_signals.find(i2) == bypass_signals.end() ||
1892 bypass_signals.find(i2)->second.find(present_state) == bypass_signals.find(i2)->second.end())
1899 for(
const auto& stateIns : bypass_signals.find(i2)->second)
1901 if(stateIns.first != present_state)
1905 bool first_i =
true;
1906 for(
const auto& in : stateIns.second)
1934 if(!unique_transition)
1944 if(reset_state == present_state)
1954 for(
unsigned int i = 0; i <
mod->get_out_port_size(); i++)
1964 if(
starts_with(
mod->get_out_port(i)->get_id(),
"selector_MUX") ||
1968 if(single_proc || output_index == i)
1989 auto*
mod = GetPointer<module>(cir);
1992 THROW_ASSERT(np,
"NP Behavioral description is missing for module: " +
1995 THROW_ASSERT(beh_desc !=
"",
"VHDL behavioral description is missing for module: " +
1998 if(!
parameters->getOption<
bool>(OPT_reset_level))
2000 boost::replace_all(beh_desc,
"1RESET_VALUE", std::string(
RESET_PORT_NAME) +
" = '0'");
2004 boost::replace_all(beh_desc,
"1RESET_VALUE", std::string(
RESET_PORT_NAME) +
" = '1'");
2006 if(
parameters->getOption<
bool>(OPT_reg_init_value))
2008 boost::replace_all(beh_desc,
"1INIT_ZERO_VALUEb",
":= '0'");
2009 boost::replace_all(beh_desc,
"1INIT_ZERO_VALUE",
":= (others => '0')");
2013 boost::replace_all(beh_desc,
"1INIT_ZERO_VALUEb",
"");
2014 boost::replace_all(beh_desc,
"1INIT_ZERO_VALUE",
"");
2035 "Expected a component or a channel got something of different");
2036 auto*
mod = GetPointer<module>(cir);
2037 bool first_it =
true;
2043 std::vector<std::string> mem_tag = string_to_container<std::vector<std::string>>(memory_str,
";");
2044 for(
const auto& i : mem_tag)
2046 std::vector<std::string> mem_add = string_to_container<std::vector<std::string>>(i,
"=");
2047 THROW_ASSERT(mem_add.size() == 2,
"malformed address");
2056 std::string name = mem_add[0];
2057 std::string
value = mem_add[1];
2067 std::vector<std::pair<std::string, structural_objectRef>> library_parameters;
2068 mod->get_NP_library_parameters(cir, library_parameters);
2069 if(library_parameters.size() and first_it)
2073 for(
const auto& library_parameter : library_parameters)
2084 const std::string& name = library_parameter.first;
2111 const auto parameter = mod->GetDefaultParameter(name);
2112 const auto parameter_type = mod->get_parameter_type(
TM, name);
2114 "---Parameter " + name +
" has default value " + parameter);
2115 switch(parameter_type)
2168 return keywords.count(boost::to_upper_copy(
id));
2174 "-->Writing builtin component " + component->get_path() +
" of type " +
GET_TYPE_NAME(component));
2175 std::string operand;
2188 const auto mod = GetPointer<const module>(component);
2190 THROW_ASSERT(GetPointer<const port_o>(
mod->get_out_port(0)),
"Not a port");
2191 const auto object_bounded =
2192 GetPointer<const port_o>(
mod->get_out_port(0))->find_bounded_object(component->get_owner());
2193 THROW_ASSERT(object_bounded,
"Object bounded to output not found");
2196 component->get_path() +
" has " +
STR(
mod->get_out_port_size()) +
" output ports");
2198 for(
unsigned int i = 0; i <
mod->get_in_port_size(); i++)
2206 const auto in_object_bounded =
2207 GetPointer<port_o>(
mod->get_in_port(i))->find_bounded_object(component->get_owner());
2212 const auto port = GetPointer<port_o>(
mod->get_in_port(i));
2213 const auto in_object_bounded = port->find_bounded_object(component);
2214 if(in_object_bounded)
2220 auto n_ports = port->get_ports_size();
2221 for(decltype(n_ports) port_index = 0; port_index < n_ports; port_index++)
2223 if(i != 0 or port_index != 0)
2227 const auto vec_in_object_bounded = GetPointer<port_o>(port->get_port(port_index))->find_bounded_object();
2241 "<--Written builtin component " + component->get_path() +
" of type " +
GET_TYPE_NAME(component));
static std::string get_mod_typename(const language_writer *lan, const structural_objectRef &cir)
Returns the module typename taking into account even the flopoco customizations.
void write_library_declaration(const structural_objectRef &cir) override
Write used library.
void write_module_parametrization_decl(const structural_objectRef &cir) override
Write the declaration of the module parameters.
#define PRESENT_STATE_PORT_NAME
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
static std::string convert_to_identifier(const language_writer *writer, const std::string &id)
Converts a generic string to a language compliant identifier.
File containing functions and utilities to support the printing of debug messagges.
#define NEXT_STATE_PORT_NAME
This file contains the structures needed to manage a graph that will represent the state transition g...
const std::string & get_id() const
Return the identifier associated with the structural_object.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
void write_module_parametrization(const structural_objectRef &cir) override
Module can be parametrized with respect different features.
void write_port_decl_header() override
Write the header for port_decl.
int debug_level
debugging level of the class
static const std::set< std::string > keywords
This class defines the methods to write VHDL descriptions.
void write_vector_port_binding(const structural_objectRef &port, bool first_port_analyzed) override
std::string get_NP_functionality(NP_functionaly_type type) const
Return the description provided the type.
void Indent()
Manually increase the indenting of the code.
void write_module_instance_begin(const structural_objectRef &cir, const std::string &module_name, bool write_parametrization) override
Write the initial part of the instance of a module.
~VHDL_writer() override
Destructor.
std::string type_converter(structural_type_descriptorRef Type) override
Return a language based type string given a structural_type_descriptor.
exceptions managed by PandA
void write_transition_output_functions(bool single_proc, unsigned int output_index, const structural_objectRef &cir, const std::string &reset_state, const std::string &reset_port, const std::string &start_port, const std::string &clock_port, std::vector< std::string >::const_iterator &first, std::vector< std::string >::const_iterator &end, bool, const std::map< unsigned int, std::map< std::string, std::set< unsigned int >>> &bypass_signals) override
Write the transition and output functions.
Class to print indented code.
const IndentedOutputStreamRef indented_output_stream
Represents the stream we are currently writing to.
std::string NumberToBinaryString(const T number, const size_t precision=0)
Function which print number in binary format.
void write_module_internal_declaration(const structural_objectRef &cir) override
Write the declaration of internal objects of the module.
VHDL_writer(const technology_managerConstRef TM, const ParameterConstRef parameters)
Constructor.
void write_module_instance_end(const structural_objectRef &cir) override
Write the ending part of the instance of a module.
#define GET_TYPE_NAME(structural_obj)
Macro returning the string name of a type.
#define STR(s)
Macro which performs a lexical_cast to a string.
void write_module_declaration(const structural_objectRef &cir) override
Write the declaration of the module.
Auxiliary methods for manipulating string.
s_type type
The type of the port or the signal.
port_direction
Enumerative type describing the direction of a port.
unsigned long long size
The size of the object (in bit). The objects having a size are: ports, signals, channels, data, and actions.
void write_io_signal_post_fix(const structural_objectRef &port, const structural_objectRef &sig) override
Write some code managing primary ports to signals connections.
virtual std::string get_kind_text() const =0
Virtual function used to get the string name of a structural_object instance.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
bool starts_with(const std::string &str, const std::string &pattern)
void write_header() override
Write the header of vhdl file.
s_type
Define the possible type of a structural object.
unsigned map[NUM_VERTICES]
void write_comment(const std::string &comment_string) override
Print a comment.
void Append(const std::string &str)
Append a string to the output.
Class specification of the data structures used to manage technology information. ...
const std::string get_path() const
Return a unique identifier of the structural object.
void write_state_declaration(const structural_objectRef &cir, const std::list< std::string > &list_of_states, const std::string &reset_port, const std::string &reset_state, bool one_hot) override
write the declaration of all the states of the finite state machine.
virtual enum so_kind get_kind() const =0
Virtual function used to find the real type of a structural_object instance.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
#define STD_OPENING_CHAR
STD include.
static bool check_keyword_vhdl(const std::string &id)
void WriteBuiltin(const structural_objectConstRef component) override
Write a builtin component.
void write_component_declaration(const structural_objectRef &cir) override
Write the declaration of a component.
void write_assign(const std::string &op0, const std::string &op1) override
#define GET_TYPE_SIZE(structural_obj)
Macro returning the size of the type of a structural object.
void write_io_signal_post_fix_vector(const structural_objectRef &port, const structural_objectRef &sig) override
std::string id_type
Original type id of the structural object.
void write_present_state_update(const structural_objectRef cir, const std::string &reset_state, const std::string &reset_port, const std::string &clock_port, const std::string &reset_type, bool connect_present_next_state_signals) override
write the present_state update process
This class describes all classes used to represent a structural object.
const structural_type_descriptorRef & get_typeRef() const
Return the type descriptor of the structural_object.
std::string encode_one_hot(unsigned int n_states, unsigned int val) const
#define STATE_NAME_PREFIX
state name prefix
void write_port_decl_tail() override
Write the tail for port_decl.
const structural_objectRef get_owner() const
Return the owner.
std::string type_converter_size(const structural_objectRef &cir) override
Return a language based type string given a structural_type_descriptor for the range of the array...
CustomOrderedSet< std::string > list_of_comp_already_def
static unsigned int bitnumber(unsigned long long n)
Counts the number of bits in an unsigned int.
const ParameterConstRef parameters
the set of input parameters
void write_module_definition_end(const structural_objectRef &cir) override
Write the end part in a module declaration.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
HDL writer base class used to specify the interface of the different language writers.
this class is used to manage the command-line or XML options.
Not parsed functionality manager.
void Deindent()
Manually reduce the indenting of the code.
void write_port_binding(const structural_objectRef &port, const structural_objectRef &object_bounded, bool first_port_analyzed) override
Write the binding of a port.
void write_signal_declaration(const structural_objectRef &cir) override
Write the declaration of a signal.
const technology_managerConstRef TM
The technology manager.
This class writes different HDL based descriptions (VHDL, Verilog, SystemC) starting from a structura...
std::string may_slice_string(const structural_objectRef &cir)
return the slice in case of a port owned by a port vector
void print(std::ostream &os) const
function that prints the class.
bool check_keyword(const std::string &) const override
void write_module_definition_begin(const structural_objectRef &cir) override
Write the top constructor declaration.
const std::string get_name() const
Returns the name of the type descriptor.
void write_NP_functionalities(const structural_objectRef &cir) override
Write in the proper language the behavioral description of the module described in "Not Parsed" form...
void write_port_declaration(const structural_objectRef &cir, bool last_port_to_analyze) override
Write the port declaration starting from a port object.
unsigned long long vector_size
The number of the elements of a vector.
#define STD_GET_SIZE(structural_obj)
Macro returning the size of a type.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...