Open
Conversation
faf42ab to
a8e840c
Compare
448dbbf to
d92fb2f
Compare
7dd5086 to
ac6988a
Compare
95757fe to
79a2d1d
Compare
d58af79 to
9ed2027
Compare
9ed2027 to
6477e78
Compare
slang bindings and picklerpickle command
038b5fa to
3795c0a
Compare
Will result in ABI mismatches i.e. segfaults otherwise
Prevent multiple inclusion of the header by adding a traditional #ifndef/define/endif include guard (BENDER_SLANG_BRIDGE_H). This replaces the lone #pragma once for better portability and ensures the header can be safely included multiple times across translation units.
Introduce safe wrapper types for the opaque FFI objects and move the
extension methods into proper Rust structs to provide a clearer,
idiomatic API and safer ownership semantics.
- Add SyntaxTree wrapper around SharedPtr<ffi::SyntaxTree> with Clone,
display, as_debug, rename, and fmt impls (Display/Debug).
- Add SlangContext wrapper around UniquePtr<ffi::SlangContext> with new,
set_includes, set_defines, and parse returning a SyntaxTree.
- Replace new_session() to return SlangContext instead of raw pointer.
- Update callers: remove use of extension traits and change formatting
at pickling to use Debug/Display impls (write!("{:?}", renamed_tree)).
bender-slang: Fix windows build 2
3795c0a to
f295d10
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces first-class Slang integration to Bender via a new
bender-slangcrate and adds the new pickle command for preprocessing/rewrite/emit workflows on SystemVerilog sources.Slang bindings
Slang is vendored in as a submodule and built with CMake during crate build, then linked statically into
bender-slang(seebuild.rs)Slang has a couple of other library dependencies (e.g.
mimalloc,fmt) which are fetched by cmake and also statically linked to improve portability of the bender binary (at the expense of binary size). Those libraries are force-fetched to prevent using preinstalled system-libaries. I also investigated linking oflibc++statically, but this depends on the OS:build.rstries to linklibc++statically, if nolibstdc++.aexists, it falls back to dynamic linking. The idea was that this would also allow to run pre-compiled bender on older linux distributions without newer C++ features (Slang requires C++ 20)Rust/C++ bridge design
The bindings between C++ and Rust are created with the
cxxcrate (from the one and only dtolnay). It allows to access native types from both sides (e.g. Rust'sStringand C++'sstd::string), andcxxgenerates the necessary glue code underneath. It also statically checks at compile time for ABI mismatches etc.You just need to create a bridge i.e.
lib.rson the Rust side and slang_bridge.h on the C++ side that define the FFI. Additionally,lib.rswraps the FFI to provide a more idiomatic Rust API.The
picklecommandpickleis the first feature to use the Slang binding in the following way:Source collection
-I) and defines (-D)--toptrimming--topslang --depfile-trimbehavior:Renaming with
--prefixand--suffix--exclude-renamePrint options
Re-emitting the SV code from the syntax trees can be done with the following (self-explanatory) options currently:
--expand-macros--strip-comments--squash-newlinesIncludes are always printed. Furthermore it is possible to print the Syntax trees instead of emitting SV code with
--ast-json.Error/Warning behaviour
Related Changes
File type classification to (e.g.
SourceType::Verilog) was moved fromscript.rstosess.rs.Open questions/TODOs
bender-slangcurrently is a path dependency and likely needs to be published as well. Otherwisecargo install -F slangwill not work, only from source installation is supported.This is part 1 of 3 in a stack made with GitButler:
picklecommand #264 👈