Skip to content

Commit

Permalink
preliminary feature for macro definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
sgherbst committed Oct 27, 2020
1 parent 0f74e13 commit 68d317f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# macOS files
.DS_Store
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svinst"
version = "0.1.3"
version = "0.1.4"
authors = ["[email protected]"]
repository = "https://github.com/sgherbst/svinst"
keywords = ["parser", "verilog", "systemverilog"]
Expand All @@ -11,8 +11,8 @@ description = "Determines the modules declared and instantiated in SystemVerilog
edition = "2018"

[dependencies]
sv-parser = "0.6.3"
sv-parser-error = "0.6.3"
sv-parser-syntaxtree = "0.6.3"
structopt = "0.3.14"
sv-parser = "0.8.2"
sv-parser-error = "0.8.2"
sv-parser-syntaxtree = "0.8.2"
structopt = "0.3.20"
enquote = "1.0.3"
47 changes: 38 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ struct Opt {
#[structopt(long = "full-tree")]
pub full_tree: bool,

/// Show the macro definitions after processing each file
#[structopt(long = "show-macro-defs")]
pub show_macro_defs: bool,

/// Treat each file as completely separate, not updating define variables after each file
#[structopt(long = "separate")]
pub separate: bool
Expand Down Expand Up @@ -80,6 +84,11 @@ fn run_opt(
if !opt.separate {
defines = new_defines;
}
// show macro definitions if desired
if opt.show_macro_defs {
println!(" macro_defs:");
show_macro_defs(&defines);
}
}
Err(x) => {
match x {
Expand Down Expand Up @@ -169,6 +178,17 @@ fn print_parse_error(
}
}

fn show_macro_defs(
defines: &HashMap<String, Option<Define>>
) {
for (_, value) in defines.into_iter() {
match value {
Some(define) => println!(" - '{:?}'", define),
_ => (),
}
}
}

fn analyze_defs(
syntax_tree: &SyntaxTree
) {
Expand Down Expand Up @@ -405,7 +425,8 @@ mod tests {
includes: vec![],
full_tree: false,
ignore_include: false,
separate: false
separate: false,
show_macro_defs: false
};
expect_pass(&opt);
}
Expand All @@ -418,7 +439,8 @@ mod tests {
includes: vec![],
full_tree: false,
ignore_include: false,
separate: false
separate: false,
show_macro_defs: false
};
expect_fail(&opt);
}
Expand All @@ -431,7 +453,8 @@ mod tests {
includes: vec![PathBuf::from("testcases/pass")],
full_tree: false,
ignore_include: false,
separate: false
separate: false,
show_macro_defs: false
};
expect_pass(&opt);
}
Expand All @@ -445,7 +468,8 @@ mod tests {
includes: vec![],
full_tree: false,
ignore_include: false,
separate: false
separate: false,
show_macro_defs: true
};
expect_pass(&opt);
}
Expand All @@ -458,7 +482,8 @@ mod tests {
includes: vec![],
full_tree: true,
ignore_include: false,
separate: false
separate: false,
show_macro_defs: false
};
expect_pass(&opt);
}
Expand All @@ -471,7 +496,8 @@ mod tests {
includes: vec![],
full_tree: false,
ignore_include: false,
separate: false
separate: false,
show_macro_defs: false
};
expect_pass(&opt);
}
Expand All @@ -484,7 +510,8 @@ mod tests {
includes: vec![],
full_tree: false,
ignore_include: false,
separate: false
separate: false,
show_macro_defs: false
};
expect_pass(&opt);
}
Expand All @@ -497,7 +524,8 @@ mod tests {
includes: vec![],
full_tree: false,
ignore_include: false,
separate: false
separate: false,
show_macro_defs: false
};
expect_pass(&opt);
}
Expand All @@ -515,7 +543,8 @@ mod tests {
includes: vec![],
full_tree: false,
ignore_include: false,
separate: false
separate: false,
show_macro_defs: false
};
expect_pass(&opt);
}
Expand Down

0 comments on commit 68d317f

Please sign in to comment.