From 5f48de69f46d4da27b22c47178b2e6216f7a7801 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 13 Jan 2025 16:12:08 +0100 Subject: Add support for cfg files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to make tools like `xa65` work seamlessly with existing configurations, allow this format too instead of making developers switch to a new file with TOML syntax. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/mapping.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/xixanta/src/mapping.rs') diff --git a/lib/xixanta/src/mapping.rs b/lib/xixanta/src/mapping.rs index f86b513..49683ab 100644 --- a/lib/xixanta/src/mapping.rs +++ b/lib/xixanta/src/mapping.rs @@ -1,3 +1,4 @@ +use crate::cfg::parse_cfg_file; use crate::object::Bundle; use toml::{Table, Value}; @@ -28,8 +29,9 @@ pub struct Segment { /// Name of the segment. pub name: String, + /// Offset from the base address from where to push the next address for + /// this segment. pub offset: usize, - pub len: usize, /// Bundles that have been generated when assembling the nodes that have /// been parsed by a previous step. @@ -41,7 +43,6 @@ impl From<&str> for Segment { Segment { name: name.to_string(), offset: 0, - len: 0, bundles: vec![], } } @@ -102,7 +103,15 @@ pub struct Mapping { pub fn get_mapping_configuration(name: &str) -> Result, String> { let configuration = if std::fs::exists(name).unwrap_or(false) { match std::fs::read_to_string(name) { - Ok(contents) => load_configuration_for(contents.as_str())?, + Ok(contents) => { + // If this is a file, then it might not be a TOML one, but a + // .cfg as used by cc65. + if name.ends_with(".cfg") { + parse_cfg_file(contents.as_str())? + } else { + load_configuration_for(contents.as_str())? + } + } Err(_) => return Err(format!("could not read '{}'", name)), } } else { -- cgit v1.2.3