Go to the documentation of this file.
15 #ifndef OPENVDB_AX_COMPILER_HAS_BEEN_INCLUDED
16 #define OPENVDB_AX_COMPILER_HAS_BEEN_INCLUDED
23 #include "../ast/Parse.h"
43 class FunctionRegistry;
53 using Ptr = std::shared_ptr<Compiler>;
77 template <
typename ExecutableT>
78 typename ExecutableT::Ptr
93 template <
typename ExecutableT>
94 typename ExecutableT::Ptr
101 if (syntaxTree)
return compile<ExecutableT>(*syntaxTree, logger, data);
113 template <
typename ExecutableT>
114 typename ExecutableT::Ptr
118 std::vector<std::string> errors;
119 openvdb::ax::Logger logger(
120 [&errors] (
const std::string& error) {
121 errors.emplace_back(error +
"\n");
124 [] (
const std::string&) {}
127 typename ExecutableT::Ptr exe;
129 exe = this->compile<ExecutableT>(*syntaxTree, logger, data);
131 if (!errors.empty()) {
132 std::ostringstream os;
133 for (
const auto& e : errors) os << e <<
"\n";
146 template <
typename ExecutableT>
147 typename ExecutableT::Ptr
151 std::vector<std::string> errors;
152 openvdb::ax::Logger logger(
153 [&errors] (
const std::string& error) {
154 errors.emplace_back(error +
"\n");
157 [] (
const std::string&) {}
159 auto exe = compile<ExecutableT>(syntaxTree, logger, data);
160 if (!errors.empty()) {
161 std::ostringstream os;
162 for (
const auto& e : errors) os << e <<
"\n";
180 template <
typename ExecutableT>
182 typename ExecutableT::Ptr
185 std::vector<std::string>* warnings) {
186 openvdb::ax::Logger logger(
188 [] (
const std::string& error) {
192 [&warnings] (
const std::string& warn) {
193 if (warnings) warnings->emplace_back(warn);
196 return compile<ExecutableT>(syntaxTree, logger, data);
199 template <
typename ExecutableT>
201 typename ExecutableT::Ptr
204 std::vector<std::string>* warnings) {
205 openvdb::ax::Logger logger(
207 [] (
const std::string& error) {
211 [&warnings] (
const std::string& warn) {
212 if (warnings) warnings->emplace_back(warn);
215 return compile<ExecutableT>(code, logger, data);
222 std::shared_ptr<llvm::LLVMContext> mContext;
224 std::shared_ptr<codegen::FunctionRegistry> mFunctionRegistry;
232 #endif // OPENVDB_AX_COMPILER_HAS_BEEN_INCLUDED
A Tree is the highest concrete (non-abstract) node in the entire AX AST hierarchy....
Definition: AST.h:562
Logger for collecting errors and warnings that occur during AX compilation.
Definition: Logger.h:55
Definition: Compiler.h:31
Definition: ax/openvdb_ax/Exceptions.h:37
std::shared_ptr< CustomData > Ptr
Definition: CustomData.h:46
ExecutableT::Ptr compile(const std::string &code, const CustomData::Ptr data=CustomData::Ptr())
Compile a given snippet of AX code into an executable object of the given type.
Definition: Compiler.h:115
Access to the CustomData class which can provide custom user user data to the OpenVDB AX Compiler.
Library and file format version numbers.
#define OPENVDB_THROW(exception, message)
Definition: openvdb/Exceptions.h:82
Compiler(const CompilerOptions &options=CompilerOptions())
Construct a compiler object with given settings.
OPENVDB_DEPRECATED ExecutableT::Ptr compile(const ast::Tree &syntaxTree, const CustomData::Ptr data, std::vector< std::string > *warnings)
deprecated methods
Definition: Compiler.h:183
ExecutableT::Ptr compile(const ast::Tree &syntaxTree, Logger &logger, const CustomData::Ptr data=CustomData::Ptr())
Compile a given AST into an executable object of the given type.
std::shared_ptr< const Tree > ConstPtr
Definition: AST.h:564
std::unique_ptr< Compiler > UniquePtr
Definition: Compiler.h:54
Logging system to collect errors and warnings throughout the different stages of parsing and compilat...
The compiler class. This holds an llvm context and set of compiler options, and constructs executable...
Definition: Compiler.h:50
ExecutableT::Ptr compile(const ast::Tree &syntaxTree, const CustomData::Ptr data=CustomData::Ptr())
Compile a given AST into an executable object of the given type.
Definition: Compiler.h:148
OPENVDB_DEPRECATED ExecutableT::Ptr compile(const std::string &code, const CustomData::Ptr data, std::vector< std::string > *warnings)
Definition: Compiler.h:202
Definition: ax/openvdb_ax/Exceptions.h:35
Settings which control how a Compiler class object behaves.
Definition: CompilerOptions.h:48
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:147
void clear()
Clear the tree-code mapping and reset the number of errors/warnings.
OpenVDB AX Compiler Options.
openvdb::ax::ast::Tree::Ptr parse(const char *code)
Construct an abstract syntax tree from a code snippet. A runtime exception will be thrown with the fi...
std::shared_ptr< Compiler > Ptr
Definition: Compiler.h:53
ExecutableT::Ptr compile(const std::string &code, Logger &logger, const CustomData::Ptr data=CustomData::Ptr())
Compile a given snippet of AX code into an executable object of the given type.
Definition: Compiler.h:95
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:95
static UniquePtr create(const CompilerOptions &options=CompilerOptions())
Static method for creating Compiler objects.
void setFunctionRegistry(std::unique_ptr< codegen::FunctionRegistry > &&functionRegistry)
Sets the compiler's function registry object.
Definition: openvdb/Exceptions.h:13