summaryrefslogtreecommitdiff
path: root/src/mir/helpers.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mir/helpers.hpp')
-rw-r--r--src/mir/helpers.hpp43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/mir/helpers.hpp b/src/mir/helpers.hpp
index 884cafa7..a986a3ae 100644
--- a/src/mir/helpers.hpp
+++ b/src/mir/helpers.hpp
@@ -22,33 +22,66 @@ namespace MIR {
class Function;
class LValue;
+struct CheckFailure:
+ public ::std::exception
+{
+};
+
+#define MIR_BUG(state, ...) ( (state).print_bug( [&](auto& _os){_os << __VA_ARGS__; } ) )
+#define MIR_ASSERT(state, cnd, ...) do { if( !(cnd) ) (state).print_bug( [&](auto& _os){_os << "ASSERT " #cnd " failed - " << __VA_ARGS__; } ); } while(0)
+#define MIR_TODO(state, ...) ( (state).print_todo( [&](auto& _os){_os << __VA_ARGS__; } ) )
+
class TypeResolve
{
public:
typedef ::std::vector< ::std::pair< ::HIR::Pattern, ::HIR::TypeRef> > args_t;
private:
+ const unsigned int STMT_TERM = ~0u;
+
const Span& sp;
+ const ::StaticTraitResolve& m_resolve;
const ::HIR::Crate& m_crate;
+ ::FmtLambda m_path;
const ::HIR::TypeRef& m_ret_type;
const args_t& m_args;
const ::MIR::Function& m_fcn;
- ::StaticTraitResolve m_resolve;
const ::HIR::SimplePath* m_lang_Box = nullptr;
+
+ unsigned int bb_idx = 0;
+ unsigned int stmt_idx = 0;
public:
- TypeResolve(const Span& sp, const ::HIR::Crate& crate, const ::HIR::TypeRef& ret_type, const args_t& args, const ::MIR::Function& fcn):
+ TypeResolve(const Span& sp, const ::StaticTraitResolve& resolve, ::FmtLambda path, const ::HIR::TypeRef& ret_type, const args_t& args, const ::MIR::Function& fcn):
sp(sp),
- m_crate(crate),
+ m_resolve(resolve),
+ m_crate(resolve.m_crate),
+ m_path(path),
m_ret_type(ret_type),
m_args(args),
- m_fcn(fcn),
- m_resolve(crate)
+ m_fcn(fcn)
{
if( m_crate.m_lang_items.count("owned_box") > 0 ) {
m_lang_Box = &m_crate.m_lang_items.at("owned_box");
}
}
+ void set_cur_stmt(unsigned int bb_idx, unsigned int stmt_idx) {
+ this->bb_idx = bb_idx;
+ this->stmt_idx = stmt_idx;
+ }
+ void set_cur_stmt_term(unsigned int bb_idx) {
+ this->bb_idx = bb_idx;
+ this->stmt_idx = STMT_TERM;
+ }
+
+ void print_bug(::std::function<void(::std::ostream& os)> cb) const {
+ print_msg("ERROR", cb);
+ }
+ void print_todo(::std::function<void(::std::ostream& os)> cb) const {
+ print_msg("TODO", cb);
+ }
+ void print_msg(const char* tag, ::std::function<void(::std::ostream& os)> cb) const;
+
const ::HIR::TypeRef& get_lvalue_type(::HIR::TypeRef& tmp, const ::MIR::LValue& val) const;
private: