}
/// The word used to define the Instruction
- uint32_t words(size_t index) const { return words_[index]; }
+ uint32_t word(size_t index) const { return words_[index]; }
/// The words used to define the Instruction
const std::vector<uint32_t>& words() const { return words_; }
- /// The operand of the Instruction at \p index
- const spv_parsed_operand_t& operands(size_t index) const {
- return operands_[index];
- }
-
/// The operands of the Instruction
const std::vector<spv_parsed_operand_t>& operands() const {
return operands_;
#include "val/Construct.h"
#include "val/Function.h"
-using std::list;
+using std::deque;
using std::make_pair;
using std::pair;
using std::string;
}
Instruction* ValidationState_t::FindDef(uint32_t id) {
- return const_cast<Instruction*>(
- const_cast<const ValidationState_t*>(this)->FindDef(id));
+ if (all_definitions_.count(id) == 0) {
+ return nullptr;
+ } else {
+ /// We are in a const function, so we cannot use defs.operator[]().
+ /// Luckily we know the key exists, so defs_.at() won't throw an
+ /// exception.
+ return all_definitions_.at(id);
+ }
}
// Increments the instruction count. Used for diagnostic
error_code);
}
-list<Function>& ValidationState_t::functions() { return module_functions_; }
+deque<Function>& ValidationState_t::functions() { return module_functions_; }
Function& ValidationState_t::current_function() {
assert(in_function_body());
#ifndef LIBSPIRV_VAL_VALIDATIONSTATE_H_
#define LIBSPIRV_VAL_VALIDATIONSTATE_H_
-#include <list>
+#include <deque>
#include <string>
#include <unordered_map>
#include <unordered_set>
/// defined
size_t unresolved_forward_id_count() const;
- /// Returns a list of unresolved forward ids.
+ /// Returns a vector of unresolved forward ids.
std::vector<uint32_t> UnresolvedForwardIds() const;
/// Returns true if the id has been defined
libspirv::DiagnosticStream diag(spv_result_t error_code) const;
/// Returns the function states
- std::list<Function>& functions();
+ std::deque<Function>& functions();
/// Returns the function states
Function& current_function();
/// nullptr
Instruction* FindDef(uint32_t id);
- /// Returns a vector of instructions in the order they appear in the binary
- const std::list<Instruction>& ordered_instructions() {
+ /// Returns a deque of instructions in the order they appear in the binary
+ const std::deque<Instruction>& ordered_instructions() {
return ordered_instructions_;
}
ModuleLayoutSection current_layout_section_;
/// A list of functions in the module
- std::list<Function> module_functions_;
+ std::deque<Function> module_functions_;
/// Mask of the capabilities available in the module
spv_capability_mask_t
module_capabilities_; /// Module's declared capabilities.
/// List of all instructions in the order they appear in the binary
- std::list<Instruction> ordered_instructions_;
+ std::deque<Instruction> ordered_instructions_;
/// Instructions that can be referenced by Ids
std::unordered_map<uint32_t, Instruction*> all_definitions_;
for (const auto& inst : _.ordered_instructions()) {
for (auto& operand : inst.operands()) {
const spv_operand_type_t& type = operand.type;
- const uint32_t operand_id = inst.words()[operand.offset];
-
- switch (type) {
- case SPV_OPERAND_TYPE_VARIABLE_ID:
- case SPV_OPERAND_TYPE_ID:
- case SPV_OPERAND_TYPE_TYPE_ID:
- case SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID:
- case SPV_OPERAND_TYPE_SCOPE_ID:
- if (auto def = _.FindDef(operand_id))
- def->RegisterUse(&inst, operand.offset);
- break;
- default:
- break;
+ const uint32_t operand_id = inst.word(operand.offset);
+ if (spvIsIdType(type) && type != SPV_OPERAND_TYPE_RESULT_ID) {
+ if (auto def = _.FindDef(operand_id))
+ def->RegisterUse(&inst, operand.offset);
}
}
}