From ecb56923896beae7e7cbab12cc9a68c8fe9b06b8 Mon Sep 17 00:00:00 2001 From: qining Date: Mon, 29 Aug 2016 16:09:40 -0400 Subject: [PATCH] Add AppendNames() interface for AssemblyBuilder --- test/opt/assembly_builder.h | 12 ++++++++++++ test/opt/test_assembly_builder.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/test/opt/assembly_builder.h b/test/opt/assembly_builder.h index 964cab6..3f238b4 100755 --- a/test/opt/assembly_builder.h +++ b/test/opt/assembly_builder.h @@ -111,6 +111,18 @@ class AssemblyBuilder { }); } + // Appends OpName instructions to this builder. Instrcution strings that do + // not start with 'OpName ' will be skipped. Returns the references of this + // assembly builder. + AssemblyBuilder& AppendNames(const std::vector& vec_asm_code) { + for (auto& inst_str : vec_asm_code) { + if (inst_str.find("OpName ") == 0) { + names_.push_back(inst_str); + } + } + return *this; + } + // Appends instructions to the types-constants-globals section and returns // the reference of this assembly builder. IDs defined in the given code will // be added to the Names section and then be registered with OpName diff --git a/test/opt/test_assembly_builder.cpp b/test/opt/test_assembly_builder.cpp index 7303047..597229e 100644 --- a/test/opt/test_assembly_builder.cpp +++ b/test/opt/test_assembly_builder.cpp @@ -253,4 +253,37 @@ TEST_F(AssemblyBuilderTest, SpecConstants) { JoinAllInsts(expected)); } +TEST_F(AssemblyBuilderTest, AppendNames) { + AssemblyBuilder builder; + builder.AppendNames({ + "OpName %void \"another_name_for_void\"", + "I am an invalid OpName instruction and should not be added", + "OpName %main \"another name for main\"", + }); + std::vector expected = { + // clang-format off + "OpCapability Shader", + "OpCapability Float64", + "%1 = OpExtInstImport \"GLSL.std.450\"", + "OpMemoryModel Logical GLSL450", + "OpEntryPoint Vertex %main \"main\"", + "OpName %void \"void\"", + "OpName %main_func_type \"main_func_type\"", + "OpName %main \"main\"", + "OpName %main_func_entry_block \"main_func_entry_block\"", + "OpName %void \"another_name_for_void\"", + "OpName %main \"another name for main\"", + "%void = OpTypeVoid", + "%main_func_type = OpTypeFunction %void", + "%main = OpFunction %void None %main_func_type", +"%main_func_entry_block = OpLabel", + "OpReturn", + "OpFunctionEnd", + // clang-format on + }; + + SinglePassRunAndCheck(builder.GetCode(), + JoinAllInsts(expected)); +} + } // anonymous namespace -- 2.7.4