OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{UdfCompiler.cpp} Namespace Reference

Classes

class  FunctionDeclVisitor
 
class  DeclASTConsumer
 
class  HandleDeclAction
 
class  ToolFactory
 
class  UdfClangDriver
 

Functions

const char * convert (const std::string &s)
 
std::string exec_output (std::string cmd)
 
std::tuple< int, int, int > get_clang_version (const std::string &clang_path)
 
std::string get_clang_path (const std::string &clang_path_override)
 
std::string remove_file_extension (const std::string &path)
 
std::string get_file_ext (const std::string &s)
 
void replace_extension (std::string &s, const std::string &new_ext)
 

Function Documentation

const char* anonymous_namespace{UdfCompiler.cpp}::convert ( const std::string &  s)

Definition at line 160 of file UdfCompiler.cpp.

Referenced by UdfCompiler::generateAST().

160  {
161  return s.c_str();
162 }

+ Here is the caller graph for this function:

std::string anonymous_namespace{UdfCompiler.cpp}::exec_output ( std::string  cmd)

Definition at line 164 of file UdfCompiler.cpp.

References heavyai::pclose(), heavyai::popen(), and run_benchmark_import::result.

Referenced by UdfCompiler::compileFromCommandLine(), get_clang_version(), and anonymous_namespace{UdfCompiler.cpp}::UdfClangDriver::UdfClangDriver().

164  {
165  std::array<char, 128> buffer;
166  std::string result;
167  std::unique_ptr<FILE, decltype(&heavyai::pclose)> pipe(heavyai::popen(cmd.c_str(), "r"),
169  if (!pipe) {
170  throw std::runtime_error("heavyai::popen(\"" + cmd + "\") failed!");
171  }
172  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
173  result += buffer.data();
174  }
175  return result;
176 }
int32_t pclose(::FILE *fh)
Definition: heavyai_fs.cpp:82
::FILE * popen(const char *command, const char *type)
Definition: heavyai_fs.cpp:78

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string anonymous_namespace{UdfCompiler.cpp}::get_clang_path ( const std::string &  clang_path_override)

Definition at line 269 of file UdfCompiler.cpp.

269  {
270  if (clang_path_override.empty()) {
271  const auto clang_path = (llvm::sys::findProgramByName("clang++").get());
272  if (clang_path.empty()) {
273  throw std::runtime_error(
274  "Unable to find clang++ to compile user defined functions");
275  }
276  return clang_path;
277  } else {
278  if (!boost::filesystem::exists(clang_path_override)) {
279  throw std::runtime_error("Path provided for udf compiler " + clang_path_override +
280  " does not exist.");
281  }
282 
283  if (boost::filesystem::is_directory(clang_path_override)) {
284  throw std::runtime_error("Path provided for udf compiler " + clang_path_override +
285  " is not to the clang++ executable.");
286  }
287  }
288  return clang_path_override;
289 }
std::tuple<int, int, int> anonymous_namespace{UdfCompiler.cpp}::get_clang_version ( const std::string &  clang_path)

Definition at line 178 of file UdfCompiler.cpp.

References exec_output(), and run_benchmark_import::result.

178  {
179  std::string cmd = clang_path + " --version";
180  std::string result = exec_output(cmd);
181  if (result.empty()) {
182  throw std::runtime_error(
183  "Invalid clang binary path detected, cannot find clang binary. Is clang "
184  "installed?");
185  }
186  int major, minor, patchlevel;
187  auto count = sscanf(result.substr(result.find("clang version")).c_str(),
188  "clang version %d.%d.%d",
189  &major,
190  &minor,
191  &patchlevel);
192  if (count != 3) {
193  throw std::runtime_error("Failed to get clang version from output:\n" + result +
194  "\n");
195  }
196  return {major, minor, patchlevel};
197 }
std::string exec_output(std::string cmd)

+ Here is the call graph for this function:

std::string anonymous_namespace{UdfCompiler.cpp}::get_file_ext ( const std::string &  s)

Definition at line 362 of file UdfCompiler.cpp.

Referenced by replace_extension().

362  {
363  size_t i = s.rfind('.', s.length());
364  if (1 != std::string::npos) {
365  return (s.substr(i + 1, s.length() - i));
366  }
367 }

+ Here is the caller graph for this function:

std::string anonymous_namespace{UdfCompiler.cpp}::remove_file_extension ( const std::string &  path)

Definition at line 349 of file UdfCompiler.cpp.

Referenced by UdfCompiler::genLLVMIRFilename(), and UdfCompiler::genNVVMIRFilename().

349  {
350  if (path == "." || path == "..") {
351  return path;
352  }
353 
354  size_t pos = path.find_last_of("\\/.");
355  if (pos != std::string::npos && path[pos] == '.') {
356  return path.substr(0, pos);
357  }
358 
359  return path;
360 }

+ Here is the caller graph for this function:

void anonymous_namespace{UdfCompiler.cpp}::replace_extension ( std::string &  s,
const std::string &  new_ext 
)

Definition at line 369 of file UdfCompiler.cpp.

References get_file_ext().

Referenced by UdfCompiler::generateAST(), and UdfCompiler::getAstFileName().

369  {
370  std::string::size_type i = s.rfind('.', s.length());
371 
372  if (i != std::string::npos) {
373  s.replace(i + 1, get_file_ext(s).length(), new_ext);
374  }
375 }
std::string get_file_ext(const std::string &s)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: