summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJosh Blum2013-08-05 01:18:36 -0700
committerJosh Blum2013-08-05 01:18:36 -0700
commit0ce842fc52e63ff2cfde2ae07afaccc8cffd0117 (patch)
tree1befc32a54bd3c5f2561bb70012ae5cbd80a0ed5 /lib
parentcb68dc4b2de256176e5ed224767241b033e2ede9 (diff)
downloadsandhi-0ce842fc52e63ff2cfde2ae07afaccc8cffd0117.tar.gz
sandhi-0ce842fc52e63ff2cfde2ae07afaccc8cffd0117.tar.bz2
sandhi-0ce842fc52e63ff2cfde2ae07afaccc8cffd0117.zip
gras: jit factory use FindProgramByName
Diffstat (limited to 'lib')
-rw-r--r--lib/CMakeLists.txt9
-rw-r--r--lib/jit_factory.cpp11
2 files changed, 5 insertions, 15 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index f8aaebc..ead097a 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -132,15 +132,6 @@ if(CLANG_FOUND)
list(APPEND GRAS_LIBRARIES ${CLANG_LIBS})
endif()
-#step 4) find clang executable as backup (found llvm but not clang dev)
-find_program(CLANG_EXECUTABLE clang DOC "clang executable")
-if(CLANG_EXECUTABLE)
- SET_SOURCE_FILES_PROPERTIES(
- ${CMAKE_CURRENT_SOURCE_DIR}/jit_factory.cpp
- PROPERTIES COMPILE_DEFINITIONS "CLANG_EXECUTABLE=${CLANG_EXECUTABLE}"
- )
-endif()
-
########################################################################
# Build library
########################################################################
diff --git a/lib/jit_factory.cpp b/lib/jit_factory.cpp
index e7362cc..331e87a 100644
--- a/lib/jit_factory.cpp
+++ b/lib/jit_factory.cpp
@@ -85,18 +85,18 @@ static ExecutionEngineMonitor &get_eemon(void)
/***********************************************************************
* Helper function to call a clang compliation -- execs clang
**********************************************************************/
-#ifdef CLANG_EXECUTABLE
static llvm::Module *call_clang_exe(const std::string &source_file, const std::vector<std::string> &flags)
{
std::cout << "GRAS compiler: compile source into bitcode..." << std::endl;
//make up bitcode file path
char bitcode_file[L_tmpnam];
- std::tmpnam(bitcode_file);
+ if (std::tmpnam(bitcode_file) == NULL) throw std::runtime_error("GRAS compiler: tmp bitcode file path failed");
//begin command setup
std::vector<std::string> cmd;
- cmd.push_back(BOOST_STRINGIZE(CLANG_EXECUTABLE));
+ llvm::sys::Path clangPath = llvm::sys::Program::FindProgramByName("clang");
+ cmd.push_back(clangPath.str());
cmd.push_back("-emit-llvm");
//inject source
@@ -141,7 +141,6 @@ static llvm::Module *call_clang_exe(const std::string &source_file, const std::v
if (not error.empty()) throw std::runtime_error("GRAS compiler: ParseBitcodeFile " + error);
return module;
}
-#endif //CLANG_EXECUTABLE
/***********************************************************************
* Helper function to call a clang compliation -- uses clang API
@@ -211,8 +210,8 @@ static llvm::Module *call_clang_api(const std::string &source_file, const std::v
void gras::jit_factory(const std::string &source, const std::vector<std::string> &flags_)
{
//write source to tmp file
- char source_file[L_tmpnam];
- std::tmpnam(source_file);
+ char source_file[L_tmpnam];\
+ if (std::tmpnam(source_file) == NULL) throw std::runtime_error("GRAS compiler: tmp source file path failed");\
std::ofstream source_fstream(source_file);
source_fstream << source;
source_fstream.close();