ty: Ty<'tcx>,
is_return: bool,
) -> PassMode {
- assert!(
- !tcx.layout_of(ParamEnv::reveal_all().and(ty))
- .unwrap()
- .is_unsized()
- );
+ assert!(!tcx
+ .layout_of(ParamEnv::reveal_all().and(ty))
+ .unwrap()
+ .is_unsized());
if let ty::Never = ty.sty {
if is_return {
PassMode::NoPass
if let Some(val) = self.lib_call(name, input_tys, return_ty, &args) {
CValue::ByVal(val, return_layout)
} else {
- CValue::ByRef(
- self.bcx.ins().iconst(self.pointer_type, 0),
- return_layout,
- )
+ CValue::ByRef(self.bcx.ins().iconst(self.pointer_type, 0), return_layout)
}
}
use crate::prelude::*;
use rustc::middle::allocator::AllocatorKind;
-use rustc_allocator::{ALLOCATOR_METHODS, AllocatorTy};
+use rustc_allocator::{AllocatorTy, ALLOCATOR_METHODS};
pub fn codegen(module: &mut Module<impl Backend + 'static>, kind: AllocatorKind) {
let usize_ty = module.target_config().pointer_type();
AllocatorTy::Ptr => arg_tys.push(usize_ty),
AllocatorTy::Usize => arg_tys.push(usize_ty),
- AllocatorTy::ResultPtr |
- AllocatorTy::Unit => panic!("invalid allocator arg"),
+ AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
}
}
let output = match method.output {
AllocatorTy::ResultPtr => Some(usize_ty),
AllocatorTy::Unit => None,
- AllocatorTy::Layout |
- AllocatorTy::Usize |
- AllocatorTy::Ptr => panic!("invalid allocator output"),
+ AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
+ panic!("invalid allocator output")
+ }
};
let sig = Signature {
lval.write_cvalue(fx, CValue::ByVal(ptr, box_layout));
}
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
- assert!(
- lval.layout()
- .ty
- .is_sized(fx.tcx.at(DUMMY_SP), ParamEnv::reveal_all())
- );
+ assert!(lval
+ .layout()
+ .ty
+ .is_sized(fx.tcx.at(DUMMY_SP), ParamEnv::reveal_all()));
let ty_size = fx.layout_of(ty).size.bytes();
let val = CValue::const_val(fx, fx.tcx.types.usize, ty_size as i64);
lval.write_cvalue(fx, val);
size: layout.size.bytes() as u32,
offset: None,
});
- let addr = fx
- .bcx
- .ins()
- .stack_addr(fx.pointer_type, stack_slot, 0);
+ let addr = fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0);
fx.bcx.ins().store(MemFlags::new(), value, addr, 0);
addr
}
match self {
CValue::ByRef(addr, layout) => {
let cton_ty = fx.cton_type(layout.ty).unwrap_or_else(|| {
- if layout.ty.is_box() && !fx
- .layout_of(layout.ty.builtin_deref(true).unwrap().ty)
- .is_unsized()
+ if layout.ty.is_box()
+ && !fx
+ .layout_of(layout.ty.builtin_deref(true).unwrap().ty)
+ .is_unsized()
{
// Consider sized box to be a ptr
pointer_ty(fx.tcx)
);
let val1_offset = layout.fields.offset(0).bytes() as i32;
let val2_offset = layout.fields.offset(1).bytes() as i32;
- let val1 =
- fx.bcx
- .ins()
- .load(fx.pointer_type, MemFlags::new(), addr, val1_offset);
- let val2 =
- fx.bcx
- .ins()
- .load(fx.pointer_type, MemFlags::new(), addr, val2_offset);
+ let val1 = fx
+ .bcx
+ .ins()
+ .load(fx.pointer_type, MemFlags::new(), addr, val1_offset);
+ let val2 = fx
+ .bcx
+ .ins()
+ .load(fx.pointer_type, MemFlags::new(), addr, val2_offset);
(val1, val2)
}
CValue::ByVal(_, _layout) => bug!("Please use load_value for ByVal"),
offset: None,
});
CPlace::Addr(
- fx.bcx
- .ins()
- .stack_addr(fx.pointer_type, stack_slot, 0),
+ fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0),
None,
layout,
)
let layout = fx.layout_of(ty);
assert!(!layout.is_unsized());
CPlace::Addr(
- fx.bcx
- .ins()
- .stack_addr(fx.pointer_type, stack_slot, 0),
+ fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0),
None,
layout,
)
let mut offset = 0;
while size - offset >= 8 {
- let byte = fx.bcx.ins().load(
- fx.pointer_type,
- MemFlags::new(),
- from,
- offset,
- );
+ let byte =
+ fx.bcx
+ .ins()
+ .load(fx.pointer_type, MemFlags::new(), from, offset);
fx.bcx.ins().store(MemFlags::new(), byte, addr, offset);
offset += 8;
}
read_target_uint, AllocId, AllocType, Allocation, ConstValue, EvalResult, GlobalId, Scalar,
};
use rustc::ty::Const;
-use rustc_mir::interpret::{EvalContext, Machine, Memory, MemoryKind, MemPlace, OpTy, PlaceTy, Pointer};
+use rustc_mir::interpret::{
+ EvalContext, Machine, MemPlace, Memory, MemoryKind, OpTy, PlaceTy, Pointer,
+};
use cranelift_module::*;
data_id: DataId,
) -> CPlace<'tcx> {
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
- let global_ptr = fx
- .bcx
- .ins()
- .global_value(fx.pointer_type, local_data_id);
+ let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
let layout = fx.layout_of(fx.monomorphize(&ty));
assert!(!layout.is_unsized(), "unsized statics aren't supported");
CPlace::Addr(global_ptr, None, layout)
panic!();
}
- fn tag_reference(_: &mut EvalContext<'a, 'mir, 'tcx, Self>, _: MemPlace, _: Ty<'tcx>, _: Size, _: Option<crate::rustc::hir::Mutability>) -> EvalResult<'tcx, MemPlace> {
+ fn tag_reference(
+ _: &mut EvalContext<'a, 'mir, 'tcx, Self>,
+ _: MemPlace,
+ _: Ty<'tcx>,
+ _: Size,
+ _: Option<crate::rustc::hir::Mutability>,
+ ) -> EvalResult<'tcx, MemPlace> {
panic!()
}
- fn tag_dereference(_: &EvalContext<'a, 'mir, 'tcx, Self>, _: MemPlace, _: Ty<'tcx>, _: Size, _: Option<crate::rustc::hir::Mutability>) -> EvalResult<'tcx, MemPlace> {
+ fn tag_dereference(
+ _: &EvalContext<'a, 'mir, 'tcx, Self>,
+ _: MemPlace,
+ _: Ty<'tcx>,
+ _: Size,
+ _: Option<crate::rustc::hir::Mutability>,
+ ) -> EvalResult<'tcx, MemPlace> {
panic!();
}
Cow::Borrowed(alloc)
}
- fn tag_new_allocation(_: &mut EvalContext<'a, 'mir, 'tcx, Self>, ptr: Pointer, _: MemoryKind<!>) -> EvalResult<'tcx, Pointer> {
+ fn tag_new_allocation(
+ _: &mut EvalContext<'a, 'mir, 'tcx, Self>,
+ ptr: Pointer,
+ _: MemoryKind<!>,
+ ) -> EvalResult<'tcx, Pointer> {
Ok(ptr)
}
}
-#![feature(rustc_private, macro_at_most_once_rep, never_type, extern_crate_item_prelude)]
+#![feature(
+ rustc_private,
+ macro_at_most_once_rep,
+ never_type,
+ extern_crate_item_prelude
+)]
#![allow(intra_doc_link_resolution_failure)]
extern crate byteorder;
pub use syntax::ast::{FloatTy, IntTy, UintTy};
pub use syntax::source_map::DUMMY_SP;
- pub use cranelift::codegen::isa::CallConv;
pub use cranelift::codegen::ir::{
condcodes::IntCC, function::Function, ExternalName, FuncRef, Inst, StackSlot,
};
+ pub use cranelift::codegen::isa::CallConv;
pub use cranelift::codegen::Context;
pub use cranelift::prelude::*;
pub use cranelift_module::{Backend, DataContext, DataId, FuncId, Linkage, Module};
let mut flags_builder = settings::builder();
flags_builder.enable("is_pic").unwrap();
let flags = settings::Flags::new(flags_builder);
- let isa = cranelift::codegen::isa::lookup(tcx.sess.target.target.llvm_target.parse().unwrap())
- .unwrap()
- .finish(flags);
+ let isa =
+ cranelift::codegen::isa::lookup(tcx.sess.target.target.llvm_target.parse().unwrap())
+ .unwrap()
+ .finish(flags);
// TODO: move to the end of this function when compiling libcore doesn't have unimplemented stuff anymore
save_incremental(tcx);
AbiParam::new(jit_module.target_config().pointer_type()),
AbiParam::new(jit_module.target_config().pointer_type()),
],
- returns: vec![AbiParam::new(jit_module.target_config().pointer_type() /*isize*/)],
+ returns: vec![AbiParam::new(
+ jit_module.target_config().pointer_type(), /*isize*/
+ )],
call_conv: CallConv::SystemV,
};
let main_func_id = jit_module
)
.unwrap(),
);
- assert_eq!(pointer_ty(tcx), faerie_module.target_config().pointer_type());
+ assert_eq!(
+ pointer_ty(tcx),
+ faerie_module.target_config().pointer_type()
+ );
codegen_mono_items(tcx, &mut faerie_module);
};
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
- let mono_items = cgus.iter().map(|cgu| {
- cgu.items().iter()
- }).flatten().collect::<FxHashSet<(_, _)>>();
+ let mono_items = cgus
+ .iter()
+ .map(|cgu| cgu.items().iter())
+ .flatten()
+ .collect::<FxHashSet<(_, _)>>();
let before = ::std::time::Instant::now();
println!("[codegen mono items] start");
crate::main_shim::maybe_create_entry_wrapper(tcx, module);
- let any_dynamic_crate = tcx.sess.dependency_formats.borrow()
+ let any_dynamic_crate = tcx
+ .sess
+ .dependency_formats
+ .borrow()
.iter()
.any(|(_, list)| {
use rustc::middle::dependency_format::Linkage;
AbiParam::new(m.target_config().pointer_type()),
AbiParam::new(m.target_config().pointer_type()),
],
- returns: vec![AbiParam::new(m.target_config().pointer_type() /*isize*/)],
+ returns: vec![AbiParam::new(
+ m.target_config().pointer_type(), /*isize*/
+ )],
call_conv: CallConv::SystemV,
};
.declare_function(&start_name, Linkage::Import, &start_sig)
.unwrap();
- let main_val = bcx.ins().func_addr(m.target_config().pointer_type(), main_func_ref);
+ let main_val = bcx
+ .ins()
+ .func_addr(m.target_config().pointer_type(), main_func_ref);
let func_ref = m.declare_func_in_func(start_func_id, &mut bcx.func);
bcx.ins().call(func_ref, &[main_val, arg_argc, arg_argv])
// Iterate over all entries in the archive:
while let Some(entry_result) = archive.next_entry() {
let mut entry = entry_result.map_err(|e| format!("{:?}", e))?;
- if entry
- .header()
- .identifier() == METADATA_FILE
- {
+ if entry.header().identifier() == METADATA_FILE {
let mut buf = Vec::new();
::std::io::copy(&mut entry, &mut buf).map_err(|e| format!("{:?}", e))?;
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
};
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
- fx.bcx
- .ins()
- .global_value(fx.pointer_type, local_data_id)
+ fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
}
fn build_vtable<'a, 'tcx: 'a>(