OmniSciDB  0bd2ec9cf4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UDFCompiler.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 #ifndef UDF_COMPILER_H
26 #define UDF_COMPILER_H
27 
28 #include <clang/Driver/Compilation.h>
29 #include <clang/Driver/Driver.h>
30 #include <clang/Frontend/CompilerInstance.h>
31 #include <string>
32 #include <vector>
33 
35  public:
37 
38  std::string getClangPath() { return clang_path; }
39  clang::driver::Driver* getClangDriver() { return &the_driver; }
40 
41  private:
42  std::string clang_path;
43  llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diag_options;
44  clang::DiagnosticConsumer* diag_client;
45  llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diag_id;
46  clang::DiagnosticsEngine diags;
47  std::unique_ptr<clang::DiagnosticConsumer> diag_client_owner;
48  clang::driver::Driver the_driver;
49 };
50 
51 class UdfCompiler {
52  public:
53  UdfCompiler(const std::string&);
54  int compileUdf();
55  const std::string& getAstFileName() const;
56 
57  private:
58  std::string removeFileExtension(const std::string& path);
59  std::string getFileExt(std::string& s);
60  int parseToAst(const char* file_name);
61  std::string genGpuIrFilename(const char* udf_file_name);
62  std::string genCpuIrFilename(const char* udf_file_name);
63  int compileToGpuByteCode(const char* udf_file_name, bool cpu_mode);
64  int compileToCpuByteCode(const char* udf_file_name);
65  void replaceExtn(std::string& s, const std::string& new_ext);
66  int compileFromCommandLine(std::vector<const char*>& command_line);
67  void readCompiledModules();
68  void readGpuCompiledModule();
69  void readCpuCompiledModule();
70  int compileForGpu();
71 
72  private:
73  std::string udf_file_name_;
74  std::string udf_ast_file_name_;
75 };
76 #endif
clang::driver::Driver * getClangDriver()
Definition: UDFCompiler.h:39
std::string genCpuIrFilename(const char *udf_file_name)
int compileToCpuByteCode(const char *udf_file_name)
void readCompiledModules()
UdfCompiler(const std::string &)
const std::string & getAstFileName() const
void readCpuCompiledModule()
std::string clang_path
Definition: UDFCompiler.h:42
std::string getClangPath()
Definition: UDFCompiler.h:38
std::string genGpuIrFilename(const char *udf_file_name)
std::string removeFileExtension(const std::string &path)
llvm::IntrusiveRefCntPtr< clang::DiagnosticIDs > diag_id
Definition: UDFCompiler.h:45
int compileToGpuByteCode(const char *udf_file_name, bool cpu_mode)
std::string udf_ast_file_name_
Definition: UDFCompiler.h:74
int parseToAst(const char *file_name)
std::string udf_file_name_
Definition: UDFCompiler.h:73
int compileUdf()
void replaceExtn(std::string &s, const std::string &new_ext)
std::unique_ptr< clang::DiagnosticConsumer > diag_client_owner
Definition: UDFCompiler.h:47
void readGpuCompiledModule()
int compileFromCommandLine(std::vector< const char * > &command_line)
std::string getFileExt(std::string &s)
int compileForGpu()
clang::driver::Driver the_driver
Definition: UDFCompiler.h:48
clang::DiagnosticsEngine diags
Definition: UDFCompiler.h:46
llvm::IntrusiveRefCntPtr< clang::DiagnosticOptions > diag_options
Definition: UDFCompiler.h:43
clang::DiagnosticConsumer * diag_client
Definition: UDFCompiler.h:44