Skip to content

Instantly share code, notes, and snippets.

@reidrac
Last active December 1, 2018 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reidrac/ea7a5caf5e98d62e7868849980c91f57 to your computer and use it in GitHub Desktop.
Save reidrac/ea7a5caf5e98d62e7868849980c91f57 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Check SDCC map files and calculate how much RAM you have left
#
# max_mem is top mem minus your code start, for example: 41179
#
set -e
if [ $# -ne 2 ]; then
echo "$0 max_mem filename.map"
exit 1
fi
CURRENT=`egrep -u "^_" < $2 | sort -u | awk ' BEGIN { t=0 } /^_/ && /bytes/ { t = t + strtonum($5) } END { print t }'`
LEFT=$(($1 - $CURRENT))
cat <<ENDL
***
Max: $1 bytes
Current: $CURRENT bytes ($2)
Left: $LEFT bytes
***
ENDL
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment