PandA-2024.02
aadl_parser.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 "aadl_parser.hpp"
41 
42 #include "Parameter.hpp"
43 #include "aadl_constants.hpp"
44 #include "aadl_information.hpp"
45 #include "aadl_parser_node.hpp"
46 #include "application_manager.hpp"
47 #include "dbgPrintHelper.hpp"
48 #include "fileIO.hpp"
49 #include "hls_manager.hpp"
50 #include "string_manipulation.hpp"
51 #include "utility.hpp"
52 
53 #define YYSTYPE AadlParserNode
54 #include "aadl_lexer.hpp"
55 
56 static std::string GetFile(const std::string& directory, const std::string& file)
57 {
58  std::string ret = file;
59  ret = ret.at(0) == '"' ? ret.substr(1, ret.size() - 2) : ret;
60  if(ret.at(0) == '/')
61  {
62  if(!std::filesystem::exists(ret))
63  {
64  THROW_ERROR(ret + " does not exist");
65  }
66  return ret;
67  }
68  if(std::filesystem::exists(ret))
69  {
70  return ret;
71  }
72  if(std::filesystem::exists(directory + "/" + ret))
73  {
74  return directory + "/" + ret;
75  }
76  THROW_ERROR(ret + " not found");
77  return "";
78 }
79 
81  : parameters(_parameters), debug_level(_parameters->get_class_debug_level("AadlParser"))
82 {
83 }
84 
85 AadlParser::AadlParser(const DesignFlowManagerConstRef _design_flow_manager, const std::string& _file_name,
86  const application_managerRef _AppM, const ParameterConstRef _parameters)
87  : ParserFlowStep(_design_flow_manager, ParserFlowStep_Type::AADL, _file_name, _parameters), AppM(_AppM)
88 {
89  debug_level = _parameters->get_class_debug_level(GET_CLASS(*this));
90 }
91 
92 AadlParser::~AadlParser() = default;
93 
95 {
97  const auto directory = std::filesystem::path(file_name).parent_path().string();
98  if(sname->fail())
99  {
100  THROW_ERROR(std::string("FILE does not exist: ") + file_name);
101  }
102  const AadlFlexLexerRef lexer(new AadlFlexLexer(parameters, sname.get(), nullptr));
104  YYParse(data, lexer);
105  AppM->input_files.erase(std::find(AppM->input_files.begin(), AppM->input_files.end(), file_name));
106  std::set<std::string> input_files;
107  const auto aadl_information = GetPointer<HLS_manager>(AppM)->aadl_information;
108  for(const auto& system : data->system_properties)
109  {
110  if(system.second.find("Source_Language") != system.second.end() and
111  system.second.find("Source_Language")->second == "VHDL")
112  {
113  if(system.second.find("Source_Text") != system.second.end())
114  {
115  const auto input_file = GetFile(directory, system.second.find("Source_Text")->second);
116  input_files.insert(input_file);
117  }
118  if(data->system_features.find(system.first) != data->system_features.end())
119  {
120  const auto features = data->system_features.find(system.first)->second;
121  for(const auto& feature : features)
122  {
123  if(feature.second.find("Taste::InterfaceName") != feature.second.end())
124  {
125  const auto top_functions =
126  parameters->getOption<std::string>(OPT_top_functions_names) + STR_CST_string_separator;
127  const auto function_name = feature.second.find("Taste::InterfaceName")->second;
128  const auto without_quota_function_name =
129  function_name.at(0) == '"' ? function_name.substr(1, function_name.size() - 2) : function_name;
130  aadl_information->top_functions_names.push_back(without_quota_function_name);
131  const_cast<Parameter*>(parameters.get())
132  ->setOption(OPT_top_functions_names, top_functions + without_quota_function_name);
134  "---Adding top function " + without_quota_function_name);
135  }
136  }
137  }
138  }
139  }
140  for(const auto& property : data->package_properties)
141  {
142  if(property.second.find("Taste::dataViewPath") != property.second.end())
143  {
144  const auto data_view_file = GetFile(directory, property.second.find("Taste::dataViewPath")->second);
145  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Added " + data_view_file + " to input files");
146  input_files.insert(data_view_file);
147  }
148  }
149  for(const auto& property : data->data_properties)
150  {
151  if(property.second.find("Source_Text") != property.second.end())
152  {
153  const auto data_view_file = GetFile(directory, property.second.find("Source_Text")->second);
154  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Added " + data_view_file + " to input files");
155  input_files.insert(data_view_file);
156  }
157  }
158  for(const auto& subprogram : data->subprogram_features)
159  {
160  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Analyzing subprogram " + subprogram.first);
161  for(const auto& feature : subprogram.second)
162  {
163  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Analyzing feature " + feature.first);
164  if(feature.second.find(STR_CST_aadl_parameter_type) != feature.second.end())
165  {
166  AadlInformation::AadlParameter aadl_parameter;
167  aadl_parameter.name = feature.first;
168  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found parameter " + feature.first);
169  aadl_parameter.asn_type = feature.second.find(STR_CST_aadl_parameter_type)->second;
170  if(aadl_parameter.asn_type.find(STR_CST_aadl_data_view) == 0)
171  {
172  aadl_parameter.asn_type = aadl_parameter.asn_type.substr(std::string(STR_CST_aadl_data_view).size());
173  }
174  THROW_ASSERT(feature.second.find(STR_CST_aadl_parameter_direction) != feature.second.end(), "");
175  THROW_ASSERT(feature.second.find(STR_CST_aadl_parameter_endianess) != feature.second.end(), "");
177  feature.second.find(STR_CST_aadl_parameter_direction)->second);
179  feature.second.find(STR_CST_aadl_parameter_endianess)->second);
180  aadl_information->function_parameters[subprogram.first].push_back(aadl_parameter);
181  }
182  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Analyzed feature " + feature.first);
183  }
184  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Analyzed subprogram " + subprogram.first);
185  }
186  AppM->input_files.insert(AppM->input_files.end(), input_files.begin(), input_files.end());
187  if(parameters->getOption<std::list<std::string>>(OPT_top_functions_names).size() > 1)
188  {
189  // TODO: fix this abomination
190  const_cast<Parameter*>(parameters.get())->setOption(OPT_disable_function_proxy, true);
191  }
193 }
The information collected from aadl file.
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
Data structure representing the entire HLS information.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
const std::string file_name
The name of the file to be parsed.
Direction direction
The direction of the parameter.
File containing functions and utilities to support the printing of debug messagges.
#define STR_CST_string_separator
The character used to separate concatenated string.
Definition: utility.hpp:61
~AadlParser() override
Destuctor.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
std::string name
The name of the parameter;.
Definition of the class representing a generic C application.
std::string asn_type
The type of the parameter.
Specification of the aadl parsing interface function.
AadlParserData(const ParameterConstRef parameters)
Constructor.
Definition: aadl_parser.cpp:80
static Direction GetDirection(const std::string &direction_string)
Return the direction.
Auxiliary methods for manipulating string.
enum ParserFlowStep_Type { } ParserFlowStep_Type
Autoheader include.
EndianessType endianess
The endianess.
void YYParse(const AadlParserDataRef data, const AadlFlexLexerRef lexer) const
Wrapper to yyparse.
#define STR_CST_aadl_parameter_direction
The type of the property storing the direction of a parameter.
utility function used to read files.
header file for LEX based lexer for aadl file.
DesignFlowStep_Status Exec() override
Execute the step.
Definition: aadl_parser.cpp:94
constants used in aadl parser
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
This file collects some utility functions and macros.
#define STR_CST_aadl_data_view
The name of the package containing type definition.
fileIO_istreamRef fileIO_istream_open(const std::string &name)
this function returns an istream compressed or not.
Definition: fileIO.cpp:55
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
#define STR_CST_aadl_parameter_type
The type of the property storing the type of a parameter.
Specification of the data structure associated with a node during aadl parsing.
static std::string GetFile(const std::string &directory, const std::string &file)
Definition: aadl_parser.cpp:56
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
const application_managerRef AppM
The application manager.
Definition: aadl_parser.hpp:87
T * get() const
Definition: refcount.hpp:169
this class is used to manage the command-line or XML options.
AadlParser(const DesignFlowManagerConstRef design_flow_manager, const std::string &file_name, const application_managerRef AppM, const ParameterConstRef parameters)
Constructor.
Definition: aadl_parser.cpp:85
int debug_level
The debug level.
Strucutre containing the characteristics of a parameter.
#define STR_CST_aadl_parameter_endianess
The name of the property storing the endianess of a parameter.
static EndianessType Endianess(const std::string &endianess_string)
Return the endianess.
#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:54 for PandA-2024.02 by doxygen 1.8.13