52void *
GCCJIT::translate(std::string code, std::set<std::string> headerpaths, std::set<std::string> librarypaths,
53 std::set<std::string> libraries, std::string &error,
bool debug)
56 if (system(
NULL) == 0)
58 error =
"system command execution not available";
64 std::string codefilename;
66 std::ofstream codeFile;
69 codefilename = ss.str();
70 codeFile.open((
path_ + codefilename + std::string(
".c")).c_str());
71 if (!codeFile.is_open())
73 error =
"failed to create code file";
81 ss <<
"gcc -c -std=c99 -fPIC -march=native -mtune=native -pipe ";
85 ss <<
"-g -O0 -Wall -Wno-unused-label ";
88 for (std::set<std::string>::const_iterator iter = headerpaths.begin(); iter != headerpaths.end(); iter++)
90 ss <<
"-I\"" << *iter <<
"\" ";
92 ss <<
path_ << codefilename <<
".c"
93 <<
" -o " <<
path_ << codefilename <<
".o";
97 int eval = system(ss.str().c_str());
102 std::cout <<
"compiler failed with code: " << eval << std::endl;
107 ss <<
"gcc -shared ";
113 for (std::set<std::string>::const_iterator iter = librarypaths.begin(); iter != librarypaths.end(); iter++)
115 ss <<
" -L" << *iter <<
" ";
118 ss <<
" -o " <<
path_ <<
"lib" << codefilename <<
".so " <<
path_ << codefilename <<
".o ";
120 for (std::set<std::string>::const_iterator iter = libraries.begin(); iter != libraries.end(); iter++)
122 ss <<
" -l\"" << *iter <<
"\" ";
125 if (!librarypaths.empty())
128 for (std::set<std::string>::const_iterator iter = librarypaths.begin(); iter != librarypaths.end(); iter++)
130 ss <<
",-rpath," << *iter;
134 eval = system(ss.str().c_str());
139 std::cout <<
"compiler failed with code: " << eval << std::endl;
142 void *lib = dlopen((
path_ +
"lib" + codefilename + std::string(
".so")).c_str(), RTLD_NOW | RTLD_LOCAL);
virtual void * translate(std::string code, std::set< std::string > headerpaths, std::set< std::string > librarypaths, std::set< std::string > libraries, std::string &error, bool debug=false)
translate C code to executable code and return a handle/pointer that identifies the compilation resul...
virtual void * getFunction(void *handle, std::string name, std::string &error)
returns a function pointer to a compiled function from the handle returned by etiss::JIT::translate