Skip to content

Commit

Permalink
Handle source node ID + line number for sections (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 authored Sep 10, 2024
1 parent 459259b commit 5e9e68c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions rgbobj.1
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ The section's address, or
if it isn't fixed.
.It Cm size
The section's size.
.It Cm src
Where the section was defined.
.It Cm type
The section's type (ROM0, ROMX, etc.) and modifier (normal, union, fragment).
.El
Expand Down
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub mod features {

features!(HeaderFeatures: +size, counts);
features!(SymbolFeatures: +name, type, src, section, value, id);
features!(SectionFeatures: +name, size, type, org, bank, align, data);
features!(SectionFeatures: +name, size, type, org, bank, align, src, data);
features!(PatchFeatures: +count, src, offset, pcsection, pcoffset, type, rpn, data);
features!(AssertionFeatures: +src, +offset, section, pcoffset, type, rpn, -data, +message);
}
Expand Down
28 changes: 26 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ fn work(args: &Args) -> Result<(), MainError> {
};
}

macro_rules! print_source_nodes {
macro_rules! print_source_nodes_helper {
($source:expr) => {{
let (id, line_no) = ($source).source();
let (id, line_no) = $source;
// TODO: wrap the node stack nicely
object
.walk_nodes::<Infallible, _>(id, &mut |node: &Node| {
Expand Down Expand Up @@ -158,6 +158,21 @@ fn work(args: &Args) -> Result<(), MainError> {
}};
}

macro_rules! print_source_nodes {
($source:expr) => {{
print_source_nodes_helper!(($source).source())
}};
}

macro_rules! opt_print_source_nodes {
($source:expr) => {{
match ($source).source() {
Some(tup) => print_source_nodes_helper!(tup),
_ => Ok(()),
}
}};
}

macro_rules! print_rpn_expr {
($indent:expr, $expr:expr) => {
println!("{}{} expression:", $indent, args.rpn);
Expand Down Expand Up @@ -397,6 +412,15 @@ fn work(args: &Args) -> Result<(), MainError> {

let indent = if first_line_empty { "" } else { " " };

if args.section.get(SectionFeatures::SRC) {
print!("{indent}");
if let Err(err) = opt_print_source_nodes!(section) {
error!("Invalid section file stack: {}", err);
}
println!();
printed_lines += 1;
}

if args.section.get(SectionFeatures::SIZE) {
let len = section.size();
println!(
Expand Down

0 comments on commit 5e9e68c

Please sign in to comment.