diff options
author | dan sinclair <dj2@everburning.com> | 2018-08-01 16:12:07 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-01 16:12:07 -0400 |
commit | c9cd73b33abd64a9578b9f668c57218fb9e84297 (patch) | |
tree | 720b467fe4c6c113a4eaa36a0c0da99945ebf633 /source/val | |
parent | d49bedcaa68a907e2b201bc372d69256e50f2ab5 (diff) |
Remove instruction_counter from ValidationState. (#1781)
The instruction counter is the same as the size of the
ordered_instruction list when we insert a new instruction. This Cl
removes instruction_counter_ and uses that instead.
Diffstat (limited to 'source/val')
-rw-r--r-- | source/val/instruction.cpp | 2 | ||||
-rw-r--r-- | source/val/instruction.h | 6 | ||||
-rw-r--r-- | source/val/validate.cpp | 1 | ||||
-rw-r--r-- | source/val/validate_id.cpp | 2 | ||||
-rw-r--r-- | source/val/validation_state.cpp | 20 | ||||
-rw-r--r-- | source/val/validation_state.h | 6 |
6 files changed, 10 insertions, 27 deletions
diff --git a/source/val/instruction.cpp b/source/val/instruction.cpp index 692ba1a2..7284eb6d 100644 --- a/source/val/instruction.cpp +++ b/source/val/instruction.cpp @@ -39,7 +39,7 @@ Instruction::Instruction(const spv_parsed_instruction_t* inst, inst_({words_.data(), inst->num_words, inst->opcode, inst->ext_inst_type, inst->type_id, inst->result_id, operands_.data(), inst->num_operands}), - instruction_position_(0), + line_num_(0), function_(defining_function), block_(defining_block), uses_() {} diff --git a/source/val/instruction.h b/source/val/instruction.h index 72881d99..db3a8abc 100644 --- a/source/val/instruction.h +++ b/source/val/instruction.h @@ -94,14 +94,14 @@ class Instruction { return *reinterpret_cast<const T*>(&words_[o.offset]); } - int InstructionPosition() const { return instruction_position_; } - void SetInstructionPosition(int pos) { instruction_position_ = pos; } + size_t LineNum() const { return line_num_; } + void SetLineNum(size_t pos) { line_num_ = pos; } private: const std::vector<uint32_t> words_; const std::vector<spv_parsed_operand_t> operands_; spv_parsed_instruction_t inst_; - int instruction_position_; + size_t line_num_; /// The function in which this instruction was declared Function* function_; diff --git a/source/val/validate.cpp b/source/val/validate.cpp index 3ba458d0..6084e483 100644 --- a/source/val/validate.cpp +++ b/source/val/validate.cpp @@ -111,7 +111,6 @@ spv_result_t ProcessExtensions(void* user_data, spv_result_t ProcessInstruction(void* user_data, const spv_parsed_instruction_t* inst) { ValidationState_t& _ = *(reinterpret_cast<ValidationState_t*>(user_data)); - _.increment_instruction_count(); if (static_cast<SpvOp>(inst->opcode) == SpvOpEntryPoint) { const auto entry_point = inst->words[2]; const SpvExecutionModel execution_model = SpvExecutionModel(inst->words[1]); diff --git a/source/val/validate_id.cpp b/source/val/validate_id.cpp index 46583844..baa8609c 100644 --- a/source/val/validate_id.cpp +++ b/source/val/validate_id.cpp @@ -80,7 +80,7 @@ class idUsage { }; #define DIAG(inst) \ - position->index = inst ? inst->InstructionPosition() : -1; \ + position->index = inst ? inst->LineNum() : -1; \ std::string disassembly; \ if (inst) { \ disassembly = module_.Disassemble( \ diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp index 8db20fe9..5c3c384e 100644 --- a/source/val/validation_state.cpp +++ b/source/val/validation_state.cpp @@ -155,7 +155,6 @@ ValidationState_t::ValidationState_t(const spv_const_context ctx, options_(opt), words_(words), num_words_(num_words), - instruction_counter_(0), unresolved_forward_ids_{}, operand_names_{}, current_layout_section_(kLayoutCapabilities), @@ -276,11 +275,6 @@ Instruction* ValidationState_t::FindDef(uint32_t id) { return it->second; } -// Increments the instruction count. Used for diagnostic -int ValidationState_t::increment_instruction_count() { - return instruction_counter_++; -} - ModuleLayoutSection ValidationState_t::current_layout_section() const { return current_layout_section_; } @@ -299,15 +293,11 @@ bool ValidationState_t::IsOpcodeInCurrentLayoutSection(SpvOp op) { DiagnosticStream ValidationState_t::diag(spv_result_t error_code, const Instruction* inst) const { - int instruction_counter = inst ? inst->InstructionPosition() : -1; std::string disassembly; - if (instruction_counter >= 0 && static_cast<size_t>(instruction_counter) <= - ordered_instructions_.size()) { - disassembly = Disassemble(ordered_instructions_[instruction_counter - 1]); - } - size_t pos = instruction_counter >= 0 ? instruction_counter : 0; - return DiagnosticStream({0, 0, pos}, context_->consumer, disassembly, - error_code); + if (inst) disassembly = Disassemble(*inst); + + return DiagnosticStream({0, 0, inst ? inst->LineNum() : 0}, + context_->consumer, disassembly, error_code); } std::vector<Function>& ValidationState_t::functions() { @@ -476,7 +466,7 @@ Instruction* ValidationState_t::AddOrderedInstruction( } else { ordered_instructions_.emplace_back(inst, nullptr, nullptr); } - ordered_instructions_.back().SetInstructionPosition(instruction_counter_); + ordered_instructions_.back().SetLineNum(ordered_instructions_.size()); return &ordered_instructions_.back(); } diff --git a/source/val/validation_state.h b/source/val/validation_state.h index 237effad..72c563bf 100644 --- a/source/val/validation_state.h +++ b/source/val/validation_state.h @@ -140,9 +140,6 @@ class ValidationState_t { /// Returns true if the id has been defined bool IsDefinedId(uint32_t id) const; - /// Increments the instruction count. Used for diagnostic - int increment_instruction_count(); - /// Increments the total number of instructions in the file. void increment_total_instructions() { total_instructions_++; } @@ -531,9 +528,6 @@ class ValidationState_t { /// The total number of functions in the binary. size_t total_functions_ = 0; - /// Tracks the number of instructions evaluated by the validator - int instruction_counter_; - /// IDs which have been forward declared but have not been defined std::unordered_set<uint32_t> unresolved_forward_ids_; |