63 debug_level(_Param->get_class_debug_level(
GET_CLASS(*this))),
66 search_function(
false)
77 THROW_ASSERT(std::filesystem::exists(std::filesystem::path(input_filename)),
78 "Input file \"" + input_filename +
"\" does not exist");
80 const auto temp_path =
Param->getOption<std::string>(OPT_output_temporary_directory) +
"pragma";
81 std::filesystem::create_directories(temp_path);
82 const auto output_filename = temp_path +
"/" + std::filesystem::path(input_filename).filename().string();
83 std::ofstream fileOutput(output_filename, std::ios::out);
89 std::ifstream instream(input_filename);
91 THROW_ASSERT(instream.is_open(),
"INPUT FILE ERROR: Could not open input file: " + input_filename);
92 while(!instream.eof())
94 std::string input_line;
95 getline(instream, input_line);
97 std::string output_line = input_line;
102 std::string::size_type notwhite = output_line.find_first_of(
'(');
103 if(notwhite != std::string::npos)
105 std::string Token = input_line;
106 Token.erase(notwhite);
130 if(input_line.find(
"#pragma") != std::string::npos)
133 output_line = input_line;
134 char const* delims =
" \t\r\n";
136 std::string::size_type notwhite = output_line.find_first_not_of(delims);
137 output_line.erase(0, notwhite);
139 notwhite = output_line.find_last_not_of(delims);
140 output_line.erase(notwhite + 1);
146 fileOutput << output_line << std::endl;
150 for(
char i : input_line)
156 "---Found {: Current level " + std::to_string(
level));
163 FloatingPragmas.clear();
179 "---Found }: Current level " + std::to_string(
level));
189 return output_filename;
197 if(!
Param->getOption<
bool>(OPT_ignore_parallelism))
207 if(Line.find(
"call_hw") != std::string::npos)
210 if(!
Param->getOption<
bool>(OPT_ignore_mapping) and !
Param->getOption<
bool>(OPT_mapping))
221 if(Line.find(
"call_point_hw") != std::string::npos)
227 if(Line.find(
"issue") != std::string::npos)
233 if(Line.find(
"profiling") != std::string::npos)
239 if(Line.find(
"generate_hw") != std::string::npos)
252 std::string original_line =
line;
256 THROW_ERROR(
"Unsupported openmp directive in line " + line);
258 bool single_line_pragma =
false;
261 switch(omp_pragma_type)
270 single_line_pragma =
true;
302 line +=
"\"" + omp_pragma_directive +
"\"";
303 original_line.erase(0, original_line.find(omp_pragma_directive) + omp_pragma_directive.size());
304 if(not single_line_pragma)
308 (original_line.size() ?
"\", \"" + original_line.substr(1, original_line.size() - 1) :
""));
311 if(original_line.size())
313 line +=
", \"" + original_line.substr(1, original_line.size() - 1) +
"\"";
321 const std::string old_line =
line;
325 std::vector<std::string> splitted =
SplitString(old_line,
" ");
326 THROW_ASSERT(splitted.size() == 4 or splitted.size() == 5,
"Error in syntax of mapping pragma: " + old_line);
330 line +=
", \"" + splitted[3] +
"\"";
331 if(splitted.size() == 5)
333 line +=
", \"" + splitted[4] +
"\"";
350 Line =
"__pragma__" + std::to_string(
number) +
"_();";
381 Line =
"__pragma__" + std::to_string(
number) +
"_();";
const ParameterConstRef Param
reference to the parameter data-structure
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
static const std::string omp_directive_keywords[OMP_UNKNOWN]
The list of omp directive keywords.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
const int debug_level
current debugging level
const std::vector< std::string > SplitString(const std::string &input, const std::string &separators)
Function which splits a string into tokens.
#define STR_CST_pragma_function_end
The function replacing an ending pragma.
exceptions managed by PandA
unsigned int level
counter for nesting level
constant strings used in pragma identification
void line(int x1, int y1, int x2, int y2, unsigned int color)
Auxiliary methods for manipulating string.
bool recognize_generic_pragma(std::string &Line)
Retrieve information about a generic pragma directive (i.e., none of the known ones has been detected...
const pragma_managerRef PM
pointer to the pragma manager data-structure
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
#define STR_CST_pragma_function_single_line_two_arguments
The function replacing a single line pragma with two argument.
std::map< unsigned int, std::list< std::string > > OpenPragmas
#define STR_CST_pragma_function_single_line_one_argument
The function replacing a single line pragma with single argument.
bool recognize_mapping_pragma(std::string &Line)
Retrieve information about a pragma directive when a mapping pragma has been found.
#define STR_CST_pragma_keyword_call_point_hw
The call_point_hw pragma keyword.
Manager for pragma annotations.
utility function used to read files.
CustomUnorderedSet< std::string > FunctionPragmas
OmpPragmaType
The possible openmp pragmas Note that sections has to go before section but after parallel sections o...
std::string name_function
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
#define STR_CST_pragma_keyword_map
The keyword 'map' which identifies mapping pragmas.
static unsigned int number
counter of generic pragma
Parsing pragma from C sources.
#define STR_CST_pragma_keyword_omp
The keyword 'omp' which identifies openmp pragmas.
bool recognize_issue_pragma(std::string &Line)
Retrieve information about a pragma directive when an issue pragma has been found.
~PragmaParser()
Destructor.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
bool analyze_pragma(std::string &Line)
Retrieve information about a pragma directive when the token "#pragma" has been found.
std::list< std::string > FloatingPragmas
this class is used to manage the command-line or XML options.
bool recognize_omp_pragma(std::string &Line)
Retrieve information about a pragma directive when a OpenMP (parallelism) pragma has been found...
PragmaParser(const pragma_managerRef PM, const ParameterConstRef Param)
Constructor.
std::string substitutePragmas(const std::string &OldFile)
Substitute the pragmas with proper functions.
bool recognize_call_point_hw_pragma(std::string &line) const
Retrieve information about a pragma directive of type pragma map call_point_hw.
static OmpPragmaType GetOmpPragmaType(const std::string &directive)
Returns the identifier corresponding to an openmp directive.
#define STR_CST_pragma_function_start
The function replacing an opening pragma.
bool recognize_profiling_pragma(std::string &Line)
Retrieve information about a pragma directive when a profiling pragma has been found.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...