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

ignore_protected feature #21

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions .github/workflows/slang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- name: Download Slang Release
run: |
curl -L -o source.tar.gz "https://github.com/MikePopoloski/slang/archive/refs/tags/v6.0.tar.gz"
curl -L -o source.tar.gz "https://github.com/MikePopoloski/slang/archive/refs/tags/v7.0.tar.gz"

- name: Extract Tarball
run: |
Expand Down Expand Up @@ -46,16 +46,16 @@ jobs:
dnf install -y python3 python3-devel
dnf install -y gcc openssl-devel libffi-devel make cmake curl git

- name: Install Clang-17
- name: Install Clang-18
run: |
dnf install -y llvm-toolset

- name: Note Clang version
run: clang-17 --version
run: clang-18 --version

- name: Download Slang Release
run: |
curl -L -o source.tar.gz "https://github.com/MikePopoloski/slang/archive/refs/tags/v6.0.tar.gz"
curl -L -o source.tar.gz "https://github.com/MikePopoloski/slang/archive/refs/tags/v7.0.tar.gz"

- name: Extract Tarball
run: |
Expand All @@ -65,8 +65,8 @@ jobs:
- name: Build Slang
working-directory: source
run: |
CC=clang-17 CXX=clang++-17 cmake -B build
CC=clang-17 CXX=clang++-17 cmake --build build -j8
CC=clang-18 CXX=clang++-18 cmake -B build
CC=clang-18 CXX=clang++-18 cmake --build build -j8

- name: Upload Binary Artifact
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "slang-rs"
version = "0.12.0"
version = "0.13.0"
edition = "2021"
license = "Apache-2.0"
description = "Rust bindings for the Slang Verilog parser"
Expand Down
32 changes: 32 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct SlangConfig<'a> {
pub libdirs: &'a [&'a str],
pub libexts: &'a [&'a str],
pub ignore_unknown_modules: bool,
pub ignore_protected: bool,
pub timescale: Option<&'a str>,
}

Expand All @@ -33,6 +34,7 @@ impl<'a> Default for SlangConfig<'a> {
libdirs: &[],
libexts: &[],
ignore_unknown_modules: true,
ignore_protected: true,
timescale: None,
}
}
Expand All @@ -45,6 +47,32 @@ fn find_slang() -> Option<String> {
.map(|p| p.to_string_lossy().to_string())
}

/// Adds options needed to make slang ignore protected envelopes.
fn push_options_to_ignore_protected(args: &mut Vec<&str>) {
let options = vec![
"--enable-legacy-protect",
"-Wno-protected-envelope",
"-Wno-expected-protect-arg",
"-Wno-expected-protect-keyword",
"-Wno-extra-protect-end",
"-Wno-invalid-encoding-byte",
"-Wno-invalid-pragma-number",
"-Wno-invalid-pragma-viewport",
"-Wno-nested-protect-begin",
"-Wno-protect-arglist",
"-Wno-protect-encoding-bytes",
"-Wno-protected-envelope",
"-Wno-raw-protect-eof",
"-Wno-unknown-protect-encoding",
"-Wno-unknown-protect-keyword",
"-Wno-unknown-protect-option",
];

for option in options {
args.push(option);
}
}

pub fn run_slang(cfg: &SlangConfig) -> Result<Value, Box<dyn std::error::Error>> {
// Run the slang binary, dumping JSON to tmp_json.

Expand All @@ -69,6 +97,10 @@ pub fn run_slang(cfg: &SlangConfig) -> Result<Value, Box<dyn std::error::Error>>
args.push("--ignore-unknown-modules");
}

if cfg.ignore_protected {
push_options_to_ignore_protected(&mut args);
}

let param_args: Vec<String> = cfg
.parameters
.iter()
Expand Down
58 changes: 58 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,62 @@ endmodule
}]
);
}

#[test]
fn test_protected() {
let verilog = str2tmpfile(
"
module foo(
input a
);
`protected
asdf
`endprotected
endmodule",
)
.unwrap();

let cfg = SlangConfig {
sources: &[verilog.path().to_str().unwrap()],
..Default::default()
};

let definitions = extract_ports(&cfg, false);
assert_eq!(
definitions["foo"],
vec![Port {
dir: PortDir::Input,
name: "a".to_string(),
ty: Type::Logic {
signed: false,
packed_dimensions: vec![],
unpacked_dimensions: vec![],
},
}]
);
}

#[test]
#[should_panic(expected = "unknown macro")]
fn test_protected_panic() {
let verilog = str2tmpfile(
"
module foo(
input a
);
`protected
asdf
`endprotected
endmodule",
)
.unwrap();

let cfg = SlangConfig {
sources: &[verilog.path().to_str().unwrap()],
ignore_protected: false,
..Default::default()
};

extract_ports(&cfg, false);
}
}
Loading