diff options
author | John Hodge <tpg@ucc.asn.au> | 2018-09-22 16:25:01 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2018-09-22 16:25:01 +0800 |
commit | 5c63b46f8dca1d65c1906c77169555229ab07412 (patch) | |
tree | 5580be06c7a535c3b46bdc3ae9f766697aa1158b /src/hir/expr_ptr.hpp | |
parent | dd4e3c887fa2eef2db6fa2795d4283636a1cc26e (diff) | |
download | mrust-5c63b46f8dca1d65c1906c77169555229ab07412.tar.gz |
All - Generate MIR for constant evaluation (has too many const_cast calls, but it's less ugly)
- Also includes some MIR optimisation changes to reduce some compile times (hopefully)
- Removed duplicated MIR consteval and now-unused HIR consteval
Diffstat (limited to 'src/hir/expr_ptr.hpp')
-rw-r--r-- | src/hir/expr_ptr.hpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/hir/expr_ptr.hpp b/src/hir/expr_ptr.hpp index 97991bf2..b510e737 100644 --- a/src/hir/expr_ptr.hpp +++ b/src/hir/expr_ptr.hpp @@ -12,10 +12,14 @@ #include <mir/mir_ptr.hpp> +class Span; + namespace HIR { class TypeRef; class ExprNode; +class Crate; +class ExprState; class ExprPtrInner { @@ -53,20 +57,49 @@ public: ::HIR::ExprNode* operator->() { assert(ptr); return ptr; } const ::HIR::ExprNode* operator->() const { assert(ptr); return ptr; } }; +class ExprStatePtr +{ + ::HIR::ExprState* ptr; +public: + ExprStatePtr(): ptr(nullptr) {} + ExprStatePtr(ExprState ); + ExprStatePtr(const ExprStatePtr&) = delete; + ExprStatePtr(ExprStatePtr&& x): ptr(x.ptr) { x.ptr = nullptr; } + ~ExprStatePtr(); + + ExprStatePtr& operator=(const ExprStatePtr&) = delete; + ExprStatePtr& operator=(ExprStatePtr&& x) { this->~ExprStatePtr(); ptr = x.ptr; x.ptr = nullptr; return *this; } + + operator bool () const { return ptr != nullptr; } + + ::HIR::ExprState& operator*() { assert(ptr); return *ptr; } + const ::HIR::ExprState& operator*() const { assert(ptr); return *ptr; } + ::HIR::ExprState* operator->() { assert(ptr); return ptr; } + const ::HIR::ExprState* operator->() const { assert(ptr); return ptr; } +}; class ExprPtr { + //::HIR::Path m_path; ::HIR::ExprPtrInner node; + public: ::std::vector< ::HIR::TypeRef> m_bindings; ::std::vector< ::HIR::TypeRef> m_erased_types; + + // Public because too much relies on access to it ::MIR::FunctionPointer m_mir; + ::HIR::ExprStatePtr m_state; + public: ExprPtr() {} ExprPtr(::std::unique_ptr< ::HIR::ExprNode> _); + ExprPtr(const ExprPtr&) = delete; + ExprPtr(ExprPtr&&) = default; + /// Take the innards and turn into a unique_ptr - used so typecheck can edit the root node. ::std::unique_ptr< ::HIR::ExprNode> into_unique(); operator bool () const { return node; } ::HIR::ExprNode* get() const { return node.get(); } @@ -76,6 +109,17 @@ public: const ::HIR::ExprNode& operator*() const { return *node; } ::HIR::ExprNode* operator->() { return &*node; } const ::HIR::ExprNode* operator->() const { return &*node; } + + //void ensure_typechecked(const ::HIR::Crate& crate) const; + /// Get MIR (checks if the MIR should be available) + const ::MIR::Function* get_mir_opt() const; + const ::MIR::Function& get_mir_or_error(const Span& sp) const; + ::MIR::Function& get_mir_or_error_mut(const Span& sp); + /// Get external MIR, returns nullptr if none + const ::MIR::Function* get_ext_mir() const; + ::MIR::Function* get_ext_mir_mut(); + + void set_mir(::MIR::FunctionPointer mir); }; } // namespace HIR |