PandA-2024.02
hdl_var_decl_fix.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) 2015-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  */
40 #include "hdl_var_decl_fix.hpp"
41 
42 #include "Parameter.hpp"
43 #include "application_manager.hpp"
44 #include "behavioral_helper.hpp"
45 #include "function_behavior.hpp"
46 #include "hls_device.hpp"
47 #include "hls_manager.hpp"
48 #include "language_writer.hpp"
49 #include "string_manipulation.hpp"
50 #include "tree_helper.hpp"
51 #include "tree_manager.hpp"
52 #include "tree_node.hpp"
53 #include "tree_reindex.hpp"
54 
55 #include <boost/algorithm/string.hpp>
56 
57 HDLVarDeclFix::HDLVarDeclFix(const application_managerRef _AppM, unsigned int _function_id,
58  const DesignFlowManagerConstRef _design_flow_manager, const ParameterConstRef _parameters)
59  : VarDeclFix(_AppM, _function_id, _design_flow_manager, _parameters, HDL_VAR_DECL_FIX),
60  hdl_writer_type(static_cast<HDLWriter_Language>(parameters->getOption<unsigned int>(OPT_writer_language)))
61 {
62  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
63 }
64 
66 
68 {
69  const tree_managerRef TM = AppM->get_tree_manager();
71  CustomUnorderedSet<unsigned int> already_examinated_decls;
72 
74  CustomUnorderedSet<std::string> already_examinated_names;
75 
77  CustomUnorderedSet<std::string> already_examinated_type_names;
78 
80  CustomUnorderedSet<unsigned int> already_visited_ae;
81 
83  const auto hdl_writer = language_writer::create_writer(
84  hdl_writer_type, GetPointer<HLS_manager>(AppM)->get_HLS_device()->get_technology_manager(), parameters);
85  const auto hdl_reserved_names = hdl_writer->GetHDLReservedNames();
86  already_examinated_names.insert(hdl_reserved_names.begin(), hdl_reserved_names.end());
87 
89  already_examinated_names.insert(std::string("this"));
90 
92  already_examinated_names.insert(Normalize(function_behavior->CGetBehavioralHelper()->get_function_name()));
93 
95  const tree_nodeRef curr_tn = TM->GetTreeNode(function_id);
96  auto* fd = GetPointer<function_decl>(curr_tn);
97  const auto fname = tree_helper::GetMangledFunctionName(fd);
98  const auto HLSMgr = GetPointer<HLS_manager>(AppM);
99 
100  for(const auto& arg : fd->list_of_args)
101  {
102  auto a = GetPointer<parm_decl>(GET_NODE(arg));
103  auto argName = GET_NODE(a->name);
104  THROW_ASSERT(GetPointer<identifier_node>(argName), "unexpected condition");
105  const std::string parm_name = GetPointer<identifier_node>(argName)->strg;
106  recursive_examinate(arg, already_examinated_decls, already_examinated_names, already_examinated_type_names,
107  already_visited_ae);
108  if(HLSMgr)
109  {
110  argName = GET_NODE(a->name);
111  THROW_ASSERT(GetPointer<identifier_node>(argName), "unexpected condition");
112  const std::string parm_name_new = GetPointer<identifier_node>(argName)->strg;
113  const auto func_arch = HLSMgr->module_arch->GetArchitecture(fname);
114  if(func_arch && parm_name != parm_name_new)
115  {
116  const auto parm_it = func_arch->parms.find(parm_name);
117  if(parm_it != func_arch->parms.end())
118  {
119  func_arch->parms[parm_name_new] = parm_it->second;
120  func_arch->parms.erase(parm_it);
121 
122  if(HLSMgr->design_interface_io.find(fname) != HLSMgr->design_interface_io.end())
123  {
124  for(auto& [bbi, ioOps] : HLSMgr->design_interface_io.find(fname)->second)
125  {
126  const auto it = ioOps.find(parm_name);
127  if(it != ioOps.end())
128  {
129  ioOps[parm_name_new] = it->second;
130  ioOps.erase(it);
131  }
132  }
133  }
134  }
135  }
136  }
137  }
138 
139  return VarDeclFix::InternalExec();
140 }
141 
142 const std::string HDLVarDeclFix::Normalize(const std::string& identifier) const
143 {
144  return hdl_writer_type == HDLWriter_Language::VHDL ? boost::to_upper_copy<std::string>(identifier) : identifier;
145 }
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:343
DesignFlowStep_Status InternalExec() override
Fixes the var_decl duplication.
Data structure representing the entire HLS information.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
HDLVarDeclFix(const application_managerRef AppM, unsigned int _function_id, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
static language_writerRef create_writer(HDLWriter_Language language, const technology_managerConstRef TM, const ParameterConstRef parameters)
Creates the specialization of the writer based on the desired language.
Pre-analysis step.
const HDLWriter_Language hdl_writer_type
The hdl language.
static std::string GetMangledFunctionName(const function_decl *fd)
Return the mangled function name.
Auxiliary methods for manipulating string.
HDLWriter_Language
This class writes different HDL based descriptions (VHDL, Verilog, SystemC) starting from a structura...
Classes specification of the tree_node data structures.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
This file collects some utility functions.
tree_nodeRef GetTreeNode(const unsigned int index) const
Return the index-th tree_node (modifiable version)
Pre-analysis step fixing var_decl duplication and HDL name conflicts.
const unsigned int function_id
The index of the function to be analyzed.
const application_managerRef AppM
The application manager.
Class specification of the tree_reindex support class.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
void recursive_examinate(const tree_nodeRef &tn, CustomUnorderedSet< unsigned int > &already_examinated_decls, CustomUnorderedSet< std::string > &already_examinated_names, CustomUnorderedSet< std::string > &already_examinated_type_names, CustomUnorderedSet< unsigned int > &already_visited_ae)
Recursive examinate tree node.
DesignFlowStep_Status InternalExec() override
Fixes the var_decl duplication.
this class is used to manage the command-line or XML options.
const std::string Normalize(const std::string &identifier) const override
Return the normalized identifier; in this class it is the identifier itself.
int debug_level
The debug level.
~HDLVarDeclFix() override
Destructor.
Class specification of the manager of the tree structures extracted from the raw file.
HLS specialization of generic_device.
A brief description of the C++ Header File.
const FunctionBehaviorRef function_behavior
The function behavior of the function to be analyzed.
#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:52 for PandA-2024.02 by doxygen 1.8.13