mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-30 06:50:06 +00:00
Add AppendNames() interface for AssemblyBuilder
This commit is contained in:
parent
d9e63de117
commit
ecb5692389
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user