From 00b72c2995736f80c9e14a5a98a9dc613a87c582 Mon Sep 17 00:00:00 2001 From: Umar Arshad Date: Wed, 1 Jun 2016 18:22:57 -0400 Subject: [PATCH] Remove redundant in_block function from Function Same test can be done through the get_current_block function --- source/validate.h | 8 ++------ source/validate_cfg.cpp | 2 +- source/validate_instruction.cpp | 2 +- source/validate_types.cpp | 20 ++++++++------------ 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/source/validate.h b/source/validate.h index dd93a55..35050cd 100644 --- a/source/validate.h +++ b/source/validate.h @@ -340,15 +340,11 @@ class Function { return undefined_blocks_; } - /// Returns true if called after a label instruction but before a branch - /// instruction - bool in_block() const; - /// Returns the block that is currently being parsed in the binary - BasicBlock& get_current_block(); + BasicBlock* get_current_block(); /// Returns the block that is currently being parsed in the binary - const BasicBlock& get_current_block() const; + const BasicBlock* get_current_block() const; /// Prints a GraphViz digraph of the CFG of the current funciton void printDotGraph() const; diff --git a/source/validate_cfg.cpp b/source/validate_cfg.cpp index e1f1191..187d820 100644 --- a/source/validate_cfg.cpp +++ b/source/validate_cfg.cpp @@ -190,7 +190,7 @@ spv_result_t FirstBlockAssert(ValidationState_t& _, uint32_t target) { << _.getIdName(_.get_current_function().get_id()) << " is targeted by block " << _.getIdName( - _.get_current_function().get_current_block().get_id()); + _.get_current_function().get_current_block()->get_id()); } return SPV_SUCCESS; } diff --git a/source/validate_instruction.cpp b/source/validate_instruction.cpp index 1a17bd0..b86028d 100644 --- a/source/validate_instruction.cpp +++ b/source/validate_instruction.cpp @@ -140,7 +140,7 @@ spv_result_t InstructionPass(ValidationState_t& _, << "Variables must have a function[7] storage class inside" " of a function"; } - if(_.get_current_function().IsFirstBlock(_.get_current_function().get_current_block().get_id()) == false) { + if(_.get_current_function().IsFirstBlock(_.get_current_function().get_current_block()->get_id()) == false) { return _.diag(SPV_ERROR_INVALID_CFG) << "Variables can only be defined in the first block of a function"; } diff --git a/source/validate_types.cpp b/source/validate_types.cpp index 88f6ad1..bba979d 100644 --- a/source/validate_types.cpp +++ b/source/validate_types.cpp @@ -315,7 +315,7 @@ Function& ValidationState_t::get_current_function() { bool ValidationState_t::in_function_body() const { return in_function_; } bool ValidationState_t::in_block() const { - return module_functions_.back().in_block(); + return module_functions_.back().get_current_block() != nullptr; } void ValidationState_t::RegisterCapability(SpvCapability cap) { @@ -372,8 +372,6 @@ Function::Function(uint32_t id, uint32_t result_type_id, variable_ids_(), parameter_ids_() {} -bool Function::in_block() const { return static_cast(current_block_); } - bool Function::IsFirstBlock(uint32_t id) const { return !ordered_blocks_.empty() && *get_first_block() == id; } @@ -409,7 +407,7 @@ spv_result_t Function::RegisterFunctionParameter(uint32_t id, assert(module_.in_function_body() == true && "RegisterFunctionParameter can only be called when parsing the binary " "outside of another function"); - assert(in_block() == false && + assert(get_current_block() == nullptr && "RegisterFunctionParameter can only be called when parsing the binary " "ouside of a block"); // TODO(umar): Validate function parameter type order and count @@ -423,7 +421,7 @@ spv_result_t Function::RegisterLoopMerge(uint32_t merge_id, uint32_t continue_id) { RegisterBlock(merge_id, false); RegisterBlock(continue_id, false); - cfg_constructs_.emplace_back(&get_current_block(), &blocks_.at(merge_id), + cfg_constructs_.emplace_back(get_current_block(), &blocks_.at(merge_id), &blocks_.at(continue_id)); return SPV_SUCCESS; @@ -431,7 +429,7 @@ spv_result_t Function::RegisterLoopMerge(uint32_t merge_id, spv_result_t Function::RegisterSelectionMerge(uint32_t merge_id) { RegisterBlock(merge_id, false); - cfg_constructs_.emplace_back(&get_current_block(), &blocks_.at(merge_id)); + cfg_constructs_.emplace_back(get_current_block(), &blocks_.at(merge_id)); return SPV_SUCCESS; } @@ -488,7 +486,7 @@ spv_result_t Function::RegisterBlock(uint32_t id, bool is_definition) { bool success = false; tie(inserted_block, success) = blocks_.insert({id, BasicBlock(id)}); if (is_definition) { // new block definition - assert(in_block() == false && + assert(get_current_block() == nullptr && "Register Block can only be called when parsing a binary outside of " "a BasicBlock"); @@ -509,7 +507,7 @@ void Function::RegisterBlockEnd(vector next_list, "RegisterBlockEnd can only be called when parsing a binary in a " "function"); assert( - in_block() == true && + get_current_block() && "RegisterBlockEnd can only be called when parsing a binary in a block"); vector next_blocks; @@ -542,10 +540,8 @@ const vector& Function::get_blocks() const { } vector& Function::get_blocks() { return ordered_blocks_; } -const BasicBlock& Function::get_current_block() const { - return *current_block_; -} -BasicBlock& Function::get_current_block() { return *current_block_; } +const BasicBlock* Function::get_current_block() const { return current_block_; } +BasicBlock* Function::get_current_block() { return current_block_; } const list& Function::get_constructs() const { return cfg_constructs_; -- 2.7.4