2019-08-30 14:21:24 +02:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
|
|
use rustc::mir;
|
|
|
|
|
|
|
|
use crate::abi::pass_mode::*;
|
2019-08-31 22:58:09 +05:30
|
|
|
use crate::prelude::*;
|
2019-08-30 14:21:24 +02:00
|
|
|
|
2019-08-30 15:07:15 +02:00
|
|
|
pub fn add_args_header_comment(fx: &mut FunctionCx<impl Backend>) {
|
2019-08-30 14:21:24 +02:00
|
|
|
fx.add_global_comment(format!(
|
2019-08-30 15:07:15 +02:00
|
|
|
"kind loc.idx param pass mode ty"
|
2019-08-30 14:21:24 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_arg_comment<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
|
2019-08-30 15:07:15 +02:00
|
|
|
kind: &str,
|
2019-08-30 14:21:24 +02:00
|
|
|
local: mir::Local,
|
|
|
|
local_field: Option<usize>,
|
|
|
|
params: EmptySinglePair<Value>,
|
|
|
|
pass_mode: PassMode,
|
|
|
|
ty: Ty<'tcx>,
|
|
|
|
) {
|
|
|
|
let local_field = if let Some(local_field) = local_field {
|
|
|
|
Cow::Owned(format!(".{}", local_field))
|
|
|
|
} else {
|
|
|
|
Cow::Borrowed("")
|
|
|
|
};
|
|
|
|
let params = match params {
|
|
|
|
Empty => Cow::Borrowed("-"),
|
|
|
|
Single(param) => Cow::Owned(format!("= {:?}", param)),
|
|
|
|
Pair(param_a, param_b) => Cow::Owned(format!("= {:?}, {:?}", param_a, param_b)),
|
|
|
|
};
|
|
|
|
let pass_mode = format!("{:?}", pass_mode);
|
|
|
|
fx.add_global_comment(format!(
|
2019-08-30 15:07:15 +02:00
|
|
|
"{kind:5}{local:>3}{local_field:<5} {params:10} {pass_mode:36} {ty:?}",
|
|
|
|
kind = kind,
|
2019-08-30 14:21:24 +02:00
|
|
|
local = format!("{:?}", local),
|
|
|
|
local_field = local_field,
|
|
|
|
params = params,
|
|
|
|
pass_mode = pass_mode,
|
|
|
|
ty = ty,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2019-08-30 15:07:15 +02:00
|
|
|
pub fn add_locals_header_comment(fx: &mut FunctionCx<impl Backend>) {
|
|
|
|
fx.add_global_comment(String::new());
|
|
|
|
fx.add_global_comment(format!(
|
|
|
|
"kind local ty size align (abi,pref)"
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2019-08-30 14:21:24 +02:00
|
|
|
pub fn add_local_place_comments<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
|
|
|
|
place: CPlace<'tcx>,
|
|
|
|
local: Local,
|
|
|
|
) {
|
|
|
|
let TyLayout { ty, details } = place.layout();
|
|
|
|
let ty::layout::LayoutDetails {
|
|
|
|
size,
|
|
|
|
align,
|
|
|
|
abi: _,
|
|
|
|
variants: _,
|
|
|
|
fields: _,
|
|
|
|
largest_niche: _,
|
|
|
|
} = details;
|
|
|
|
match *place.inner() {
|
|
|
|
CPlaceInner::Var(var) => {
|
|
|
|
assert_eq!(local, var);
|
|
|
|
fx.add_global_comment(format!(
|
2019-08-30 15:07:15 +02:00
|
|
|
"ssa {:5} {:20} {:4}b {}, {}",
|
|
|
|
format!("{:?}", local),
|
|
|
|
format!("{:?}", ty),
|
2019-08-30 14:21:24 +02:00
|
|
|
size.bytes(),
|
|
|
|
align.abi.bytes(),
|
|
|
|
align.pref.bytes(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
CPlaceInner::NoPlace => fx.add_global_comment(format!(
|
2019-08-30 15:07:15 +02:00
|
|
|
"zst {:5} {:20} {:4}b {}, {}",
|
|
|
|
format!("{:?}", local),
|
|
|
|
format!("{:?}", ty),
|
2019-08-30 14:21:24 +02:00
|
|
|
size.bytes(),
|
|
|
|
align.abi.bytes(),
|
|
|
|
align.pref.bytes(),
|
|
|
|
)),
|
2019-12-20 16:02:47 +01:00
|
|
|
CPlaceInner::Addr(ptr, None) => fx.add_global_comment(format!(
|
|
|
|
"reuse {:5} {:20} {:4}b {}, {} storage={:?}",
|
2019-08-30 15:41:33 +02:00
|
|
|
format!("{:?}", local),
|
|
|
|
format!("{:?}", ty),
|
|
|
|
size.bytes(),
|
|
|
|
align.abi.bytes(),
|
|
|
|
align.pref.bytes(),
|
2019-12-20 16:02:47 +01:00
|
|
|
ptr,
|
2019-08-30 15:41:33 +02:00
|
|
|
)),
|
|
|
|
CPlaceInner::Addr(_, Some(_)) => unreachable!(),
|
2019-08-30 14:21:24 +02:00
|
|
|
}
|
|
|
|
}
|