OmniSciDB  471d68cefb
 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 159 of file UdfCompiler.cpp.

Referenced by UdfCompiler::generateAST().

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

+ Here is the caller graph for this function:

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

Definition at line 163 of file UdfCompiler.cpp.

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

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

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

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

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

Definition at line 177 of file UdfCompiler.cpp.

References count, exec_output(), and run_benchmark_import::result.

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

+ Here is the call graph for this function:

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

Definition at line 357 of file UdfCompiler.cpp.

References i.

Referenced by replace_extension().

357  {
358  size_t i = s.rfind('.', s.length());
359  if (1 != std::string::npos) {
360  return (s.substr(i + 1, s.length() - i));
361  }
362 }

+ Here is the caller graph for this function:

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

Definition at line 344 of file UdfCompiler.cpp.

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

344  {
345  if (path == "." || path == "..") {
346  return path;
347  }
348 
349  size_t pos = path.find_last_of("\\/.");
350  if (pos != std::string::npos && path[pos] == '.') {
351  return path.substr(0, pos);
352  }
353 
354  return path;
355 }

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

References get_file_ext(), and i.

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

364  {
365  std::string::size_type i = s.rfind('.', s.length());
366 
367  if (i != std::string::npos) {
368  s.replace(i + 1, get_file_ext(s).length(), new_ext);
369  }
370 }
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: