lld_pg/lld/
mod.rs

1use std::fmt;
2
3pub struct Script {
4    pub others1: String,
5    pub memory: Memory,
6    pub others2: String,
7}
8
9// name [(attr)] : ORIGIN = origin, LENGTH = len
10#[derive(Debug, PartialEq)]
11pub struct Block {
12    pub name: String,
13    pub attr: Option<String>,
14    pub origin: u64,
15    pub length: u64,
16}
17
18pub struct Memory {
19    pub blocks: Vec<Block>,
20}
21
22impl fmt::Display for Script {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        writeln!(f,"{}",self.others1)?;
25        writeln!(f,"{}",self.memory)?;
26        writeln!(f,"{}",self.others2)
27    }
28}
29
30impl fmt::Display for Block {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        write!(
33            f,
34            "{} ({}) : ORIGIN = {}, LENGTH = {}",
35            self.name,
36            self.attr
37                .as_ref()
38                .map(|attr| " ".to_string() + attr)
39                .unwrap_or_else(|| "".to_string()),
40            self.origin,
41            self.length
42        )
43    }
44}
45
46impl fmt::Display for Memory {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        writeln!(f, "MEMORY {{")?;
49        for block in &self.blocks {
50            writeln!(f, "{}", block)?;
51        }
52        writeln!(f, "}}")
53    }
54}