Skip to content

Commit

Permalink
array-proxy for disjoint arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Oct 14, 2023
1 parent 460ea2e commit c28a3bb
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,8 @@ fn expand_register(
Register::Array(info, array_info) => {
let sequential_addresses = (array_info.dim == 1)
|| (register_size == array_info.dim_increment * BITS_PER_BYTE);
let disjoint_sequential_addresses = (array_info.dim == 1)
|| (register_size <= array_info.dim_increment * BITS_PER_BYTE);

let convert_list = match config.keep_list {
true => match &array_info.dim_name {
Expand All @@ -1208,20 +1210,22 @@ fn expand_register(
} else {
"".into()
};
let array_convertible = match derive_info {
let ac = match derive_info {
DeriveInfo::Implicit(_) => {
ty_name = util::replace_suffix(&info_name, &index);
sequential_addresses && convert_list && sequential_indexes_from0
convert_list && sequential_indexes_from0
}
DeriveInfo::Explicit(_) => {
ty_name = util::replace_suffix(&info_name, &index);
sequential_addresses && convert_list && sequential_indexes_from0
convert_list && sequential_indexes_from0
}
_ => sequential_addresses && convert_list,
_ => convert_list,
};
let array_convertible = ac && sequential_addresses;
let array_proxy_convertible = ac && disjoint_sequential_addresses;
let ty = name_to_ty(&ty_name);

if array_convertible {
if array_convertible || (array_proxy_convertible && config.const_generic) {
let accessors = if sequential_indexes_from0 {
Vec::new()
} else {
Expand All @@ -1247,14 +1251,22 @@ fn expand_register(
}
accessors
};
let array_ty = new_syn_array(ty, array_info.dim);
let array_ty = if array_convertible {
new_syn_array(ty, array_info.dim)
} else {
array_proxy_type(ty, array_info)
};
let syn_field =
new_syn_field(ty_name.to_snake_case_ident(Span::call_site()), array_ty);
register_expanded.push(RegisterBlockField {
syn_field,
description,
offset: info.address_offset,
size: register_size * array_info.dim,
size: if array_convertible {
register_size * array_info.dim
} else {
0
},
accessors,
});
} else {
Expand Down

0 comments on commit c28a3bb

Please sign in to comment.