about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2018-11-13 14:55:18 +0100
committerOliver Scherer <github35764891676564198441@oli-obk.de>2018-11-24 11:36:31 +0100
commitcc2f46e55a3fe52affe0dd4aee2ececd75c78031 (patch)
treedec6decec05dd6ec0536ecc4fa49672073cf2881 /src
parent20dee47a66a802c0e7f0b8884632592ad9311357 (diff)
downloadrust-cc2f46e55a3fe52affe0dd4aee2ececd75c78031.tar.gz
rust-cc2f46e55a3fe52affe0dd4aee2ececd75c78031.zip
Reorder methods in `allocation.rs`
Diffstat (limited to 'src')
-rw-r--r--src/librustc/mir/interpret/allocation.rs170
1 files changed, 85 insertions, 85 deletions
diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs
index bafa32df848..2e08baa6f51 100644
--- a/src/librustc/mir/interpret/allocation.rs
+++ b/src/librustc/mir/interpret/allocation.rs
@@ -89,6 +89,91 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
     }
 }
 
+/// Byte accessors
+impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
+    /// The last argument controls whether we error out when there are undefined
+    /// or pointer bytes.  You should never call this, call `get_bytes` or
+    /// `get_bytes_with_undef_and_ptr` instead,
+    ///
+    /// This function also guarantees that the resulting pointer will remain stable
+    /// even when new allocations are pushed to the `HashMap`. `copy_repeatedly` relies
+    /// on that.
+    fn get_bytes_internal(
+        &self,
+        cx: &impl HasDataLayout,
+        ptr: Pointer<Tag>,
+        size: Size,
+        align: Align,
+        check_defined_and_ptr: bool,
+    ) -> EvalResult<'tcx, &[u8]> {
+        self.check_align(ptr.into(), align)?;
+        self.check_bounds(cx, ptr, size)?;
+
+        if check_defined_and_ptr {
+            self.check_defined(ptr, size)?;
+            self.check_relocations(cx, ptr, size)?;
+        } else {
+            // We still don't want relocations on the *edges*
+            self.check_relocation_edges(cx, ptr, size)?;
+        }
+
+        AllocationExtra::memory_read(self, ptr, size)?;
+
+        assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
+        assert_eq!(size.bytes() as usize as u64, size.bytes());
+        let offset = ptr.offset.bytes() as usize;
+        Ok(&self.bytes[offset..offset + size.bytes() as usize])
+    }
+
+    #[inline]
+    fn get_bytes(
+        &self,
+        cx: &impl HasDataLayout,
+        ptr: Pointer<Tag>,
+        size: Size,
+        align: Align
+    ) -> EvalResult<'tcx, &[u8]> {
+        self.get_bytes_internal(cx, ptr, size, align, true)
+    }
+
+    /// It is the caller's responsibility to handle undefined and pointer bytes.
+    /// However, this still checks that there are no relocations on the *edges*.
+    #[inline]
+    pub fn get_bytes_with_undef_and_ptr(
+        &self,
+        cx: &impl HasDataLayout,
+        ptr: Pointer<Tag>,
+        size: Size,
+        align: Align
+    ) -> EvalResult<'tcx, &[u8]> {
+        self.get_bytes_internal(cx, ptr, size, align, false)
+    }
+
+    /// Just calling this already marks everything as defined and removes relocations,
+    /// so be sure to actually put data there!
+    pub fn get_bytes_mut(
+        &mut self,
+        cx: &impl HasDataLayout,
+        ptr: Pointer<Tag>,
+        size: Size,
+        align: Align,
+    ) -> EvalResult<'tcx, &mut [u8]> {
+        assert_ne!(size.bytes(), 0, "0-sized accesses should never even get a `Pointer`");
+        self.check_align(ptr.into(), align)?;
+        self.check_bounds(cx, ptr, size)?;
+
+        self.mark_definedness(ptr, size, true)?;
+        self.clear_relocations(cx, ptr, size)?;
+
+        AllocationExtra::memory_written(self, ptr, size)?;
+
+        assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
+        assert_eq!(size.bytes() as usize as u64, size.bytes());
+        let offset = ptr.offset.bytes() as usize;
+        Ok(&mut self.bytes[offset..offset + size.bytes() as usize])
+    }
+}
+
 /// Reading and writing
 impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
     pub fn read_c_str(
@@ -291,91 +376,6 @@ fn int_align(
     ity.align(cx).abi
 }
 
-/// Byte accessors
-impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
-    /// The last argument controls whether we error out when there are undefined
-    /// or pointer bytes.  You should never call this, call `get_bytes` or
-    /// `get_bytes_with_undef_and_ptr` instead,
-    ///
-    /// This function also guarantees that the resulting pointer will remain stable
-    /// even when new allocations are pushed to the `HashMap`. `copy_repeatedly` relies
-    /// on that.
-    fn get_bytes_internal(
-        &self,
-        cx: &impl HasDataLayout,
-        ptr: Pointer<Tag>,
-        size: Size,
-        align: Align,
-        check_defined_and_ptr: bool,
-    ) -> EvalResult<'tcx, &[u8]> {
-        self.check_align(ptr.into(), align)?;
-        self.check_bounds(cx, ptr, size)?;
-
-        if check_defined_and_ptr {
-            self.check_defined(ptr, size)?;
-            self.check_relocations(cx, ptr, size)?;
-        } else {
-            // We still don't want relocations on the *edges*
-            self.check_relocation_edges(cx, ptr, size)?;
-        }
-
-        AllocationExtra::memory_read(self, ptr, size)?;
-
-        assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
-        assert_eq!(size.bytes() as usize as u64, size.bytes());
-        let offset = ptr.offset.bytes() as usize;
-        Ok(&self.bytes[offset..offset + size.bytes() as usize])
-    }
-
-    #[inline]
-    fn get_bytes(
-        &self,
-        cx: &impl HasDataLayout,
-        ptr: Pointer<Tag>,
-        size: Size,
-        align: Align
-    ) -> EvalResult<'tcx, &[u8]> {
-        self.get_bytes_internal(cx, ptr, size, align, true)
-    }
-
-    /// It is the caller's responsibility to handle undefined and pointer bytes.
-    /// However, this still checks that there are no relocations on the *edges*.
-    #[inline]
-    pub fn get_bytes_with_undef_and_ptr(
-        &self,
-        cx: &impl HasDataLayout,
-        ptr: Pointer<Tag>,
-        size: Size,
-        align: Align
-    ) -> EvalResult<'tcx, &[u8]> {
-        self.get_bytes_internal(cx, ptr, size, align, false)
-    }
-
-    /// Just calling this already marks everything as defined and removes relocations,
-    /// so be sure to actually put data there!
-    pub fn get_bytes_mut(
-        &mut self,
-        cx: &impl HasDataLayout,
-        ptr: Pointer<Tag>,
-        size: Size,
-        align: Align,
-    ) -> EvalResult<'tcx, &mut [u8]> {
-        assert_ne!(size.bytes(), 0, "0-sized accesses should never even get a `Pointer`");
-        self.check_align(ptr.into(), align)?;
-        self.check_bounds(cx, ptr, size)?;
-
-        self.mark_definedness(ptr, size, true)?;
-        self.clear_relocations(cx, ptr, size)?;
-
-        AllocationExtra::memory_written(self, ptr, size)?;
-
-        assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
-        assert_eq!(size.bytes() as usize as u64, size.bytes());
-        let offset = ptr.offset.bytes() as usize;
-        Ok(&mut self.bytes[offset..offset + size.bytes() as usize])
-    }
-}
-
 /// Relocations
 impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
     /// Return all relocations overlapping with the given ptr-offset pair.