2020-09-23 15:13:49 +02:00
|
|
|
//! Annotate the clif ir with comments describing how arguments are passed into the current function
|
|
|
|
//! and where all locals are stored.
|
|
|
|
|
2019-08-30 14:21:24 +02:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2020-03-31 13:20:19 +02:00
|
|
|
use rustc_middle::mir;
|
2021-02-01 10:11:46 +01:00
|
|
|
use rustc_target::abi::call::PassMode;
|
2019-08-30 14:21:24 +02:00
|
|
|
|
2020-06-27 11:58:44 +02:00
|
|
|
use cranelift_codegen::entity::EntityRef;
|
|
|
|
|
2019-08-31 22:58:09 +05:30
|
|
|
use crate::prelude::*;
|
2019-08-30 14:21:24 +02:00
|
|
|
|
2020-10-01 10:38:23 +02:00
|
|
|
pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
|
2020-11-03 11:00:04 +01:00
|
|
|
fx.add_global_comment(
|
|
|
|
"kind loc.idx param pass mode ty".to_string(),
|
|
|
|
);
|
2019-08-30 14:21:24 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 13:18:21 +01:00
|
|
|
pub(super) fn add_arg_comment<'tcx>(
|
2020-10-01 10:38:23 +02:00
|
|
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
2019-08-30 15:07:15 +02:00
|
|
|
kind: &str,
|
2020-01-11 16:49:42 +01:00
|
|
|
local: Option<mir::Local>,
|
2019-08-30 14:21:24 +02:00
|
|
|
local_field: Option<usize>,
|
2021-02-01 10:11:46 +01:00
|
|
|
params: &[Value],
|
|
|
|
arg_abi_mode: PassMode,
|
|
|
|
arg_layout: TyAndLayout<'tcx>,
|
2019-08-30 14:21:24 +02:00
|
|
|
) {
|
2020-01-11 16:49:42 +01:00
|
|
|
let local = if let Some(local) = local {
|
|
|
|
Cow::Owned(format!("{:?}", local))
|
|
|
|
} else {
|
|
|
|
Cow::Borrowed("???")
|
|
|
|
};
|
2019-08-30 14:21:24 +02:00
|
|
|
let local_field = if let Some(local_field) = local_field {
|
|
|
|
Cow::Owned(format!(".{}", local_field))
|
|
|
|
} else {
|
|
|
|
Cow::Borrowed("")
|
|
|
|
};
|
2020-01-11 16:49:42 +01:00
|
|
|
|
2019-08-30 14:21:24 +02:00
|
|
|
let params = match params {
|
2021-02-01 10:11:46 +01:00
|
|
|
[] => Cow::Borrowed("-"),
|
|
|
|
[param] => Cow::Owned(format!("= {:?}", param)),
|
|
|
|
[param_a, param_b] => Cow::Owned(format!("= {:?},{:?}", param_a, param_b)),
|
|
|
|
params => Cow::Owned(format!(
|
|
|
|
"= {}",
|
|
|
|
params
|
|
|
|
.iter()
|
|
|
|
.map(ToString::to_string)
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(",")
|
|
|
|
)),
|
2019-08-30 14:21:24 +02:00
|
|
|
};
|
2020-01-11 16:49:42 +01:00
|
|
|
|
2021-02-01 10:11:46 +01:00
|
|
|
let pass_mode = format!("{:?}", arg_abi_mode);
|
2019-08-30 14:21:24 +02:00
|
|
|
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,
|
2020-01-11 16:49:42 +01:00
|
|
|
local = local,
|
2019-08-30 14:21:24 +02:00
|
|
|
local_field = local_field,
|
|
|
|
params = params,
|
|
|
|
pass_mode = pass_mode,
|
2021-02-01 10:11:46 +01:00
|
|
|
ty = arg_layout.ty,
|
2019-08-30 14:21:24 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2020-10-01 10:38:23 +02:00
|
|
|
pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
|
2019-08-30 15:07:15 +02:00
|
|
|
fx.add_global_comment(String::new());
|
2020-11-03 11:00:04 +01:00
|
|
|
fx.add_global_comment(
|
|
|
|
"kind local ty size align (abi,pref)".to_string(),
|
|
|
|
);
|
2019-08-30 15:07:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-27 12:14:45 +01:00
|
|
|
pub(super) fn add_local_place_comments<'tcx>(
|
2020-10-01 10:38:23 +02:00
|
|
|
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
2019-08-30 14:21:24 +02:00
|
|
|
place: CPlace<'tcx>,
|
|
|
|
local: Local,
|
|
|
|
) {
|
2020-03-30 19:00:24 +02:00
|
|
|
let TyAndLayout { ty, layout } = place.layout();
|
2020-04-03 11:54:18 +02:00
|
|
|
let rustc_target::abi::Layout {
|
2019-08-30 14:21:24 +02:00
|
|
|
size,
|
|
|
|
align,
|
|
|
|
abi: _,
|
|
|
|
variants: _,
|
|
|
|
fields: _,
|
|
|
|
largest_niche: _,
|
2020-03-28 14:20:24 +01:00
|
|
|
} = layout;
|
2019-12-22 15:27:25 +01:00
|
|
|
|
|
|
|
let (kind, extra) = match *place.inner() {
|
2020-06-27 11:58:44 +02:00
|
|
|
CPlaceInner::Var(place_local, var) => {
|
|
|
|
assert_eq!(local, place_local);
|
|
|
|
("ssa", Cow::Owned(format!(",var={}", var.index())))
|
2019-08-30 14:21:24 +02:00
|
|
|
}
|
2020-07-02 19:23:21 -03:00
|
|
|
CPlaceInner::VarPair(place_local, var1, var2) => {
|
|
|
|
assert_eq!(local, place_local);
|
2020-08-28 12:10:48 +02:00
|
|
|
(
|
|
|
|
"ssa",
|
|
|
|
Cow::Owned(format!(",var=({}, {})", var1.index(), var2.index())),
|
|
|
|
)
|
2020-07-02 19:23:21 -03:00
|
|
|
}
|
2020-03-28 15:21:58 +01:00
|
|
|
CPlaceInner::VarLane(_local, _var, _lane) => unreachable!(),
|
2020-01-25 16:23:54 +01:00
|
|
|
CPlaceInner::Addr(ptr, meta) => {
|
|
|
|
let meta = if let Some(meta) = meta {
|
|
|
|
Cow::Owned(format!(",meta={}", meta))
|
|
|
|
} else {
|
|
|
|
Cow::Borrowed("")
|
|
|
|
};
|
|
|
|
match ptr.base_and_offset() {
|
2020-08-28 12:10:48 +02:00
|
|
|
(crate::pointer::PointerBase::Addr(addr), offset) => (
|
|
|
|
"reuse",
|
|
|
|
format!("storage={}{}{}", addr, offset, meta).into(),
|
|
|
|
),
|
|
|
|
(crate::pointer::PointerBase::Stack(stack_slot), offset) => (
|
|
|
|
"stack",
|
|
|
|
format!("storage={}{}{}", stack_slot, offset, meta).into(),
|
|
|
|
),
|
|
|
|
(crate::pointer::PointerBase::Dangling(align), offset) => (
|
|
|
|
"zst",
|
|
|
|
format!("align={},offset={}", align.bytes(), offset).into(),
|
|
|
|
),
|
2019-12-22 15:27:25 +01:00
|
|
|
}
|
2020-01-25 16:23:54 +01:00
|
|
|
}
|
2019-12-22 15:27:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
fx.add_global_comment(format!(
|
|
|
|
"{:<5} {:5} {:30} {:4}b {}, {}{}{}",
|
|
|
|
kind,
|
|
|
|
format!("{:?}", local),
|
|
|
|
format!("{:?}", ty),
|
|
|
|
size.bytes(),
|
|
|
|
align.abi.bytes(),
|
|
|
|
align.pref.bytes(),
|
2020-08-28 12:10:48 +02:00
|
|
|
if extra.is_empty() {
|
|
|
|
""
|
|
|
|
} else {
|
|
|
|
" "
|
|
|
|
},
|
2019-12-22 15:27:25 +01:00
|
|
|
extra,
|
|
|
|
));
|
2019-08-30 14:21:24 +02:00
|
|
|
}
|