pub struct ModInst { /* private fields */ }Expand description
Represents an instance of a module definition, like <mod_def_name> <mod_inst_name> ( ... ); in Verilog.
Implementations§
Source§impl ModInst
impl ModInst
Sourcepub fn get_port(&self, name: impl AsRef<str>) -> Port
pub fn get_port(&self, name: impl AsRef<str>) -> Port
Returns the port on this instance with the given name. Panics if no such port exists.
Examples found in repository?
examples/demo.rs (line 31)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn main() {
// Path to the "examples" folder
let examples = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples");
// Import the adder module definition from a Verilog file
let adder_8_bit = ModDef::from_verilog_file(
"adder",
&examples.join("input").join("adder.sv"),
true,
false,
);
let adder_9_bit = adder_8_bit.parameterize(&[("W", 9)], None, None);
// Create a top-level module definition
let top = ModDef::new("top");
// Instantiate adders in a tree
let i00 = top.instantiate(&adder_8_bit, Some("i00"), None);
let i01 = top.instantiate(&adder_8_bit, Some("i01"), None);
let i11 = top.instantiate(&adder_9_bit, Some("i11"), None);
let a = top.add_port("in0", i00.get_port("a").io());
let b = top.add_port("in1", i00.get_port("b").io());
let c = top.add_port("in2", i01.get_port("a").io());
let sum = top.add_port("sum", i11.get_port("sum").io());
// Wire together adders in a tree
a.connect(&i00.get_port("a"));
i00.get_port("b").connect(&b); // order doesn't matter
c.connect(&i01.get_port("a"));
i01.get_port("b").tieoff(42); // required because unconnected inputs are not allowed
i00.get_port("sum").connect(&i11.get_port("a"));
i01.get_port("sum").connect(&i11.get_port("b"));
// Connect the final adder output the top-level output
sum.connect(&i11.get_port("sum"));
// Emit the final Verilog code
let output_dir = examples.join("output");
std::fs::create_dir_all(&output_dir).expect("should be possible to create output dir");
let output_file = output_dir.join("top.sv");
top.emit_to_file(&output_file, true);
eprintln!("Emitted to output file: {}", output_file.display());
}Sourcepub fn get_port_slice(
&self,
name: impl AsRef<str>,
msb: usize,
lsb: usize,
) -> PortSlice
pub fn get_port_slice( &self, name: impl AsRef<str>, msb: usize, lsb: usize, ) -> PortSlice
Returns a slice of the port on this instance with the given name, from
msb down to lsb, inclusive. Panics if no such port exists.
Sourcepub fn get_ports(&self, prefix: Option<&str>) -> Vec<Port>
pub fn get_ports(&self, prefix: Option<&str>) -> Vec<Port>
Returns a vector of ports on this instance with the given prefix, or all
ports if prefix is None.
Sourcepub fn get_intf(&self, name: impl AsRef<str>) -> Intf
pub fn get_intf(&self, name: impl AsRef<str>) -> Intf
Returns the interface on this instance with the given name. Panics if no such interface exists.
Sourcepub fn get_mod_def(&self) -> ModDef
pub fn get_mod_def(&self) -> ModDef
Returns the ModDef that this is an instance of.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ModInst
impl !RefUnwindSafe for ModInst
impl !Send for ModInst
impl !Sync for ModInst
impl Unpin for ModInst
impl !UnwindSafe for ModInst
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more