30
30
31
31
#include < openvdb_ax/ast/AST.h>
32
32
#include < openvdb_ax/ast/Scanners.h>
33
+ #include < openvdb_ax/ast/PrintTree.h>
33
34
#include < openvdb_ax/codegen/FunctionRegistry.h>
34
35
#include < openvdb_ax/compiler/Compiler.h>
35
36
#include < openvdb_ax/compiler/PointExecutable.h>
@@ -57,6 +58,7 @@ struct ProgOptions
57
58
std::string mInputVDBFile = " " ;
58
59
std::string mOutputVDBFile = " " ;
59
60
bool mVerbose = false ;
61
+ bool mPrintAST = false ;
60
62
};
61
63
62
64
void
@@ -70,6 +72,7 @@ usage [[noreturn]] (int exitStatus = EXIT_FAILURE)
70
72
" -f file.txt execute text file containing a code snippet on the input.vdb file\n " <<
71
73
" -v verbose (print timing and diagnostics)\n " <<
72
74
" --list-functions list all available functions, their signatures and their documentation\n " <<
75
+ " --print-ast print the abstract syntax tree generated for point and volume execution\n " <<
73
76
" Warning:\n " <<
74
77
" Providing the same file-path to both input.vdb and output.vdb arguments will overwrite\n " <<
75
78
" the file. If no output file is provided, the input.vdb will be processed but will remain\n " <<
@@ -205,6 +208,8 @@ main(int argc, char *argv[])
205
208
initializer.initializeCompiler ();
206
209
printFunctions (std::cout);
207
210
return EXIT_SUCCESS;
211
+ } else if (parser.check (i, " --print-ast" , 0 )) {
212
+ options.mPrintAST = true ;
208
213
} else if (arg == " -h" || arg == " -help" || arg == " --help" ) {
209
214
usage (EXIT_SUCCESS);
210
215
} else {
@@ -259,6 +264,14 @@ main(int argc, char *argv[])
259
264
initializer.initializeCompiler ();
260
265
openvdb::ax::Compiler::Ptr compiler = openvdb::ax::Compiler::create ();
261
266
267
+ // parse
268
+
269
+ const openvdb::ax::ast::Tree::ConstPtr syntaxTree =
270
+ openvdb::ax::ast::parse (options.mInputCode .c_str ());
271
+ if (options.mPrintAST ) {
272
+ openvdb::ax::ast::print (*syntaxTree);
273
+ }
274
+
262
275
// Execute on PointDataGrids
263
276
264
277
bool executeOnPoints = false ;
@@ -276,9 +289,6 @@ main(int argc, char *argv[])
276
289
openvdb::ax::CustomData::Ptr customData = openvdb::ax::CustomData::create ();
277
290
PointExecutable::Ptr pointExecutable;
278
291
279
- const openvdb::ax::ast::Tree::ConstPtr syntaxTree =
280
- openvdb::ax::ast::parse (options.mInputCode .c_str ());
281
-
282
292
if (options.mVerbose ) std::cout << " OpenVDB PointDataGrids Found" << std::endl;
283
293
std::vector<std::string> warnings;
284
294
@@ -348,7 +358,7 @@ main(int argc, char *argv[])
348
358
try {
349
359
if (options.mVerbose ) std::cout << " Compiling for Volume VDB Grid..." ;
350
360
volumeExecutable =
351
- compiler->compile <VolumeExecutable>(options. mInputCode , customData, &warnings);
361
+ compiler->compile <VolumeExecutable>(*syntaxTree , customData, &warnings);
352
362
} catch (std::exception & e) {
353
363
OPENVDB_LOG_FATAL (" Compilation error!" );
354
364
OPENVDB_LOG_FATAL (" Errors:" );
0 commit comments