Add AppendNames() interface for AssemblyBuilder
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 @@
     });
   }
 
+  // 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<std::string>& 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 @@
                                        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<const char*> 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<opt::NullPass>(builder.GetCode(),
+                                       JoinAllInsts(expected));
+}
+
 }  // anonymous namespace