1 // Copyright 2021 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SRC_WRITER_GLSL_GENERATOR_H_
16 #define SRC_WRITER_GLSL_GENERATOR_H_
17 
18 #include <memory>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 #include "src/ast/pipeline_stage.h"
24 #include "src/writer/text.h"
25 
26 namespace tint {
27 
28 // Forward declarations
29 class Program;
30 
31 namespace writer {
32 namespace glsl {
33 
34 // Forward declarations
35 class GeneratorImpl;
36 
37 /// Configuration options used for generating GLSL.
38 struct Options {};
39 
40 /// The result produced when generating GLSL.
41 struct Result {
42   /// Constructor
43   Result();
44 
45   /// Destructor
46   ~Result();
47 
48   /// Copy constructor
49   Result(const Result&);
50 
51   /// True if generation was successful.
52   bool success = false;
53 
54   /// The errors generated during code generation, if any.
55   std::string error;
56 
57   /// The generated GLSL.
58   std::string glsl = "";
59 
60   /// The list of entry points in the generated GLSL.
61   std::vector<std::pair<std::string, ast::PipelineStage>> entry_points;
62 };
63 
64 /// Generate GLSL for a program, according to a set of configuration options.
65 /// The result will contain the GLSL, as well as success status and diagnostic
66 /// information.
67 /// @param program the program to translate to GLSL
68 /// @param options the configuration options to use when generating GLSL
69 /// @returns the resulting GLSL and supplementary information
70 Result Generate(const Program* program,
71                 const Options& options,
72                 const std::string& entry_point);
73 
74 }  // namespace glsl
75 }  // namespace writer
76 }  // namespace tint
77 
78 #endif  // SRC_WRITER_GLSL_GENERATOR_H_
79