1 // Copyright 2020 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_WGSL_GENERATOR_H_ 16 #define SRC_WRITER_WGSL_GENERATOR_H_ 17 18 #include <memory> 19 #include <string> 20 21 #include "src/writer/text.h" 22 23 namespace tint { 24 25 // Forward declarations 26 class Program; 27 28 namespace writer { 29 namespace wgsl { 30 31 class GeneratorImpl; 32 33 /// Configuration options used for generating WGSL. 34 struct Options {}; 35 36 /// The result produced when generating WGSL. 37 struct Result { 38 /// Constructor 39 Result(); 40 41 /// Destructor 42 ~Result(); 43 44 /// Copy constructor 45 Result(const Result&); 46 47 /// True if generation was successful. 48 bool success = false; 49 50 /// The errors generated during code generation, if any. 51 std::string error; 52 53 /// The generated WGSL. 54 std::string wgsl = ""; 55 }; 56 57 /// Generate WGSL for a program, according to a set of configuration options. 58 /// The result will contain the WGSL, as well as success status and diagnostic 59 /// information. 60 /// @param program the program to translate to WGSL 61 /// @param options the configuration options to use when generating WGSL 62 /// @returns the resulting WGSL and supplementary information 63 Result Generate(const Program* program, const Options& options); 64 65 } // namespace wgsl 66 } // namespace writer 67 } // namespace tint 68 69 #endif // SRC_WRITER_WGSL_GENERATOR_H_ 70