Remove byteorder dependency

This commit is contained in:
bjorn3 2020-09-16 16:54:58 +02:00
parent 7285c134d1
commit 55d4afd2ba
3 changed files with 12 additions and 9 deletions

1
Cargo.lock generated
View File

@ -317,7 +317,6 @@ name = "rustc_codegen_cranelift"
version = "0.1.0"
dependencies = [
"ar",
"byteorder",
"cfg-if",
"cranelift-codegen",
"cranelift-frontend",

View File

@ -19,7 +19,6 @@ gimli = { version = "0.21.0", default-features = false, features = ["write"]}
object = { version = "0.21.1", default-features = false, features = ["read", "std", "write"] }
ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" }
byteorder = "1.2.7"
indexmap = "1.0.2"
cfg-if = "0.1.10"
libloading = { version = "0.6.0", optional = true }

View File

@ -168,18 +168,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()
}