Add code_size, data_size to generated config.json

Also simplify project config generation by skipping default fields
This commit is contained in:
2023-09-14 17:24:00 -04:00
parent 59a4eb33d0
commit 400fb7fa7f
4 changed files with 55 additions and 15 deletions

View File

@@ -293,4 +293,29 @@ impl ObjInfo {
.filter(|(_, _, _, split)| split.unit == unit)
.all(|(_, _, _, split)| split.autogenerated)
}
/// Calculate the total size of all code sections.
pub fn code_size(&self) -> u32 {
self.sections
.iter()
.filter(|(_, section)| section.kind == ObjSectionKind::Code)
.map(|(_, section)| section.size as u32)
.sum()
}
/// Calculate the total size of all data sections, including common BSS symbols.
pub fn data_size(&self) -> u32 {
self.sections
.iter()
.filter(|(_, section)| section.kind != ObjSectionKind::Code)
.map(|(_, section)| section.size as u32)
.chain(
// Include common symbols
self.symbols
.iter()
.filter(|&symbol| symbol.flags.is_common())
.map(|s| s.size as u32),
)
.sum()
}
}