MemorySpec

Struct MemorySpec 

Source
pub struct MemorySpec { /* private fields */ }

Implementations§

Source§

impl MemorySpec

Source

pub fn regions(&self) -> &HashMap<String, Regions>

Examples found in repository?
examples/print_to_stdout.rs (line 14)
4fn main() {
5    let content = std::fs::read_to_string("examples/memory.kdl").unwrap();
6    let memoryspec = match MemorySpec::from_str(&content) {
7        Ok(m) => m,
8        Err(e) => {
9            eprintln!("{}", e);
10            return;
11        }
12    };
13
14    let primary_slot = &memoryspec.regions()["appcore_flash"]["primary_slot"];
15    let primary_slot_origin = primary_slot.origin();
16    let primary_slot_length = primary_slot.length();
17    let appcore_ram = &memoryspec.regions()["appcore_ram"]["low_ram"];
18    let appcore_ram_origin = appcore_ram.origin();
19    let appcore_ram_length = appcore_ram.length();
20    let symbols = memoryspec.render_symbols();
21    let consts = memoryspec.render_consts();
22
23    let output = println!(
24        "\
25memory.x:
26MEMORY
27{{
28  FLASH : ORIGIN = 0x{primary_slot_origin:08x}, LENGTH = 0x{primary_slot_length:04x}
29  RAM : ORIGIN = 0x{appcore_ram_origin:08x}, LENGTH = 0x{appcore_ram_length:04x}
30}}
31{symbols}
32
33
34consts.rs:
35{consts}"
36    );
37}
Source

pub fn render_symbols(&self) -> String

Render out all symbols into a string that can be included in a linker script.

Examples found in repository?
examples/print_to_stdout.rs (line 20)
4fn main() {
5    let content = std::fs::read_to_string("examples/memory.kdl").unwrap();
6    let memoryspec = match MemorySpec::from_str(&content) {
7        Ok(m) => m,
8        Err(e) => {
9            eprintln!("{}", e);
10            return;
11        }
12    };
13
14    let primary_slot = &memoryspec.regions()["appcore_flash"]["primary_slot"];
15    let primary_slot_origin = primary_slot.origin();
16    let primary_slot_length = primary_slot.length();
17    let appcore_ram = &memoryspec.regions()["appcore_ram"]["low_ram"];
18    let appcore_ram_origin = appcore_ram.origin();
19    let appcore_ram_length = appcore_ram.length();
20    let symbols = memoryspec.render_symbols();
21    let consts = memoryspec.render_consts();
22
23    let output = println!(
24        "\
25memory.x:
26MEMORY
27{{
28  FLASH : ORIGIN = 0x{primary_slot_origin:08x}, LENGTH = 0x{primary_slot_length:04x}
29  RAM : ORIGIN = 0x{appcore_ram_origin:08x}, LENGTH = 0x{appcore_ram_length:04x}
30}}
31{symbols}
32
33
34consts.rs:
35{consts}"
36    );
37}
Source

pub fn render_consts(&self) -> String

Render out all consts into a string that can be included in a rust source file.

Examples found in repository?
examples/print_to_stdout.rs (line 21)
4fn main() {
5    let content = std::fs::read_to_string("examples/memory.kdl").unwrap();
6    let memoryspec = match MemorySpec::from_str(&content) {
7        Ok(m) => m,
8        Err(e) => {
9            eprintln!("{}", e);
10            return;
11        }
12    };
13
14    let primary_slot = &memoryspec.regions()["appcore_flash"]["primary_slot"];
15    let primary_slot_origin = primary_slot.origin();
16    let primary_slot_length = primary_slot.length();
17    let appcore_ram = &memoryspec.regions()["appcore_ram"]["low_ram"];
18    let appcore_ram_origin = appcore_ram.origin();
19    let appcore_ram_length = appcore_ram.length();
20    let symbols = memoryspec.render_symbols();
21    let consts = memoryspec.render_consts();
22
23    let output = println!(
24        "\
25memory.x:
26MEMORY
27{{
28  FLASH : ORIGIN = 0x{primary_slot_origin:08x}, LENGTH = 0x{primary_slot_length:04x}
29  RAM : ORIGIN = 0x{appcore_ram_origin:08x}, LENGTH = 0x{appcore_ram_length:04x}
30}}
31{symbols}
32
33
34consts.rs:
35{consts}"
36    );
37}

Trait Implementations§

Source§

impl Clone for MemorySpec

Source§

fn clone(&self) -> MemorySpec

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemorySpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MemorySpec

Source§

fn default() -> MemorySpec

Returns the “default value” for a type. Read more
Source§

impl FromStr for MemorySpec

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(content: &str) -> Result<Self, Error>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.