Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore comments in linker script (fix) #84

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/argument_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
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()
}
Expand Down
31 changes: 28 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ 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),
};
Expand All @@ -335,8 +335,8 @@ fn perform_addition(line: &str) -> u64 {

// Handle unit
let multiplier = match unit {
Some("K") => 1024,
Some("M") => 1024 * 1024,
Some('K') => 1024,
Some('M') => 1024 * 1024,
None => 1,
_ => unreachable!(),
};
Expand Down Expand Up @@ -401,6 +401,31 @@ mod tests {
);
}

#[test]
fn ingore_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";
Expand Down
Loading