diff options
author | John Hodge <tpg@mutabah.net> | 2016-12-10 16:31:50 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-12-10 16:31:50 +0800 |
commit | c1348ccd50cd7877cf72af1db65c8671c9b70c91 (patch) | |
tree | 97b152bfad0b132d3d173e02239da8fbbb607366 /src/mir/cleanup.cpp | |
parent | 23af1651d3ac05597da74c38dead7dfb8422080f (diff) | |
download | mrust-c1348ccd50cd7877cf72af1db65c8671c9b70c91.tar.gz |
MIR Cleanup - BorrowOf support
Diffstat (limited to 'src/mir/cleanup.cpp')
-rw-r--r-- | src/mir/cleanup.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/mir/cleanup.cpp b/src/mir/cleanup.cpp index 8a3454c4..c73bc66b 100644 --- a/src/mir/cleanup.cpp +++ b/src/mir/cleanup.cpp @@ -627,12 +627,28 @@ void MIR_Cleanup(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path, } ), (Borrow, - if( lit_ptr->is_BorrowOf() ) { - // TODO: - if( te.inner->m_data.is_Slice() ) { - // TODO: Create DST + if( lit_ptr->is_BorrowOf() ) + { + const auto& path = lit_ptr->as_BorrowOf(); + if( te.inner->m_data.is_Slice() ) + { + ::HIR::TypeRef tmp; + const auto& ty = state.get_static_type(tmp, path); + MIR_ASSERT(state, ty.m_data.is_Array(), "BorrowOf returning slice not of an array"); + unsigned int size = ty.m_data.as_Array().size_val; + + auto ptr_type = ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Shared, + (&ty == &tmp ? mv$(tmp) : ty.clone()) + ); + + auto ptr_lval = mutator.in_temporary( mv$(ptr_type), ::MIR::Constant::make_ItemAddr(path.clone()) ); + auto size_lval = mutator.in_temporary( ::HIR::CoreType::Usize, ::MIR::Constant::make_Uint(size) ); + se.src = ::MIR::RValue::make_MakeDst({ mv$(ptr_lval), mv$(size_lval) }); + } + else + { + e = ::MIR::Constant::make_ItemAddr( path.clone() ); } - e = ::MIR::Constant::make_ItemAddr( lit_ptr->as_BorrowOf().clone() ); } else if( te.inner->m_data.is_Slice() && *te.inner->m_data.as_Slice().inner == ::HIR::CoreType::U8 ) { ::std::vector<uint8_t> bytestr; |