svlog: ty: Improve ranges, add From for dims
@@ -992,6 +992,12 @@ impl PackedDim {
}
}
+impl From<Range> for PackedDim {
+ fn from(range: Range) -> Self {
+ Self::Range(range)
+ }
+}
+
impl Display for PackedDim {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
@@ -1485,6 +1491,17 @@ impl UnpackedDim<'_> {
}
}
+impl From<usize> for UnpackedDim<'_> {
+ fn from(size: usize) -> Self {
+ Self::Array(size)
+ }
+}
+impl From<Range> for UnpackedDim<'_> {
+ fn from(range: Range) -> Self {
+ Self::Range(range)
+ }
+}
+
impl Display for UnpackedDim<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
@@ -1857,6 +1874,17 @@ pub enum RangeDir {
Down,
}
+impl Range {
+ /// Create a new `[<size>-1:0]` range.
+ pub fn with_size(size: usize) -> Self {
+ Self {
+ size,
+ dir: RangeDir::Down,
+ offset: 0,
+ }
+ }
+}
+
impl std::fmt::Debug for Range {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self)
