-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract some shared functionality between SV and VHDL
- Loading branch information
Showing
4 changed files
with
64 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! Shared utilities | ||
use std::borrow::Cow; | ||
|
||
use crate::{instantiation::RealWire, linker::get_builtin_type, TypeUUID}; | ||
|
||
|
||
pub fn mangle(str: &str) -> String { | ||
let mut result = String::with_capacity(str.len()); | ||
for c in str.chars() { | ||
if c.is_whitespace() || c == ':' { | ||
continue; | ||
} | ||
result.push(if c.is_alphanumeric() { c } else { '_' }); | ||
} | ||
result | ||
} | ||
|
||
pub fn get_type_name_size(id: TypeUUID) -> u64 { | ||
if id == get_builtin_type("int") { | ||
32 // TODO concrete int sizes | ||
} else if id == get_builtin_type("bool") { | ||
1 | ||
} else { | ||
println!("TODO Named Structs Size"); | ||
1 // todo!() // Named structs are not implemented yet | ||
} | ||
} | ||
|
||
pub fn wire_name_with_latency(wire: &RealWire, absolute_latency: i64, use_latency: bool) -> Cow<str> { | ||
assert!(wire.absolute_latency <= absolute_latency); | ||
if use_latency && (wire.absolute_latency != absolute_latency) { | ||
if absolute_latency < 0 { | ||
Cow::Owned(format!("_{}_N{}", wire.name, -absolute_latency)) | ||
} else { | ||
Cow::Owned(format!("_{}_D{}", wire.name, absolute_latency)) | ||
} | ||
} else { | ||
Cow::Borrowed(&wire.name) | ||
} | ||
} | ||
|
||
pub fn wire_name_self_latency(wire: &RealWire, use_latency: bool) -> Cow<str> { | ||
wire_name_with_latency(wire, wire.absolute_latency, use_latency) | ||
} |
This file contains 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
This file contains 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