MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / ParseInstruction

Method ParseInstruction

source/name_mapper.cpp:164–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164spv_result_t FriendlyNameMapper::ParseInstruction(
165 const spv_parsed_instruction_t& inst) {
166 const auto result_id = inst.result_id;
167 switch (spv::Op(inst.opcode)) {
168 case spv::Op::OpName:
169 SaveName(inst.words[1], spvDecodeLiteralStringOperand(inst, 1));
170 break;
171 case spv::Op::OpDecorate:
172 // Decorations come after OpName. So OpName will take precedence over
173 // decorations.
174 //
175 // In theory, we should also handle OpGroupDecorate. But that's unlikely
176 // to occur.
177 if (spv::Decoration(inst.words[2]) == spv::Decoration::BuiltIn) {
178 assert(inst.num_words > 3);
179 SaveBuiltInName(inst.words[1], inst.words[3]);
180 }
181 break;
182 case spv::Op::OpTypeVoid:
183 SaveName(result_id, "void");
184 break;
185 case spv::Op::OpTypeBool:
186 SaveName(result_id, "bool");
187 break;
188 case spv::Op::OpTypeInt: {
189 std::string signedness;
190 std::string root;
191 const auto bit_width = inst.words[2];
192 switch (bit_width) {
193 case 8:
194 root = "char";
195 break;
196 case 16:
197 root = "short";
198 break;
199 case 32:
200 root = "int";
201 break;
202 case 64:
203 root = "long";
204 break;
205 default:
206 root = to_string(bit_width);
207 signedness = "i";
208 break;
209 }
210 if (0 == inst.words[3]) signedness = "u";
211 SaveName(result_id, signedness + root);
212 } break;
213 case spv::Op::OpTypeFloat: {
214 const auto bit_width = inst.words[2];
215 if (inst.num_words > 3) {
216 if (spv::FPEncoding(inst.words[3]) == spv::FPEncoding::BFloat16KHR) {
217 SaveName(result_id, "bfloat16");
218 break;
219 }
220 if (spv::FPEncoding(inst.words[3]) == spv::FPEncoding::Float8E4M3EXT) {
221 SaveName(result_id, "fp8e4m3");

Callers 1

Calls 6

DecorationClass · 0.85
EmitNumericLiteralFunction · 0.85
to_stringFunction · 0.70
strMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected