1#ifndef CPPAD_CG_CLANG_COMPILER_INCLUDED
2#define CPPAD_CG_CLANG_COMPILER_INCLUDED
30 std::set<std::string> _bcfiles;
37 this->_compileFlags.push_back(
"-O2");
38 this->_compileLibFlags.push_back(
"-O2");
39 this->_compileLibFlags.push_back(
"-shared");
40 this->_compileLibFlags.push_back(
"-rdynamic");
46 const std::string& getVersion() {
47 if(_version.empty()) {
48 std::vector<std::string>
args {
"--version"};
52 std::string
vv =
"version ";
54 if(
is == std::string::npos) {
55 throw CGException(
"Failed to determine Clang version");
68 virtual const std::set<std::string>& getBitCodeFiles()
const {
72 virtual void generateLLVMBitCode(
const std::map<std::string, std::string>&
sources,
75 this->_compileFlags.push_back(
"-emit-llvm");
79 this->_compileFlags.pop_back();
92#if CPPAD_CG_SYSTEM_APPLE
94#elif CPPAD_CG_SYSTEM_LINUX
98 for (
size_t i = 0;
i < this->_linkFlags.size();
i++)
101 std::vector<std::string>
args;
102 args.insert(
args.end(),
this->_compileLibFlags.begin(),
this->_compileLibFlags.end());
104 args.push_back(
"-o");
107 for (
const std::string&
it : this->_ofiles) {
111 if (
timer !=
nullptr) {
112 timer->startingJob(
"'" +
library +
"'", JobTimer::COMPILING_DYNAMIC_LIBRARY);
113 }
else if (this->_verbose) {
114 std::cout <<
"building library '" <<
library <<
"'" << std::endl;
119 if (
timer !=
nullptr) {
120 timer->finishedJob();
126 for (
const std::string&
it : _bcfiles) {
127 if (remove(
it.c_str()) != 0)
128 std::cerr <<
"Failed to delete temporary file '" <<
it <<
"'" << std::endl;
140 static std::vector<std::string> parseVersion(
const std::string&
version) {
143 auto vv2 = explode(
vv[2],
"-");
144 if (
vv2.size() > 1) {
145 vv.erase(
vv.begin() + 2);
146 vv.insert(
vv.begin() + 2,
vv2.begin(),
vv2.end());
162 const std::string&
output,
164 std::vector<std::string>
args;
165 args.push_back(
"-x");
167 args.insert(
args.end(),
this->_compileFlags.begin(),
this->_compileFlags.end());
168 args.push_back(
"-c");
171 args.push_back(
"-fPIC");
173 args.push_back(
"-o");
180 const std::string&
output,
182 std::vector<std::string>
args;
183 args.push_back(
"-x");
185 args.insert(
args.end(),
this->_compileFlags.begin(),
this->_compileFlags.end());
187 args.push_back(
"-fPIC");
189 args.push_back(
"-c");
191 args.push_back(
"-o");
void compileSources(const std::map< std::string, std::string > &sources, bool posIndepCode, JobTimer *timer=nullptr) override
void compileSource(const std::string &source, const std::string &output, bool posIndepCode) override
void compileFile(const std::string &path, const std::string &output, bool posIndepCode) override
void buildDynamic(const std::string &library, JobTimer *timer=nullptr) override
void callExecutable(const std::string &executable, const std::vector< std::string > &args, std::string *stdOutErrMessage=nullptr, const std::string *stdInMessage=nullptr)
bool GreaterThanZero(const cg::CG< Base > &x)