Skip to content

Commit 70abeee

Browse files
committed
Be more careful computing the size of an array Cluster.
1 parent f66f169 commit 70abeee

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/generate/peripheral.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,23 @@ fn expand(
592592
Ok(ercs_expanded)
593593
}
594594

595-
/// Recursively calculate the size of a cluster. A cluster's size is the maximum
596-
/// end position of its recursive children.
595+
/// Calculate the size of a Cluster. If it is an array, then the dimensions
596+
/// tell us the size of the array. Otherwise, inspect the contents using
597+
/// [cluster_info_size_in_bits].
597598
fn cluster_size_in_bits(
599+
cluster: &Cluster,
600+
defs: &RegisterProperties,
601+
config: &Config,
602+
) -> Result<u32> {
603+
match cluster {
604+
Cluster::Single(info) => cluster_info_size_in_bits(info, defs, config),
605+
Cluster::Array(_info, dim) => Ok(dim.dim * dim.dim_increment * BITS_PER_BYTE),
606+
}
607+
}
608+
609+
/// Recursively calculate the size of a ClusterInfo. A cluster's size is the
610+
/// maximum end position of its recursive children.
611+
fn cluster_info_size_in_bits(
598612
info: &ClusterInfo,
599613
defs: &RegisterProperties,
600614
config: &Config,
@@ -632,7 +646,7 @@ fn expand_cluster(
632646

633647
let defs = cluster.default_register_properties.derive_from(defs);
634648

635-
let cluster_size = cluster_size_in_bits(cluster, &defs, config)
649+
let cluster_size = cluster_info_size_in_bits(cluster, &defs, config)
636650
.with_context(|| format!("Cluster {} has no determinable `size` field", cluster.name))?;
637651

638652
match cluster {

0 commit comments

Comments
 (0)