summaryrefslogtreecommitdiff
path: root/tools/standalone_miri/value.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-03-04 21:20:00 +0800
committerJohn Hodge <tpg@mutabah.net>2018-03-17 18:52:16 +0800
commita8cd5861fdee9040a82654cc9d1fd41f98759d8b (patch)
treed5a05b794a422b4a3b25af874d6b155b9cf877d0 /tools/standalone_miri/value.cpp
parent5d78f1ba303a0e8196e62d4bd0c7708387164993 (diff)
downloadmrust-a8cd5861fdee9040a82654cc9d1fd41f98759d8b.tar.gz
Standalone MIRI - Filled with hacks, but advancing
Diffstat (limited to 'tools/standalone_miri/value.cpp')
-rw-r--r--tools/standalone_miri/value.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/tools/standalone_miri/value.cpp b/tools/standalone_miri/value.cpp
index 745e9b1b..168df328 100644
--- a/tools/standalone_miri/value.cpp
+++ b/tools/standalone_miri/value.cpp
@@ -31,6 +31,13 @@ AllocationPtr AllocationPtr::new_string(const ::std::string* ptr)
rv.m_ptr = reinterpret_cast<void*>( reinterpret_cast<uintptr_t>(ptr) + static_cast<uintptr_t>(Ty::StdString) );
return rv;
}
+AllocationPtr AllocationPtr::new_ffi(FFIPointer info)
+{
+ AllocationPtr rv;
+ auto* ptr = new FFIPointer(info);
+ rv.m_ptr = reinterpret_cast<void*>( reinterpret_cast<uintptr_t>(ptr) + static_cast<uintptr_t>(Ty::FfiPointer) );
+ return rv;
+}
AllocationPtr::AllocationPtr(const AllocationPtr& x):
m_ptr(nullptr)
{
@@ -55,8 +62,12 @@ AllocationPtr::AllocationPtr(const AllocationPtr& x):
// No ownership semantics, just clone the pointer
m_ptr = x.m_ptr;
break;
- case Ty::Unused2:
- throw "BUG";
+ case Ty::FfiPointer: {
+ auto ptr_i = reinterpret_cast<uintptr_t>(new FFIPointer(x.ffi()));
+ assert( (ptr_i & 3) == 0 );
+ m_ptr = reinterpret_cast<void*>( ptr_i + static_cast<uintptr_t>(Ty::FfiPointer) );
+ assert(get_ty() == Ty::FfiPointer);
+ } break;
}
}
else
@@ -86,7 +97,9 @@ AllocationPtr::~AllocationPtr()
case Ty::StdString: {
// No ownership semantics
} break;
- case Ty::Unused2: {
+ case Ty::FfiPointer: {
+ auto* ptr = const_cast<FFIPointer*>(&ffi());
+ delete ptr;
} break;
}
}
@@ -107,7 +120,8 @@ AllocationPtr::~AllocationPtr()
case AllocationPtr::Ty::StdString:
os << "\"" << x.str() << "\"";
break;
- case AllocationPtr::Ty::Unused2:
+ case AllocationPtr::Ty::FfiPointer:
+ os << "FFI " << x.ffi().source_function << " " << x.ffi().ptr_value;
break;
}
}
@@ -403,13 +417,24 @@ Value Value::new_fnptr(const ::HIR::Path& fn_path)
rv.allocation.alloc().mask.at(0) = 0xFF; // TODO: Get pointer size and make that much valid instead of 8 bytes
return rv;
}
+Value Value::new_ffiptr(FFIPointer ffi)
+{
+ Value rv( ::HIR::TypeRef(::HIR::CoreType { RawType::USize }) );
+ rv.create_allocation();
+ rv.allocation.alloc().relocations.push_back(Relocation { 0, AllocationPtr::new_ffi(ffi) });
+ rv.allocation.alloc().data.at(0) = 0;
+ rv.allocation.alloc().mask.at(0) = 0xFF; // TODO: Get pointer size and make that much valid instead of 8 bytes
+ return rv;
+}
void Value::create_allocation()
{
assert(!this->allocation);
this->allocation = Allocation::new_alloc(this->direct_data.size);
- this->allocation.alloc().mask[0] = this->direct_data.mask[0];
- this->allocation.alloc().mask[1] = this->direct_data.mask[1];
+ if( this->direct_data.size > 0 )
+ this->allocation.alloc().mask[0] = this->direct_data.mask[0];
+ if( this->direct_data.size > 8 )
+ this->allocation.alloc().mask[1] = this->direct_data.mask[1];
::std::memcpy(this->allocation.alloc().data.data(), this->direct_data.data, this->direct_data.size);
}
void Value::check_bytes_valid(size_t ofs, size_t size) const