// Copyright (c) 2016 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef SOURCE_NAME_MAPPER_H_ #define SOURCE_NAME_MAPPER_H_ #include <functional> #include <string> #include <unordered_map> #include <unordered_set> #include "source/assembly_grammar.h" #include "spirv-tools/libspirv.h" namespace spvtools { // A NameMapper maps SPIR-V Id values to names. Each name is valid to use in // SPIR-V assembly. The mapping is one-to-one, i.e. no two Ids map to the same // name. NameMapper; // Returns a NameMapper which always maps an Id to its decimal representation. NameMapper GetTrivialNameMapper(); // A FriendlyNameMapper parses a module upon construction. If the parse is // successful, then the NameForId method maps an Id to a friendly name // while also satisfying the constraints on a NameMapper. // // The mapping is friendly in the following sense: // - If an Id has a debug name (via OpName), then that will be used when // possible. // - Well known scalar types map to friendly names. For example, // OpTypeVoid should be %void. Scalar types map to their names in OpenCL // when // there is a correspondence, and otherwise as follows: // - unsigned integer type of n bits map to "u" followed by n // - signed integer type of n bits map to "i" followed by n // - floating point type of n bits map to "fp" followed by n // - Vector type names map to "v" followed by the number of components, // followed by the friendly name for the base type. // - Matrix type names map to "mat" followed by the number of columns, // followed by the friendly name for the base vector type. // - Pointer types map to "_ptr_", then the name of the storage class, then the // name for the pointee type. // - Exotic types like event, pipe, opaque, queue, reserve-id map to their own // human readable names. // - A struct type maps to "_struct_" followed by the raw Id number. That's // pretty simplistic, but workable. // - A built-in variable maps to its GLSL variable name. // - Numeric literals in OpConstant map to a human-friendly name. class FriendlyNameMapper { … }; } // namespace spvtools #endif // SOURCE_NAME_MAPPER_H_