diff --git a/Cargo.toml b/Cargo.toml index 00d613d..9fd1a60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "svinst" -version = "0.1.1" +version = "0.1.3" authors = ["sgherbst@gmail.com"] repository = "https://github.com/sgherbst/svinst" keywords = ["parser", "verilog", "systemverilog"] diff --git a/src/main.rs b/src/main.rs index 6ba4f56..ce385c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,9 +26,13 @@ struct Opt { #[structopt(long = "ignore-include")] pub ignore_include: bool, - /// Ignore any include + /// Show the full syntax tree rather than just module instantiation #[structopt(long = "full-tree")] - pub full_tree: bool + pub full_tree: bool, + + /// Treat each file as completely separate, not updating define variables after each file + #[structopt(long = "separate")] + pub separate: bool } fn main() { @@ -63,7 +67,7 @@ fn run_opt( println!("files:"); for path in &opt.files { match parse_sv(&path, &defines, &opt.includes, opt.ignore_include) { - Ok((syntax_tree, _new_defines)) => { + Ok((syntax_tree, new_defines)) => { println!(" - file_name: \"{}\"", path.to_str().unwrap()); if !opt.full_tree { println!(" defs:"); @@ -72,6 +76,10 @@ fn run_opt( println!(" syntax_tree:"); print_full_tree(&syntax_tree); } + // update the preprocessor state if desired + if !opt.separate { + defines = new_defines; + } } Err(x) => { match x { @@ -396,7 +404,8 @@ mod tests { defines: vec![], includes: vec![], full_tree: false, - ignore_include: false + ignore_include: false, + separate: false }; expect_pass(&opt); } @@ -408,7 +417,8 @@ mod tests { defines: vec![], includes: vec![], full_tree: false, - ignore_include: false + ignore_include: false, + separate: false }; expect_fail(&opt); } @@ -420,7 +430,8 @@ mod tests { defines: vec![], includes: vec![PathBuf::from("testcases/pass")], full_tree: false, - ignore_include: false + ignore_include: false, + separate: false }; expect_pass(&opt); } @@ -433,7 +444,8 @@ mod tests { String::from("EXTRA_INSTANCE")], includes: vec![], full_tree: false, - ignore_include: false + ignore_include: false, + separate: false }; expect_pass(&opt); } @@ -445,7 +457,8 @@ mod tests { defines: vec![], includes: vec![], full_tree: true, - ignore_include: false + ignore_include: false, + separate: false }; expect_pass(&opt); } @@ -457,7 +470,8 @@ mod tests { defines: vec![], includes: vec![], full_tree: false, - ignore_include: false + ignore_include: false, + separate: false }; expect_pass(&opt); } @@ -469,7 +483,8 @@ mod tests { defines: vec![], includes: vec![], full_tree: false, - ignore_include: false + ignore_include: false, + separate: false }; expect_pass(&opt); } @@ -481,7 +496,26 @@ mod tests { defines: vec![], includes: vec![], full_tree: false, - ignore_include: false + ignore_include: false, + separate: false + }; + expect_pass(&opt); + } + + #[test] + fn test_multi() { + let opt = Opt{ + files: vec![ + PathBuf::from("testcases/pass/multi/define1.v"), + PathBuf::from("testcases/pass/multi/test1.sv"), + PathBuf::from("testcases/pass/multi/define2.v"), + PathBuf::from("testcases/pass/multi/dut.v") + ], + defines: vec![], + includes: vec![], + full_tree: false, + ignore_include: false, + separate: false }; expect_pass(&opt); } diff --git a/testcases/pass/multi/define1.v b/testcases/pass/multi/define1.v new file mode 100644 index 0000000..a372569 --- /dev/null +++ b/testcases/pass/multi/define1.v @@ -0,0 +1 @@ +`define WIDTH 16 diff --git a/testcases/pass/multi/define2.v b/testcases/pass/multi/define2.v new file mode 100644 index 0000000..fe462dc --- /dev/null +++ b/testcases/pass/multi/define2.v @@ -0,0 +1,2 @@ +`undef WIDTH +`define WIDTH 32 diff --git a/testcases/pass/multi/dut.v b/testcases/pass/multi/dut.v new file mode 100644 index 0000000..154857a --- /dev/null +++ b/testcases/pass/multi/dut.v @@ -0,0 +1,9 @@ +module dut(input clk); + +reg [`WIDTH-1:0] cnt; + +always @(posedge clk) begin +cnt <= cnt + 1; +end + +endmodule diff --git a/testcases/pass/multi/test1.sv b/testcases/pass/multi/test1.sv new file mode 100644 index 0000000..bd99226 --- /dev/null +++ b/testcases/pass/multi/test1.sv @@ -0,0 +1,9 @@ +module test; + +reg [`WIDTH-1:0] cnt; +reg clk=0; +always #1 clk = ~clk; + +dut u0(clk); + +endmodule