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 #include "spirv-tools/linter.hpp"
16
17 namespace spvtools {
18
19 struct Linter::Impl {
Implspvtools::Linter::Impl20 explicit Impl(spv_target_env env) : target_env(env) {
21 message_consumer = [](spv_message_level_t /*level*/, const char* /*source*/,
22 const spv_position_t& /*position*/,
23 const char* /*message*/) {};
24 }
25
26 spv_target_env target_env; // Target environment.
27 MessageConsumer message_consumer; // Message consumer.
28 };
29
Linter(spv_target_env env)30 Linter::Linter(spv_target_env env) : impl_(new Impl(env)) {}
31
~Linter()32 Linter::~Linter() {}
33
SetMessageConsumer(MessageConsumer consumer)34 void Linter::SetMessageConsumer(MessageConsumer consumer) {
35 impl_->message_consumer = consumer;
36 }
37
consumer() const38 const MessageConsumer& Linter::consumer() const {
39 return impl_->message_consumer;
40 }
41
Run(const uint32_t * binary,size_t binary_size)42 bool Linter::Run(const uint32_t* binary, size_t binary_size) {
43 (void)binary;
44 (void)binary_size;
45
46 consumer()(SPV_MSG_INFO, "", {0, 0, 0}, "Hello, world!");
47
48 return true;
49 }
50
51 } // namespace spvtools
52