Remove redundant in_block function from Function
Same test can be done through the get_current_block function
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 @@
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();
/// Returns the block that is currently being parsed in the binary
- 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 @@
<< _.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 @@
<< "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 @@
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 @@
variable_ids_(),
parameter_ids_() {}
-bool Function::in_block() const { return static_cast<bool>(current_block_); }
-
bool Function::IsFirstBlock(uint32_t id) const {
return !ordered_blocks_.empty() && *get_first_block() == id;
}
@@ -409,7 +407,7 @@
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 @@
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::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 @@
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 @@
"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<BasicBlock*> next_blocks;
@@ -542,10 +540,8 @@
}
vector<BasicBlock*>& 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<CFConstruct>& Function::get_constructs() const {
return cfg_constructs_;