Add AppendNames() interface for AssemblyBuilder

This commit is contained in:
qining 2016-08-29 16:09:40 -04:00 committed by David Neto
parent d9e63de117
commit ecb5692389
2 changed files with 45 additions and 0 deletions

View File

@ -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<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

View File

@ -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<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