PandA-2024.02
ASMModuleGenerator.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) 2022-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  */
48 #include "ASMModuleGenerator.hpp"
49 
50 #include "behavioral_helper.hpp"
51 #include "function_behavior.hpp"
52 #include "hls_manager.hpp"
53 #include "language_writer.hpp"
54 #include "op_graph.hpp"
55 
56 #include <boost/algorithm/string/replace.hpp>
57 
58 ASMModuleGenerator::ASMModuleGenerator(const HLS_managerRef& _HLSMgr) : Registrar(_HLSMgr)
59 {
60 }
61 
62 void ASMModuleGenerator::InternalExec(std::ostream& out, structural_objectRef /* mod */, unsigned int function_id,
63  vertex op_v, 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  const auto FB = HLSMgr->CGetFunctionBehavior(function_id);
70  const auto cfg = FB->CGetOpGraph(FunctionBehavior::CFG);
71  std::string asm_string = FB->CGetBehavioralHelper()->get_asm_string(cfg->CGetOpNodeInfo(op_v)->GetNodeId());
72  boost::replace_all(asm_string, "%%", "&percent;");
73  boost::replace_all(asm_string, "&percent;", "%");
74  boost::replace_all(asm_string, "\\n", "\n");
75  boost::replace_all(asm_string, "\\\"", "\"");
76  boost::replace_all(asm_string, "\\\'", "\'");
77 
78  if(asm_string.empty())
79  {
80  out << "assign done_port = start_port;\n";
81  }
82  else
83  {
84  if(language == HDLWriter_Language::VHDL)
85  {
86  out << "begin\n";
87  }
89  auto open_curl = false;
90  auto count_pipes = 0U;
91  const auto skip_count = language == HDLWriter_Language::VHDL ? 3U : 2U;
92  char prec_char = '\0';
93  for(auto i = 0U; i < asm_string.size(); ++i)
94  {
95  const auto& current_char = asm_string[i];
96  if(current_char == '{' && prec_char != '%')
97  {
98  open_curl = true;
99  }
100  else if(current_char == '}' && prec_char != '%')
101  {
102  open_curl = false;
103  count_pipes = 0U;
104  }
105  else if(open_curl && current_char == '|' && prec_char != '%')
106  {
107  ++count_pipes;
108  }
109  else if(open_curl && count_pipes != skip_count)
110  {
111  }
112  else if(open_curl && count_pipes == skip_count)
113  {
114  out << current_char;
115  }
116  else
117  {
118  out << current_char;
119  }
120  prec_char = current_char;
121  }
122  out << "\n";
123  }
124 }
Data structure representing the entire HLS information.
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
HDLWriter_Language
Control flow graph.
This class writes different HDL based descriptions (VHDL, Verilog, SystemC) starting from a structura...
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
ASMModuleGenerator(const HLS_managerRef &HLSMgr)
Data structures used in operations graph.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
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