44 #include "config_LIBBAMBU_SRCDIR.hpp" 46 #include "config_PANDA_DATA_INSTALLDIR.hpp" 76 #define FILENAME_NORM(name) (std::filesystem::path(name).lexically_normal().string()) 127 {
"_IO_getc",
"getc"}};
130 {
"__suseconds_t",
"long int"}};
133 {
"__errno_location",
"exit",
"abort"},
139 {
"atof",
"stdlib.h"}, {
"atoi",
"stdlib.h"}, {
"srand48",
"stdlib.h"},
140 {
"va_start",
"stdarg.h"}, {
"va_end",
"stdarg.h"}, {
"lgamma",
"math.h"},
141 {
"lgammaf",
"math.h"}, {
"lgamma_r",
"math.h"}, {
"lgammaf_r",
"math.h"}};
144 unsigned int _function_id,
const DesignFlowManagerConstRef _design_flow_manager)
146 behavioral_helper(AppM->CGetFunctionBehavior(function_id)->CGetBehavioralHelper()),
147 TM(AppM->get_tree_manager()),
148 already_executed(
false)
163 switch(relationship_type)
167 relationships.insert(std::make_pair(IR_LOWERING,
SAME_FUNCTION));
172 relationships.insert(std::make_pair(UN_COMPARISON_LOWERING,
SAME_FUNCTION));
184 return relationships;
195 const auto fd = GetPointerS<function_decl>(curr_tn);
196 const auto sl = GetPointerS<statement_list>(
GET_NODE(fd->body));
201 for(
const auto f :
AppM->get_functions_without_body())
206 for(
const auto& bbi_bb : sl->list_of_bloc)
208 const auto& bb = bbi_bb.second;
211 for(
const auto& stmt : bb->CGetStmtList())
233 if(already_visited.count(index))
237 already_visited.insert(index);
238 THROW_ASSERT(curr_tn->
get_kind() != tree_reindex_K,
"Passed tree_reindex instead of real node");
243 case aggr_init_expr_K:
245 const auto ce = GetPointerS<call_expr>(curr_tn);
247 for(
const auto&
arg : ce->args)
255 const auto ce = GetPointerS<gimple_call>(curr_tn);
257 for(
const auto&
arg : ce->args)
263 case gimple_assign_K:
265 const auto gm = GetPointerS<gimple_assign>(curr_tn);
280 const auto dn = GetPointerS<decl_node>(curr_tn);
281 auto fd = GetPointer<function_decl>(curr_tn);
286 dn->library_system_flag =
true;
288 else if(!dn->operating_system_flag && !dn->library_system_flag && (is_system ||
is_system_include(include)))
291 const auto sr = GetPointer<srcp>(curr_tn);
292 if(!is_system && sr && sr->include_name !=
"")
296 fd = GetPointer<function_decl>(curr_tn);
303 dn->library_system_flag =
true;
307 dn->operating_system_flag =
true;
312 dn->operating_system_flag =
true;
317 dn->operating_system_flag =
true;
322 dn->library_system_flag =
true;
323 const auto sr = GetPointer<srcp>(curr_tn);
327 if(curr_tn->
get_kind() == function_decl_K)
329 fd = GetPointerS<function_decl>(curr_tn);
330 const auto sr = GetPointer<srcp>(curr_tn);
331 if(fd->type && fd->undefined_flag && !fd->operating_system_flag && !fd->library_system_flag &&
332 sr->include_name !=
"<built-in>")
334 const auto ft = GetPointerS<function_type>(
GET_NODE(fd->type));
335 if(!ft->prms && ft->retn && GetPointer<integer_type>(
GET_NODE(ft->retn)))
337 const auto it = GetPointerS<integer_type>(
GET_NODE(ft->retn));
338 if(it->name && GetPointer<type_decl>(
GET_NODE(it->name)))
340 const auto td = GetPointerS<type_decl>(
GET_NODE(it->name));
341 if(td->name && GetPointer<identifier_node>(
GET_NODE(td->name)))
343 const auto in = GetPointerS<identifier_node>(
GET_NODE(td->name));
344 if(in->strg ==
"int")
346 fd->include_name =
"<built-in>";
352 if(fd->name &&
GET_NODE(fd->name)->get_kind() == identifier_node_K)
354 const auto in = GetPointerS<identifier_node>(
GET_NODE(fd->name));
362 if(curr_tn->
get_kind() == type_decl_K)
364 const auto td = GetPointerS<type_decl>(curr_tn);
365 if(td->name &&
GET_NODE(td->name)->get_kind() == identifier_node_K)
367 const auto in = GetPointerS<identifier_node>(
GET_NODE(td->name));
374 if(curr_tn->
get_kind() == var_decl_K && dn->artificial_flag &&
378 dn->library_system_flag =
true;
380 if(include.find(
"etc/libbambu") != std::string::npos)
383 dn->libbambu_flag =
true;
385 else if(dn->libbambu_flag)
394 const auto sn = GetPointerS<ssa_name>(curr_tn);
410 if(GetPointerS<tree_list>(current)->purp)
415 current = GetPointerS<tree_list>(current)->chan;
425 const auto ue = GetPointerS<unary_expr>(curr_tn);
435 const auto be = GetPointerS<binary_expr>(curr_tn);
446 const auto te = GetPointerS<ternary_expr>(curr_tn);
464 const auto qe = GetPointerS<quaternary_expr>(curr_tn);
486 const auto le = GetPointerS<lut_expr>(curr_tn);
521 const auto co = GetPointerS<constructor>(curr_tn);
528 for(
const auto& it : co->list_of_idx_valu)
537 const auto gc = GetPointerS<gimple_cond>(curr_tn);
541 case gimple_switch_K:
543 const auto se = GetPointerS<gimple_switch>(curr_tn);
547 case gimple_multi_way_if_K:
549 const auto gmwi = GetPointerS<gimple_multi_way_if>(curr_tn);
550 for(
const auto& cond : gmwi->list_of_cond)
559 case gimple_return_K:
561 const auto re = GetPointerS<gimple_return>(curr_tn);
570 const auto fe = GetPointerS<gimple_for>(curr_tn);
578 const auto we = GetPointerS<gimple_while>(curr_tn);
584 const auto ge = GetPointerS<gimple_goto>(curr_tn);
590 const auto ty = GetPointerS<type_node>(curr_tn);
601 const auto bt = GetPointerS<boolean_type>(curr_tn);
602 if(bt->name && GetPointer<type_decl>(
GET_NODE(bt->name)))
604 const auto td = GetPointerS<type_decl>(
GET_NODE(bt->name));
605 if(td->name && GetPointer<identifier_node>(
GET_NODE(td->name)))
607 const auto in = GetPointerS<identifier_node>(
GET_NODE(td->name));
609 parameters->getOption<std::string>(OPT_gcc_standard) ==
"c99" && in->strg ==
"_Bool")
611 const std::string INT =
"int";
620 const auto vt = GetPointerS<vector_type>(curr_tn);
626 const auto at = GetPointerS<array_type>(curr_tn);
632 const auto rt = GetPointerS<record_type>(curr_tn);
633 for(
const auto& it : rt->list_of_flds)
638 rt->libbambu_flag =
true;
641 for(
const auto& it : rt->list_of_fncs)
649 const auto ut = GetPointerS<union_type>(curr_tn);
650 for(
const auto& it : ut->list_of_flds)
655 ut->libbambu_flag =
true;
658 for(
const auto& it : ut->list_of_fncs)
666 const auto pt = GetPointerS<pointer_type>(curr_tn);
670 case reference_type_K:
672 const auto rt = GetPointerS<reference_type>(curr_tn);
679 case function_type_K:
681 const auto ft = GetPointerS<function_type>(curr_tn);
694 const auto mt = GetPointerS<method_type>(curr_tn);
711 const auto it = GetPointerS<integer_type>(curr_tn);
712 if(it->name && GetPointer<identifier_node>(
GET_NODE(it->name)))
714 const auto in = GetPointerS<identifier_node>(
GET_NODE(it->name));
715 if(in->strg ==
"sizetype")
717 const std::string INT =
"unsigned long";
720 if(in->strg ==
"ssizetype")
722 const std::string INT =
"long";
725 else if(in->strg ==
"bitsizetype")
727 const std::string INT =
"unsigned long long int";
730 else if(in->strg ==
"bit_size_type")
732 const std::string INT =
"unsigned long long int";
738 case template_type_parm_K:
740 const auto ttp = GetPointerS<template_type_parm>(curr_tn);
744 case typename_type_K:
746 const auto tt = GetPointerS<typename_type>(curr_tn);
751 case enumeral_type_K:
754 case type_pack_expansion_K:
755 case type_argument_pack_K:
764 case aggr_init_expr_K:
765 case case_label_expr_K:
766 case identifier_node_K:
769 case qual_union_type_K:
772 case statement_list_K:
774 case target_mem_ref_K:
775 case target_mem_ref461_K:
795 if((include.find(
"etc/libbambu") != std::string::npos) ||
796 (include.find(PANDA_DATA_INSTALLDIR
"/panda/ac_types/include") != std::string::npos) ||
797 (include.find(PANDA_DATA_INSTALLDIR
"/panda/ac_math/include") != std::string::npos) ||
798 (ty->name && GetPointer<const type_decl>(
GET_CONST_NODE(ty->name)) &&
799 GetPointerS<const type_decl>(
GET_CONST_NODE(ty->name))->libbambu_flag))
801 ty->libbambu_flag =
true;
806 ty->system_flag =
true;
807 const auto sr = GetPointer<srcp>(curr_tn);
808 if(!is_system && sr && sr->include_name !=
"")
815 case target_mem_ref_K:
817 const auto tmr = GetPointerS<target_mem_ref>(curr_tn);
832 case target_mem_ref461_K:
834 const auto tmr = GetPointerS<target_mem_ref461>(curr_tn);
856 case case_label_expr_K:
859 case gimple_pragma_K:
860 case gimple_predict_K:
861 case identifier_node_K:
866 const auto ce = GetPointerS<cast_expr>(curr_tn);
876 case ctor_initializer_K:
887 case template_id_expr_K:
888 case template_parm_index_K:
893 case nontype_argument_pack_K:
894 case expr_pack_expansion_K:
899 case statement_list_K:
917 if(include ==
"<built-in>")
924 if(include_p.compare(0, i.size() + 1, i +
"/") == 0)
938 std::vector<std::string> Splitted;
939 compiler_wrapper->GetSystemIncludes(Splitted);
941 for(
const auto& tok_iter : Splitted)
947 if(getenv(
"MINGW_INST_DIR"))
949 std::string mingw_prefix = getenv(
"MINGW_INST_DIR");
958 else if(getenv(
"APPDIR"))
960 const std::string app_prefix = getenv(
"APPDIR");
962 const auto canon_temp = std::filesystem::weakly_canonical(temp, ec);
966 if(temp.find(app_prefix) != 0)
972 temp = temp.substr(app_prefix.size());
980 const auto canon_temp = std::filesystem::weakly_canonical(temp, ec);
987 systemIncPath.push_back(
"/usr/local/share/hframework/include");
988 if(!parameters->isOption(OPT_pretty_print))
1001 if(include_p.compare(0, i.size() + 1, i +
"/") == 0)
1003 const auto trimmed = include_p.substr(i.size() + 1);
1008 else if(LIBBAMBU_SRCDIR == i &&
starts_with(trimmed,
"libm/"))
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
static const CustomUnorderedMap< std::string, std::string > rename_function
Associates a function to its original name.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define CASE_BINARY_EXPRESSION
This macro collects all case labels for binary_expr objects.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
#define CASE_DECL_NODES
NOTE that cast_expr is a unary expression but it could not be included in the CASE_UNARY_EXPRESSION b...
RelationshipType
The relationship type.
Source must be executed to satisfy target.
void recursive_examinate(const tree_nodeRef &tn, CustomUnorderedSet< unsigned int > &already_visited) const
Examinate recursively the tree to detect system types and system variables.
static const CustomUnorderedMap< std::string, std::string > undefined_library_function_include
Map undefined library function to corresponding header.
#define GET_INDEX_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
static std::string print_function_name(const tree_managerConstRef &TM, const function_decl *fd)
Return the name of the function in a string.
Data structure describing a basic block at tree level.
static const CustomUnorderedMap< std::string, std::string > inclNameToPath
Associates to each system header file its full path.
static bool IsInLibbambu(const tree_managerConstRef &TM, const unsigned int index)
Return true if the decl node or type is in libbambu.
virtual enum kind get_kind() const =0
Virtual function returning the type of the actual class.
#define STR(s)
Macro which performs a lexical_cast to a string.
virtual std::tuple< std::string, unsigned int, unsigned int > get_definition(unsigned int index, bool &is_system) const
Returns where the type index is defined.
Auxiliary methods for manipulating string.
CheckSystemType(const ParameterConstRef _parameters, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
virtual std::string get_kind_text() const =0
Virtual function returning the name of the actual class.
bool starts_with(const std::string &str, const std::string &pattern)
static std::vector< std::string > systemIncPath
Contains the list of the folders containing the system header files.
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
#define CASE_QUATERNARY_EXPRESSION
This macro collects all case labels for quaternary_expr objects.
#define CASE_UNARY_EXPRESSION
This macro collects all case labels for unary_expr objects.
static const CustomUnorderedMap< std::string, std::string > rename_types
Associates a type to its original name.
bool already_executed
Already executed.
DesignFlowStep_Status InternalExec() override
Adds the system_flag to the tree_node's of variables and types when necessary.
Target must be reexecuted.
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.
~CheckSystemType() override
Destructor.
#define GET_CONST_NODE(t)
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
bool is_system_include(std::string include) const
Check if an header is a system header.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
analyse srcp of variables and types to detect system ones; the identified one are flagged ...
std::string PrintVariable(unsigned int var) const
Print the name of the variable associated to the index.
#define CASE_TYPE_NODES
This macro collects all case labels for type objects.
This file collects some utility functions.
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
static void build_include_structures(ParameterConstRef parameters)
Build the include map, the function rename map and library system sets.
const unsigned int function_id
The index of the function to be analyzed.
#define CASE_CST_NODES
This macro collects all case labels for cast nodes.
const application_managerRef AppM
The application manager.
Class specification of the tree_reindex support class.
#define CASE_FAKE_NODES
This macro collects all case labels for fake or empty nodes.
static std::string getRealInclName(const std::string &include)
Given the string stored in a srcp of the raw return the correct include name.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
#define THROW_ERROR_CODE(code, str_expr)
helper function used to throw an error with a code error
static const CustomUnorderedSet< std::string > library_system_includes
The set of headers which contains function which have to be considered library_system.
static const CustomUnorderedSet< std::string > library_system_functions
The set of functions which have to be considered library_system.
Classes specification of the tree_node data structures not present in the gcc.
this class is used to manage the command-line or XML options.
#define CASE_CPP_NODES
This macro collects all case labels for cpp nodes.
Main class for wrapping the frontend compiler.
#define CASE_GIMPLE_NODES
This macro collects all cases labels for gimple nodes.
int debug_level
The debug level.
const tree_managerRef TM
The tree manager.
#define FILENAME_NORM(name)
Autoheader include.
#define CASE_TERNARY_EXPRESSION
This macro collects all case labels for ternary_expr objects.
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
const BehavioralHelperConstRef behavioral_helper
The helper associated with the current function.
#define CASE_PRAGMA_NODES
This macro collects all case labels for pragma objects.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Implementation of the wrapper to Gcc for C sources.