2017-03-08 18:59:01 +00:00
|
|
|
// Copyright (c) 2017 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.
|
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "source/extensions.h"
|
2017-03-08 18:59:01 +00:00
|
|
|
|
2017-03-10 20:58:15 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <sstream>
|
2017-03-08 18:59:01 +00:00
|
|
|
#include <string>
|
|
|
|
|
2021-12-08 17:01:26 +00:00
|
|
|
#include "source/binary.h"
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "source/enum_string_mapping.h"
|
2017-03-15 21:28:24 +00:00
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
namespace spvtools {
|
2017-03-08 18:59:01 +00:00
|
|
|
|
2017-03-10 20:58:15 +00:00
|
|
|
std::string GetExtensionString(const spv_parsed_instruction_t* inst) {
|
2022-11-04 21:27:10 +00:00
|
|
|
if (inst->opcode != static_cast<uint16_t>(spv::Op::OpExtension)) {
|
|
|
|
return "ERROR_not_op_extension";
|
|
|
|
}
|
2017-03-10 20:58:15 +00:00
|
|
|
|
|
|
|
assert(inst->num_operands == 1);
|
|
|
|
|
|
|
|
const auto& operand = inst->operands[0];
|
|
|
|
assert(operand.type == SPV_OPERAND_TYPE_LITERAL_STRING);
|
|
|
|
assert(inst->num_words > operand.offset);
|
2021-12-08 17:01:26 +00:00
|
|
|
(void)operand; /* No unused variables in release builds. */
|
2017-03-10 20:58:15 +00:00
|
|
|
|
2021-12-08 17:01:26 +00:00
|
|
|
return spvDecodeLiteralStringOperand(*inst, 0);
|
2017-03-10 20:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ExtensionSetToString(const ExtensionSet& extensions) {
|
|
|
|
std::stringstream ss;
|
2023-07-13 18:40:47 +00:00
|
|
|
for (auto extension : extensions) {
|
|
|
|
ss << ExtensionToString(extension) << " ";
|
|
|
|
}
|
2017-03-10 20:58:15 +00:00
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
} // namespace spvtools
|