Skip to content

Commit

Permalink
preserve preprocessor state from one file to the next by default
Browse files Browse the repository at this point in the history
  • Loading branch information
sgherbst committed Jul 6, 2020
1 parent 282c526 commit 1fb1b01
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svinst"
version = "0.1.1"
version = "0.1.3"
authors = ["[email protected]"]
repository = "https://github.com/sgherbst/svinst"
keywords = ["parser", "verilog", "systemverilog"]
Expand Down
56 changes: 45 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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:");
Expand All @@ -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 {
Expand Down Expand Up @@ -396,7 +404,8 @@ mod tests {
defines: vec![],
includes: vec![],
full_tree: false,
ignore_include: false
ignore_include: false,
separate: false
};
expect_pass(&opt);
}
Expand All @@ -408,7 +417,8 @@ mod tests {
defines: vec![],
includes: vec![],
full_tree: false,
ignore_include: false
ignore_include: false,
separate: false
};
expect_fail(&opt);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -445,7 +457,8 @@ mod tests {
defines: vec![],
includes: vec![],
full_tree: true,
ignore_include: false
ignore_include: false,
separate: false
};
expect_pass(&opt);
}
Expand All @@ -457,7 +470,8 @@ mod tests {
defines: vec![],
includes: vec![],
full_tree: false,
ignore_include: false
ignore_include: false,
separate: false
};
expect_pass(&opt);
}
Expand All @@ -469,7 +483,8 @@ mod tests {
defines: vec![],
includes: vec![],
full_tree: false,
ignore_include: false
ignore_include: false,
separate: false
};
expect_pass(&opt);
}
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions testcases/pass/multi/define1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`define WIDTH 16
2 changes: 2 additions & 0 deletions testcases/pass/multi/define2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`undef WIDTH
`define WIDTH 32
9 changes: 9 additions & 0 deletions testcases/pass/multi/dut.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module dut(input clk);

reg [`WIDTH-1:0] cnt;

always @(posedge clk) begin
cnt <= cnt + 1;
end

endmodule
9 changes: 9 additions & 0 deletions testcases/pass/multi/test1.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module test;

reg [`WIDTH-1:0] cnt;
reg clk=0;
always #1 clk = ~clk;

dut u0(clk);

endmodule

0 comments on commit 1fb1b01

Please sign in to comment.