From 877083d07a7fbce460f7f083bc1d5deef4d9ed47 Mon Sep 17 00:00:00 2001 From: "I-Jui (Ray) Sung" Date: Fri, 3 Mar 2017 17:08:16 -0800 Subject: Added addString() method to android::spirit::Module MakeString() was in Builder, but Module does not have the counterpart to add an OpString to the Debug Info section. The OpString SPIR-V instruction may be used to carry debugging information and other metadata. This CL also added a test case to verify the result. Bug: 30964317 Test: SPIRIT unit tests (gtest), Change-Id: I5aff827041f5d5e71978a12e366f829d0de819c1 --- rsov/compiler/spirit/builder_test.cpp | 2 ++ rsov/compiler/spirit/module.cpp | 14 ++++++++++++++ rsov/compiler/spirit/module.h | 2 ++ 3 files changed, 18 insertions(+) (limited to 'rsov') diff --git a/rsov/compiler/spirit/builder_test.cpp b/rsov/compiler/spirit/builder_test.cpp index 48030aeb..bb935b66 100644 --- a/rsov/compiler/spirit/builder_test.cpp +++ b/rsov/compiler/spirit/builder_test.cpp @@ -44,6 +44,7 @@ TEST(BuilderTest, testBuildAndSerialize) { m->addSourceExtension("GL_ARB_shading_language_420pack"); m->addSourceExtension("GL_GOOGLE_cpp_style_line_directive"); m->addSourceExtension("GL_GOOGLE_include_directive"); + m->addString("Foo Bar Baz"); auto FloatTy = m->getFloatType(32); auto VF4Ty = m->getVectorType(FloatTy, 4); @@ -178,6 +179,7 @@ TEST(BuilderTest, testBuildAndSerialize) { EXPECT_EQ(2, countEntity(m)); EXPECT_EQ(2, countEntity(m)); EXPECT_EQ(5, countEntity(m)); + EXPECT_EQ(1, countEntity(m)); m->consolidateAnnotations(); diff --git a/rsov/compiler/spirit/module.cpp b/rsov/compiler/spirit/module.cpp index 98001124..9880f780 100644 --- a/rsov/compiler/spirit/module.cpp +++ b/rsov/compiler/spirit/module.cpp @@ -214,6 +214,14 @@ Module *Module::addSourceExtension(const char *ext) { return this; } +Module *Module::addString(const char *str) { + if (!mDebugInfo) { + mDebugInfo.reset(mBuilder->MakeDebugInfoSection()); + } + mDebugInfo->addString(str); + return this; +} + Module *Module::addEntryPoint(EntryPointDefinition *entry) { mEntryPoints.push_back(entry); auto newModes = entry->getExecutionModes(); @@ -515,6 +523,12 @@ DebugInfoSection *DebugInfoSection::addSourceExtension(const char *ext) { return this; } +DebugInfoSection *DebugInfoSection::addString(const char *str) { + StringInst *source = mBuilder->MakeString(str); + mSources.push_back(source); + return this; +} + Instruction *DebugInfoSection::lookupByName(const char *name) const { for (auto inst : mNames) { if (inst->getOpCode() == OpName) { diff --git a/rsov/compiler/spirit/module.h b/rsov/compiler/spirit/module.h index a69d255f..33011602 100644 --- a/rsov/compiler/spirit/module.h +++ b/rsov/compiler/spirit/module.h @@ -124,6 +124,7 @@ public: Module *addExtInstImport(const char *extName); Module *addSource(SourceLanguage lang, int version); Module *addSourceExtension(const char *ext); + Module *addString(const char *ext); Module *addEntryPoint(EntryPointDefinition *entry); ExtInstImportInst *getGLExt() const { return mGLExt; } @@ -312,6 +313,7 @@ public: DebugInfoSection *addSource(SourceLanguage lang, int version); DebugInfoSection *addSourceExtension(const char *ext); + DebugInfoSection *addString(const char *str); Instruction *lookupByName(const char *name) const; const char *lookupNameByInstruction(const Instruction *) const; -- cgit v1.2.3