From 2bb46097d7ecbe20b69b2da827664abeba2525c4 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 21 May 2021 13:58:36 +0200 Subject: [PATCH] handle no units in linker script parser --- src/main.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main.rs b/src/main.rs index 8ef8b4e..88b36c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -305,6 +305,8 @@ fn find_ram_in_linker_script(linker_script: &str) -> Option { total_length += length * 1024; } else if unit == Some('M') { total_length += length * 1024 * 1024; + } else if unit == None { + total_length += length; } } return Some(MemoryEntry { @@ -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 ";