]> git.lizzy.rs Git - rust.git/blobdiff - src/vtable.rs
Add custom driver
[rust.git] / src / vtable.rs
index d23b077148e594102491537bb26bb1dd55e82d0a..d6bb9c912b557a449d004e4ac4b6c8be60420756 100644 (file)
@@ -1,4 +1,7 @@
+//! Codegen vtables and vtable accesses.
+//!
 //! See librustc_codegen_llvm/meth.rs for reference
+// FIXME dedup this logic between miri, cg_llvm and cg_clif
 
 use crate::prelude::*;
 
@@ -168,18 +171,23 @@ fn build_vtable<'tcx>(
 }
 
 fn write_usize(tcx: TyCtxt<'_>, buf: &mut [u8], idx: usize, num: u64) {
-    use byteorder::{BigEndian, LittleEndian, WriteBytesExt};
-
-    let usize_size = tcx
+    let pointer_size = tcx
         .layout_of(ParamEnv::reveal_all().and(tcx.types.usize))
         .unwrap()
         .size
         .bytes() as usize;
-    let mut target = &mut buf[idx * usize_size..(idx + 1) * usize_size];
+    let target = &mut buf[idx * pointer_size..(idx + 1) * pointer_size];
 
     match tcx.data_layout.endian {
-        rustc_target::abi::Endian::Little => target.write_uint::<LittleEndian>(num, usize_size),
-        rustc_target::abi::Endian::Big => target.write_uint::<BigEndian>(num, usize_size),
+        rustc_target::abi::Endian::Little => match pointer_size {
+            4 => target.copy_from_slice(&(num as u32).to_le_bytes()),
+            8 => target.copy_from_slice(&(num as u64).to_le_bytes()),
+            _ => todo!("pointer size {} is not yet supported", pointer_size),
+        },
+        rustc_target::abi::Endian::Big => match pointer_size {
+            4 => target.copy_from_slice(&(num as u32).to_be_bytes()),
+            8 => target.copy_from_slice(&(num as u64).to_be_bytes()),
+            _ => todo!("pointer size {} is not yet supported", pointer_size),
+        },
     }
-    .unwrap()
 }