From d4098b3fa4639ac91e9dcfd1318fe51ec75de4f5 Mon Sep 17 00:00:00 2001 From: Brigitte Markmann Date: Wed, 1 Nov 2023 11:18:12 +0100 Subject: [PATCH 1/4] Adds test for comments in linker script. --- src/main.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main.rs b/src/main.rs index 6208163..de15bf1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -401,6 +401,31 @@ mod tests { ); } + #[test] + fn parse_comment() { + const LINKER_SCRIPT: &str = "MEMORY + { + FLASH : ORIGIN = 0x00000000, LENGTH = 256K + RAM : ORIGIN = 0x20000000, LENGTH = 64K /* This is a comment */ + } + + 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 test_perform_addition_hex_and_number() { const ADDITION: &str = "0x20000000 + 1000"; From 5be81b37060122244c3236c1ff2bef94093417c2 Mon Sep 17 00:00:00 2001 From: Brigitte Markmann Date: Wed, 1 Nov 2023 12:41:26 +0100 Subject: [PATCH 2/4] Ignore comments in linker script. --- src/main.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index de15bf1..082e004 100644 --- a/src/main.rs +++ b/src/main.rs @@ -321,22 +321,20 @@ fn perform_addition(line: &str) -> u64 { let (number, unit) = match segment.find(['K', 'M']) { Some(unit_pos) => { let (number, unit) = segment.split_at(unit_pos); - (number, Some(unit)) + (number, unit.chars().next()) } None => (segment, None), }; - // Parse number let (number, radix) = match number.strip_prefix("0x") { Some(s) => (s, 16), None => (number, 10), }; let length = tryc!(u64::from_str_radix(number, radix)); - // Handle unit let multiplier = match unit { - Some("K") => 1024, - Some("M") => 1024 * 1024, + Some('K') => 1024, + Some('M') => 1024 * 1024, None => 1, _ => unreachable!(), }; @@ -402,7 +400,7 @@ mod tests { } #[test] - fn parse_comment() { + fn ingore_comment() { const LINKER_SCRIPT: &str = "MEMORY { FLASH : ORIGIN = 0x00000000, LENGTH = 256K From 117e1ac3654b89e23b48f18e97e905afd0bbeda0 Mon Sep 17 00:00:00 2001 From: Brigitte Markmann Date: Wed, 1 Nov 2023 12:49:04 +0100 Subject: [PATCH 3/4] Comply to new clippy complaint; adds back in empty lines. --- src/argument_parser.rs | 3 ++- src/main.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/argument_parser.rs b/src/argument_parser.rs index 68c206b..14f13c2 100644 --- a/src/argument_parser.rs +++ b/src/argument_parser.rs @@ -10,7 +10,8 @@ pub fn get_output_path(args: &[String]) -> crate::Result<&String> { /// Get `search_paths`, specified by `-L` pub fn get_search_paths(args: &[String]) -> Vec { args.windows(2) - .filter_map(|x| (x[0] == "-L").then(|| PathBuf::from(&x[1]))) + .filter(|&x| (x[0] == "-L")) + .map(|x| PathBuf::from(&x[1])) .inspect(|path| log::trace!("new search path: {}", path.display())) .collect() } diff --git a/src/main.rs b/src/main.rs index 082e004..3125bba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -325,12 +325,14 @@ fn perform_addition(line: &str) -> u64 { } None => (segment, None), }; + // Parse number let (number, radix) = match number.strip_prefix("0x") { Some(s) => (s, 16), None => (number, 10), }; let length = tryc!(u64::from_str_radix(number, radix)); + // Handle unit let multiplier = match unit { Some('K') => 1024, From 64c1db41c0074ee3091f3dc2114f8130cb0f939d Mon Sep 17 00:00:00 2001 From: Brigitte Markmann Date: Wed, 1 Nov 2023 13:05:45 +0100 Subject: [PATCH 4/4] Adds pr to changelog. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 382cd04..f930ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +- [#84]: Fix for comments in linker script + +[#84]: https://github.com/knurling-rs/flip-link/pull/84 + ## [v0.1.7] - 2023-07-20 - [#79]: Summer cleanup