Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f99b527

Browse files
authored
Merge pull request rust-lang#693 from bjorn3/abi_refactor
Abi handling refactor
2 parents b3311ed + 15b9834 commit f99b527

File tree

7 files changed

+479
-386
lines changed

7 files changed

+479
-386
lines changed

example/example.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,7 @@ fn get_sized_field_ref_from_unsized_type(u: &Unsized) -> &u8 {
202202
fn get_unsized_field_ref_from_unsized_type(u: &Unsized) -> &str {
203203
&u.1
204204
}
205+
206+
pub fn reuse_byref_argument_storage(a: (u8, u16, u32)) -> u8 {
207+
a.0
208+
}

src/abi/comments.rs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
use std::borrow::Cow;
2+
3+
use rustc::mir;
4+
5+
use crate::prelude::*;
6+
use crate::abi::pass_mode::*;
7+
8+
pub 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 fn add_arg_comment<'tcx>(
15+
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
16+
kind: &str,
17+
local: mir::Local,
18+
local_field: Option<usize>,
19+
params: EmptySinglePair<Value>,
20+
pass_mode: PassMode,
21+
ty: Ty<'tcx>,
22+
) {
23+
let local_field = if let Some(local_field) = local_field {
24+
Cow::Owned(format!(".{}", local_field))
25+
} else {
26+
Cow::Borrowed("")
27+
};
28+
let params = match params {
29+
Empty => Cow::Borrowed("-"),
30+
Single(param) => Cow::Owned(format!("= {:?}", param)),
31+
Pair(param_a, param_b) => Cow::Owned(format!("= {:?}, {:?}", param_a, param_b)),
32+
};
33+
let pass_mode = format!("{:?}", pass_mode);
34+
fx.add_global_comment(format!(
35+
"{kind:5}{local:>3}{local_field:<5} {params:10} {pass_mode:36} {ty:?}",
36+
kind = kind,
37+
local = format!("{:?}", local),
38+
local_field = local_field,
39+
params = params,
40+
pass_mode = pass_mode,
41+
ty = ty,
42+
));
43+
}
44+
45+
pub fn add_locals_header_comment(fx: &mut FunctionCx<impl Backend>) {
46+
fx.add_global_comment(String::new());
47+
fx.add_global_comment(format!(
48+
"kind local ty size align (abi,pref)"
49+
));
50+
}
51+
52+
pub fn add_local_place_comments<'tcx>(
53+
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
54+
place: CPlace<'tcx>,
55+
local: Local,
56+
) {
57+
let TyLayout { ty, details } = place.layout();
58+
let ty::layout::LayoutDetails {
59+
size,
60+
align,
61+
abi: _,
62+
variants: _,
63+
fields: _,
64+
largest_niche: _,
65+
} = details;
66+
match *place.inner() {
67+
CPlaceInner::Var(var) => {
68+
assert_eq!(local, var);
69+
fx.add_global_comment(format!(
70+
"ssa {:5} {:20} {:4}b {}, {}",
71+
format!("{:?}", local),
72+
format!("{:?}", ty),
73+
size.bytes(),
74+
align.abi.bytes(),
75+
align.pref.bytes(),
76+
));
77+
}
78+
CPlaceInner::Stack(stack_slot) => fx.add_entity_comment(
79+
stack_slot,
80+
format!(
81+
"{:?}: {:?} size={} align={},{}",
82+
local,
83+
ty,
84+
size.bytes(),
85+
align.abi.bytes(),
86+
align.pref.bytes(),
87+
),
88+
),
89+
CPlaceInner::NoPlace => fx.add_global_comment(format!(
90+
"zst {:5} {:20} {:4}b {}, {}",
91+
format!("{:?}", local),
92+
format!("{:?}", ty),
93+
size.bytes(),
94+
align.abi.bytes(),
95+
align.pref.bytes(),
96+
)),
97+
CPlaceInner::Addr(addr, None) => fx.add_global_comment(format!(
98+
"reuse {:5} {:20} {:4}b {}, {} storage={}",
99+
format!("{:?}", local),
100+
format!("{:?}", ty),
101+
size.bytes(),
102+
align.abi.bytes(),
103+
align.pref.bytes(),
104+
addr,
105+
)),
106+
CPlaceInner::Addr(_, Some(_)) => unreachable!(),
107+
}
108+
}

0 commit comments

Comments
 (0)