OmniSciDB  72c90bc290
 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 163 of file UdfCompiler.cpp.

Referenced by UdfCompiler::generateAST().

163  {
164  return s.c_str();
165 }

+ Here is the caller graph for this function:

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

Definition at line 167 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().

167  {
168  std::array<char, 128> buffer;
169  std::string result;
170  std::unique_ptr<FILE, decltype(&heavyai::pclose)> pipe(heavyai::popen(cmd.c_str(), "r"),
172  if (!pipe) {
173  throw std::runtime_error("heavyai::popen(\"" + cmd + "\") failed!");
174  }
175  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
176  result += buffer.data();
177  }
178  return result;
179 }
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 290 of file UdfCompiler.cpp.

290  {
291  if (clang_path_override.empty()) {
292  const auto clang_path = (llvm::sys::findProgramByName("clang++").get());
293  if (clang_path.empty()) {
294  throw std::runtime_error(
295  "Unable to find clang++ to compile user defined functions");
296  }
297  return clang_path;
298  } else {
299  if (!boost::filesystem::exists(clang_path_override)) {
300  throw std::runtime_error("Path provided for udf compiler " + clang_path_override +
301  " does not exist.");
302  }
303 
304  if (boost::filesystem::is_directory(clang_path_override)) {
305  throw std::runtime_error("Path provided for udf compiler " + clang_path_override +
306  " is not to the clang++ executable.");
307  }
308  }
309  return clang_path_override;
310 }
std::tuple<int, int, int> anonymous_namespace{UdfCompiler.cpp}::get_clang_version ( const std::string &  clang_path)

Definition at line 181 of file UdfCompiler.cpp.

References exec_output(), and run_benchmark_import::result.

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

Referenced by replace_extension().

383  {
384  size_t i = s.rfind('.', s.length());
385  if (1 != std::string::npos) {
386  return (s.substr(i + 1, s.length() - i));
387  }
388 }

+ Here is the caller graph for this function:

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

Definition at line 370 of file UdfCompiler.cpp.

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

370  {
371  if (path == "." || path == "..") {
372  return path;
373  }
374 
375  size_t pos = path.find_last_of("\\/.");
376  if (pos != std::string::npos && path[pos] == '.') {
377  return path.substr(0, pos);
378  }
379 
380  return path;
381 }

+ 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 390 of file UdfCompiler.cpp.

References get_file_ext().

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

390  {
391  std::string::size_type i = s.rfind('.', s.length());
392 
393  if (i != std::string::npos) {
394  s.replace(i + 1, get_file_ext(s).length(), new_ext);
395  }
396 }
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: