3 # A small script that parses a codewarrior mapfile and produces
\r
4 # lists of object files and how much .data and .bss they take.
\r
6 # Usage: gawk -f <this_file> <mapfile>
\r
8 function collect( section ) {
\r
12 while( getline > 0 ) {
\r
17 if ( $6 ~ /^\.[a-z]/ ) {
\r
19 section[curr_obj]=strtonum("0x" $2)
\r
25 # http://stackoverflow.com/questions/5342782/sort-associative-array-with-awk
\r
27 function sort_and_print( arr , indices , tmpidx ) {
\r
30 tmpidx[sprintf("%12s", arr[i]),i] = i
\r
32 num = asorti(tmpidx)
\r
34 for (i=1; i<=num; i++) {
\r
35 split(tmpidx[i], tmp, SUBSEP)
\r
36 indices[++j] = tmp[2]
\r
38 for (i=num; i>0; i--) {
\r
39 printf("%35s %d\n",indices[i], arr[indices[i]])
\r
52 printf " .data\n----------------------------------------------\n"
\r
53 sort_and_print(data_sec)
\r
55 printf " .bss\n----------------------------------------------\n"
\r
56 sort_and_print(bss_sec)
\r