mirror of
https://github.com/RPCSX/SPIRV-Tools.git
synced 2025-03-05 01:37:48 +00:00
Empty assembly text compiles to no instructions.
But it's still a valid module.
This commit is contained in:
parent
aef608c40d
commit
ea633a6427
@ -642,8 +642,8 @@ spv_result_t spvTextToBinaryInternal(const libspirv::AssemblyGrammar& grammar,
|
|||||||
spv_diagnostic* pDiagnostic) {
|
spv_diagnostic* pDiagnostic) {
|
||||||
if (!pDiagnostic) return SPV_ERROR_INVALID_DIAGNOSTIC;
|
if (!pDiagnostic) return SPV_ERROR_INVALID_DIAGNOSTIC;
|
||||||
libspirv::AssemblyContext context(text, pDiagnostic);
|
libspirv::AssemblyContext context(text, pDiagnostic);
|
||||||
if (!text->str || !text->length)
|
if (!text->str)
|
||||||
return context.diagnostic() << "Text stream is empty.";
|
return context.diagnostic() << "Missing assembly text.";
|
||||||
|
|
||||||
if (!grammar.isValid()) {
|
if (!grammar.isValid()) {
|
||||||
return SPV_ERROR_INVALID_TABLE;
|
return SPV_ERROR_INVALID_TABLE;
|
||||||
@ -655,7 +655,8 @@ spv_result_t spvTextToBinaryInternal(const libspirv::AssemblyGrammar& grammar,
|
|||||||
|
|
||||||
std::vector<spv_instruction_t> instructions;
|
std::vector<spv_instruction_t> instructions;
|
||||||
|
|
||||||
if (context.advance()) return context.diagnostic() << "Text stream is empty.";
|
// Skip past whitespace and comments.
|
||||||
|
context.advance();
|
||||||
|
|
||||||
spv_ext_inst_type_t extInstType = SPV_EXT_INST_TYPE_NONE;
|
spv_ext_inst_type_t extInstType = SPV_EXT_INST_TYPE_NONE;
|
||||||
while (context.hasText()) {
|
while (context.hasText()) {
|
||||||
|
@ -24,28 +24,35 @@
|
|||||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||||
|
|
||||||
|
#include "gmock/gmock.h"
|
||||||
#include "TestFixture.h"
|
#include "TestFixture.h"
|
||||||
#include "UnitSPIRV.h"
|
#include "UnitSPIRV.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using spvtest::Concatenate;
|
||||||
|
using spvtest::MakeInstruction;
|
||||||
|
using spvtest::MakeVector;
|
||||||
using spvtest::TextToBinaryTest;
|
using spvtest::TextToBinaryTest;
|
||||||
|
using testing::Eq;
|
||||||
|
|
||||||
TEST_F(TextToBinaryTest, Whitespace) {
|
TEST_F(TextToBinaryTest, Whitespace) {
|
||||||
SetText(R"(
|
std::string input = R"(
|
||||||
; I'm a proud comment at the begining of the file
|
; I'm a proud comment at the begining of the file
|
||||||
; I hide: OpCapability Shader
|
; I hide: OpCapability Shader
|
||||||
OpMemoryModel Logical Simple ; comment after instruction
|
OpMemoryModel Logical Simple ; comment after instruction
|
||||||
;;;;;;;; many ;'s
|
;;;;;;;; many ;'s
|
||||||
%glsl450 = OpExtInstImport "GLSL.std.450"
|
%glsl450 = OpExtInstImport "GLSL.std.450"
|
||||||
; comment indented
|
; comment indented
|
||||||
)");
|
)";
|
||||||
EXPECT_EQ(SPV_SUCCESS,
|
|
||||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
EXPECT_THAT(
|
||||||
extInstTable, &binary, &diagnostic));
|
CompiledInstructions(input),
|
||||||
if (diagnostic) {
|
Eq(Concatenate({MakeInstruction(SpvOpMemoryModel,
|
||||||
spvDiagnosticPrint(diagnostic);
|
{uint32_t(SpvAddressingModelLogical),
|
||||||
}
|
uint32_t(SpvMemoryModelSimple)}),
|
||||||
|
MakeInstruction(SpvOpExtInstImport, {1},
|
||||||
|
MakeVector("GLSL.std.450"))})));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
@ -62,7 +62,7 @@ class TextToBinaryTestBase : public T {
|
|||||||
|
|
||||||
// Returns subvector v[from:end).
|
// Returns subvector v[from:end).
|
||||||
SpirvVector Subvector(const SpirvVector& v, SpirvVector::size_type from) {
|
SpirvVector Subvector(const SpirvVector& v, SpirvVector::size_type from) {
|
||||||
assert(from < v.size());
|
assert(from <= v.size());
|
||||||
return SpirvVector(v.begin() + from, v.end());
|
return SpirvVector(v.begin() + from, v.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||||
|
|
||||||
#include "TestFixture.h"
|
#include "TestFixture.h"
|
||||||
|
#include "gmock/gmock.h"
|
||||||
#include "UnitSPIRV.h"
|
#include "UnitSPIRV.h"
|
||||||
#include "util/bitutils.h"
|
#include "util/bitutils.h"
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ using libspirv::AssemblyContext;
|
|||||||
using libspirv::AssemblyGrammar;
|
using libspirv::AssemblyGrammar;
|
||||||
using spvtest::TextToBinaryTest;
|
using spvtest::TextToBinaryTest;
|
||||||
using spvtest::AutoText;
|
using spvtest::AutoText;
|
||||||
|
using testing::Eq;
|
||||||
|
|
||||||
TEST(GetWord, Simple) {
|
TEST(GetWord, Simple) {
|
||||||
EXPECT_EQ("", AssemblyContext(AutoText(""), nullptr).getWord());
|
EXPECT_EQ("", AssemblyContext(AutoText(""), nullptr).getWord());
|
||||||
@ -302,6 +304,8 @@ TEST_F(TextToBinaryTest, InvalidText) {
|
|||||||
ASSERT_EQ(SPV_ERROR_INVALID_TEXT,
|
ASSERT_EQ(SPV_ERROR_INVALID_TEXT,
|
||||||
spvTextToBinary(nullptr, 0, opcodeTable, operandTable, extInstTable,
|
spvTextToBinary(nullptr, 0, opcodeTable, operandTable, extInstTable,
|
||||||
&binary, &diagnostic));
|
&binary, &diagnostic));
|
||||||
|
EXPECT_NE(nullptr, diagnostic);
|
||||||
|
EXPECT_THAT(diagnostic->error, Eq(std::string("Missing assembly text.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TextToBinaryTest, InvalidTable) {
|
TEST_F(TextToBinaryTest, InvalidTable) {
|
||||||
@ -345,6 +349,12 @@ TEST_F(TextToBinaryTest, InvalidPrefix) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TextToBinaryTest, EmptyAssemblyString) {
|
||||||
|
// An empty assembly module is valid!
|
||||||
|
// It should produce a valid module with zero instructions.
|
||||||
|
EXPECT_THAT(CompiledInstructions(""), Eq(std::vector<uint32_t>{}));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(TextToBinaryTest, StringSpace) {
|
TEST_F(TextToBinaryTest, StringSpace) {
|
||||||
SetText("OpSourceExtension \"string with spaces\"");
|
SetText("OpSourceExtension \"string with spaces\"");
|
||||||
EXPECT_EQ(SPV_SUCCESS,
|
EXPECT_EQ(SPV_SUCCESS,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user