Remove source/message.h (#1838)

The code in source/message was only used in a single set of tests to
format the output results. This CL changes the test to verify the
message instead of all the error values and removes the source/message
code.
This commit is contained in:
dan sinclair 2018-08-14 15:41:21 -04:00 committed by GitHub
parent 1963a2dbda
commit ef678672fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 23 additions and 127 deletions

View File

@ -301,7 +301,6 @@ static_library("spvtools") {
"source/instruction.h", "source/instruction.h",
"source/libspirv.cpp", "source/libspirv.cpp",
"source/macro.h", "source/macro.h",
"source/message.cpp",
"source/name_mapper.cpp", "source/name_mapper.cpp",
"source/name_mapper.h", "source/name_mapper.h",
"source/opcode.cpp", "source/opcode.cpp",

View File

@ -266,7 +266,6 @@ set(SPIRV_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/extensions.cpp ${CMAKE_CURRENT_SOURCE_DIR}/extensions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/id_descriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/id_descriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libspirv.cpp ${CMAKE_CURRENT_SOURCE_DIR}/libspirv.cpp
${CMAKE_CURRENT_SOURCE_DIR}/message.cpp
${CMAKE_CURRENT_SOURCE_DIR}/name_mapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/name_mapper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/opcode.cpp ${CMAKE_CURRENT_SOURCE_DIR}/opcode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/operand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/operand.cpp

View File

@ -58,14 +58,14 @@ spv_result_t spvDiagnosticPrint(const spv_diagnostic diagnostic) {
<< diagnostic->position.column + 1 << ": " << diagnostic->error << diagnostic->position.column + 1 << ": " << diagnostic->error
<< "\n"; << "\n";
return SPV_SUCCESS; return SPV_SUCCESS;
} else {
// NOTE: Assume this is a binary position
std::cerr << "error: ";
if (diagnostic->position.index > 0)
std::cerr << diagnostic->position.index << ": ";
std::cerr << diagnostic->error << "\n";
return SPV_SUCCESS;
} }
// NOTE: Assume this is a binary position
std::cerr << "error: ";
if (diagnostic->position.index > 0)
std::cerr << diagnostic->position.index << ": ";
std::cerr << diagnostic->error << "\n";
return SPV_SUCCESS;
} }
namespace spvtools { namespace spvtools {

View File

@ -1,54 +0,0 @@
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "source/message.h"
#include <sstream>
namespace spvtools {
std::string StringifyMessage(spv_message_level_t level, const char* source,
const spv_position_t& position,
const char* message) {
const char* level_string = nullptr;
switch (level) {
case SPV_MSG_FATAL:
level_string = "fatal";
break;
case SPV_MSG_INTERNAL_ERROR:
level_string = "internal error";
break;
case SPV_MSG_ERROR:
level_string = "error";
break;
case SPV_MSG_WARNING:
level_string = "warning";
break;
case SPV_MSG_INFO:
level_string = "info";
break;
case SPV_MSG_DEBUG:
level_string = "debug";
break;
}
std::ostringstream oss;
oss << level_string << ": ";
if (source) oss << source << ":";
oss << position.line << ":" << position.column << ":";
oss << position.index << ": ";
if (message) oss << message;
return oss.str();
}
} // namespace spvtools

View File

@ -1,33 +0,0 @@
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SOURCE_MESSAGE_H_
#define SOURCE_MESSAGE_H_
#include <string>
#include "spirv-tools/libspirv.h"
namespace spvtools {
// A helper function to compose and return a string from the message in the
// following format:
// "<level>: <source>:<line>:<column>:<index>: <message>"
std::string StringifyMessage(spv_message_level_t level, const char* source,
const spv_position_t& position,
const char* message);
} // namespace spvtools
#endif // SOURCE_MESSAGE_H_

View File

@ -18,7 +18,6 @@
#include "source/latest_version_spirv_header.h" #include "source/latest_version_spirv_header.h"
#include "source/extensions.h" #include "source/extensions.h"
#include "source/message.h"
#include "spirv-tools/libspirv.hpp" #include "spirv-tools/libspirv.hpp"
typedef struct spv_opcode_desc_t { typedef struct spv_opcode_desc_t {

View File

@ -33,7 +33,6 @@
#include "source/diagnostic.h" #include "source/diagnostic.h"
#include "source/ext_inst.h" #include "source/ext_inst.h"
#include "source/instruction.h" #include "source/instruction.h"
#include "source/message.h"
#include "source/opcode.h" #include "source/opcode.h"
#include "source/operand.h" #include "source/operand.h"
#include "source/spirv_constant.h" #include "source/spirv_constant.h"

View File

@ -25,7 +25,6 @@
#include "source/diagnostic.h" #include "source/diagnostic.h"
#include "source/instruction.h" #include "source/instruction.h"
#include "source/message.h"
#include "source/text.h" #include "source/text.h"
#include "spirv-tools/libspirv.h" #include "spirv-tools/libspirv.h"

View File

@ -21,7 +21,6 @@
#include <vector> #include <vector>
#include "source/instruction.h" #include "source/instruction.h"
#include "source/message.h"
#include "source/table.h" #include "source/table.h"
#include "spirv-tools/libspirv.h" #include "spirv-tools/libspirv.h"

View File

@ -27,7 +27,6 @@
#include "source/diagnostic.h" #include "source/diagnostic.h"
#include "source/instruction.h" #include "source/instruction.h"
#include "source/message.h"
#include "source/opcode.h" #include "source/opcode.h"
#include "source/operand.h" #include "source/operand.h"
#include "source/spirv_validator_options.h" #include "source/spirv_validator_options.h"

View File

@ -20,7 +20,6 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "source/latest_version_opencl_std_header.h" #include "source/latest_version_opencl_std_header.h"
#include "source/message.h"
#include "source/table.h" #include "source/table.h"
#include "test/test_fixture.h" #include "test/test_fixture.h"
#include "test/unit_spirv.h" #include "test/unit_spirv.h"

View File

@ -13,7 +13,6 @@
// limitations under the License. // limitations under the License.
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "source/message.h"
#include "source/table.h" #include "source/table.h"
#include "spirv-tools/libspirv.h" #include "spirv-tools/libspirv.h"

View File

@ -15,7 +15,6 @@
#include "source/opt/log.h" #include "source/opt/log.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "source/message.h"
namespace spvtools { namespace spvtools {
namespace { namespace {

View File

@ -20,7 +20,6 @@
#include <vector> #include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "source/message.h"
#include "source/opt/build_module.h" #include "source/opt/build_module.h"
#include "source/opt/ir_context.h" #include "source/opt/ir_context.h"
#include "spirv-tools/libspirv.hpp" #include "spirv-tools/libspirv.hpp"
@ -321,11 +320,12 @@ TEST(IrBuilder, KeepModuleProcessedInRightPlace) {
// Checks the given |error_message| is reported when trying to build a module // Checks the given |error_message| is reported when trying to build a module
// from the given |assembly|. // from the given |assembly|.
void DoErrorMessageCheck(const std::string& assembly, void DoErrorMessageCheck(const std::string& assembly,
const std::string& error_message) { const std::string& error_message, uint32_t line_num) {
auto consumer = [error_message](spv_message_level_t level, const char* source, auto consumer = [error_message, line_num](spv_message_level_t, const char*,
const spv_position_t& position, const spv_position_t& position,
const char* m) { const char* m) {
EXPECT_EQ(error_message, StringifyMessage(level, source, position, m)); EXPECT_EQ(error_message, m);
EXPECT_EQ(line_num, position.line);
}; };
SpirvTools t(SPV_ENV_UNIVERSAL_1_1); SpirvTools t(SPV_ENV_UNIVERSAL_1_1);
@ -336,13 +336,12 @@ void DoErrorMessageCheck(const std::string& assembly,
TEST(IrBuilder, FunctionInsideFunction) { TEST(IrBuilder, FunctionInsideFunction) {
DoErrorMessageCheck("%2 = OpFunction %1 None %3\n%5 = OpFunction %4 None %6", DoErrorMessageCheck("%2 = OpFunction %1 None %3\n%5 = OpFunction %4 None %6",
"error: <instruction>:2:0:0: function inside function"); "function inside function", 2);
} }
TEST(IrBuilder, MismatchOpFunctionEnd) { TEST(IrBuilder, MismatchOpFunctionEnd) {
DoErrorMessageCheck("OpFunctionEnd", DoErrorMessageCheck("OpFunctionEnd",
"error: <instruction>:1:0:0: OpFunctionEnd without " "OpFunctionEnd without corresponding OpFunction", 1);
"corresponding OpFunction");
} }
TEST(IrBuilder, OpFunctionEndInsideBasicBlock) { TEST(IrBuilder, OpFunctionEndInsideBasicBlock) {
@ -350,12 +349,12 @@ TEST(IrBuilder, OpFunctionEndInsideBasicBlock) {
"%2 = OpFunction %1 None %3\n" "%2 = OpFunction %1 None %3\n"
"%4 = OpLabel\n" "%4 = OpLabel\n"
"OpFunctionEnd", "OpFunctionEnd",
"error: <instruction>:3:0:0: OpFunctionEnd inside basic block"); "OpFunctionEnd inside basic block", 3);
} }
TEST(IrBuilder, BasicBlockOutsideFunction) { TEST(IrBuilder, BasicBlockOutsideFunction) {
DoErrorMessageCheck("OpCapability Shader\n%1 = OpLabel", DoErrorMessageCheck("OpCapability Shader\n%1 = OpLabel",
"error: <instruction>:2:0:0: OpLabel outside function"); "OpLabel outside function", 2);
} }
TEST(IrBuilder, OpLabelInsideBasicBlock) { TEST(IrBuilder, OpLabelInsideBasicBlock) {
@ -363,26 +362,23 @@ TEST(IrBuilder, OpLabelInsideBasicBlock) {
"%2 = OpFunction %1 None %3\n" "%2 = OpFunction %1 None %3\n"
"%4 = OpLabel\n" "%4 = OpLabel\n"
"%5 = OpLabel", "%5 = OpLabel",
"error: <instruction>:3:0:0: OpLabel inside basic block"); "OpLabel inside basic block", 3);
} }
TEST(IrBuilder, TerminatorOutsideFunction) { TEST(IrBuilder, TerminatorOutsideFunction) {
DoErrorMessageCheck( DoErrorMessageCheck("OpReturn", "terminator instruction outside function", 1);
"OpReturn",
"error: <instruction>:1:0:0: terminator instruction outside function");
} }
TEST(IrBuilder, TerminatorOutsideBasicBlock) { TEST(IrBuilder, TerminatorOutsideBasicBlock) {
DoErrorMessageCheck("%2 = OpFunction %1 None %3\nOpReturn", DoErrorMessageCheck("%2 = OpFunction %1 None %3\nOpReturn",
"error: <instruction>:2:0:0: terminator instruction " "terminator instruction outside basic block", 2);
"outside basic block");
} }
TEST(IrBuilder, NotAllowedInstAppearingInFunction) { TEST(IrBuilder, NotAllowedInstAppearingInFunction) {
DoErrorMessageCheck("%2 = OpFunction %1 None %3\n%5 = OpVariable %4 Function", DoErrorMessageCheck("%2 = OpFunction %1 None %3\n%5 = OpVariable %4 Function",
"error: <instruction>:2:0:0: Non-OpFunctionParameter " "Non-OpFunctionParameter (opcode: 59) found inside "
"(opcode: 59) found inside function but outside basic " "function but outside basic block",
"block"); 2);
} }
TEST(IrBuilder, UniqueIds) { TEST(IrBuilder, UniqueIds) {

View File

@ -19,7 +19,6 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "source/message.h"
#include "source/opt/build_module.h" #include "source/opt/build_module.h"
#include "source/opt/module.h" #include "source/opt/module.h"
#include "spirv-tools/libspirv.hpp" #include "spirv-tools/libspirv.hpp"

View File

@ -17,7 +17,6 @@
#include <vector> #include <vector>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "source/message.h"
#include "test/test_fixture.h" #include "test/test_fixture.h"
#include "test/unit_spirv.h" #include "test/unit_spirv.h"

View File

@ -22,7 +22,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "source/message.h"
#include "source/opt/log.h" #include "source/opt/log.h"
#include "source/opt/loop_peeling.h" #include "source/opt/loop_peeling.h"
#include "source/opt/set_spec_constant_default_value_pass.h" #include "source/opt/set_spec_constant_default_value_pass.h"