PandA-2024.02
TestbenchArrayModuleGenerator.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  */
46 
47 #include "Parameter.hpp"
48 #include "behavioral_helper.hpp"
49 #include "function_behavior.hpp"
50 #include "hls_manager.hpp"
51 #include "language_writer.hpp"
52 #include "math_function.hpp"
53 #include "structural_manager.hpp"
54 #include "tree_helper.hpp"
55 #include "utility.hpp"
56 
58 {
59 }
60 
62  unsigned int function_id, vertex /* op_v */,
63  const HDLWriter_Language language,
64  const std::vector<ModuleGenerator::parameter>& /* _p */,
65  const std::vector<ModuleGenerator::parameter>& /* _ports_in */,
66  const std::vector<ModuleGenerator::parameter>& /* _ports_out */,
67  const std::vector<ModuleGenerator::parameter>& /* _ports_inout */)
68 {
69  if(language != HDLWriter_Language::VERILOG)
70  {
71  THROW_UNREACHABLE("Unsupported output language");
72  return;
73  }
74 
75  const auto arg_name = mod_cir->get_id().substr(sizeof("if_array_") - 1U, std::string::npos);
76 
77  const auto top_bh = HLSMgr->CGetFunctionBehavior(function_id)->CGetBehavioralHelper();
78  const auto top_fname = top_bh->GetMangledFunctionName();
79  const auto& iface_attrs = HLSMgr->module_arch->GetArchitecture(top_fname)->ifaces.at(arg_name);
80  const auto if_dir = port_o::to_port_direction(iface_attrs.at(FunctionArchitecture::iface_direction));
81  const auto n_channels = HLSMgr->get_parameter()->getOption<unsigned int>(OPT_channels_number);
82 
83  std::string np_library = mod_cir->get_id() + " index WRITE_DELAY READ_DELAY";
84  const auto add_port_parametric = [&](unsigned idx, const std::string& name, port_o::port_direction dir,
85  unsigned port_size) {
86  const auto port_name = arg_name + "_" + name + STR(idx);
87  structural_manager::add_port(port_name, dir, mod_cir,
89  np_library += " " + port_name;
90  return port_name;
91  };
92  std::vector<std::string> ce, we, address, d, q;
93  for(unsigned i = 0; i < n_channels; ++i)
94  {
95  address.push_back(add_port_parametric(i, "address", port_o::IN, 1U));
96  ce.push_back(add_port_parametric(i, "ce", port_o::IN, 0U));
97  if(if_dir != port_o::IN)
98  {
99  we.push_back(add_port_parametric(i, "we", port_o::IN, 0U));
100  d.push_back(add_port_parametric(i, "d", port_o::IN, 1U));
101  }
102  else
103  {
104  we.push_back("1'b0");
105  d.push_back("{BITSIZE_dq{1'b0}}");
106  }
107  if(if_dir != port_o::OUT)
108  {
109  q.push_back(add_port_parametric(i, "q", port_o::OUT, 1U));
110  }
111  }
113 
114  out << "localparam CHANNELS_NUMBER=" << n_channels << ",\n"
115  << " BITSIZE_address=BITSIZE_" << arg_name << "_address0,\n"
116  << " BITSIZE_dq=BITSIZE_" << arg_name << (if_dir == port_o::IN ? "_q0" : "_d0") << ";\n\n";
117 
118  out << "TestbenchArrayImpl #(.index(index),\n"
119  << " .WRITE_DELAY(WRITE_DELAY),\n"
120  << " .READ_DELAY(READ_DELAY),\n"
121  << " .PORTSIZE_address(CHANNELS_NUMBER),\n"
122  << " .BITSIZE_address(BITSIZE_address),\n"
123  << " .PORTSIZE_ce(CHANNELS_NUMBER),\n"
124  << " .PORTSIZE_we(CHANNELS_NUMBER),\n"
125  << " .PORTSIZE_d(CHANNELS_NUMBER),\n"
126  << " .BITSIZE_d(BITSIZE_dq),\n"
127  << " .PORTSIZE_q(CHANNELS_NUMBER),\n"
128  << " .BITSIZE_q(BITSIZE_dq)) array_impl(.clock(clock),\n"
129  << " .setup_port(setup_port),\n"
130  << " .ce({" << container_to_string(ce, ",") << "}),\n"
131  << " .we({" << container_to_string(we, ",") << "}),\n"
132  << " .address({" << container_to_string(address, ",") << "}),\n"
133  << " .d({" << container_to_string(d, ",") << "})";
134  if(q.size())
135  {
136  out << ",\n .q({" << container_to_string(q, ",") << "})";
137  }
138  out << ");\n";
139 }
Data structure representing the entire HLS information.
refcount< structural_type_descriptor > structural_type_descriptorRef
RefCount type definition of the structural_type_descriptor class structure.
Structure representing the most relevant information about the type of a structural object...
const std::string & get_id() const
Return the identifier associated with the structural_object.
mathematical utility function not provided by standard libraries
#define STR(s)
Macro which performs a lexical_cast to a string.
HDLWriter_Language
port_direction
Enumerative type describing the direction of a port.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
static void add_NP_functionality(structural_objectRef cir, NP_functionality::NP_functionaly_type dt, std::string functionality_description)
Add a not-parsed functionality.
This class writes different HDL based descriptions (VHDL, Verilog, SystemC) starting from a structura...
static port_direction to_port_direction(const std::string &val)
Convert a string into the corresponding port_direction enumerative type.
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.
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
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
This file collects some utility functions and macros.
This file collects some utility functions.
TestbenchArrayModuleGenerator(const HLS_managerRef &HLSMgr)
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
this class is used to manage the command-line or XML options.
std::string container_to_string(_InputIt first, _InputIt last, const std::string &separator, bool trim_empty=true)
Definition: utility.hpp:122
Class implementation of the structural_manager.
A brief description of the C++ Header File.

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