]> git.lizzy.rs Git - rust.git/blob - src/abi/comments.rs
Enable the rust_2018_idioms and unused_lifetimes lints and fix all warnings
[rust.git] / src / abi / comments.rs
1 use std::borrow::Cow;
2
3 use rustc_middle::mir;
4
5 use crate::abi::pass_mode::*;
6 use crate::prelude::*;
7
8 pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, impl Backend>) {
9     fx.add_global_comment(format!(
10         "kind  loc.idx   param    pass mode                            ty"
11     ));
12 }
13
14 pub(super) fn add_arg_comment<'tcx>(
15     fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
16     kind: &str,
17     local: Option<mir::Local>,
18     local_field: Option<usize>,
19     params: EmptySinglePair<Value>,
20     pass_mode: PassMode,
21     ty: Ty<'tcx>,
22 ) {
23     let local = if let Some(local) = local {
24         Cow::Owned(format!("{:?}", local))
25     } else {
26         Cow::Borrowed("???")
27     };
28     let local_field = if let Some(local_field) = local_field {
29         Cow::Owned(format!(".{}", local_field))
30     } else {
31         Cow::Borrowed("")
32     };
33
34     let params = match params {
35         Empty => Cow::Borrowed("-"),
36         Single(param) => Cow::Owned(format!("= {:?}", param)),
37         Pair(param_a, param_b) => Cow::Owned(format!("= {:?}, {:?}", param_a, param_b)),
38     };
39
40     let pass_mode = format!("{:?}", pass_mode);
41     fx.add_global_comment(format!(
42         "{kind:5}{local:>3}{local_field:<5} {params:10} {pass_mode:36} {ty:?}",
43         kind = kind,
44         local = local,
45         local_field = local_field,
46         params = params,
47         pass_mode = pass_mode,
48         ty = ty,
49     ));
50 }
51
52 pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, impl Backend>) {
53     fx.add_global_comment(String::new());
54     fx.add_global_comment(format!(
55         "kind  local ty                              size align (abi,pref)"
56     ));
57 }
58
59 pub(super) fn add_local_place_comments<'tcx>(
60     fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
61     place: CPlace<'tcx>,
62     local: Local,
63 ) {
64     let TyAndLayout { ty, layout } = place.layout();
65     let rustc_target::abi::Layout {
66         size,
67         align,
68         abi: _,
69         variants: _,
70         fields: _,
71         largest_niche: _,
72     } = layout;
73
74     let (kind, extra) = match *place.inner() {
75         CPlaceInner::Var(var) => {
76             assert_eq!(local, var);
77             ("ssa", std::borrow::Cow::Borrowed(""))
78         }
79         CPlaceInner::NoPlace => ("zst", "".into()),
80         CPlaceInner::Addr(ptr, meta) => {
81             let meta = if let Some(meta) = meta {
82                 Cow::Owned(format!(",meta={}", meta))
83             } else {
84                 Cow::Borrowed("")
85             };
86             match ptr.base_and_offset() {
87                 (crate::pointer::PointerBase::Addr(addr), offset) => {
88                     ("reuse", format!("storage={}{}{}", addr, offset, meta).into())
89                 }
90                 (crate::pointer::PointerBase::Stack(stack_slot), offset) => {
91                     ("stack", format!("storage={}{}{}", stack_slot, offset, meta).into())
92                 }
93             }
94         }
95     };
96
97     fx.add_global_comment(format!(
98         "{:<5} {:5} {:30} {:4}b {}, {}{}{}",
99         kind,
100         format!("{:?}", local),
101         format!("{:?}", ty),
102         size.bytes(),
103         align.abi.bytes(),
104         align.pref.bytes(),
105         if extra.is_empty() { "" } else { "              " },
106         extra,
107     ));
108 }