-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrom_usage.awk
More file actions
36 lines (27 loc) · 787 Bytes
/
rom_usage.awk
File metadata and controls
36 lines (27 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Pipe main.map into this to get ROM size info.
# https://stackoverflow.com/a/32437561/211234
function parse_hex(hex_string) {
if (hex_string ~ /^0x/) {
hex_string = substr(hex_string, 3)
}
value = 0
for (i = 1; i <= length(hex_string); i++) {
value = value*16 + H[substr(hex_string, i, 1)]
}
return value
}
BEGIN {
# Build map from hex digit to value.
for (i = 0; i < 16; i++) {
H[sprintf("%x",i)] = i
H[sprintf("%X",i)] = i
}
}
/^CODE/ { code_start = parse_hex($2) }
/^RODATA/ { rodata_end = parse_hex($3) }
/^VECTORS/ { vectors_start = parse_hex($2) }
END {
code = rodata_end - code_start + 1
all = vectors_start - code_start
printf "%d of %d ROM bytes (%d%%) used\n", code, all, code*100/all
}