Skip to content

Commit 7876752

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

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/generate/peripheral.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,24 @@ 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) =>
606+
Ok(dim.dim * dim.dim_increment * BITS_PER_BYTE),
607+
}
608+
}
609+
610+
/// Recursively calculate the size of a ClusterInfo. A cluster's size is the
611+
/// maximum end position of its recursive children.
612+
fn cluster_info_size_in_bits(
598613
info: &ClusterInfo,
599614
defs: &RegisterProperties,
600615
config: &Config,
@@ -632,7 +647,7 @@ fn expand_cluster(
632647

633648
let defs = cluster.default_register_properties.derive_from(defs);
634649

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

638653
match cluster {

0 commit comments

Comments
 (0)