44 #include "config_RELEASE.hpp" 67 size_t len1 = strlen(argv[i]);
68 size_t len2 = strlen(argv[i + 1]);
69 auto* tmp =
new char[1 + len1 + 1 + len2 + 1];
71 strcpy(tmp + 1, argv[i]);
72 *(tmp + 1 + len1) =
'=';
73 strcpy(tmp + 1 + len1 + 1, argv[i + 1]);
81 auto** argv_copied =
new char*[
static_cast<unsigned>(argc) + 1u];
83 for(
int i = 0; i < argc; ++i)
87 if(strcmp(argv[i],
"-include") == 0 || strcmp(argv[i],
"-isystem") == 0 || strcmp(argv[i],
"-iquote") == 0 ||
88 strcmp(argv[i],
"-isysroot") == 0 || strcmp(argv[i],
"-imultilib") == 0 || strcmp(argv[i],
"-MF") == 0 ||
89 strcmp(argv[i],
"-MT") == 0 || strcmp(argv[i],
"-MQ") == 0)
93 else if(strcmp(argv[i],
"-print-libgcc-file-name") == 0)
95 const char newvalue[] =
"--print-file-name=libgcc.a";
96 tmp =
new char[strlen(newvalue) + 1];
97 strcpy(tmp, newvalue);
101 tmp =
new char[strlen(argv[i]) + 2];
102 strcpy(tmp, argv[i]);
104 argv_copied[i + dec] = tmp;
107 argv_copied[argc] =
nullptr;
113 for(
int i = 0; i < argc; ++i)
115 delete[] argv_copied[i];
117 delete[] argv_copied;
123 if(Param && not(Param->getOption<
bool>(OPT_no_clean)))
125 std::filesystem::remove_all(Param->getOption<std::string>(OPT_output_temporary_directory));
134 int main(
int argc,
char* argv_orig[])
145 switch(Param->Exec())
150 throw "Bad Parameters format";
167 auto output_level = Param->getOption<
int>(OPT_output_level);
170 Param->PrintFullHeader(std::cerr);
173 auto debug_level = Param->getOption<
int>(OPT_debug_level);
178 if(Param->isOption(OPT_input_file))
180 long int wrapping_time;
204 auto input_files = [&]() {
205 const auto flist = Param->getOption<std::list<std::string>>(OPT_input_file);
206 return std::vector<std::string>(flist.begin(), flist.end());
210 "Created list of files: " + std::to_string(input_files.size()) +
211 " input source code files to be concatenated");
228 if(!Param->isOption(OPT_gcc_E) && !Param->isOption(OPT_gcc_S))
232 if(Param->isOption(OPT_obj_files))
235 for(
const auto& object_file : object_files)
237 if(!std::filesystem::exists(object_file))
239 THROW_ERROR(
"File " + object_file +
" does not exist");
242 TM->merge_tree_managers(TM_new);
245 if(Param->isOption(OPT_archive_files))
248 for(
const auto& archive_file : archive_files)
250 if(!std::filesystem::exists(archive_file))
252 THROW_ERROR(
"File " + archive_file +
" does not exist");
254 const auto temp_path =
unique_path(Param->getOption<std::string>(OPT_output_temporary_directory) +
255 "/temp-archive-dir-%%%%-%%%%-%%%%-%%%%");
256 std::filesystem::create_directories(temp_path);
257 const auto local_archive_file =
GetPath(archive_file);
259 const auto command =
"cd " + temp_path.string() +
"; ar x " + local_archive_file;
262 THROW_ERROR(
"ar returns an error during archive extraction ");
264 for(
const auto& entry : std::filesystem::directory_iterator{temp_path})
267 TM->merge_tree_managers(TM_new);
269 if(!Param->getOption<
bool>(OPT_no_clean))
271 std::filesystem::remove_all(temp_path);
281 std::string raw_file_name;
282 if(Param->isOption(OPT_compress_archive))
284 auto archive_file = Param->getOption<std::string>(OPT_compress_archive);
285 std::string fname = archive_file.substr(0, archive_file.find(
'.'));
286 fname = fname +
".o";
293 std::string
command =
"ar cru " + archive_file +
" " + fname;
298 THROW_ERROR(
"ar returns an error during archive creation ");
303 if(Param->isOption(OPT_output_file))
305 raw_file_name = Param->getOption<std::string>(OPT_output_file);
309 raw_file_name =
"a.tree";
327 catch(
const char*
str)
329 std::cerr << str << std::endl;
331 catch(
const std::string& str)
333 std::cerr << str << std::endl;
335 catch(std::exception& e)
337 std::cerr << e.what() << std::endl;
341 std::cerr <<
"Unknown error type" << std::endl;
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
int exit_code
NOTE: this file must be included only by source code of the executable (i.e., the file with the main)...
#define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
fileIO_ostreamRef fileIO_ostream_open(const std::string &name)
this function returns an ostream compressed or not.
static void dealloc_argv(int argc, char *argv_copied[])
This class manages the tree structures extracted from the raw file.
int main(int argc, char *argv_orig[])
Main file used to perform Hardware/Software Codesign starting from C/C++/SystemC specification.
static char * alloc_long_option(char *argv[], int &i, int &dec)
exceptions managed by PandA
Specification of the tree (GCC raw) parsing interface function.
#define OUTPUT_LEVEL_MINIMUM
minimum debugging print is performed.
static void close_everything(int argc, char *argv[], const ParameterRef &Param)
Include a set of utilities used to manage CPU time measures.
static char ** alloc_argv(int &argc, char *argv[])
CompilerWrapper_OptimizationSet
Possible optimization sets.
bool IsError(const int error_value)
Utility include.
std::filesystem::path unique_path(const std::filesystem::path &model)
#define START_TIME(time_var)
Macro used to store the start time into time_var.
void dump_exec_time(const std::string &thing, long et)
default table used by THR LLVM optimization step.
#define PARAMETER_PARSED
An integer value to return if parameters have been right parsed.
#define STOP_TIME(time_var)
Macro used to store the elapsed time into time_var.
refcount< Parameter > ParameterRef
utility function used to read files.
CompilerWrapper_CompilerTarget
target of the compiler
This file collects some utility functions and macros.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
#define STR_cost_latency_table_default
default string for latencies
int PandaSystem(const ParameterConstRef Param, const std::string &system_command, bool host_exec, const std::string &output, const unsigned int type, const bool background, const size_t timeout)
System call forcing execution with bash.
std::string GetPath(std::filesystem::path path)
refcount< CompilerWrapper > CompilerWrapperRef
Refcount definition for the CompilerWrapper class.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
this class is used to manage the command-line or XML options.
Main class for wrapping the frontend compiler.
#define DEBUG_LEVEL_VERBOSE
verbose debugging print is performed.
tree_managerRef ParseTreeFile(const ParameterConstRef &Param, const std::string &f)
Function that parse the dump of the patched GCC.
Class specification of the manager of the tree structures extracted from the raw file.
#define DEBUG_LEVEL_MINIMUM
minimum debugging print is performed.
#define PARAMETER_NOTPARSED
Implementation of the wrapper to Gcc for C sources.