Commit 47d92d92 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

modify usage of var in prepare_instrumentation.sh

parent a3bc23c7
Loading
Loading
Loading
Loading
Loading
+64 −68
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ function usage {
    exit
}


# default values
MODE="FULL"
PROJECT="FLOAT"
@@ -66,24 +65,22 @@ while getopts "m:p:h" OPTIONS; do
done
shift $((OPTIND - 1))


wmc_opt=""
if [ "$MODE" = "MEM_ONLY" ]; then
    wmc_opt="-s"
fi


system=`uname -s`
if [[ ($system = "Linux") && (`uname -a` =~ (microsoft|Microsoft|wsl|WSL) ) ]]; then
system=$(uname -s)
if [[ ($system = "Linux") && ($(uname -a) =~ (microsoft|Microsoft|wsl|WSL)) ]]; then
    system="Linux"
fi

coan_exists() {
  type coan &> /dev/null ;
    type coan &>/dev/null
}

cppp_exists() {
  type cppp/cppp.pl &> /dev/null ;
    type cppp/cppp.pl &>/dev/null
}

if ! (coan_exists || cppp_exists); then
@@ -95,8 +92,8 @@ fi

targetdir=c-code_instrument

currdir=`pwd`
scriptdir=`dirname $0`
currdir=$(pwd)
scriptdir=$(dirname $0)
ifdef_list=ifdef_instrument.list
sourcedir=$scriptdir/..
cd $scriptdir
@@ -118,7 +115,6 @@ rm -f $ifdef_list
touch $ifdef_list

# LC3plus-related stuff -> only in float code
if [ "$PROJECT" = "FLOAT" ]; then
# Add LC3plus feature defines to options.h so that they are stripped correctly
# Generate list of active defines in LC3plus defines.h
lc3plus_defines=$(
@@ -129,9 +125,8 @@ if [ "$PROJECT" = "FLOAT" ]; then

# Filter defines that come from outside of the header lib_lc3plus/defines.h
lc3plus_defines_filtered=""
    while IFS=' \n' read -r line;
    do
       line=`echo $line | tr -d '\n'`
while IFS=' \n' read -r line; do
    line=$(echo $line | tr -d '\n')
    if grep -wqF "$line" "$targetdir/lib_lc3plus/defines.h"; then
        lc3plus_defines_filtered+=$line$'\n'
    fi
@@ -142,6 +137,11 @@ if [ "$PROJECT" = "FLOAT" ]; then
/* LC3plus switches */
#ifndef OPTIONS_H_LC3_DEFINES
#define OPTIONS_H_LC3_DEFINES
$lc3plus_defines_filtered
" >>$targetdir/lib_com/options.h

if [ "$PROJECT" = "BASOP" ]; then
    echo "
    #define ENABLE_HR_MODE
    //#define DYNMEM_COUNT
    #define CR10_A_ATTENUATION_CURVE_SELECTOR
@@ -151,25 +151,32 @@ if [ "$PROJECT" = "FLOAT" ]; then
    #define SUBSET_SWB
    #define SUBSET_FB
    #define SUBSET_UB
    $lc3plus_defines_filtered
    " >>$targetdir/lib_com/options.h
fi

echo "
#endif /* OPTIONS_H_LC3_DEFINES */
" >>$targetdir/lib_com/options.h

if [ "$PROJECT" = "BASOP" ]; then
    # Clean out memory tool which breaks wmc_tool instrumentation
    perl -i -0777 -pe 's/Dyn_Mem_Deluxe_In\(((.|\s)*?)\);/$1/g' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/Dyn_Mem_Deluxe_Out\s*\([^)]*\)\s*;/;/sg' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/\sDyn_Mem_In\((.|\s)*?\);//g' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/Dyn_Mem_Out\s*\([^)]*\)\s*;/;/sg' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/scratchAlign\(\s*((?:.|\s)*?)\s*,\s*((?:.|\s)*?)\s*\);/(void *)(((uintptr_t)($1) + ($2) + 0x3) & ~0x3);/g' $targetdir/lib_lc3plus/*.c
    # expand LC3plus BASOP macros
    perl -i -0777 -pe 's/cplxMpy32_32_32_2\(\s*([^,]+?),\s*([^,]+?),\s*([^,]+?),\s*([^,]+?),\s*([^,]+?),\s*([^,]+?)\s*\);/do { $1 = L_sub(Mpy_32_32_0($3, $5), Mpy_32_32_0($4, $6)); $2 = L_add(Mpy_32_32_0($3, $6), Mpy_32_32_0($4, $5)); } while (0);/g' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/cplxMpy32_32_16_2\(\s*([^,]+?),\s*([^,]+?),\s*([^,]+?),\s*([^,]+?),\s*([^,]+?),\s*([^,]+?)\s*\);/do { $1 = L_sub(L_shr_pos(Mpy_32_16_lc3plus($3, $5), 1), L_shr_pos(Mpy_32_16_lc3plus($4, $6), 1)); $2 = L_add(L_shr_pos(Mpy_32_16_lc3plus($3, $6), 1), L_shr_pos(Mpy_32_16_lc3plus($4, $5), 1)); } while (0);/g' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/extractW16/extract_h/g' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/(UL_l|l|L_|)(sh[lr](_r)?)(?:_pos){1,2}/$1$2/g' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/scratchAlign\(\s*((?:.|\s)*?)\s*,\s*((?:.|\s)*?)\s*\);/(void *)(((uintptr_t)($1) + ($2) + 0x3) & ~0x3);/g' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/BASOP_sub(_sub)?_start/push_wmops/g' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/BASOP_sub(_sub)?_end/pop_wmops/g' $targetdir/lib_lc3plus/*.c
    perl -i -0777 -pe 's/#if\s*WMOPS/#ifdef WMOPS/g' $targetdir/lib_lc3plus/*.c

    # perl -i -0777 -pe 's/BASOP_sub(_sub)?_start/push_wmops/g' $targetdir/lib_lc3plus/*.c
    # perl -i -0777 -pe 's/BASOP_sub(_sub)?_end/pop_wmops/g' $targetdir/lib_lc3plus/*.c
    # perl -i -0777 -pe 's/#if\s*WMOPS/#ifdef WMOPS/g' $targetdir/lib_lc3plus/*.c
fi
# remove spaces in preprocessor directives
perl -i -0777 -pe 's/#\s+(if|else|elif|endif|define)/#$1/g' $targetdir/lib_lc3plus/*.[ch]
perl -i -0777 -pe 's/#(ifdef|ifndef)\s{2,}/#ifdef /g' $targetdir/lib_lc3plus/*.[ch]

# get switches from options.h and append it to $ifdef_list
parse_options_opt=""
@@ -198,16 +205,11 @@ if coan_exists; then
    sed -i "/-UMEM_COUNT_DETAILS/d" $ifdef_list

    coan source --replace --no-transients -E -K --file $ifdef_list $targetdir/apps/*.[hc]
    if [ "$PROJECT" = "FLOAT" ]; then
    coan source --replace --no-transients -E -K --file $ifdef_list $targetdir/lib_{com,dec,enc,isar,rend,util,debug}/!(wmc_auto*).[hc]
    coan source --replace --no-transients -E -K --file $ifdef_list $targetdir/lib_lc3plus/!(wmc_auto*).[hc]
    if [ -n "$fftdir" ]; then
        coan source --replace --no-transients -E -K --file $ifdef_list $targetdir/lib_lc3plus/fft/!(wmc_auto*).[hc]
    fi
    else
        # same as first call from if, but without "isar" and "debug" to avoid coan warning
        coan source --replace --no-transients -E -K --file $ifdef_list $targetdir/lib_{com,dec,enc,rend,util}/!(wmc_auto*).[hc]
    fi
else
    ./strip_defines_cppp.sh $targetdir $ifdef_list
fi
@@ -220,8 +222,6 @@ find $targetdir -name "*.[ch]" -exec sed -i.bak -e "s/\(0x[0-9a-fA-F]*\)UL/\(\(u
set -e
"tools/$system/wmc_tool" $wmc_opt -m "$targetdir/apps/encoder.c" "$targetdir/lib_enc/*.c" "$targetdir/lib_com/*.c" >>wmc_tool_output.txt 2>&1
"tools/$system/wmc_tool" $wmc_opt -m "$targetdir/apps/decoder.c" "$targetdir/lib_dec/*.c" "$targetdir/lib_rend/*.c" >>wmc_tool_output.txt 2>&1
# ISAR post-renderer and lc3plus sources only need to be instrumented in float code
if [ "$PROJECT" = "FLOAT" ]; then
for bak_file in $targetdir/lib_rend/*.bak; do mv "$bak_file" "${bak_file%.*}"; done # restore fresh .c files to avoid time-consuming des-instrumentation of files by the WMC tool
"tools/$system/wmc_tool" $wmc_opt -m "$targetdir/apps/renderer.c" "$targetdir/lib_rend/*.c" "$targetdir/lib_lc3plus/*.c" "$fftdir" >>wmc_tool_output.txt 2>&1
for bak_file in $targetdir/lib_lc3plus/*.bak; do mv "$bak_file" "${bak_file%.*}"; done # restore fresh .c files to avoid time-consuming des-instrumentation of files by the WMC tool
@@ -229,10 +229,6 @@ if [ "$PROJECT" = "FLOAT" ]; then
    for bak_file in $targetdir/lib_lc3plus/fft/*.bak; do mv "$bak_file" "${bak_file%.*}"; done # restore fresh .c files to avoid time-consuming des-instrumentation of files by the WMC tool
fi
"tools/$system/wmc_tool" $wmc_opt -m "$targetdir/apps/isar_post_rend.c" "$targetdir/lib_isar/*.c" "$targetdir/lib_lc3plus/*.c" "$fftdir" >>wmc_tool_output.txt 2>&1
else
    for bak_file in $targetdir/lib_rend/*.bak; do mv "$bak_file" "${bak_file%.*}"; done      # restore fresh .c files to avoid time-consuming des-instrumentation of files by the WMC tool
    "tools/$system/wmc_tool" $wmc_opt -m "$targetdir/apps/renderer.c" "$targetdir/lib_rend/*.c" >> wmc_tool_output.txt 2>&1
fi
set +e

# automatically enable #define WMOPS in options.h