PandA-2024.02
hdl_function_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  */
43 
45 #include "Parameter.hpp"
46 
48 #include "application_manager.hpp"
49 
51 #include "language_writer.hpp"
52 
54 #include "hls_device.hpp"
55 #include "hls_manager.hpp"
56 
58 #include "token_interface.hpp"
59 
61 #include "tree_manager.hpp"
62 #include "tree_manipulation.hpp"
63 #include "tree_node.hpp"
64 #include "tree_reindex.hpp"
65 
66 #include "string_manipulation.hpp" // for GET_CLASS
67 
69  const DesignFlowManagerConstRef _design_flow_manager,
70  const ParameterConstRef _parameters)
71  : ApplicationFrontendFlowStep(_AppM, HDL_FUNCTION_DECL_FIX, _design_flow_manager, _parameters)
72 {
73  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
74 }
75 
77 
79 {
80  bool changed_tree = false;
81  const tree_managerRef TM = AppM->get_tree_manager();
82  const auto hdl_writer_type =
83  static_cast<HDLWriter_Language>(parameters->getOption<unsigned int>(OPT_writer_language));
84  const auto hdl_writer = language_writer::create_writer(
85  hdl_writer_type, GetPointer<HLS_manager>(AppM)->get_HLS_device()->get_technology_manager(), parameters);
86  const auto hdl_reserved_names = hdl_writer->GetHDLReservedNames();
88  if(hdl_writer_type == HDLWriter_Language::VHDL)
89  {
90  for(const auto& hdl_reserved_name : hdl_reserved_names)
91  {
92  found_names.insert(boost::to_upper_copy<std::string>(hdl_reserved_name));
93  }
94  }
95  else
96  {
97  found_names = hdl_reserved_names;
98  }
99 
100  for(const auto function : TM->GetAllFunctions())
101  {
102  auto fd = GetPointer<function_decl>(TM->get_tree_node_const(function));
103  if(not fd->name)
104  {
105  continue;
106  }
107  auto in = GetPointer<identifier_node>(GET_NODE(fd->name));
108  const auto identifier =
109  hdl_writer_type == HDLWriter_Language::VHDL ? boost::to_upper_copy<std::string>(in->strg) : in->strg;
110  if(found_names.find(identifier) != found_names.end())
111  {
112  std::map<TreeVocabularyTokenTypes_TokenEnum, std::string> IR_schema;
113  unsigned int var_decl_name_nid_test;
114  unsigned var_decl_unique_id = 0;
115  do
116  {
117  IR_schema[TOK(TOK_STRG)] = in->strg + STR(var_decl_unique_id++);
118  var_decl_name_nid_test = TM->find(identifier_node_K, IR_schema);
119  } while(var_decl_name_nid_test);
120  found_names.insert(in->strg + STR(var_decl_unique_id - 1));
121  const auto tree_man = tree_manipulationConstRef(new tree_manipulation(TM, parameters, AppM));
122  fd->name = tree_man->create_identifier_node(IR_schema[TOK(TOK_STRG)]);
123  }
124  else
125  {
126  found_names.insert(identifier);
127  }
128  }
130 }
131 
134 {
136  switch(relationship_type)
137  {
139  {
140  relationships.insert(std::make_pair(CREATE_TREE_MANAGER, WHOLE_APPLICATION));
141  break;
142  }
145  {
146  break;
147  }
148  default:
149  {
150  THROW_UNREACHABLE("");
151  }
152  }
153  return relationships;
154 }
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:343
Data structure representing the entire HLS information.
Step successfully executed.
DesignFlowStep_Status Exec() override
Fixes the var_decl duplication.
const CustomUnorderedSet< unsigned int > GetAllFunctions() const
Returns all the functions in the tree_manager.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
~HDLFunctionDeclFix() override
Destructor.
Definition of the class representing a generic C application.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
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.
A simple interface to token object of the raw files.
#define TOK(token)
Macro used to convert a token symbol into a treeVocabularyTokenTypes.
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
HDLWriter_Language
HDLFunctionDeclFix(const application_managerRef AppM, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
const tree_nodeRef get_tree_node_const(unsigned int i) const
Return the reference to the i-th tree_node Constant version of get_tree_node.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
unsigned int find(enum kind tree_node_type, const std::map< TreeVocabularyTokenTypes_TokenEnum, std::string > &tree_node_schema)
if there exist return the node id of a tree node compatible with the tree_node_schema and of type tre...
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.
Class defining some useful functions to create tree nodes and to manipulate the tree manager...
const application_managerRef AppM
The application manager.
Class specification of the tree_reindex support class.
const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionRelationship > > ComputeFrontendRelationships(const DesignFlowStep::RelationshipType relationship_type) const override
Return the set of analyses in relationship with this design step.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
refcount< const tree_manipulation > tree_manipulationConstRef
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
Pre-analysis step fixing names of functions which clash with signal names.
This class creates a layer to add nodes and to manipulate the tree_nodes manager. ...
Class specification of the manager of the tree structures extracted from the raw file.
HLS specialization of generic_device.

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