Use AnonConst for asm! constants
This commit is contained in:
parent
cbd6ec7604
commit
32be124e30
37 changed files with 281 additions and 242 deletions
|
@ -822,41 +822,37 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
|
||||
}
|
||||
mir::InlineAsmOperand::Const { ref value } => {
|
||||
if let mir::Operand::Constant(constant) = value {
|
||||
let const_value = self
|
||||
.eval_mir_constant(constant)
|
||||
.unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved"));
|
||||
let ty = constant.ty();
|
||||
let size = bx.layout_of(ty).size;
|
||||
let scalar = match const_value {
|
||||
ConstValue::Scalar(s) => s,
|
||||
_ => span_bug!(
|
||||
span,
|
||||
"expected Scalar for promoted asm const, but got {:#?}",
|
||||
const_value
|
||||
),
|
||||
};
|
||||
let value = scalar.assert_bits(size);
|
||||
let string = match ty.kind() {
|
||||
ty::Uint(_) => value.to_string(),
|
||||
ty::Int(int_ty) => {
|
||||
match int_ty.normalize(bx.tcx().sess.target.pointer_width) {
|
||||
ty::IntTy::I8 => (value as i8).to_string(),
|
||||
ty::IntTy::I16 => (value as i16).to_string(),
|
||||
ty::IntTy::I32 => (value as i32).to_string(),
|
||||
ty::IntTy::I64 => (value as i64).to_string(),
|
||||
ty::IntTy::I128 => (value as i128).to_string(),
|
||||
ty::IntTy::Isize => unreachable!(),
|
||||
}
|
||||
let const_value = self
|
||||
.eval_mir_constant(value)
|
||||
.unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved"));
|
||||
let ty = value.ty();
|
||||
let size = bx.layout_of(ty).size;
|
||||
let scalar = match const_value {
|
||||
ConstValue::Scalar(s) => s,
|
||||
_ => span_bug!(
|
||||
span,
|
||||
"expected Scalar for promoted asm const, but got {:#?}",
|
||||
const_value
|
||||
),
|
||||
};
|
||||
let value = scalar.assert_bits(size);
|
||||
let string = match ty.kind() {
|
||||
ty::Uint(_) => value.to_string(),
|
||||
ty::Int(int_ty) => {
|
||||
match int_ty.normalize(bx.tcx().sess.target.pointer_width) {
|
||||
ty::IntTy::I8 => (value as i8).to_string(),
|
||||
ty::IntTy::I16 => (value as i16).to_string(),
|
||||
ty::IntTy::I32 => (value as i32).to_string(),
|
||||
ty::IntTy::I64 => (value as i64).to_string(),
|
||||
ty::IntTy::I128 => (value as i128).to_string(),
|
||||
ty::IntTy::Isize => unreachable!(),
|
||||
}
|
||||
ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(),
|
||||
ty::Float(ty::FloatTy::F64) => f64::from_bits(value as u64).to_string(),
|
||||
_ => span_bug!(span, "asm const has bad type {}", ty),
|
||||
};
|
||||
InlineAsmOperandRef::Const { string }
|
||||
} else {
|
||||
span_bug!(span, "asm const is not a constant");
|
||||
}
|
||||
}
|
||||
ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(),
|
||||
ty::Float(ty::FloatTy::F64) => f64::from_bits(value as u64).to_string(),
|
||||
_ => span_bug!(span, "asm const has bad type {}", ty),
|
||||
};
|
||||
InlineAsmOperandRef::Const { string }
|
||||
}
|
||||
mir::InlineAsmOperand::SymFn { ref value } => {
|
||||
let literal = self.monomorphize(value.literal);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue