diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2016-04-28 15:57:49 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2016-05-16 09:13:42 +0200 |
| commit | bfe789c04412fd8bfb33d1d66f7f8c233a349345 (patch) | |
| tree | 0e7c669ea7b49b0c735268342db5c40cac1b2b42 | |
| parent | cd81b60a4aa45f0eb72c5170673f24dc1a1c3592 (diff) | |
fixes to `librustc_borrowck::bitslice::bits_to_string`, used for graphviz printing.
| -rw-r--r-- | src/librustc_borrowck/bitslice.rs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/librustc_borrowck/bitslice.rs b/src/librustc_borrowck/bitslice.rs index 0454b0f3e7c..ca672e80884 100644 --- a/src/librustc_borrowck/bitslice.rs +++ b/src/librustc_borrowck/bitslice.rs @@ -78,25 +78,29 @@ fn bit_str(bit: usize) -> String { format!("[{}:{}-{:02x}]", bit, byte, lobits) } -pub fn bits_to_string(words: &[usize], bytes: usize) -> String { +pub fn bits_to_string(words: &[usize], bits: usize) -> String { let mut result = String::new(); let mut sep = '['; // Note: this is a little endian printout of bytes. + // i tracks how many bits we have printed so far. let mut i = 0; for &word in words.iter() { let mut v = word; - for _ in 0..mem::size_of::<usize>() { - let byte = v & 0xFF; - if i >= bytes { - assert!(byte == 0); - } else { - result.push(sep); - result.push_str(&format!("{:02x}", byte)); - } + loop { // for each byte in `v`: + let remain = bits - i; + // If less than a byte remains, then mask just that many bits. + let mask = if remain <= 8 { (1 << remain) - 1 } else { 0xFF }; + assert!(mask <= 0xFF); + let byte = v & mask; + + result.push(sep); + result.push_str(&format!("{:02x}", byte)); + + if remain <= 8 { break; } v >>= 8; - i += 1; + i += 8; sep = '-'; } } |
