14 body +=
"/***************************************\n";
15 body +=
"\tAuteur : Pierre Aubert\n";
16 body +=
"\tMail : pierre.aubert@lapp.in2p3.fr\n";
17 body +=
"\tLicence : CeCILL-C\n";
18 body +=
"****************************************/\n\n\n";
20 body +=
"//Warning : this file has been generated automatically by the phoenix_hpc_proxy program\n";
21 body +=
"//You can find it at https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/PhoenixHPCProxy\n";
22 body +=
"//Do NOT modify it\n\n\n";
31 return "handle_" + functionName;
39 return "FunctionTypehandle_" + functionName;
47 return "update_" + fileName.eraseExtension();
62 for(PVecArgument::iterator it(vecArg.begin()); it != vecArg.end(); ++it){
63 if(isComma){body +=
", ";}
64 body += it->getType() +
" ";
65 if(it->getPtrRef() !=
""){body += it->getPtrRef() +
" ";}
66 body += it->getName();
67 if(it->getDefaultValue() !=
""){body +=
" = " + it->getDefaultValue();}
73 for(PVecArgument::iterator it(vecArg.begin()); it != vecArg.end(); ++it){
74 if(isComma){body +=
", ";}
75 body += it->getName();
93 for(PVecArgument::iterator it(vecArg.begin()); it != vecArg.end(); ++it){
94 if(isComma){body +=
", ";}
95 body += it->getType();
96 if(it->getPtrRef() !=
""){body +=
" " + it->getPtrRef();}
109 PString baseMacro(
"__" + source.
getName().eraseExtension().toUpper() +
"_PROXY_H__");
110 body +=
"#ifndef " + baseMacro +
"\n";
111 body +=
"#define " + baseMacro +
"\n\n";
112 body +=
"#include <iostream>\n\n\n";
114 for(PVecFunction::iterator it(vecFunction.begin()); it != vecFunction.end(); ++it){
118 for(PVecFunction::iterator it(vecFunction.begin()); it != vecFunction.end(); ++it){
123 for(PVecFunction::iterator it(vecFunction.begin()); it != vecFunction.end(); ++it){
128 body +=
"#endif\n\n";
138 if(libraryName ==
""){
return functionName;}
139 PPath outputTmpFile(
".mangledFunctionName.txt");
140 PString command(
"objdump --syms "+libraryName+
" | grep \".text\" | sed -e \"s/ /\\n/g\" | grep "+functionName+
" | head -n 1 > "+outputTmpFile);
141 if(system(command.c_str()) != 0){
144 PString fullFileContent(outputTmpFile.loadFileContent());
145 std::cerr <<
"getMangleFunctionName : full file content mangle function '"<<functionName<<
"' : " << fullFileContent << std::endl;
146 PString mangleFunction(fullFileContent.eraseChar(
"\n\t "));
147 if(remove(outputTmpFile.c_str()) != 0){
148 std::cerr <<
"DPS::LibraryHandle::mangleFunctionName : cannot remove file '"<<outputTmpFile<<
"'" << std::endl;
150 return mangleFunction;
160 body +=
"#include <stdio.h>\n";
161 body +=
"#include <stdlib.h>\n";
162 body +=
"#include <dlfcn.h>\n\n";
163 body +=
"#include \""+source.
getName().eraseExtension()+
".h\"\n\n";
166 for(PVecFunction::iterator it(vecFunction.begin()); it != vecFunction.end(); ++it){
171 body +=
"///Update the all the function handles of the file\n";
172 body +=
"/**\t@param handle : pointer to loaded library\n";
175 for(PVecFunction::iterator it(vecFunction.begin()); it != vecFunction.end(); ++it){
193 PPath baseFileName(source.
getName().eraseExtension());
194 PPath outputHeaderFile(outputDir / baseFileName + PString(
".h"));
195 PPath outputSourceFile(outputDir / baseFileName + PString(
".cpp"));
196 if(!outputHeaderFile.saveFileContent(headerSrc)){
197 std::cerr <<
"cpp_backend : cannot save header file '"<<outputHeaderFile<<
"'" << std::endl;
200 std::cout <<
"cpp_backend : create header file '"<<outputHeaderFile<<
"'" <<std::endl;
201 if(!outputSourceFile.saveFileContent(sourceSrc)){
202 std::cerr <<
"cpp_backend : cannot save source file '"<<outputSourceFile<<
"'" << std::endl;
205 std::cout <<
"cpp_backend : create source file '"<<outputSourceFile<<
"'" <<std::endl;
217 for(PVecSource::iterator it(vecSource.begin()); it != vecSource.end(); ++it){
PString cpp_licenceSaveStr()
Get the licence in string.
PString getHandleFunctionType(const PString &functionName)
Get the handle type name of the given function.
PString getMangleFunctionName(const PString &libraryName, const PString &functionName)
Get the mangled name of the given function name.
bool cpp_backend(PSource &source, const PString &libName, const PPath &outputDir)
Save a vector of PSource in the output directory.
PString getUpdateFunction(const PPath &fileName)
Get the update type name of the given file.
PString getHandleFunction(const PString &functionName)
Get the handle name of the given function.
PString cpp_backendTableHeaderInline(PFunction &function)
Save the function prototype as an inline function.
PString cpp_backendHeader(PSource &source)
Save the header of the given PSource.
PString cpp_backendTableHeaderHandleType(PFunction &function)
Save the function prototype as an inline function.
PString cpp_backendSource(PSource &source, const PString &libName)
Save the source of the given PSource.
const PString & getName() const
Gets the name of the PFunction.
const PString & getDocString() const
Gets the docString of the PFunction.
const PString & getOutputType() const
Gets the outputType of the PFunction.
const PString & getOtherCode() const
Gets the otherCode of the PFunction.
const PString & getTemplateDef() const
Gets the templateDef of the PFunction.
const std::vector< PArgument > & getVecArgument() const
Gets the vecArgument of the PFunction.
Configuration file which will produce a source and header in C++.
const PPath & getName() const
Gets the name of the PSource.
const std::vector< PFunction > & getVecFunction() const
Gets the vecFunction of the PSource.
bool repr_isFunction(const PFunction &fct)
Say if the current function is a function prototype.
std::vector< PSource > PVecSource
std::vector< PArgument > PVecArgument
std::vector< PFunction > PVecFunction