Make AWK script gawk-compatible.

This commit is contained in:
Lawrence Kesteloot 2018-08-03 13:40:52 -07:00
parent d9594ce3ad
commit 381713b83f
1 changed files with 25 additions and 3 deletions

View File

@ -1,10 +1,32 @@
# Pipe main.map into this to get ROM size info.
/^CODE/ { code_start = ("0x" $2) + 0 }
# https://stackoverflow.com/a/32437561/211234
function parse_hex(hex_string) {
if (hex_string ~ /^0x/) {
hex_string = substr(hex_string, 3)
}
/^RODATA/ { rodata_end = ("0x" $3) + 0 }
value = 0
for (i = 1; i <= length(hex_string); i++) {
value = value*16 + H[substr(hex_string, i, 1)]
}
/^VECTORS/ { vectors_start = ("0x" $2) + 0 }
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