PandA-2024.02
TestbenchFifoModuleGenerator.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 "behavioral_helper.hpp"
47 #include "function_behavior.hpp"
48 #include "hls_manager.hpp"
49 #include "language_writer.hpp"
50 #include "structural_manager.hpp"
51 #include "tree_helper.hpp"
52 #include "tree_manager.hpp"
53 #include "utility.hpp"
54 
56 {
57 }
58 
60  unsigned int function_id, vertex /* op_v */,
61  const HDLWriter_Language language,
62  const std::vector<ModuleGenerator::parameter>& /* _p */,
63  const std::vector<ModuleGenerator::parameter>& /* _ports_in */,
64  const std::vector<ModuleGenerator::parameter>& /* _ports_out */,
65  const std::vector<ModuleGenerator::parameter>& /* _ports_inout */)
66 {
67  if(language != HDLWriter_Language::VERILOG)
68  {
69  THROW_UNREACHABLE("Unsupported output language");
70  return;
71  }
72 
73  const auto arg_name = mod_cir->get_id().substr(sizeof("if_fifo_") - 1U, std::string::npos);
74 
75  const auto top_bh = HLSMgr->CGetFunctionBehavior(function_id)->CGetBehavioralHelper();
76  const auto top_fname = top_bh->GetMangledFunctionName();
77  const auto top_fnode = HLSMgr->get_tree_manager()->CGetTreeReindex(function_id);
78  const auto& iface_attrs = HLSMgr->module_arch->GetArchitecture(top_fname)->ifaces.at(arg_name);
79  const auto if_dir = port_o::to_port_direction(iface_attrs.at(FunctionArchitecture::iface_direction));
80  const auto if_alignment = iface_attrs.at(FunctionArchitecture::iface_alignment);
81  const auto if_ndir = if_dir == port_o::IN ? port_o::OUT : port_o::IN;
82  std::string np_library = mod_cir->get_id() + " index";
83  std::vector<std::string> ip_components;
84  const auto addPort = [&](const std::string& port_name, port_o::port_direction dir, unsigned port_size,
85  bool isParametric = false) {
86  structural_manager::add_port(port_name, dir, mod_cir,
88  if(isParametric)
89  {
90  np_library += " " + port_name;
91  }
92  };
93  out << "localparam BITSIZE_data=BITSIZE_" << arg_name << ((if_dir == port_o::IN) ? "_dout" : "_din") << ";\n";
94 
95  if(if_dir == port_o::IN)
96  {
97  addPort(arg_name + "_dout", if_ndir, 1U, true);
98  addPort(arg_name + "_empty_n", if_ndir, 0U);
99  addPort(arg_name + "_read", if_dir, 0U);
100  ip_components.push_back("TestbenchFifoRead");
101  out << "assign tb_done_port = 1'b1;\n\n"
102  << "TestbenchFifoRead #(.index(index),\n"
103  << " .CHECK_ACK(1),\n"
104  << " .BITSIZE_dout(BITSIZE_data)) fifo_read(.clock(clock),\n"
105  << " .setup_port(setup_port),\n"
106  << " .done_port(done_port),\n"
107  << " .empty_n(" << arg_name << "_empty_n),\n"
108  << " .read(" << arg_name << "_read),\n"
109  << " .dout(" << arg_name << "_dout));\n";
110  }
111  else if(if_dir == port_o::OUT)
112  {
113  addPort(arg_name + "_din", if_ndir, 1U, true);
114  addPort(arg_name + "_full_n", if_dir, 0U);
115  addPort(arg_name + "_write", if_ndir, 0U);
116  ip_components.push_back("TestbenchFifoWrite");
117  out << "wire _full_n;\n\n"
118  << "assign " << arg_name << "_full_n = _full_n;\n"
119  << "assign tb_done_port = ~_full_n;\n\n"
120  << "TestbenchFifoWrite #(.index(index),\n"
121  << " .BITSIZE_din(BITSIZE_data)) fifo_write(.clock(clock),\n"
122  << " .setup_port(setup_port),\n"
123  << " .done_port(done_port),\n"
124  << " .full_n(_full_n),\n"
125  << " .write(" << arg_name << "_write),\n"
126  << " .din(" << arg_name << "_din));\n";
127  }
128  else
129  {
130  THROW_UNREACHABLE("Unknown FIFO interface port direction: " + port_o::GetString(if_dir));
131  }
133  container_to_string(ip_components, ","));
135 }
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.
static std::string GetString(enum port_direction)
TestbenchFifoModuleGenerator(const HLS_managerRef &HLSMgr)
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.
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.
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
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
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.
Class specification of the manager of the tree structures extracted from the raw file.
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