87void *
GCCJIT::translate(std::string code, std::set<std::string> headerpaths, std::set<std::string> librarypaths,
88 std::set<std::string> libraries, std::string &error,
bool debug)
91 if (system(
NULL) == 0)
93 error =
"system command execution not available";
99 std::string codefilename;
101 std::ofstream codeFile;
102 std::stringstream ss;
103 ss <<
"code_" << lid;
104 codefilename = ss.str();
105 codeFile.open((
path_ + codefilename + std::string(
".c")).c_str());
106 if (!codeFile.is_open())
108 error =
"failed to create code file";
115 std::stringstream ss;
116 ss <<
"gcc -c -std=c99 -fPIC -march=native -mtune=native -pipe ";
118 ss <<
"-g -O0 -Wall -Wno-unused-label ";
121 for (std::set<std::string>::const_iterator iter = headerpaths.begin(); iter != headerpaths.end(); iter++)
123 ss <<
"-I\"" << *iter <<
"\" ";
125 ss <<
path_ << codefilename <<
".c"
126 <<
" -o " <<
path_ << codefilename <<
".o";
130 int eval = system(ss.str().c_str());
135 std::cout <<
"compiler failed with code: " << eval << std::endl;
140 ss <<
"gcc -shared ";
146 for (std::set<std::string>::const_iterator iter = librarypaths.begin();iter != librarypaths.end();iter++){
147 ss <<
" -L" << *iter <<
" ";
150 ss <<
" -o " <<
path_ <<
"lib" << codefilename <<
".so " <<
path_ << codefilename <<
".o ";
153 for (std::set<std::string>::const_iterator iter = libraries.begin();iter != libraries.end();iter++){
154 ss <<
" -l\"" << *iter <<
"\" ";
157 if(!librarypaths.empty())
160 for (std::set<std::string>::const_iterator iter = librarypaths.begin();iter != librarypaths.end();iter++){
161 ss <<
",-rpath," << *iter;
165 eval = system(ss.str().c_str());
170 std::cout <<
"compiler failed with code: " << eval << std::endl;
173 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