PandA-2024.02
TestbenchDUTModuleGenerator.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2023-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
45 
46 #include "Parameter.hpp"
47 #include "behavioral_helper.hpp"
48 #include "hls.hpp"
49 #include "hls_manager.hpp"
50 #include "hls_step.hpp"
51 #include "language_writer.hpp"
52 #include "structural_manager.hpp"
53 #include "verilog_writer.hpp"
54 
55 #include <set>
56 #include <string>
57 #include <vector>
58 
60 {
61 }
62 
63 void TestbenchDUTModuleGenerator::InternalExec(std::ostream& out, structural_objectRef dut_cir, unsigned int top_id,
64  vertex /* op_v */, const HDLWriter_Language language,
65  const std::vector<ModuleGenerator::parameter>& /* _p */,
66  const std::vector<ModuleGenerator::parameter>& /* _ports_in */,
67  const std::vector<ModuleGenerator::parameter>& /* _ports_out */,
68  const std::vector<ModuleGenerator::parameter>& /* _ports_inout */)
69 {
70  if(language != HDLWriter_Language::VERILOG)
71  {
72  THROW_UNREACHABLE("Unsupported output language");
73  return;
74  }
75 
76  const auto top = HLSMgr->get_HLS(top_id)->top;
77  const auto top_cir = top->get_circ();
78  const auto top_mod = GetPointer<module>(top_cir);
79  THROW_ASSERT(top_mod, "");
80  const auto parameters = HLSMgr->get_parameter();
81  const auto interface_type = parameters->getOption<HLSFlowStep_Type>(OPT_interface_type);
82  const auto memory_mapped_top = parameters->getOption<bool>(OPT_memory_mapped_top);
83 
84  std::string signals, modules;
85  std::set<std::string> internal_ports;
86  const auto escape_keyword = [&](const std::string& str) -> std::string {
88  {
89  return "\\" + str + " ";
90  }
91  return str;
92  };
93 
94  if(memory_mapped_top)
95  {
96  if(interface_type == HLSFlowStep_Type::WB4_INTERFACE_GENERATION)
97  {
98  structural_manager::add_port(DONE_PORT_NAME, port_o::port_direction::OUT, dut_cir,
100  signals += "wire irq;\n";
101  modules += "assign done_port = irq;\n\n";
102  internal_ports.insert("irq");
103  }
104  else if(interface_type == HLSFlowStep_Type::MINIMAL_INTERFACE_GENERATION)
105  {
106  }
107  else
108  {
109  THROW_ERROR("Interface type not supported for memory mapped top simulation.");
110  }
111 
112  // Dummy start port
113  structural_manager::add_port(START_PORT_NAME, port_o::port_direction::IN, dut_cir,
115  }
116 
117  const auto mod_id = escape_keyword(top_mod->get_id());
118  std::string dut_body = mod_id + " top(";
119  const auto port_count = top_mod->get_num_ports();
120  for(auto i = 0U; i < port_count; ++i)
121  {
122  const auto top_port = GetPointerS<port_o>(top_mod->get_positional_port(i));
123  const auto port_id = top_port->get_id();
124  if(!internal_ports.count(port_id))
125  {
126  const auto port_bitsize = GET_TYPE_SIZE(top_port);
127  const auto port_size = [&]() {
128  if(top_port->get_id() == CLOCK_PORT_NAME || top_port->get_id() == RESET_PORT_NAME ||
129  top_port->get_id() == START_PORT_NAME || top_port->get_id() == DONE_PORT_NAME)
130  {
131  return 0ULL;
132  }
133  return top_port->get_kind() == port_vector_o_K ? (port_bitsize * top_port->get_ports_size()) : port_bitsize;
134  }();
135  structural_manager::add_port(port_id, top_port->get_port_direction(), dut_cir,
137  }
138  dut_body += "\n ." + escape_keyword(port_id) + "(" + escape_keyword(port_id) + "),";
139  }
140  dut_body.pop_back();
141  dut_body += ");\n";
142 
143  out << signals << "\n" << modules << "\n" << dut_body;
144 }
Data structure representing the entire HLS information.
void * top(node_stack *head)
Definition: tree.c:75
refcount< structural_type_descriptor > structural_type_descriptorRef
RefCount type definition of the structural_type_descriptor class structure.
#define START_PORT_NAME
Structure representing the most relevant information about the type of a structural object...
TestbenchDUTModuleGenerator(const HLS_managerRef &HLSMgr)
HDLWriter_Language
#define CLOCK_PORT_NAME
standard name for ports
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
Class for system verilog writing.
#define DONE_PORT_NAME
HLSFlowStep_Type
Definition: hls_step.hpp:95
This class writes different HDL based descriptions (VHDL, Verilog, SystemC) starting from a structura...
static structural_objectRef add_port(const std::string &id, port_o::port_direction pdir, structural_objectRef owner, structural_type_descriptorRef type_descr, unsigned int treenode=0)
Create a new port.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
#define GET_TYPE_SIZE(structural_obj)
Macro returning the size of the type of a structural object.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
char str[25]
Definition: fixedptc.c:8
static bool check_keyword_verilog(const std::string &word)
void InternalExec(std::ostream &out, structural_objectRef mod, unsigned int function_id, vertex op_v, const HDLWriter_Language language, const std::vector< ModuleGenerator::parameter > &_p, const std::vector< ModuleGenerator::parameter > &_ports_in, const std::vector< ModuleGenerator::parameter > &_ports_out, const std::vector< ModuleGenerator::parameter > &_ports_inout) final
this class is used to manage the command-line or XML options.
#define RESET_PORT_NAME
Class implementation of the structural_manager.
Data structure definition for high-level synthesis flow.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

Generated on Mon Feb 12 2024 13:02:54 for PandA-2024.02 by doxygen 1.8.13