From 755eb6dcfca680a23e1d7abab8d78ee0ed17f498 Mon Sep 17 00:00:00 2001 From: Dejan Mircevski Date: Tue, 15 Mar 2016 15:16:40 -0400 Subject: [PATCH] Remove AssemblyContext::getWord(). Fixes #152. --- source/text.cpp | 5 +---- source/text_handler.cpp | 19 ------------------- source/text_handler.h | 5 ----- test/TextToBinary.Miscellaneous.cpp | 16 +++++++++++++++- test/TextToBinary.cpp | 16 ---------------- 5 files changed, 16 insertions(+), 45 deletions(-) diff --git a/source/text.cpp b/source/text.cpp index 91c04a4..c9fc8e9 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -478,7 +478,6 @@ spv_result_t encodeInstructionStartingWithImmediate( } return SPV_SUCCESS; } -} // anonymous namespace /// @brief Translate single Opcode and operands to binary form /// @@ -545,7 +544,7 @@ spv_result_t spvTextEncodeOpcode(const libspirv::AssemblyGrammar& grammar, error = grammar.lookupOpcode(pInstName, &opcodeEntry); if (error) { return context->diagnostic(error) << "Invalid Opcode name '" - << context->getWord() << "'"; + << opcodeName << "'"; } if (opcodeEntry->hasResult && result_id.empty()) { return context->diagnostic() @@ -652,8 +651,6 @@ spv_result_t spvTextEncodeOpcode(const libspirv::AssemblyGrammar& grammar, return SPV_SUCCESS; } -namespace { - enum { kAssemblerVersion = 0 }; /// @brief Populate a binary stream's words with this generator's header. diff --git a/source/text_handler.cpp b/source/text_handler.cpp index 851d1b1..17453fe 100644 --- a/source/text_handler.cpp +++ b/source/text_handler.cpp @@ -233,25 +233,6 @@ bool AssemblyContext::hasText() const { return text_->length > current_position_.index; } -std::string AssemblyContext::getWord() const { - uint64_t index = current_position_.index; - while (true) { - switch (text_->str[index]) { - case '\0': - case '\t': - case '\v': - case '\r': - case '\n': - case ' ': - return std::string(text_->str, text_->str + index); - default: - index++; - } - } - assert(0 && "Unreachable"); - return ""; // Make certain compilers happy. -} - void AssemblyContext::seekForward(uint32_t size) { current_position_.index += size; current_position_.column += size; diff --git a/source/text_handler.h b/source/text_handler.h index 386a4dc..c0a3df4 100644 --- a/source/text_handler.h +++ b/source/text_handler.h @@ -149,11 +149,6 @@ class AssemblyContext { // the next location past the end of the word. spv_result_t getWord(std::string& word, spv_position endPosition); - // Returns the next word in the input stream. It is invalid to call this - // method if position has been set to a location in the stream that does not - // exist. If there are no subsequent words, the empty string will be returned. - std::string getWord() const; - // Returns true if the next word in the input is the start of a new Opcode. bool startsWithOp(); diff --git a/test/TextToBinary.Miscellaneous.cpp b/test/TextToBinary.Miscellaneous.cpp index 55aac28..d99af52 100644 --- a/test/TextToBinary.Miscellaneous.cpp +++ b/test/TextToBinary.Miscellaneous.cpp @@ -29,8 +29,8 @@ #include "UnitSPIRV.h" -#include "gmock/gmock.h" #include "TestFixture.h" +#include "gmock/gmock.h" namespace { @@ -51,4 +51,18 @@ TEST_F(TextToBinaryMisc, OpUndef) { EXPECT_THAT(Subvector(code, 3), Eq(MakeInstruction(SpvOpUndef, {typeID, 2}))); } +TEST_F(TextToBinaryMisc, OpWrong) { + EXPECT_THAT(CompileFailure(" OpWrong %1 %2"), + Eq("Invalid Opcode name 'OpWrong'")); +} + +TEST_F(TextToBinaryMisc, OpWrongAfterRight) { + const auto assembly = R"( +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpXYZ +)"; + EXPECT_THAT(CompileFailure(assembly), Eq("Invalid Opcode name 'OpXYZ'")); +} + } // anonymous namespace diff --git a/test/TextToBinary.cpp b/test/TextToBinary.cpp index 182dcf5..841e964 100644 --- a/test/TextToBinary.cpp +++ b/test/TextToBinary.cpp @@ -46,22 +46,6 @@ using spvtest::MakeInstruction; using spvtest::TextToBinaryTest; using testing::Eq; -TEST(GetWord, Simple) { - EXPECT_EQ("", AssemblyContext(AutoText(""), nullptr).getWord()); - EXPECT_EQ("", AssemblyContext(AutoText("\0a"), nullptr).getWord()); - EXPECT_EQ("", AssemblyContext(AutoText(" a"), nullptr).getWord()); - EXPECT_EQ("", AssemblyContext(AutoText("\ta"), nullptr).getWord()); - EXPECT_EQ("", AssemblyContext(AutoText("\va"), nullptr).getWord()); - EXPECT_EQ("", AssemblyContext(AutoText("\ra"), nullptr).getWord()); - EXPECT_EQ("", AssemblyContext(AutoText("\na"), nullptr).getWord()); - EXPECT_EQ("abc", AssemblyContext(AutoText("abc"), nullptr).getWord()); - EXPECT_EQ("abc", AssemblyContext(AutoText("abc "), nullptr).getWord()); - EXPECT_EQ("abc", AssemblyContext(AutoText("abc\t"), nullptr).getWord()); - EXPECT_EQ("abc", AssemblyContext(AutoText("abc\r"), nullptr).getWord()); - EXPECT_EQ("abc", AssemblyContext(AutoText("abc\v"), nullptr).getWord()); - EXPECT_EQ("abc", AssemblyContext(AutoText("abc\n"), nullptr).getWord()); -} - // An mask parsing test case. struct MaskCase { spv_operand_type_t which_enum; -- 2.7.4