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

Add string encoding suffixes #127

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
  • Loading branch information
Artentus committed Nov 3, 2021
commit 3ef877c8d7fb89726badfad1e7fe44c71f03f478
8 changes: 4 additions & 4 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum OutputFormat
HexC,
LogiSim8,
LogiSim16,
Debugger,
AddressSpan,
}


Expand Down Expand Up @@ -102,7 +102,7 @@ fn drive_inner(
Some("c") => OutputFormat::HexC,
Some("logisim8") => OutputFormat::LogiSim8,
Some("logisim16") => OutputFormat::LogiSim16,
Some("debugger") => OutputFormat::Debugger,
Some("addrspan") => OutputFormat::AddressSpan,

None => if out_stdout
{ OutputFormat::AnnotatedHex }
Expand Down Expand Up @@ -229,7 +229,7 @@ fn drive_inner(

OutputFormat::AnnotatedHex => binary.format_annotated_hex(fileserver).bytes().collect(),
OutputFormat::AnnotatedBin => binary.format_annotated_bin(fileserver).bytes().collect(),
OutputFormat::Debugger => binary.format_debugger (fileserver).bytes().collect(),
OutputFormat::AddressSpan => binary.format_addrspan (fileserver).bytes().collect(),
};

if out_stdout
Expand Down Expand Up @@ -290,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, debugger", "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
98 changes: 40 additions & 58 deletions src/util/bitvec_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,72 +478,54 @@ impl util::BitVec

result
}

pub fn format_debugger(&self, fileserver: &dyn util::FileServer) -> String
{
let mut result = String::new();

let mut addr_width = 4;
let mut line_width = 4;

let mut sorted_spans = self.spans.clone();
sorted_spans.sort_by(|a, b|
{
a.offset.cmp(&b.offset)
});

for span in &sorted_spans
{
let chars = fileserver.get_chars(RcReport::new(), &span.span.file, None).ok().unwrap();
let counter = CharCounter::new(&chars);

addr_width = std::cmp::max(
addr_width,
format!("{:x}", span.addr).len());

if let Some((start, _)) = span.span.location
{
let (line, _) = counter.get_line_column_at_index(start);
line_width = std::cmp::max(
line_width,
format!("{}", line).len());
}
}

result.push_str(&format!(" {:>1$} |", "addr", addr_width));
result.push_str(&format!(" {:>1$} | file", "line", line_width));
result.push_str("\n");
result.push_str("\n");

let mut prev_filename = "";

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(RcReport::new(), &span.span.file, None).ok().unwrap();
let counter = CharCounter::new(&chars);
let chars = fileserver.get_chars(diagn::RcReport::new(), &span.span.file, None).ok().unwrap();
let counter = util::CharCounter::new(&chars);

let line = if let Some((start, _)) = span.span.location
{
let (l, _) = counter.get_line_column_at_index(start);
l
}
else
{
0
};
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!(" {:1$x} | ", span.addr, addr_width));
result.push_str(&format!("{:1$} | ", line, line_width));
result.push_str(&format!("{:x} | ", span.addr));

if &*span.span.file != prev_filename
if let Some((start, end)) = span.span.location
{
prev_filename = &*span.span.file;
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(prev_filename);
result.push_str("\n");
}
result
}
}
result
}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.