From 71bacc12021feefa4d598d9cc57d2d07ad893861 Mon Sep 17 00:00:00 2001 From: Mathis Rech Date: Mon, 20 Sep 2021 16:15:39 +0200 Subject: [PATCH] add the `addrspan` output format --- src/driver.rs | 5 +++- src/util/bitvec_format.rs | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index 0aa3ef63..a0142e46 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -19,6 +19,7 @@ enum OutputFormat HexC, LogiSim8, LogiSim16, + AddressSpan, } @@ -101,6 +102,7 @@ fn drive_inner( Some("c") => OutputFormat::HexC, Some("logisim8") => OutputFormat::LogiSim8, Some("logisim16") => OutputFormat::LogiSim16, + Some("addrspan") => OutputFormat::AddressSpan, None => if out_stdout { OutputFormat::AnnotatedHex } @@ -227,6 +229,7 @@ fn drive_inner( OutputFormat::AnnotatedHex => binary.format_annotated_hex(fileserver).bytes().collect(), OutputFormat::AnnotatedBin => binary.format_annotated_bin(fileserver).bytes().collect(), + OutputFormat::AddressSpan => binary.format_addrspan (fileserver).bytes().collect(), }; if out_stdout @@ -287,7 +290,7 @@ fn drive_inner( fn make_opts() -> getopts::Options { let mut opts = getopts::Options::new(); - opts.optopt("f", "format", "The format of the output file. Possible formats: binary, annotated, annotatedbin, binstr, hexstr, bindump, hexdump, mif, intelhex, deccomma, hexcomma, decc, hexc, logisim8, logisim16", "FORMAT"); + opts.optopt("f", "format", "The format of the output file. Possible formats: binary, annotated, annotatedbin, binstr, hexstr, bindump, hexdump, mif, intelhex, deccomma, hexcomma, decc, hexc, logisim8, logisim16, addrspan", "FORMAT"); opts.opt("o", "output", "The name of the output file.", "FILE", getopts::HasArg::Maybe, getopts::Occur::Optional); opts.optopt("", "symbol-format", "The format of the symbol file. Possible formats: default, mesen-mlb", "SYMBOL-FORMAT"); opts.opt("s", "symbol", "The name of the output symbol file.", "FILE", getopts::HasArg::Maybe, getopts::Occur::Optional); diff --git a/src/util/bitvec_format.rs b/src/util/bitvec_format.rs index 0aa761d1..39fb68e5 100644 --- a/src/util/bitvec_format.rs +++ b/src/util/bitvec_format.rs @@ -476,4 +476,55 @@ impl util::BitVec result } + + + pub fn format_addrspan(&self, fileserver: &dyn util::FileServer) -> String + { + let mut result = String::new(); + + let mut sorted_spans = self.spans.clone(); + sorted_spans.sort_by(|a, b| a.offset.cmp(&b.offset)); + + result.push_str("; "); + result.push_str("physical address : bit offset | "); + result.push_str("logical address | "); + result.push_str("file : line start : column start : line end : column end\n"); + + for span in &sorted_spans + { + let chars = fileserver.get_chars(diagn::RcReport::new(), &span.span.file, None).ok().unwrap(); + let counter = util::CharCounter::new(&chars); + + if let Some(offset) = span.offset + { + result.push_str(&format!("{:x}:{:x} | ", offset / 8, offset % 8)); + } + else + { + result.push_str(&format!("-:- | ")); + } + + result.push_str(&format!("{:x} | ", span.addr)); + + if let Some((start, end)) = span.span.location + { + let (line_start, col_start) = counter.get_line_column_at_index(start); + let (line_end, col_end) = counter.get_line_column_at_index(end); + + result.push_str( + &format!("{}:{}:{}:{}:{}", + &span.span.file, + line_start, col_start, + line_end, col_end)); + } + else + { + result.push_str(&format!("{}:-:-:-:-", &span.span.file)); + }; + + result.push_str("\n"); + } + + result + } } \ No newline at end of file