blob: c264077ffd1be29ea565d3f8a3b5904da2953df7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
use crate::*;
pub fn format_debug(segments: &[Segment]) -> Result<Vec<u8>, FormatError> {
let mut output = String::new();
for segment in segments {
// Find maximum width of all words in the segment.
let width = segment.words.iter().map(|w| w.to_string().chars().count()).max().unwrap_or(0);
let address = &segment.address;
output.push_str(&format!("SEGMENT: 0x{address:>04x}\n"));
for word in &segment.words {
let string = word.to_string();
let w = width as usize;
output.push_str(&format!(" {string:>w$}\n"));
}
}
return Ok(output.into_bytes());
}
|