Skip to content

Commit 0b4ede3

Browse files
committed
Add pretty param and local info comments to clif
1 parent 9882576 commit 0b4ede3

File tree

2 files changed

+77
-28
lines changed

2 files changed

+77
-28
lines changed

example/example.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ fn bcd(b: bool, a: u8) -> u8 {
1818
}
1919
}
2020

21-
// FIXME make calls work
2221
fn call() {
2322
abc(42);
2423
}
@@ -33,14 +32,12 @@ enum BoolOption {
3332
None,
3433
}
3534

36-
/*
3735
fn option_unwrap_or(o: BoolOption, d: bool) -> bool {
3836
match o {
3937
BoolOption::Some(b) => b,
4038
BoolOption::None => d,
4139
}
4240
}
43-
*/
4441

4542
fn ret_42() -> u8 {
4643
42
@@ -62,18 +59,18 @@ fn cmp_raw_ptr(a: *const u8, b: *const u8) -> bool {
6259
a == b
6360
}
6461

65-
/*fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize, u8, u32) {
62+
fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize, u8, u32) {
6663
(
6764
a as u8, a as u16, a as u32, a as usize, a as i8, a as i16, a as i32, a as isize, b as u8,
6865
b as u32,
6966
)
70-
}*/
67+
}
7168

7269
fn char_cast(c: char) -> u8 {
7370
c as u8
7471
}
7572

76-
struct DebugTuple(());
73+
pub struct DebugTuple(());
7774

7875
fn debug_tuple() -> DebugTuple {
7976
DebugTuple(())
@@ -87,47 +84,51 @@ fn use_size_of() -> usize {
8784
size_of::<u64>()
8885
}
8986

90-
/*unsafe fn use_copy_intrinsic(src: *const u8, dst: *mut u8) {
87+
unsafe fn use_copy_intrinsic(src: *const u8, dst: *mut u8) {
9188
intrinsics::copy::<u8>(src, dst, 1);
92-
}*/
89+
}
9390

94-
/*unsafe fn use_copy_intrinsic_ref(src: *const u8, dst: *mut u8) {
95-
let copy2 = &copy::<u8>;
91+
unsafe fn use_copy_intrinsic_ref(src: *const u8, dst: *mut u8) {
92+
let copy2 = &intrinsics::copy::<u8>;
9693
copy2(src, dst, 1);
97-
}*/
94+
}
9895

9996
const Abc: u8 = 6 * 7;
10097

10198
fn use_const() -> u8 {
10299
Abc
103100
}
104101

105-
fn call_closure_3arg() {
102+
pub fn call_closure_3arg() {
106103
(|_, _, _| {})(0u8, 42u16, 0u8)
107104
}
108105

109-
fn call_closure_2arg() {
106+
pub fn call_closure_2arg() {
110107
(|_, _| {})(0u8, 42u16)
111108
}
112109

113110
struct IsNotEmpty;
114111

115112
impl<'a, 'b> FnOnce<(&'a &'b [u16],)> for IsNotEmpty {
116-
type Output = bool;
113+
type Output = (u8, u8);
117114

118115
#[inline]
119-
extern "rust-call" fn call_once(mut self, arg: (&'a &'b [u16],)) -> bool {
116+
extern "rust-call" fn call_once(mut self, arg: (&'a &'b [u16],)) -> (u8, u8) {
120117
self.call_mut(arg)
121118
}
122119
}
123120

124121
impl<'a, 'b> FnMut<(&'a &'b [u16],)> for IsNotEmpty {
125122
#[inline]
126-
extern "rust-call" fn call_mut(&mut self, arg: (&'a &'b [u16],)) -> bool {
127-
true
123+
extern "rust-call" fn call_mut(&mut self, arg: (&'a &'b [u16],)) -> (u8, u8) {
124+
(0, 42)
128125
}
129126
}
130127

128+
pub fn call_is_not_empty() {
129+
IsNotEmpty.call_once((&(&[0u16] as &[_]),));
130+
}
131+
131132
fn eq_char(a: char, b: char) -> bool {
132133
a == b
133134
}
@@ -140,7 +141,6 @@ unsafe fn call_uninit() -> u8 {
140141
intrinsics::uninit()
141142
}
142143

143-
// TODO: enable when fat pointers are supported
144144
unsafe fn deref_str_ptr(s: *const str) -> &'static str {
145145
&*s
146146
}
@@ -157,9 +157,9 @@ fn array_as_slice(arr: &[u8; 3]) -> &[u8] {
157157
arr
158158
}
159159

160-
/*unsafe fn use_ctlz_nonzero(a: u16) -> u16 {
160+
unsafe fn use_ctlz_nonzero(a: u16) -> u16 {
161161
intrinsics::ctlz_nonzero(a)
162-
}*/
162+
}
163163

164164
fn ptr_as_usize(ptr: *const u8) -> usize {
165165
ptr as usize
@@ -169,9 +169,9 @@ fn float_cast(a: f32, b: f64) -> (f64, f32) {
169169
(a as f64, b as f32)
170170
}
171171

172-
/*fn int_to_float(a: u8, b: i32) -> (f64, f32) {
172+
fn int_to_float(a: u8, b: i32) -> (f64, f32) {
173173
(a as f64, b as f32)
174-
}*/
174+
}
175175

176176
fn make_array() -> [u8; 3] {
177177
[42, 0, 5]

src/abi.rs

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::iter;
23

34
use rustc::hir;
@@ -270,6 +271,41 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
270271
}
271272
}
272273

274+
fn add_local_comment<'a, 'tcx: 'a>(
275+
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
276+
msg: &str,
277+
local: mir::Local,
278+
local_field: Option<usize>,
279+
param: Option<Value>,
280+
pass_mode: Option<PassMode>,
281+
ssa: crate::analyze::Flags,
282+
ty: Ty<'tcx>,
283+
) {
284+
let local_field = if let Some(local_field) = local_field {
285+
Cow::Owned(format!(".{}", local_field))
286+
} else {
287+
Cow::Borrowed("")
288+
};
289+
let param = if let Some(param) = param {
290+
Cow::Owned(format!("= {:?}", param))
291+
} else {
292+
Cow::Borrowed("-")
293+
};
294+
let pass_mode = if let Some(pass_mode) = pass_mode {
295+
Cow::Owned(format!("{:?}", pass_mode))
296+
} else {
297+
Cow::Borrowed("-")
298+
};
299+
fx.add_global_comment(format!(
300+
"{msg:5} {local:>3}{local_field:<5} {param:10} {pass_mode:20} {ssa:10} {ty:?}",
301+
msg=msg, local=format!("{:?}", local), local_field=local_field, param=param, pass_mode=pass_mode, ssa=format!("{:?}", ssa), ty=ty,
302+
));
303+
}
304+
305+
fn add_local_header_comment(fx: &mut FunctionCx<impl Backend>) {
306+
fx.add_global_comment(format!("msg loc.idx param pass mode ssa flags ty"));
307+
}
308+
273309
pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
274310
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
275311
start_ebb: Ebb,
@@ -331,12 +367,6 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
331367

332368
fx.add_global_comment(format!("ssa {:?}", ssa_analyzed));
333369

334-
for local in fx.mir.args_iter() {
335-
let arg_ty = fx.monomorphize(&fx.mir.local_decls[local].ty);
336-
let pass_mode = get_pass_mode(fx.tcx, fx.self_sig().abi, arg_ty, false);
337-
fx.add_global_comment(format!("pass {:?}: {:?} {:?}", local, arg_ty, pass_mode));
338-
}
339-
340370
match output_pass_mode {
341371
PassMode::NoPass => {
342372
let null = fx.bcx.ins().iconst(fx.pointer_type, 0);
@@ -359,9 +389,26 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
359389
}
360390
}
361391

392+
add_local_header_comment(fx);
393+
add_local_comment(fx, "ret", RETURN_PLACE, None, ret_param, Some(output_pass_mode), ssa_analyzed[&RETURN_PLACE], ret_layout.ty);
394+
362395
for (local, arg_kind, ty) in func_params {
363396
let layout = fx.layout_of(ty);
364397

398+
match arg_kind {
399+
ArgKind::Normal(ebb_param) => {
400+
let pass_mode = get_pass_mode(fx.tcx, fx.self_sig().abi, ty, false);
401+
add_local_comment(fx, "arg", local, None, Some(ebb_param), Some(pass_mode), ssa_analyzed[&local], ty);
402+
}
403+
ArgKind::Spread(ref ebb_params) => {
404+
for (i, &ebb_param) in ebb_params.iter().enumerate() {
405+
let sub_layout = layout.field(fx, i);
406+
let pass_mode = get_pass_mode(fx.tcx, fx.self_sig().abi, sub_layout.ty, false);
407+
add_local_comment(fx, "arg", local, Some(i), Some(ebb_param), Some(pass_mode), ssa_analyzed[&local], sub_layout.ty);
408+
}
409+
}
410+
}
411+
365412
if let ArgKind::Normal(ebb_param) = arg_kind {
366413
if !ssa_analyzed
367414
.get(&local)
@@ -422,6 +469,8 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
422469
let ty = fx.mir.local_decls[local].ty;
423470
let layout = fx.layout_of(ty);
424471

472+
add_local_comment(fx, "local", local, None, None, None, ssa_analyzed[&local], ty);
473+
425474
let place = if ssa_analyzed
426475
.get(&local)
427476
.unwrap()

0 commit comments

Comments
 (0)