Rename trans to codegen
This commit is contained in:
parent
8063c37b7e
commit
d27f2f0932
9 changed files with 77 additions and 77 deletions
|
@ -497,7 +497,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
.tcx
|
.tcx
|
||||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
|
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
|
||||||
|
|
||||||
let destination = destination.map(|(place, bb)| (trans_place(fx, place), bb));
|
let destination = destination.map(|(place, bb)| (codegen_place(fx, place), bb));
|
||||||
|
|
||||||
// Handle special calls like instrinsics and empty drop glue.
|
// Handle special calls like instrinsics and empty drop glue.
|
||||||
let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() {
|
let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() {
|
||||||
|
@ -550,8 +550,8 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
// Unpack arguments tuple for closures
|
// Unpack arguments tuple for closures
|
||||||
let args = if fn_sig.abi == Abi::RustCall {
|
let args = if fn_sig.abi == Abi::RustCall {
|
||||||
assert_eq!(args.len(), 2, "rust-call abi requires two arguments");
|
assert_eq!(args.len(), 2, "rust-call abi requires two arguments");
|
||||||
let self_arg = trans_operand(fx, &args[0]);
|
let self_arg = codegen_operand(fx, &args[0]);
|
||||||
let pack_arg = trans_operand(fx, &args[1]);
|
let pack_arg = codegen_operand(fx, &args[1]);
|
||||||
|
|
||||||
let tupled_arguments = match pack_arg.layout().ty.kind() {
|
let tupled_arguments = match pack_arg.layout().ty.kind() {
|
||||||
ty::Tuple(ref tupled_arguments) => tupled_arguments,
|
ty::Tuple(ref tupled_arguments) => tupled_arguments,
|
||||||
|
@ -566,7 +566,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
args
|
args
|
||||||
} else {
|
} else {
|
||||||
args.iter()
|
args.iter()
|
||||||
.map(|arg| trans_operand(fx, arg))
|
.map(|arg| codegen_operand(fx, arg))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -610,7 +610,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
let nop_inst = fx.bcx.ins().nop();
|
let nop_inst = fx.bcx.ins().nop();
|
||||||
fx.add_comment(nop_inst, "indirect call");
|
fx.add_comment(nop_inst, "indirect call");
|
||||||
}
|
}
|
||||||
let func = trans_operand(fx, func).load_scalar(fx);
|
let func = codegen_operand(fx, func).load_scalar(fx);
|
||||||
(
|
(
|
||||||
Some(func),
|
Some(func),
|
||||||
args.get(0)
|
args.get(0)
|
||||||
|
|
80
src/base.rs
80
src/base.rs
|
@ -5,7 +5,7 @@ use rustc_middle::ty::adjustment::PointerCast;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub(crate) fn trans_fn<'tcx>(
|
pub(crate) fn codegen_fn<'tcx>(
|
||||||
cx: &mut crate::CodegenCx<'tcx, impl Module>,
|
cx: &mut crate::CodegenCx<'tcx, impl Module>,
|
||||||
instance: Instance<'tcx>,
|
instance: Instance<'tcx>,
|
||||||
linkage: Linkage,
|
linkage: Linkage,
|
||||||
|
@ -202,7 +202,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
|
||||||
fx.bcx.ins().nop();
|
fx.bcx.ins().nop();
|
||||||
for stmt in &bb_data.statements {
|
for stmt in &bb_data.statements {
|
||||||
fx.set_debug_loc(stmt.source_info);
|
fx.set_debug_loc(stmt.source_info);
|
||||||
trans_stmt(fx, block, stmt);
|
codegen_stmt(fx, block, stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
@ -258,7 +258,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let cond = trans_operand(fx, cond).load_scalar(fx);
|
let cond = codegen_operand(fx, cond).load_scalar(fx);
|
||||||
|
|
||||||
let target = fx.get_block(*target);
|
let target = fx.get_block(*target);
|
||||||
let failure = fx.bcx.create_block();
|
let failure = fx.bcx.create_block();
|
||||||
|
@ -276,8 +276,8 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
|
||||||
|
|
||||||
match msg {
|
match msg {
|
||||||
AssertKind::BoundsCheck { ref len, ref index } => {
|
AssertKind::BoundsCheck { ref len, ref index } => {
|
||||||
let len = trans_operand(fx, len).load_scalar(fx);
|
let len = codegen_operand(fx, len).load_scalar(fx);
|
||||||
let index = trans_operand(fx, index).load_scalar(fx);
|
let index = codegen_operand(fx, index).load_scalar(fx);
|
||||||
let location = fx
|
let location = fx
|
||||||
.get_caller_location(bb_data.terminator().source_info.span)
|
.get_caller_location(bb_data.terminator().source_info.span)
|
||||||
.load_scalar(fx);
|
.load_scalar(fx);
|
||||||
|
@ -301,7 +301,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
|
||||||
switch_ty,
|
switch_ty,
|
||||||
targets,
|
targets,
|
||||||
} => {
|
} => {
|
||||||
let discr = trans_operand(fx, discr).load_scalar(fx);
|
let discr = codegen_operand(fx, discr).load_scalar(fx);
|
||||||
|
|
||||||
if switch_ty.kind() == fx.tcx.types.bool.kind() {
|
if switch_ty.kind() == fx.tcx.types.bool.kind() {
|
||||||
assert_eq!(targets.iter().count(), 1);
|
assert_eq!(targets.iter().count(), 1);
|
||||||
|
@ -396,14 +396,14 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
|
||||||
| TerminatorKind::FalseUnwind { .. }
|
| TerminatorKind::FalseUnwind { .. }
|
||||||
| TerminatorKind::DropAndReplace { .. }
|
| TerminatorKind::DropAndReplace { .. }
|
||||||
| TerminatorKind::GeneratorDrop => {
|
| TerminatorKind::GeneratorDrop => {
|
||||||
bug!("shouldn't exist at trans {:?}", bb_data.terminator());
|
bug!("shouldn't exist at codegen {:?}", bb_data.terminator());
|
||||||
}
|
}
|
||||||
TerminatorKind::Drop {
|
TerminatorKind::Drop {
|
||||||
place,
|
place,
|
||||||
target,
|
target,
|
||||||
unwind: _,
|
unwind: _,
|
||||||
} => {
|
} => {
|
||||||
let drop_place = trans_place(fx, *place);
|
let drop_place = codegen_place(fx, *place);
|
||||||
crate::abi::codegen_drop(fx, bb_data.terminator().source_info.span, drop_place);
|
crate::abi::codegen_drop(fx, bb_data.terminator().source_info.span, drop_place);
|
||||||
|
|
||||||
let target_block = fx.get_block(*target);
|
let target_block = fx.get_block(*target);
|
||||||
|
@ -416,7 +416,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
|
||||||
fx.bcx.finalize();
|
fx.bcx.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trans_stmt<'tcx>(
|
fn codegen_stmt<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||||
#[allow(unused_variables)] cur_block: Block,
|
#[allow(unused_variables)] cur_block: Block,
|
||||||
stmt: &Statement<'tcx>,
|
stmt: &Statement<'tcx>,
|
||||||
|
@ -439,19 +439,19 @@ fn trans_stmt<'tcx>(
|
||||||
place,
|
place,
|
||||||
variant_index,
|
variant_index,
|
||||||
} => {
|
} => {
|
||||||
let place = trans_place(fx, **place);
|
let place = codegen_place(fx, **place);
|
||||||
crate::discriminant::codegen_set_discriminant(fx, place, *variant_index);
|
crate::discriminant::codegen_set_discriminant(fx, place, *variant_index);
|
||||||
}
|
}
|
||||||
StatementKind::Assign(to_place_and_rval) => {
|
StatementKind::Assign(to_place_and_rval) => {
|
||||||
let lval = trans_place(fx, to_place_and_rval.0);
|
let lval = codegen_place(fx, to_place_and_rval.0);
|
||||||
let dest_layout = lval.layout();
|
let dest_layout = lval.layout();
|
||||||
match &to_place_and_rval.1 {
|
match &to_place_and_rval.1 {
|
||||||
Rvalue::Use(operand) => {
|
Rvalue::Use(operand) => {
|
||||||
let val = trans_operand(fx, operand);
|
let val = codegen_operand(fx, operand);
|
||||||
lval.write_cvalue(fx, val);
|
lval.write_cvalue(fx, val);
|
||||||
}
|
}
|
||||||
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
|
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
|
||||||
let place = trans_place(fx, *place);
|
let place = codegen_place(fx, *place);
|
||||||
let ref_ = place.place_ref(fx, lval.layout());
|
let ref_ = place.place_ref(fx, lval.layout());
|
||||||
lval.write_cvalue(fx, ref_);
|
lval.write_cvalue(fx, ref_);
|
||||||
}
|
}
|
||||||
|
@ -460,29 +460,29 @@ fn trans_stmt<'tcx>(
|
||||||
lval.write_cvalue(fx, val);
|
lval.write_cvalue(fx, val);
|
||||||
}
|
}
|
||||||
Rvalue::BinaryOp(bin_op, lhs, rhs) => {
|
Rvalue::BinaryOp(bin_op, lhs, rhs) => {
|
||||||
let lhs = trans_operand(fx, lhs);
|
let lhs = codegen_operand(fx, lhs);
|
||||||
let rhs = trans_operand(fx, rhs);
|
let rhs = codegen_operand(fx, rhs);
|
||||||
|
|
||||||
let res = crate::num::codegen_binop(fx, *bin_op, lhs, rhs);
|
let res = crate::num::codegen_binop(fx, *bin_op, lhs, rhs);
|
||||||
lval.write_cvalue(fx, res);
|
lval.write_cvalue(fx, res);
|
||||||
}
|
}
|
||||||
Rvalue::CheckedBinaryOp(bin_op, lhs, rhs) => {
|
Rvalue::CheckedBinaryOp(bin_op, lhs, rhs) => {
|
||||||
let lhs = trans_operand(fx, lhs);
|
let lhs = codegen_operand(fx, lhs);
|
||||||
let rhs = trans_operand(fx, rhs);
|
let rhs = codegen_operand(fx, rhs);
|
||||||
|
|
||||||
let res = if !fx.tcx.sess.overflow_checks() {
|
let res = if !fx.tcx.sess.overflow_checks() {
|
||||||
let val =
|
let val =
|
||||||
crate::num::trans_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
|
crate::num::codegen_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
|
||||||
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
|
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
|
||||||
CValue::by_val_pair(val, is_overflow, lval.layout())
|
CValue::by_val_pair(val, is_overflow, lval.layout())
|
||||||
} else {
|
} else {
|
||||||
crate::num::trans_checked_int_binop(fx, *bin_op, lhs, rhs)
|
crate::num::codegen_checked_int_binop(fx, *bin_op, lhs, rhs)
|
||||||
};
|
};
|
||||||
|
|
||||||
lval.write_cvalue(fx, res);
|
lval.write_cvalue(fx, res);
|
||||||
}
|
}
|
||||||
Rvalue::UnaryOp(un_op, operand) => {
|
Rvalue::UnaryOp(un_op, operand) => {
|
||||||
let operand = trans_operand(fx, operand);
|
let operand = codegen_operand(fx, operand);
|
||||||
let layout = operand.layout();
|
let layout = operand.layout();
|
||||||
let val = operand.load_scalar(fx);
|
let val = operand.load_scalar(fx);
|
||||||
let res = match un_op {
|
let res = match un_op {
|
||||||
|
@ -500,7 +500,7 @@ fn trans_stmt<'tcx>(
|
||||||
ty::Int(IntTy::I128) => {
|
ty::Int(IntTy::I128) => {
|
||||||
// FIXME remove this case once ineg.i128 works
|
// FIXME remove this case once ineg.i128 works
|
||||||
let zero = CValue::const_val(fx, layout, 0);
|
let zero = CValue::const_val(fx, layout, 0);
|
||||||
crate::num::trans_int_binop(fx, BinOp::Sub, zero, operand)
|
crate::num::codegen_int_binop(fx, BinOp::Sub, zero, operand)
|
||||||
}
|
}
|
||||||
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
|
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
|
||||||
ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
|
ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
|
||||||
|
@ -534,11 +534,11 @@ fn trans_stmt<'tcx>(
|
||||||
| Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, to_ty)
|
| Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, to_ty)
|
||||||
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => {
|
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => {
|
||||||
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
|
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
|
||||||
let operand = trans_operand(fx, operand);
|
let operand = codegen_operand(fx, operand);
|
||||||
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
|
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
|
||||||
}
|
}
|
||||||
Rvalue::Cast(CastKind::Misc, operand, to_ty) => {
|
Rvalue::Cast(CastKind::Misc, operand, to_ty) => {
|
||||||
let operand = trans_operand(fx, operand);
|
let operand = codegen_operand(fx, operand);
|
||||||
let from_ty = operand.layout().ty;
|
let from_ty = operand.layout().ty;
|
||||||
let to_ty = fx.monomorphize(to_ty);
|
let to_ty = fx.monomorphize(to_ty);
|
||||||
|
|
||||||
|
@ -639,7 +639,7 @@ fn trans_stmt<'tcx>(
|
||||||
operand,
|
operand,
|
||||||
_to_ty,
|
_to_ty,
|
||||||
) => {
|
) => {
|
||||||
let operand = trans_operand(fx, operand);
|
let operand = codegen_operand(fx, operand);
|
||||||
match *operand.layout().ty.kind() {
|
match *operand.layout().ty.kind() {
|
||||||
ty::Closure(def_id, substs) => {
|
ty::Closure(def_id, substs) => {
|
||||||
let instance = Instance::resolve_closure(
|
let instance = Instance::resolve_closure(
|
||||||
|
@ -657,18 +657,18 @@ fn trans_stmt<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), operand, _to_ty) => {
|
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), operand, _to_ty) => {
|
||||||
let operand = trans_operand(fx, operand);
|
let operand = codegen_operand(fx, operand);
|
||||||
operand.unsize_value(fx, lval);
|
operand.unsize_value(fx, lval);
|
||||||
}
|
}
|
||||||
Rvalue::Discriminant(place) => {
|
Rvalue::Discriminant(place) => {
|
||||||
let place = trans_place(fx, *place);
|
let place = codegen_place(fx, *place);
|
||||||
let value = place.to_cvalue(fx);
|
let value = place.to_cvalue(fx);
|
||||||
let discr =
|
let discr =
|
||||||
crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
|
crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
|
||||||
lval.write_cvalue(fx, discr);
|
lval.write_cvalue(fx, discr);
|
||||||
}
|
}
|
||||||
Rvalue::Repeat(operand, times) => {
|
Rvalue::Repeat(operand, times) => {
|
||||||
let operand = trans_operand(fx, operand);
|
let operand = codegen_operand(fx, operand);
|
||||||
let times = fx
|
let times = fx
|
||||||
.monomorphize(times)
|
.monomorphize(times)
|
||||||
.eval(fx.tcx, ParamEnv::reveal_all())
|
.eval(fx.tcx, ParamEnv::reveal_all())
|
||||||
|
@ -706,7 +706,7 @@ fn trans_stmt<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Rvalue::Len(place) => {
|
Rvalue::Len(place) => {
|
||||||
let place = trans_place(fx, *place);
|
let place = codegen_place(fx, *place);
|
||||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||||
let len = codegen_array_len(fx, place);
|
let len = codegen_array_len(fx, place);
|
||||||
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
|
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
|
||||||
|
@ -754,13 +754,13 @@ fn trans_stmt<'tcx>(
|
||||||
Rvalue::Aggregate(kind, operands) => match **kind {
|
Rvalue::Aggregate(kind, operands) => match **kind {
|
||||||
AggregateKind::Array(_ty) => {
|
AggregateKind::Array(_ty) => {
|
||||||
for (i, operand) in operands.iter().enumerate() {
|
for (i, operand) in operands.iter().enumerate() {
|
||||||
let operand = trans_operand(fx, operand);
|
let operand = codegen_operand(fx, operand);
|
||||||
let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
|
let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
|
||||||
let to = lval.place_index(fx, index);
|
let to = lval.place_index(fx, index);
|
||||||
to.write_cvalue(fx, operand);
|
to.write_cvalue(fx, operand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!("shouldn't exist at trans {:?}", to_place_and_rval.1),
|
_ => unreachable!("shouldn't exist at codegen {:?}", to_place_and_rval.1),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -813,20 +813,20 @@ fn trans_stmt<'tcx>(
|
||||||
assert!(!alignstack);
|
assert!(!alignstack);
|
||||||
|
|
||||||
assert_eq!(inputs.len(), 2);
|
assert_eq!(inputs.len(), 2);
|
||||||
let leaf = trans_operand(fx, &inputs[0].1).load_scalar(fx); // %eax
|
let leaf = codegen_operand(fx, &inputs[0].1).load_scalar(fx); // %eax
|
||||||
let subleaf = trans_operand(fx, &inputs[1].1).load_scalar(fx); // %ecx
|
let subleaf = codegen_operand(fx, &inputs[1].1).load_scalar(fx); // %ecx
|
||||||
|
|
||||||
let (eax, ebx, ecx, edx) =
|
let (eax, ebx, ecx, edx) =
|
||||||
crate::intrinsics::codegen_cpuid_call(fx, leaf, subleaf);
|
crate::intrinsics::codegen_cpuid_call(fx, leaf, subleaf);
|
||||||
|
|
||||||
assert_eq!(outputs.len(), 4);
|
assert_eq!(outputs.len(), 4);
|
||||||
trans_place(fx, outputs[0])
|
codegen_place(fx, outputs[0])
|
||||||
.write_cvalue(fx, CValue::by_val(eax, fx.layout_of(fx.tcx.types.u32)));
|
.write_cvalue(fx, CValue::by_val(eax, fx.layout_of(fx.tcx.types.u32)));
|
||||||
trans_place(fx, outputs[1])
|
codegen_place(fx, outputs[1])
|
||||||
.write_cvalue(fx, CValue::by_val(ebx, fx.layout_of(fx.tcx.types.u32)));
|
.write_cvalue(fx, CValue::by_val(ebx, fx.layout_of(fx.tcx.types.u32)));
|
||||||
trans_place(fx, outputs[2])
|
codegen_place(fx, outputs[2])
|
||||||
.write_cvalue(fx, CValue::by_val(ecx, fx.layout_of(fx.tcx.types.u32)));
|
.write_cvalue(fx, CValue::by_val(ecx, fx.layout_of(fx.tcx.types.u32)));
|
||||||
trans_place(fx, outputs[3])
|
codegen_place(fx, outputs[3])
|
||||||
.write_cvalue(fx, CValue::by_val(edx, fx.layout_of(fx.tcx.types.u32)));
|
.write_cvalue(fx, CValue::by_val(edx, fx.layout_of(fx.tcx.types.u32)));
|
||||||
}
|
}
|
||||||
"xgetbv" => {
|
"xgetbv" => {
|
||||||
|
@ -892,7 +892,7 @@ fn codegen_array_len<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn trans_place<'tcx>(
|
pub(crate) fn codegen_place<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||||
place: Place<'tcx>,
|
place: Place<'tcx>,
|
||||||
) -> CPlace<'tcx> {
|
) -> CPlace<'tcx> {
|
||||||
|
@ -964,16 +964,16 @@ pub(crate) fn trans_place<'tcx>(
|
||||||
cplace
|
cplace
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn trans_operand<'tcx>(
|
pub(crate) fn codegen_operand<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||||
operand: &Operand<'tcx>,
|
operand: &Operand<'tcx>,
|
||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
match operand {
|
match operand {
|
||||||
Operand::Move(place) | Operand::Copy(place) => {
|
Operand::Move(place) | Operand::Copy(place) => {
|
||||||
let cplace = trans_place(fx, *place);
|
let cplace = codegen_place(fx, *place);
|
||||||
cplace.to_cvalue(fx)
|
cplace.to_cvalue(fx)
|
||||||
}
|
}
|
||||||
Operand::Constant(const_) => crate::constant::trans_constant(fx, const_),
|
Operand::Constant(const_) => crate::constant::codegen_constant(fx, const_),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -406,7 +406,7 @@ impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
|
||||||
caller.line as u32,
|
caller.line as u32,
|
||||||
caller.col_display as u32 + 1,
|
caller.col_display as u32 + 1,
|
||||||
));
|
));
|
||||||
crate::constant::trans_const_value(self, const_loc, self.tcx.caller_location_ty())
|
crate::constant::codegen_const_value(self, const_loc, self.tcx.caller_location_ty())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn triple(&self) -> &target_lexicon::Triple {
|
pub(crate) fn triple(&self) -> &target_lexicon::Triple {
|
||||||
|
|
|
@ -106,7 +106,7 @@ fn codegen_static_ref<'tcx>(
|
||||||
CPlace::for_ptr(crate::pointer::Pointer::new(global_ptr), layout)
|
CPlace::for_ptr(crate::pointer::Pointer::new(global_ptr), layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn trans_constant<'tcx>(
|
pub(crate) fn codegen_constant<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||||
constant: &Constant<'tcx>,
|
constant: &Constant<'tcx>,
|
||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
|
@ -151,10 +151,10 @@ pub(crate) fn trans_constant<'tcx>(
|
||||||
| ConstKind::Error(_) => unreachable!("{:?}", const_),
|
| ConstKind::Error(_) => unreachable!("{:?}", const_),
|
||||||
};
|
};
|
||||||
|
|
||||||
trans_const_value(fx, const_val, const_.ty)
|
codegen_const_value(fx, const_val, const_.ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn trans_const_value<'tcx>(
|
pub(crate) fn codegen_const_value<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||||
const_val: ConstValue<'tcx>,
|
const_val: ConstValue<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
|
|
|
@ -64,11 +64,11 @@ fn codegen_mono_items<'tcx>(
|
||||||
|
|
||||||
for (mono_item, (linkage, visibility)) in mono_items {
|
for (mono_item, (linkage, visibility)) in mono_items {
|
||||||
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
||||||
trans_mono_item(cx, mono_item, linkage);
|
codegen_mono_item(cx, mono_item, linkage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trans_mono_item<'tcx, M: Module>(
|
fn codegen_mono_item<'tcx, M: Module>(
|
||||||
cx: &mut crate::CodegenCx<'tcx, M>,
|
cx: &mut crate::CodegenCx<'tcx, M>,
|
||||||
mono_item: MonoItem<'tcx>,
|
mono_item: MonoItem<'tcx>,
|
||||||
linkage: Linkage,
|
linkage: Linkage,
|
||||||
|
@ -80,7 +80,7 @@ fn trans_mono_item<'tcx, M: Module>(
|
||||||
crate::PrintOnPanic(|| format!("{:?} {}", inst, tcx.symbol_name(inst).name));
|
crate::PrintOnPanic(|| format!("{:?} {}", inst, tcx.symbol_name(inst).name));
|
||||||
debug_assert!(!inst.substs.needs_infer());
|
debug_assert!(!inst.substs.needs_infer());
|
||||||
tcx.sess
|
tcx.sess
|
||||||
.time("codegen fn", || crate::base::trans_fn(cx, inst, linkage));
|
.time("codegen fn", || crate::base::codegen_fn(cx, inst, linkage));
|
||||||
}
|
}
|
||||||
MonoItem::Static(def_id) => {
|
MonoItem::Static(def_id) => {
|
||||||
crate::constant::codegen_static(&mut cx.constants_cx, def_id);
|
crate::constant::codegen_static(&mut cx.constants_cx, def_id);
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
|
||||||
inputs.push((
|
inputs.push((
|
||||||
reg,
|
reg,
|
||||||
new_slot(reg.reg_class()),
|
new_slot(reg.reg_class()),
|
||||||
crate::base::trans_operand(fx, value).load_scalar(fx),
|
crate::base::codegen_operand(fx, value).load_scalar(fx),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
InlineAsmOperand::Out {
|
InlineAsmOperand::Out {
|
||||||
|
@ -64,7 +64,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
|
||||||
outputs.push((
|
outputs.push((
|
||||||
reg,
|
reg,
|
||||||
new_slot(reg.reg_class()),
|
new_slot(reg.reg_class()),
|
||||||
crate::base::trans_place(fx, place),
|
crate::base::codegen_place(fx, place),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,13 +79,13 @@ pub(crate) fn codegen_inline_asm<'tcx>(
|
||||||
inputs.push((
|
inputs.push((
|
||||||
reg,
|
reg,
|
||||||
new_slot(reg.reg_class()),
|
new_slot(reg.reg_class()),
|
||||||
crate::base::trans_operand(fx, in_value).load_scalar(fx),
|
crate::base::codegen_operand(fx, in_value).load_scalar(fx),
|
||||||
));
|
));
|
||||||
if let Some(out_place) = out_place {
|
if let Some(out_place) = out_place {
|
||||||
outputs.push((
|
outputs.push((
|
||||||
reg,
|
reg,
|
||||||
new_slot(reg.reg_class()),
|
new_slot(reg.reg_class()),
|
||||||
crate::base::trans_place(fx, out_place),
|
crate::base::codegen_place(fx, out_place),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,10 @@ macro intrinsic_arg {
|
||||||
$arg
|
$arg
|
||||||
},
|
},
|
||||||
(c $fx:expr, $arg:ident) => {
|
(c $fx:expr, $arg:ident) => {
|
||||||
trans_operand($fx, $arg)
|
codegen_operand($fx, $arg)
|
||||||
},
|
},
|
||||||
(v $fx:expr, $arg:ident) => {
|
(v $fx:expr, $arg:ident) => {
|
||||||
trans_operand($fx, $arg).load_scalar($fx)
|
codegen_operand($fx, $arg).load_scalar($fx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ macro call_intrinsic_match {
|
||||||
assert!($substs.is_noop());
|
assert!($substs.is_noop());
|
||||||
if let [$(ref $arg),*] = *$args {
|
if let [$(ref $arg),*] = *$args {
|
||||||
let ($($arg,)*) = (
|
let ($($arg,)*) = (
|
||||||
$(trans_operand($fx, $arg),)*
|
$(codegen_operand($fx, $arg),)*
|
||||||
);
|
);
|
||||||
let res = $fx.easy_call(stringify!($func), &[$($arg),*], $fx.tcx.types.$ty);
|
let res = $fx.easy_call(stringify!($func), &[$($arg),*], $fx.tcx.types.$ty);
|
||||||
$ret.write_cvalue($fx, res);
|
$ret.write_cvalue($fx, res);
|
||||||
|
@ -577,7 +577,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
"unchecked_shr" => BinOp::Shr,
|
"unchecked_shr" => BinOp::Shr,
|
||||||
_ => unreachable!("intrinsic {}", intrinsic),
|
_ => unreachable!("intrinsic {}", intrinsic),
|
||||||
};
|
};
|
||||||
let res = crate::num::trans_int_binop(fx, bin_op, x, y);
|
let res = crate::num::codegen_int_binop(fx, bin_op, x, y);
|
||||||
ret.write_cvalue(fx, res);
|
ret.write_cvalue(fx, res);
|
||||||
};
|
};
|
||||||
_ if intrinsic.ends_with("_with_overflow"), (c x, c y) {
|
_ if intrinsic.ends_with("_with_overflow"), (c x, c y) {
|
||||||
|
@ -589,7 +589,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
_ => unreachable!("intrinsic {}", intrinsic),
|
_ => unreachable!("intrinsic {}", intrinsic),
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = crate::num::trans_checked_int_binop(
|
let res = crate::num::codegen_checked_int_binop(
|
||||||
fx,
|
fx,
|
||||||
bin_op,
|
bin_op,
|
||||||
x,
|
x,
|
||||||
|
@ -605,7 +605,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
"wrapping_mul" => BinOp::Mul,
|
"wrapping_mul" => BinOp::Mul,
|
||||||
_ => unreachable!("intrinsic {}", intrinsic),
|
_ => unreachable!("intrinsic {}", intrinsic),
|
||||||
};
|
};
|
||||||
let res = crate::num::trans_int_binop(
|
let res = crate::num::codegen_int_binop(
|
||||||
fx,
|
fx,
|
||||||
bin_op,
|
bin_op,
|
||||||
x,
|
x,
|
||||||
|
@ -623,7 +623,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
|
|
||||||
let signed = type_sign(T);
|
let signed = type_sign(T);
|
||||||
|
|
||||||
let checked_res = crate::num::trans_checked_int_binop(
|
let checked_res = crate::num::codegen_checked_int_binop(
|
||||||
fx,
|
fx,
|
||||||
bin_op,
|
bin_op,
|
||||||
lhs,
|
lhs,
|
||||||
|
@ -867,7 +867,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
size_of | pref_align_of | min_align_of | needs_drop | type_id | type_name | variant_count, () {
|
size_of | pref_align_of | min_align_of | needs_drop | type_id | type_name | variant_count, () {
|
||||||
let const_val =
|
let const_val =
|
||||||
fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
|
fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
|
||||||
let val = crate::constant::trans_const_value(
|
let val = crate::constant::codegen_const_value(
|
||||||
fx,
|
fx,
|
||||||
const_val,
|
const_val,
|
||||||
ret.layout().ty,
|
ret.layout().ty,
|
||||||
|
@ -886,12 +886,12 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
};
|
};
|
||||||
|
|
||||||
ptr_guaranteed_eq, (c a, c b) {
|
ptr_guaranteed_eq, (c a, c b) {
|
||||||
let val = crate::num::trans_ptr_binop(fx, BinOp::Eq, a, b);
|
let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b);
|
||||||
ret.write_cvalue(fx, val);
|
ret.write_cvalue(fx, val);
|
||||||
};
|
};
|
||||||
|
|
||||||
ptr_guaranteed_ne, (c a, c b) {
|
ptr_guaranteed_ne, (c a, c b) {
|
||||||
let val = crate::num::trans_ptr_binop(fx, BinOp::Ne, a, b);
|
let val = crate::num::codegen_ptr_binop(fx, BinOp::Ne, a, b);
|
||||||
ret.write_cvalue(fx, val);
|
ret.write_cvalue(fx, val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1069,7 +1069,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
};
|
};
|
||||||
|
|
||||||
fadd_fast | fsub_fast | fmul_fast | fdiv_fast | frem_fast, (c x, c y) {
|
fadd_fast | fsub_fast | fmul_fast | fdiv_fast | frem_fast, (c x, c y) {
|
||||||
let res = crate::num::trans_float_binop(fx, match intrinsic {
|
let res = crate::num::codegen_float_binop(fx, match intrinsic {
|
||||||
"fadd_fast" => BinOp::Add,
|
"fadd_fast" => BinOp::Add,
|
||||||
"fsub_fast" => BinOp::Sub,
|
"fsub_fast" => BinOp::Sub,
|
||||||
"fmul_fast" => BinOp::Mul,
|
"fmul_fast" => BinOp::Mul,
|
||||||
|
|
|
@ -111,7 +111,7 @@ mod prelude {
|
||||||
pub(crate) use cranelift_module::{self, DataContext, DataId, FuncId, Linkage, Module};
|
pub(crate) use cranelift_module::{self, DataContext, DataId, FuncId, Linkage, Module};
|
||||||
|
|
||||||
pub(crate) use crate::abi::*;
|
pub(crate) use crate::abi::*;
|
||||||
pub(crate) use crate::base::{trans_operand, trans_place};
|
pub(crate) use crate::base::{codegen_operand, codegen_place};
|
||||||
pub(crate) use crate::cast::*;
|
pub(crate) use crate::cast::*;
|
||||||
pub(crate) use crate::common::*;
|
pub(crate) use crate::common::*;
|
||||||
pub(crate) use crate::debuginfo::{DebugContext, UnwindContext};
|
pub(crate) use crate::debuginfo::{DebugContext, UnwindContext};
|
||||||
|
|
18
src/num.rs
18
src/num.rs
|
@ -89,10 +89,10 @@ pub(crate) fn codegen_binop<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
match in_lhs.layout().ty.kind() {
|
match in_lhs.layout().ty.kind() {
|
||||||
ty::Bool => crate::num::trans_bool_binop(fx, bin_op, in_lhs, in_rhs),
|
ty::Bool => crate::num::codegen_bool_binop(fx, bin_op, in_lhs, in_rhs),
|
||||||
ty::Uint(_) | ty::Int(_) => crate::num::trans_int_binop(fx, bin_op, in_lhs, in_rhs),
|
ty::Uint(_) | ty::Int(_) => crate::num::codegen_int_binop(fx, bin_op, in_lhs, in_rhs),
|
||||||
ty::Float(_) => crate::num::trans_float_binop(fx, bin_op, in_lhs, in_rhs),
|
ty::Float(_) => crate::num::codegen_float_binop(fx, bin_op, in_lhs, in_rhs),
|
||||||
ty::RawPtr(..) | ty::FnPtr(..) => crate::num::trans_ptr_binop(fx, bin_op, in_lhs, in_rhs),
|
ty::RawPtr(..) | ty::FnPtr(..) => crate::num::codegen_ptr_binop(fx, bin_op, in_lhs, in_rhs),
|
||||||
_ => unreachable!(
|
_ => unreachable!(
|
||||||
"{:?}({:?}, {:?})",
|
"{:?}({:?}, {:?})",
|
||||||
bin_op,
|
bin_op,
|
||||||
|
@ -102,7 +102,7 @@ pub(crate) fn codegen_binop<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn trans_bool_binop<'tcx>(
|
pub(crate) fn codegen_bool_binop<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||||
bin_op: BinOp,
|
bin_op: BinOp,
|
||||||
in_lhs: CValue<'tcx>,
|
in_lhs: CValue<'tcx>,
|
||||||
|
@ -123,7 +123,7 @@ pub(crate) fn trans_bool_binop<'tcx>(
|
||||||
CValue::by_val(res, fx.layout_of(fx.tcx.types.bool))
|
CValue::by_val(res, fx.layout_of(fx.tcx.types.bool))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn trans_int_binop<'tcx>(
|
pub(crate) fn codegen_int_binop<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||||
bin_op: BinOp,
|
bin_op: BinOp,
|
||||||
in_lhs: CValue<'tcx>,
|
in_lhs: CValue<'tcx>,
|
||||||
|
@ -196,7 +196,7 @@ pub(crate) fn trans_int_binop<'tcx>(
|
||||||
CValue::by_val(val, in_lhs.layout())
|
CValue::by_val(val, in_lhs.layout())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn trans_checked_int_binop<'tcx>(
|
pub(crate) fn codegen_checked_int_binop<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||||
bin_op: BinOp,
|
bin_op: BinOp,
|
||||||
in_lhs: CValue<'tcx>,
|
in_lhs: CValue<'tcx>,
|
||||||
|
@ -357,7 +357,7 @@ pub(crate) fn trans_checked_int_binop<'tcx>(
|
||||||
out_place.to_cvalue(fx)
|
out_place.to_cvalue(fx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn trans_float_binop<'tcx>(
|
pub(crate) fn codegen_float_binop<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||||
bin_op: BinOp,
|
bin_op: BinOp,
|
||||||
in_lhs: CValue<'tcx>,
|
in_lhs: CValue<'tcx>,
|
||||||
|
@ -402,7 +402,7 @@ pub(crate) fn trans_float_binop<'tcx>(
|
||||||
CValue::by_val(res, in_lhs.layout())
|
CValue::by_val(res, in_lhs.layout())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn trans_ptr_binop<'tcx>(
|
pub(crate) fn codegen_ptr_binop<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||||
bin_op: BinOp,
|
bin_op: BinOp,
|
||||||
in_lhs: CValue<'tcx>,
|
in_lhs: CValue<'tcx>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue