| // Copyright 2023 The Tint Authors. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #ifndef SRC_TINT_CMD_HELPER_H_ |
| #define SRC_TINT_CMD_HELPER_H_ |
| |
| #include <memory> |
| #include <string> |
| |
| #include "tint/tint.h" |
| |
| namespace tint::cmd { |
| |
| /// Information on a loaded program |
| struct ProgramInfo { |
| /// The loaded program |
| std::unique_ptr<tint::Program> program; |
| /// The source file information |
| std::unique_ptr<tint::Source::File> source_file; |
| }; |
| |
| /// Reporter callback for internal tint errors |
| /// @param diagnostics the diagnostics to emit |
| [[noreturn]] void TintInternalCompilerErrorReporter(const tint::diag::List& diagnostics); |
| |
| /// PrintWGSL writes the WGSL of the program to the provided ostream, if the |
| /// WGSL writer is enabled, otherwise it does nothing. |
| /// @param out the output stream to write the WGSL to |
| /// @param program the program |
| void PrintWGSL(std::ostream& out, const tint::Program& program); |
| |
| /// Prints inspector data information to stderr |
| /// @param inspector the inspector to print. |
| void PrintInspectorData(tint::inspector::Inspector& inspector); |
| |
| /// Prints inspector binding information to stderr |
| /// @param inspector the inspector to print. |
| void PrintInspectorBindings(tint::inspector::Inspector& inspector); |
| |
| /// Options for the LoadProgramInfo call |
| struct LoadProgramOptions { |
| /// The file to be loaded |
| std::string filename; |
| #if TINT_BUILD_SPV_READER |
| /// Spirv-reader options |
| tint::reader::spirv::Options spirv_reader_options; |
| #endif |
| }; |
| |
| /// Loads the source and program information for the given file |
| /// @param opts the loading options |
| ProgramInfo LoadProgramInfo(const LoadProgramOptions& opts); |
| |
| } // namespace tint::cmd |
| |
| #endif // SRC_TINT_CMD_HELPER_H_ |