PandA-2024.02
hls_instruction_writer.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) 2004-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 "application_manager.hpp"
49 #include "behavioral_helper.hpp"
50 #include "c_writer.hpp"
51 #include "function_behavior.hpp"
52 #include "hls_manager.hpp"
54 #include "tree_helper.hpp"
55 #include "tree_manager.hpp"
56 #include "tree_node.hpp"
57 #include "tree_reindex.hpp"
58 #include "utility.hpp"
59 #include "var_pp_functor.hpp"
60 
61 #include <regex>
62 
64  const IndentedOutputStreamRef _indented_output_stream,
65  const ParameterConstRef _parameters)
66  : InstructionWriter(_app_man, _indented_output_stream, _parameters)
67 {
68 }
69 
71 
72 void HLSInstructionWriter::declareFunction(const unsigned int function_id)
73 {
74  // All I have to do is to change main in _main
75  const auto TM = AppM->get_tree_manager();
76  const auto FB = AppM->CGetFunctionBehavior(function_id);
77  const auto BH = FB->CGetBehavioralHelper();
78  const auto fname = BH->GetMangledFunctionName();
79  auto fdecl = tree_helper::PrintType(TM, TM->CGetTreeReindex(function_id), false, true, false, nullptr,
81 
82  const auto HLSMgr = GetPointer<const HLS_manager>(AppM);
83  if(HLSMgr)
84  {
85  const auto func_arch = HLSMgr->module_arch->GetArchitecture(fname);
86  if(func_arch)
87  {
88  THROW_ASSERT(func_arch, "Expected interface architecture for function " + fname);
89  const auto parm_original_typename = [&]() -> std::vector<std::string> {
90  std::vector<std::string> parm_ot(func_arch->parms.size(), "");
91  for(auto& [parm, attrs] : func_arch->parms)
92  {
93  const auto idx = std::strtoul(attrs.at(FunctionArchitecture::parm_index).c_str(), nullptr, 10);
94  parm_ot[idx] = attrs.at(FunctionArchitecture::parm_original_typename);
95  }
96  return parm_ot;
97  }();
98  const std::regex param_match("[^,(]+\\s(\\w+)\\s*([,)]\\s?)");
99  auto param_idx = 0U;
100  auto it = fdecl.cbegin();
101  std::string if_fdecl;
102  std::smatch match;
103  while(std::regex_search(it, fdecl.cend(), match, param_match))
104  {
105  THROW_ASSERT(param_idx < parm_original_typename.size(), "Too many parameters matched.");
106  it += match.position() + match.length();
107  if_fdecl += match.prefix();
108  if_fdecl += parm_original_typename.at(param_idx++) + " ";
109  if_fdecl += match[1];
110  if_fdecl += match[2];
111  }
112  THROW_ASSERT(param_idx == parm_original_typename.size(), "Expected to match all parameter declarations.");
113  if(param_idx)
114  {
115  fdecl = if_fdecl;
116  }
117  }
118  }
119  if(fname == "main")
120  {
121  boost::replace_all(fdecl, " main(", " _main(");
122  }
124 
126 }
Data structure representing the entire HLS information.
Definition of the class representing a generic C application.
score match(base b1, base b2)
void declareFunction(const unsigned int function_id) override
Write the declaration of a function.
Class to print indented code.
Simple class to print single instruction.
~HLSInstructionWriter() override
Destructor.
Standard functor that returns the name of a variable.
void Append(const std::string &str)
Append a string to the output.
Classes specification of the tree_node data structures.
This file collects some utility functions and macros.
const application_managerConstRef AppM
The application manager.
This file collects some utility functions.
const IndentedOutputStreamRef indented_output_stream
The indented output stream.
Class specification of the tree_reindex support class.
static std::string PrintType(const tree_managerConstRef &TM, const tree_nodeConstRef &type, bool global=false, bool print_qualifiers=false, bool print_storage=false, const tree_nodeConstRef &var=nullptr, const var_pp_functorConstRef &vppf=var_pp_functorConstRef(), const std::string &prefix="", const std::string &tail="")
Print a type and its variable in case var is not zero.
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.
This file contains the routines necessary to create a C executable program.
HLSInstructionWriter(const application_managerConstRef app_man, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef parameters)
Constructor.
refcount< const var_pp_functor > var_pp_functorConstRef
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
#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:51 for PandA-2024.02 by doxygen 1.8.13