• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2018 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 "reduce_test_util.h"
16 
17 namespace spvtools {
18 namespace reduce {
19 
CheckEqual(const spv_target_env env,const std::vector<uint32_t> & expected_binary,const std::vector<uint32_t> & actual_binary)20 void CheckEqual(const spv_target_env env,
21                 const std::vector<uint32_t>& expected_binary,
22                 const std::vector<uint32_t>& actual_binary) {
23   if (expected_binary != actual_binary) {
24     SpirvTools t(env);
25     std::string expected_disassembled;
26     std::string actual_disassembled;
27     ASSERT_TRUE(t.Disassemble(expected_binary, &expected_disassembled,
28                               kReduceDisassembleOption));
29     ASSERT_TRUE(t.Disassemble(actual_binary, &actual_disassembled,
30                               kReduceDisassembleOption));
31     ASSERT_EQ(expected_disassembled, actual_disassembled);
32   }
33 }
34 
CheckEqual(const spv_target_env env,const std::string & expected_text,const std::vector<uint32_t> & actual_binary)35 void CheckEqual(const spv_target_env env, const std::string& expected_text,
36                 const std::vector<uint32_t>& actual_binary) {
37   std::vector<uint32_t> expected_binary;
38   SpirvTools t(env);
39   ASSERT_TRUE(
40       t.Assemble(expected_text, &expected_binary, kReduceAssembleOption));
41   CheckEqual(env, expected_binary, actual_binary);
42 }
43 
CheckEqual(const spv_target_env env,const std::string & expected_text,const opt::IRContext * actual_ir)44 void CheckEqual(const spv_target_env env, const std::string& expected_text,
45                 const opt::IRContext* actual_ir) {
46   std::vector<uint32_t> actual_binary;
47   actual_ir->module()->ToBinary(&actual_binary, false);
48   CheckEqual(env, expected_text, actual_binary);
49 }
50 
CheckValid(spv_target_env env,const opt::IRContext * ir)51 void CheckValid(spv_target_env env, const opt::IRContext* ir) {
52   std::vector<uint32_t> binary;
53   ir->module()->ToBinary(&binary, false);
54   SpirvTools t(env);
55   ASSERT_TRUE(t.Validate(binary));
56 }
57 
ToString(spv_target_env env,const opt::IRContext * ir)58 std::string ToString(spv_target_env env, const opt::IRContext* ir) {
59   std::vector<uint32_t> binary;
60   ir->module()->ToBinary(&binary, false);
61   SpirvTools t(env);
62   std::string result;
63   t.Disassemble(binary, &result, kReduceDisassembleOption);
64   return result;
65 }
66 
NopDiagnostic(spv_message_level_t,const char *,const spv_position_t &,const char *)67 void NopDiagnostic(spv_message_level_t /*level*/, const char* /*source*/,
68                    const spv_position_t& /*position*/,
69                    const char* /*message*/) {}
70 
71 }  // namespace reduce
72 }  // namespace spvtools
73