diff options
Diffstat (limited to 'src/mir/check.cpp')
-rw-r--r-- | src/mir/check.cpp | 81 |
1 files changed, 33 insertions, 48 deletions
diff --git a/src/mir/check.cpp b/src/mir/check.cpp index f669623a..58bcaf55 100644 --- a/src/mir/check.cpp +++ b/src/mir/check.cpp @@ -105,15 +105,13 @@ void MIR_Validate_ValState(::MIR::TypeResolve& state, const ::MIR::Function& fcn Valid, }; State ret_state = State::Invalid; - ::std::vector<State> arguments; - ::std::vector<State> temporaries; - ::std::vector<State> variables; + ::std::vector<State> args; + ::std::vector<State> locals; ValStates() {} - ValStates(size_t n_args, size_t n_temps, size_t n_vars): - arguments(n_args, State::Valid), - temporaries(n_temps), - variables(n_vars) + ValStates(size_t n_args, size_t n_locals): + args(n_args, State::Valid), + locals(n_locals) { } @@ -144,22 +142,20 @@ void MIR_Validate_ValState(::MIR::TypeResolve& state, const ::MIR::Function& fcn } } }; - fmt_val_range("arg", this->arguments); - fmt_val_range("tmp", this->temporaries); - fmt_val_range("var", this->variables); + fmt_val_range("arg", this->args); + fmt_val_range("_", this->locals); os << "}"; } bool operator==(const ValStates& x) const { - if( ret_state != x.ret_state ) return false; - if( arguments != x.arguments ) return false; - if( temporaries != x.temporaries ) return false; - if( variables != x.variables ) return false; + if( ret_state != x.ret_state ) return false; + if( args != x.args ) return false; + if( locals != x.locals ) return false; return true; } bool empty() const { - return arguments.empty() && temporaries.empty() && variables.empty(); + return locals.empty() && args.empty(); } bool merge(unsigned bb_idx, ValStates& other) @@ -178,9 +174,8 @@ void MIR_Validate_ValState(::MIR::TypeResolve& state, const ::MIR::Function& fcn { bool rv = false; rv |= ValStates::merge_state(this->ret_state, other.ret_state); - rv |= ValStates::merge_lists(this->arguments , other.arguments); - rv |= ValStates::merge_lists(this->temporaries, other.temporaries); - rv |= ValStates::merge_lists(this->variables , other.variables); + rv |= ValStates::merge_lists(this->args , other.args ); + rv |= ValStates::merge_lists(this->locals, other.locals); return rv; } } @@ -194,42 +189,32 @@ void MIR_Validate_ValState(::MIR::TypeResolve& state, const ::MIR::Function& fcn ret_state = is_valid ? State::Valid : State::Invalid; ), (Argument, - MIR_ASSERT(state, e.idx < this->arguments.size(), ""); - DEBUG("arg" << e.idx << " = " << (is_valid ? "Valid" : "Invalid")); - this->arguments[e.idx] = is_valid ? State::Valid : State::Invalid; + MIR_ASSERT(state, e.idx < this->args.size(), "Argument index out of range"); + DEBUG("arg$" << e.idx << " = " << (is_valid ? "Valid" : "Invalid")); + this->args[e.idx] = is_valid ? State::Valid : State::Invalid; ), - (Variable, - MIR_ASSERT(state, e < this->variables.size(), ""); - DEBUG("var" << e << " = " << (is_valid ? "Valid" : "Invalid")); - this->variables[e] = is_valid ? State::Valid : State::Invalid; - ), - (Temporary, - MIR_ASSERT(state, e.idx < this->temporaries.size(), ""); - DEBUG("tmp" << e.idx << " = " << (is_valid ? "Valid" : "Invalid")); - this->temporaries[e.idx] = is_valid ? State::Valid : State::Invalid; + (Local, + MIR_ASSERT(state, e < this->locals.size(), "Local index out of range"); + DEBUG("_" << e << " = " << (is_valid ? "Valid" : "Invalid")); + this->locals[e] = is_valid ? State::Valid : State::Invalid; ) ) } void ensure_valid(const ::MIR::TypeResolve& state, const ::MIR::LValue& lv) { TU_MATCH( ::MIR::LValue, (lv), (e), - (Variable, - MIR_ASSERT(state, e < this->variables.size(), ""); - if( this->variables[e] != State::Valid ) - MIR_BUG(state, "Use of non-valid variable - " << lv); - ), - (Temporary, - MIR_ASSERT(state, e.idx < this->temporaries.size(), ""); - if( this->temporaries[e.idx] != State::Valid ) - MIR_BUG(state, "Use of non-valid temporary - " << lv); + (Return, + if( this->ret_state != State::Valid ) + MIR_BUG(state, "Use of non-valid lvalue - " << lv); ), (Argument, - MIR_ASSERT(state, e.idx < this->arguments.size(), ""); - if( this->arguments[e.idx] != State::Valid ) - MIR_BUG(state, "Use of non-valid argument - " << lv); + MIR_ASSERT(state, e.idx < this->args.size(), "Arg index out of range"); + if( this->args[e.idx] != State::Valid ) + MIR_BUG(state, "Use of non-valid lvalue - " << lv); ), - (Return, - if( this->ret_state != State::Valid ) + (Local, + MIR_ASSERT(state, e < this->locals.size(), "Local index out of range"); + if( this->locals[e] != State::Valid ) MIR_BUG(state, "Use of non-valid lvalue - " << lv); ), (Static, @@ -309,7 +294,7 @@ void MIR_Validate_ValState(::MIR::TypeResolve& state, const ::MIR::Function& fcn src_path.push_back(idx); to_visit_blocks.push_back( ToVisit { idx, mv$(src_path), mv$(vs) } ); }; - add_to_visit( 0, {}, ValStates { state.m_args.size(), fcn.temporaries.size(), fcn.named_variables.size() } ); + add_to_visit( 0, {}, ValStates { state.m_args.size(), fcn.locals.size() } ); while( to_visit_blocks.size() > 0 ) { auto block = to_visit_blocks.back().bb; @@ -430,12 +415,12 @@ void MIR_Validate_ValState(::MIR::TypeResolve& state, const ::MIR::Function& fcn // Check if the return value has been set val_state.ensure_valid( state, ::MIR::LValue::make_Return({}) ); // Ensure that no other non-Copy values are valid - for(unsigned int i = 0; i < val_state.variables.size(); i ++) + for(unsigned int i = 0; i < val_state.locals.size(); i ++) { - if( val_state.variables[i] == ValStates::State::Invalid ) + if( val_state.locals[i] == ValStates::State::Invalid ) { } - else if( state.m_resolve.type_is_copy(state.sp, fcn.named_variables[i]) ) + else if( state.m_resolve.type_is_copy(state.sp, fcn.locals[i]) ) { } else |