1 // Copyright (c) 2021 Google LLC. 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 INCLUDE_SPIRV_TOOLS_LINTER_HPP_ 16 #define INCLUDE_SPIRV_TOOLS_LINTER_HPP_ 17 18 #include "libspirv.hpp" 19 20 namespace spvtools { 21 22 // C++ interface for SPIR-V linting functionalities. It wraps the context 23 // (including target environment and the corresponding SPIR-V grammar) and 24 // provides a method for linting. 25 // 26 // Instances of this class provides basic thread-safety guarantee. 27 class Linter { 28 public: 29 explicit Linter(spv_target_env env); 30 31 ~Linter(); 32 33 // Sets the message consumer to the given |consumer|. The |consumer| will be 34 // invoked once for each message communicated from the library. 35 void SetMessageConsumer(MessageConsumer consumer); 36 37 // Returns a reference to the registered message consumer. 38 const MessageConsumer& Consumer() const; 39 40 bool Run(const uint32_t* binary, size_t binary_size); 41 42 private: 43 struct Impl; 44 std::unique_ptr<Impl> impl_; 45 }; 46 } // namespace spvtools 47 48 #endif // INCLUDE_SPIRV_TOOLS_LINTER_HPP_ 49