From 381713b83f2722a755d3e222b3e7ecbfdeb3f447 Mon Sep 17 00:00:00 2001 From: Lawrence Kesteloot Date: Fri, 3 Aug 2018 13:40:52 -0700 Subject: [PATCH] Make AWK script gawk-compatible. --- rom_usage.awk | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/rom_usage.awk b/rom_usage.awk index bcc2f26..78919cf 100644 --- a/rom_usage.awk +++ b/rom_usage.awk @@ -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