Fixes #152.
}
return SPV_SUCCESS;
}
-} // anonymous namespace
/// @brief Translate single Opcode and operands to binary form
///
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()
return SPV_SUCCESS;
}
-namespace {
-
enum { kAssemblerVersion = 0 };
/// @brief Populate a binary stream's words with this generator's header.
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;
// 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();
#include "UnitSPIRV.h"
-#include "gmock/gmock.h"
#include "TestFixture.h"
+#include "gmock/gmock.h"
namespace {
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
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;