pub struct Rendered {
pub tokens: Vec<Token>,
}Expand description
A line as tokens (whitespace included).
Fields§
§tokens: Vec<Token>The tokens, in order.
Implementations§
Source§impl Rendered
impl Rendered
Sourcepub fn text(&self) -> String
pub fn text(&self) -> String
The line’s text.
Examples found in repository?
examples/listing.rs (line 52)
33fn main() {
34 let args: Vec<String> = std::env::args().collect();
35 let path = args
36 .get(1)
37 .expect("usage: listing FILE [ADDRESS [LINES] | --all]");
38 let data = std::fs::read(path).unwrap();
39 let image = Image::parse(&data).unwrap();
40 let db = Database::new(&image, Seeds::ALL).unwrap();
41 let references = Instant::now();
42 db.references();
43 let references = references.elapsed();
44 let before = resident_kib();
45 let start = Instant::now();
46 let listing = Listing::build(&db, &Options::default());
47 let built = start.elapsed();
48 let after = resident_kib();
49 match args.get(2).map(String::as_str) {
50 Some("--all") => {
51 for n in 0..listing.len() {
52 println!("{}", listing.render(&db, n).text());
53 }
54 }
55 Some(address) => {
56 let address = u64::from_str_radix(address.trim_start_matches("0x"), 16).unwrap();
57 let count: u64 = args.get(3).map_or(40, |n| n.parse().unwrap());
58 let first = listing.line_of(address);
59 // From the item's first line (its header and labels).
60 let head = listing.line(first).unwrap().address;
61 let mut n = first;
62 while n > 0 && listing.line(n - 1).is_some_and(|l| l.address == head) {
63 n -= 1;
64 }
65 for n in n..(n + count).min(listing.len()) {
66 println!("{}", listing.render(&db, n).text());
67 }
68 }
69 None => {
70 let render = Instant::now();
71 let (mut symbolised, mut instructions) = (0u64, 0u64);
72 for n in 0..listing.len() {
73 let rendered = listing.render(&db, n);
74 if listing.line(n).unwrap().kind == LineKind::Instruction {
75 instructions += 1;
76 symbolised += rendered
77 .tokens
78 .iter()
79 .filter(|t| {
80 matches!(
81 t.role,
82 Role::CodeName
83 | Role::DataName
84 | Role::ImportName
85 | Role::LocalName
86 )
87 })
88 .count() as u64;
89 }
90 }
91 let stats = listing.stats();
92 println!(
93 "{path}: references {:.2} s; line space {:.3} s, RSS +{} MiB ({} MiB, peak {} MiB); \
94 {} lines, {} instructions, {} data items, {} dummy names, {} string names; \
95 rendering every line {:.2} s: {} operands symbolised in {} instructions",
96 references.as_secs_f64(),
97 built.as_secs_f64(),
98 after.saturating_sub(before) / 1024,
99 after / 1024,
100 status_kib("VmHWM:") / 1024,
101 stats.lines,
102 stats.instructions,
103 stats.data_items,
104 stats.dummy_names,
105 stats.string_names,
106 render.elapsed().as_secs_f64(),
107 symbolised,
108 instructions,
109 );
110 }
111 }
112}Trait Implementations§
impl Eq for Rendered
impl StructuralPartialEq for Rendered
Auto Trait Implementations§
impl Forget for Rendered
impl Freeze for Rendered
impl Move for Rendered
impl RefUnwindSafe for Rendered
impl Send for Rendered
impl Sync for Rendered
impl Unpin for Rendered
impl UnsafeUnpin for Rendered
impl UnwindSafe for Rendered
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more