Skip to content

Commit

Permalink
handle no units in linker script parser
Browse files Browse the repository at this point in the history
  • Loading branch information
japaric committed May 21, 2021
1 parent 49a506e commit 2bb4609
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ fn find_ram_in_linker_script(linker_script: &str) -> Option<MemoryEntry> {
total_length += length * 1024;
} else if unit == Some('M') {
total_length += length * 1024 * 1024;
} else if unit == None {
total_length += length;
}
}
return Some(MemoryEntry {
Expand All @@ -329,6 +331,32 @@ mod tests {
RAM : ORIGIN = 0x20000000, LENGTH = 64K
}
INCLUDE device.x
";

assert_eq!(
find_ram_in_linker_script(LINKER_SCRIPT),
Some(MemoryEntry {
line: 3,
origin: 0x20000000,
length: 64 * 1024,
})
);

assert_eq!(
get_includes_from_linker_script(LINKER_SCRIPT),
vec!["device.x"]
);
}

#[test]
fn parse_no_units() {
const LINKER_SCRIPT: &str = "MEMORY
{
FLASH : ORIGIN = 0x00000000, LENGTH = 262144
RAM : ORIGIN = 0x20000000, LENGTH = 65536
}
INCLUDE device.x
";

Expand Down

0 comments on commit 2bb4609

Please sign in to comment.