Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
add the addrspan output format
Browse files Browse the repository at this point in the history
  • Loading branch information
Artentus authored and hlorenzi committed Nov 2, 2021
1 parent 4453e9b commit 71bacc1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum OutputFormat
HexC,
LogiSim8,
LogiSim16,
AddressSpan,
}


Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
51 changes: 51 additions & 0 deletions src/util/bitvec_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 71bacc1

Please sign in to comment.