});
}
+ // 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
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