diff options
author | Tom Stellard <[email protected]> | 2012-11-27 21:57:15 +0000 |
---|---|---|
committer | Tom Stellard <[email protected]> | 2012-12-13 19:22:44 +0000 |
commit | c68babfc3c7b65dd53697528781bd6b6186f5190 (patch) | |
tree | 5c5546488db700d88940510b166986f8d7be1ff2 /src/gallium/state_trackers/clover/llvm | |
parent | 7f71efcf7a8eace124e71ca72c86d4c2bdc8042d (diff) |
clover: Add support for compiler flags
Reviewed-by: Francisco Jerez <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/llvm')
-rw-r--r-- | src/gallium/state_trackers/clover/llvm/invocation.cpp | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp index 2b07053ba20..c9973679a4c 100644 --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp @@ -23,6 +23,7 @@ #include "core/compiler.hpp" #include <clang/Frontend/CompilerInstance.h> +#include <clang/Frontend/TextDiagnosticBuffer.h> #include <clang/Frontend/TextDiagnosticPrinter.h> #include <clang/CodeGen/CodeGenAction.h> #include <llvm/Bitcode/BitstreamWriter.h> @@ -51,6 +52,7 @@ #include <iomanip> #include <fstream> #include <cstdio> +#include <sstream> using namespace clover; @@ -98,15 +100,49 @@ namespace { llvm::Module * compile(const std::string &source, const std::string &name, - const std::string &triple) { + const std::string &triple, const std::string &opts) { clang::CompilerInstance c; + clang::CompilerInvocation invocation; clang::EmitLLVMOnlyAction act(&llvm::getGlobalContext()); std::string log; llvm::raw_string_ostream s_log(log); - c.getFrontendOpts().Inputs.push_back( - clang::FrontendInputFile(name, clang::IK_OpenCL)); + // Parse the compiler options: + std::vector<std::string> opts_array; + std::istringstream ss(opts); + + while (!ss.eof()) { + std::string opt; + getline(ss, opt, ' '); + opts_array.push_back(opt); + } + + opts_array.push_back(name); + + std::vector<const char *> opts_carray; + for (unsigned i = 0; i < opts_array.size(); i++) { + opts_carray.push_back(opts_array.at(i).c_str()); + } + + llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID; + llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts; + clang::TextDiagnosticBuffer *DiagsBuffer; + + DiagID = new clang::DiagnosticIDs(); + DiagOpts = new clang::DiagnosticOptions(); + DiagsBuffer = new clang::TextDiagnosticBuffer(); + + clang::DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer); + bool Success; + + Success = clang::CompilerInvocation::CreateFromArgs(c.getInvocation(), + opts_carray.data(), + opts_carray.data() + opts_carray.size(), + Diags); + if (!Success) { + throw invalid_option_error(); + } c.getFrontendOpts().ProgramAction = clang::frontend::EmitLLVMOnly; c.getHeaderSearchOpts().UseBuiltinIncludes = true; c.getHeaderSearchOpts().UseStandardSystemIncludes = true; @@ -271,11 +307,14 @@ namespace { module clover::compile_program_llvm(const compat::string &source, enum pipe_shader_ir ir, - const compat::string &triple) { + const compat::string &triple, + const compat::string &opts) { std::vector<llvm::Function *> kernels; - llvm::Module *mod = compile(source, "cl_input", triple); + // The input file name must have the .cl extension in order for the + // CompilerInvocation class to recognize it as an OpenCL source file. + llvm::Module *mod = compile(source, "input.cl", triple, opts); find_kernels(mod, kernels); |