From d195b119fb0eb6dd209519010827ba5cee0ab8db Mon Sep 17 00:00:00 2001 From: angie Date: Wed, 24 Apr 2024 15:18:08 -0400 Subject: [PATCH] write_other_files --- slinky-cli/src/main.rs | 18 ++++-------------- slinky/src/linker_writer.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/slinky-cli/src/main.rs b/slinky-cli/src/main.rs index 03b6dc9..73a8fb0 100644 --- a/slinky-cli/src/main.rs +++ b/slinky-cli/src/main.rs @@ -1,7 +1,7 @@ /* SPDX-FileCopyrightText: © 2024 decompals */ /* SPDX-License-Identifier: MIT */ -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use clap::Parser; @@ -47,17 +47,7 @@ fn main() { // writer_test.save_linker_script(Path::new("test.ld")).expect("idk"); //} - if let Some(d_path) = &document.settings.d_path { - if let Some(target_path) = &document.settings.target_path { - writer - .save_dependencies_file(d_path, target_path) - .expect("Error writing dependencies file"); - } - } - - if let Some(symbols_header_path) = &document.settings.symbols_header_path { - writer - .save_symbol_header(symbols_header_path) - .expect("Error writing symbol header file"); - } + writer + .write_other_files() + .expect("Error writing other files listed on the document"); } diff --git a/slinky/src/linker_writer.rs b/slinky/src/linker_writer.rs index b023fd8..46915cf 100644 --- a/slinky/src/linker_writer.rs +++ b/slinky/src/linker_writer.rs @@ -9,7 +9,7 @@ use crate::{utils, Settings}; use crate::{FileInfo, Segment}; pub struct LinkerWriter<'a> { - pub linker_symbols: HashSet, + linker_symbols: HashSet, // Used for dependency generation files_paths: Vec, @@ -159,6 +159,7 @@ impl<'a> LinkerWriter<'a> { self.writeln(""); } + /* pub fn add_single_segment(&mut self, segment: &Segment) { assert!(self.buffer.is_empty()); @@ -251,6 +252,7 @@ impl<'a> LinkerWriter<'a> { self.end_sections(); } + */ pub fn save_linker_script(&self, path: &Path) -> Result<(), SlinkyError> { let mut f = utils::create_file_and_parents(path)?; @@ -280,7 +282,7 @@ impl<'a> LinkerWriter<'a> { } pub fn save_dependencies_file( - &mut self, + &self, path: &Path, target_path: &Path, ) -> Result<(), SlinkyError> { @@ -415,6 +417,27 @@ impl<'a> LinkerWriter<'a> { ret } + + #[must_use] + pub fn get(&self) -> &HashSet { + &self.linker_symbols + } +} + +impl LinkerWriter<'_> { + pub fn write_other_files(&self) -> Result<(), SlinkyError> { + if let Some(d_path) = &self.settings.d_path { + if let Some(target_path) = &self.settings.target_path { + self.save_dependencies_file(d_path, target_path)?; + } + } + + if let Some(symbols_header_path) = &self.settings.symbols_header_path { + self.save_symbol_header(symbols_header_path)?; + } + + Ok(()) + } } // internal functions