Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 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_TINT_WRITER_WRITER_H_ |
| 16 | #define SRC_TINT_WRITER_WRITER_H_ |
| 17 | |
| 18 | #include <string> |
| 19 | |
dan sinclair | 67e79fe | 2022-04-07 14:43:05 +0000 | [diff] [blame] | 20 | namespace tint::writer { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 21 | |
| 22 | /// Base class for the output writers |
| 23 | class Writer { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 24 | public: |
| 25 | virtual ~Writer(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 26 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 27 | /// @returns the writer error string |
| 28 | const std::string& error() const { return error_; } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 29 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 30 | /// Converts the module into the desired format |
| 31 | /// @returns true on success; false on failure |
| 32 | virtual bool Generate() = 0; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 33 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 34 | protected: |
| 35 | /// Sets the error string |
| 36 | /// @param msg the error message |
| 37 | void set_error(const std::string& msg) { error_ = msg; } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 38 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 39 | /// An error message, if an error was encountered |
| 40 | std::string error_; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
dan sinclair | 67e79fe | 2022-04-07 14:43:05 +0000 | [diff] [blame] | 43 | } // namespace tint::writer |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 44 | |
| 45 | #endif // SRC_TINT_WRITER_WRITER_H_ |