1 // Copyright Contributors to the Open Shading Language project.
2 // SPDX-License-Identifier: BSD-3-Clause
3 // https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
4 
5 #pragma once
6 
7 #include <OSL/oslconfig.h>
8 
9 OSL_NAMESPACE_ENTER
10 
11 
12 namespace pvt {
13 class OSLCompilerImpl;
14 }
15 
16 
17 
18 class OSLCOMPPUBLIC OSLCompiler {
19 public:
20     OSLCompiler(ErrorHandler* errhandler = NULL);
21     ~OSLCompiler();
22 
23     /// Compile the given file, using the list of command-line options. The
24     /// stdoslpath parameter provides a custom path for finding stdosl.h.
25     /// Return true if ok, false if the compile failed.
26     bool compile(string_view filename, const std::vector<std::string>& options,
27                  string_view stdoslpath = string_view());
28 
29     /// Compile the given source code buffer, using the list of command-line
30     /// options, placing the resulting "oso" in osobuffer. The stdoslpath
31     /// parameter provides a custom path for finding stdosl.h. The filename
32     /// optionally provides a name for the buffer, used for error reporting
33     /// (the compile() from file method would have used the name of the
34     /// actual file for this purpose). Return true if ok, false if the
35     /// compile failed.
36     bool compile_buffer(string_view sourcecode, std::string& osobuffer,
37                         const std::vector<std::string>& options,
38                         string_view stdoslpath = string_view(),
39                         string_view filename   = string_view());
40 
41     /// Return the name of our compiled output (must be called after
42     /// compile()).
43     string_view output_filename() const;
44 
45 private:
46     pvt::OSLCompilerImpl* m_impl;
47 };
48 
49 
50 
51 OSL_NAMESPACE_EXIT
52