FreeRTOS-Kernel/verification/verifast/custom_build_scripts_RP2040/vf_rewrite.sh
2022-11-16 10:28:31 -05:00

59 lines
1.7 KiB
Bash
Executable file

ps -o comm= -p $$
VF_RW_WD=`pwd`
SOURCE_FILE="$1"
BACKUP_IDX=0
# IMPORTANT:
# None of the provided regexes must contain the unescaped character '|'
#
# $1 : sed 'find' regex
# $2 : sed 'replace' regex
rewrite()
{
FIND_REGEX=$1
REPLACE_REGEX=$2
echo "VF RW: \"$FIND_REGEX\" -> \"$REPLACE_REGEX\""
echo "backup : $VF_RW_WD/$SOURCE_FILE.backup-$BACKUP_IDX"
sed -i."backup-$BACKUP_IDX" "s|$FIND_REGEX|$REPLACE_REGEX|g" $SOURCE_FILE
((BACKUP_IDX=BACKUP_IDX+1))
echo "\n"
}
echo "Commenting out line/file pragmas"
rewrite "^#" "// &"
echo "Fixing order of 'long', 'unsigned'"
rewrite "long unsigned int" "unsigned long int"
echo "Delete fixed-sized array typedefs"
rewrite "typedef .*\[[0-9]*\];" ""
echo "Delete attributes"
#rewrite "\_\_attribute\_\_\(\(\_\_[a-z\_]*\_\_\)\)" ""
rewrite "__attribute__(([_a-z]*))" ""
# TODO: Why does matching `\s` or `:space:` not work on MacOs?
rewrite "__attribute__( ( [_a-z]* ) )" ""
echo "Delete void casts (used to suppress compiler warnings)"
echo "Reported issue 335"
echo "https://github.com/verifast/verifast/issues/335"
rewrite "( void ) memset" "memset"
echo "Removing const qualifiers from pointers"
echo "Reported issue 333:"
echo "https://github.com/verifast/verifast/issues/333"
rewrite "[*] const" "*"
rewrite "const [*]" "*"
echo "Uncomment special includes to allow VeriFast proofs to refer to config macros"
rewrite "//VF_include #include" "#include"
rewrite "//VF_macro #" "#"
#echo "VF RW: 'long unsigned int' -> 'unsinged long int'"
#echo "backup : $VF_RW_WD/$SOURCE_FILE.backup-$BACKUP_IDX"
#echo backup index $BACKUP_IDX
#sed -i."backup-$BACKUP_IDX" 's|long unsigned int|unsigned long int|g' $SOURCE_FILE
#((BACKUP_IDX=BACKUP_IDX+1))
#echo backup index $BACKUP_IDX