Fixed a warning when compiling with LLVM 3.1
authorBenjamin Segovia <benjamin.segovia@intel.com>
Fri, 9 Nov 2012 08:29:08 +0000 (00:29 -0800)
committerBenjamin Segovia <benjamin.segovia@intel.com>
Fri, 9 Nov 2012 08:29:08 +0000 (00:29 -0800)
Replaced invocatiopn of clang with dirty "system()" by a cleaner "popen()". The
cleanest solution should to use the clang API

backend/src/backend/context.cpp
backend/src/backend/program.cpp
backend/src/llvm/llvm_gen_backend.cpp
src/cl_program.c

index 7c047f1..196497d 100644 (file)
@@ -245,7 +245,7 @@ namespace gbe
     unit(unit), fn(*unit.getFunction(name)), name(name), liveness(NULL), dag(NULL)
   {
     GBE_ASSERT(unit.getPointerSize() == ir::POINTER_32_BITS);
-    this->liveness = GBE_NEW(ir::Liveness, (ir::Function&) fn);
+    this->liveness = GBE_NEW(ir::Liveness, const_cast<ir::Function&>(fn));
     this->dag = GBE_NEW(ir::FunctionDAG, *this->liveness);
     this->partitioner = GBE_NEW_NO_ARG(RegisterFilePartitioner);
     if (fn.getSimdWidth() == 0)
index f3afea2..975c5c9 100644 (file)
@@ -115,16 +115,22 @@ namespace gbe {
     fclose(clFile);
 
     // Now compile the code to llvm using clang
-    // XXX use popen and stuff instead of that
 #if LLVM_VERSION_MINOR <= 1
-    std::string compileCmd = "clang -x cl -fno-color-diagnostics -emit-llvm -O3 -ccc-host-triple ptx32 -c ";
+    std::string compileCmd = LLVM_PREFIX "/bin/clang -x cl -fno-color-diagnostics -emit-llvm -O3 -ccc-host-triple ptx32 -c ";
 #else
-    std::string compileCmd = "clang -target nvptx -x cl -fno-color-diagnostics -emit-llvm -O3 -c ";
+    std::string compileCmd = LLVM_PREFIX "/bin/clang -target nvptx -x cl -fno-color-diagnostics -emit-llvm -O3 -c ";
 #endif /* LLVM_VERSION_MINOR <= 1 */
     compileCmd += clName;
     compileCmd += " -o ";
     compileCmd += llName;
-    if (UNLIKELY(system(compileCmd.c_str()) != 0)) return NULL;
+
+    // Open a pipe and compile from here. Using Clang API instead is better
+    FILE *pipe = popen(compileCmd.c_str(), "r");
+    FATAL_IF (pipe == NULL, "Unable to run extern compilation command");
+    char msg[256];
+    while (fgets(msg, sizeof(msg), pipe))
+      std::cout << msg;
+    pclose(pipe);
 
     // Now build the program from llvm
     return gbe_program_new_from_llvm(llName.c_str(), stringSize, err, errSize);
index db46703..32631b0 100644 (file)
@@ -1680,7 +1680,6 @@ namespace gbe
         CallSite::arg_iterator AE = CS.arg_end();
 #endif /* GBE_DEBUG */
 
-
         switch (it->second) {
           case GEN_OCL_MAD:
           {
index 5f409d0..42ef822 100644 (file)
@@ -271,7 +271,7 @@ cl_program_build(cl_program p)
 
   if (p->source_type == FROM_SOURCE) {
     /* XXX support multiple sources later */
-    FATAL_IF (p->src_n != 1, "Only ONE source supported");
+    FATAL_IF (p->src_n != 1, "Only ONE source file supported");
     p->opaque = gbe_program_new_from_source(p->sources[0], 0, NULL, NULL);
     if (UNLIKELY(p->opaque == NULL)) {
       err = CL_INVALID_PROGRAM;