blob: ea7016ef5fe366e598f798def3d2bb0a9ee6b3da [file] [log] [blame]
Ryan Harrisondbc13af2022-02-21 15:19:07 +00001// 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 sinclair67e79fe2022-04-07 14:43:05 +000020namespace tint::writer {
Ryan Harrisondbc13af2022-02-21 15:19:07 +000021
22/// Base class for the output writers
23class Writer {
dan sinclair41e4d9a2022-05-01 14:40:55 +000024 public:
25 virtual ~Writer();
Ryan Harrisondbc13af2022-02-21 15:19:07 +000026
dan sinclair41e4d9a2022-05-01 14:40:55 +000027 /// @returns the writer error string
28 const std::string& error() const { return error_; }
Ryan Harrisondbc13af2022-02-21 15:19:07 +000029
dan sinclair41e4d9a2022-05-01 14:40:55 +000030 /// Converts the module into the desired format
31 /// @returns true on success; false on failure
32 virtual bool Generate() = 0;
Ryan Harrisondbc13af2022-02-21 15:19:07 +000033
dan sinclair41e4d9a2022-05-01 14:40:55 +000034 protected:
35 /// Sets the error string
36 /// @param msg the error message
37 void set_error(const std::string& msg) { error_ = msg; }
Ryan Harrisondbc13af2022-02-21 15:19:07 +000038
dan sinclair41e4d9a2022-05-01 14:40:55 +000039 /// An error message, if an error was encountered
40 std::string error_;
Ryan Harrisondbc13af2022-02-21 15:19:07 +000041};
42
dan sinclair67e79fe2022-04-07 14:43:05 +000043} // namespace tint::writer
Ryan Harrisondbc13af2022-02-21 15:19:07 +000044
45#endif // SRC_TINT_WRITER_WRITER_H_