Commit 441c57ac authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

add instrumentation scripts

parent d18cbee3
Loading
Loading
Loading
Loading
+248 −0
Original line number Diff line number Diff line
#!/bin/bash

#
#   (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
#   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
#   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
#   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
#   contributors to this repository. All Rights Reserved.
#
#   This software is protected by copyright law and by international treaties.
#   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
#   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
#   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
#   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
#   contributors to this repository retain full ownership rights in their respective contributions in
#   the software. This notice grants no license of any kind, including but not limited to patent
#   license, nor is any license granted by implication, estoppel or otherwise.
#
#   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
#   contributions.
#
#   This software is provided "AS IS", without any express or implied warranties. The software is in the
#   development stage. It is intended exclusively for experts who have experience with such software and
#   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
#   and fitness for a particular purpose are hereby disclaimed and excluded.
#
#   Any dispute, controversy or claim arising under or in relation to providing this software shall be
#   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
#   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
#   the United Nations Convention on Contracts on the International Sales of Goods.
#

# Simple script to format or check formatting of your working copy before you commit to the SVN
# for questions: dla@iis.fhg.de

if [ ! -d "lib_com" ]; then
    echo "not in root directory! - please run in IVAS root"
    exit 255
fi

CLANG_FORMAT=clang-format
CLANG_FORMAT_REQUIRED_VERSION="13.0" 

# list (with space between entries) of substrings that are excluded from the file list, e.g. very large files
EXCLUDE_FILES="ivas_rom_binaural_crend_head.c"

NUMPROCS=1

function usage() {
    cat <<EOM
Usage: $(basename "$0") [OPTIONS] [FILES]
  -f          format code
  -a          check all files
  -c          color
  -D          don't show diff
  -V          no version check
  -e EXE      custom clang-format EXE (instead of 'clang-format')
  -p NUMPROCS run in parallel 
  -h          display help
EOM
    exit 254
}

cl-format-check-version() {
    ${CLANG_FORMAT} --version | sed 's/.*version \([1-9]*\.[0-9]*\).*/\1/'
}

cl-format-apply() {
    ${CLANG_FORMAT} -i $1
}

ensure-one-newline()
{
    # first command adds a newline at the end of the file if there might be none
    # -> clang-format-13 does not add them and warnings e.g. on MacOS are triggered by them
    sed -i -e '$a\' $1
    # second command removes multiple newlines at the end of a file so that there is only one left
    # -> clang-format-13 does not do that, but complains about it
    sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' $1
}

cl-format-check() {
    local I=$1
    local COLOR=$2
    local RED=""
    local GREEN=""
    local DEFAULT=""

    if [[ $NUMPROCS -lt 2 ]]; then
        printf '%-50s' $I
    fi

    if [ $COLOR ]; then
        RED="\e[41m"
        GREEN="\e[42m"
        DEFAULT="\e[49m"
    fi

    local O=$(${CLANG_FORMAT} $I)
    local DIFF=$(diff $I <(echo "$O"))

    if [[ $NUMPROCS -ge 2 ]]; then
        printf '%-50s' $I
    fi

    if [ "$DIFF" != "" ]; then
        printf '[%bFAIL%b]\n' $RED $DEFAULT
        if [ ! $NODIFF ]; then
            DIFF=$(diff -u $I <(echo "$O"))
            if [ $COLOR ]; then
                if [[ "$OSTYPE" == "darwin"* ]]; then
                   echo "$DIFF" | sed "s/^-/`echo -e \"\x1b\"`[41m-/;s/^+/`echo -e \"\x1b\"`[42m+/;s/^@/`echo -e \"\x1b\"`[34m@/;s/$/`echo -e \"\x1b\"`[0m/"
                else
                    echo "$DIFF" | sed 's/^-/\x1b[41m-/;s/^+/\x1b[42m+/;s/^@/\x1b[34m@/;s/$/\x1b[0m/'
                fi
            else
                echo "$DIFF"
            fi
        fi
        return 1
    else
        printf '[%bOK%b]\n' $GREEN $DEFAULT
        return 0
    fi
}

while getopts "facDVe:p:h" OPTIONS; do
    case ${OPTIONS} in
    f)
        FORMAT=true
        ;;
    a)
        ALL=true
        ;;
    c)
        COLOR=true
        ;;
    D)
        NODIFF=true
        ;;
    V)
        NOVERSION=true
        ;;
    e)
        CLANG_FORMAT=$OPTARG
        ;;
    p)
        NUMPROCS=$OPTARG
        ;;
    h | *)
        usage
        ;;
    esac
done
shift $((OPTIND-1))
FILES="$@"

if [ ! -d "lib_com" ]; then
    echo "not in root directory! - please run in IVAS root"
    exit 253
fi

if [ ! $NOVERSION ]; then
    if [[ $(cl-format-check-version) != "${CLANG_FORMAT_REQUIRED_VERSION}"* ]]; then
        echo "clang-format must be version ${CLANG_FORMAT_REQUIRED_VERSION} but is $(cl-format-check-version) !!!"
        echo "Executables for Win32 could be downloaded from https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/LLVM-13.0.1-win32.exe"
        exit 252
    fi
fi

if [ -z "$FILES" ]; then
    if [ $ALL ]; then
        FILES=$(ls lib_com/*.[c,h] lib_dec/*.[c,h] lib_enc/*.[c,h] lib_isar/*.[c,h] lib_rend/*.[c,h] lib_util/*.[c,h] apps/*.[c,h])
    elif [ -d ".svn" ]; then
        if [ ! -x "$(command -v svn)" ]; then
            echo "Subversion doesn't seem to be installed. Please ensure svn is in your PATH"
            exit 251
        fi
        if [[ "$OSTYPE" == "darwin"* ]]; then
            FILES=$(svn st | grep '^M' | cut -b 9- | grep -E "\.c|\.h")
        else
            FILES=$(svn st | grep '^M' | cut -b 9- | grep '\.c$\|\.h$')
        fi
    elif [ -d ".git" ]; then
        if [ ! -x "$(command -v git)" ]; then
            echo "GIT doesn't seem to be installed. Please ensure git is in your PATH"
            exit 251
        fi
        if [[ "$OSTYPE" == "darwin"* ]]; then
            FILES=$(git status | grep 'modified: ' | cut -b 14- | grep -E "\.c|\.h")
        else
            FILES=$(git status | grep 'modified: ' | cut -b 14- | grep '\.c$\|\.h$')
        fi
    else
        echo "Warning: no files checked (either no cmdl params or no modified files)"
        exit 0
    fi
    for i in ${EXCLUDE_FILES}; do
        FILES=$(echo ${FILES} | xargs -n 1 | grep -v ${i} | tr '\n' ' ')
    done
fi

if [[ $NUMPROCS -lt 2 ]]; then
    NUMFAILS=0
    for i in ${FILES}; do
        cl-format-check $i $COLOR
        RET=$?
        ((NUMFAILS+=RET))
        if [ $FORMAT ]; then
            ensure-one-newline $i
            cl-format-apply $i
        fi
    done
    if [[ $NUMFAILS -gt 0 ]]; then
        echo "Total fails:  $NUMFAILS"
#        exit $NUMFAILS  ## uncomment if script should have num fails as return code
    fi
else
    NUMFAILS=0
    NUMFAILSTMPFILE=$(mktemp)
    # parallel processing. Note that return code is always 0 then and fails are not counted
    for i in ${FILES}; do
        (
        cl-format-check $i $COLOR
        RET=$?
        if [[ $RET -gt 0 ]]
        then
            echo "1" >> "$NUMFAILSTMPFILE"
        fi
        ((NUMFAILS+=RET))
        if [ $FORMAT ]; then
            ensure-one-newline $i
            cl-format-apply $i
        fi ) &
        while [[ $(jobs -r -p | wc -l) -ge $NUMPROCS ]];do
            sleep 0.1
        done
    done
    wait
    NUMFAILS=`cat $NUMFAILSTMPFILE | wc -l`
    rm "$NUMFAILSTMPFILE"
    if [[ $NUMFAILS -gt 0 ]]; then
        echo "Total fails:  $NUMFAILS"
        exit $NUMFAILS  ## uncomment if script should have num fails as return code
    fi
fi

exit 0
+85 −0
Original line number Diff line number Diff line
-UDEBUGGING
-DSUPPORT_JBM_TRACEFILE
-DNON_BE_FIX_1048_THRESHOLD_COH_BASOP
-DNONBE_FIX_1054_NEGATIVE_LVQ_INDEX
-DNONBE_FIX_738_QUATERNION_SLERP_PRECISION
-DFIX_1033_MEMORY_LEAK_OMASA
-DFIX_976_USAN_PVQ_ENC_DEC_EVS_CR
-DFIX_1027_GSC_INT_OVERFLOW
-DNONBE_FIX_1096_NAN_VALUES_IN_DIRAC_TO_STEREO
-DNON_BE_1055_RESET_LP_MEMORIES
-DNONBE_FIX_1069_SVD_TUNING
-DNONBE_FIX_1010_STEREO_CNG_DIV_BY_ZERO
-DNONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES
-DNONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID
-DNON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING
-DNONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE
-DFIX_BASOP_812_NAN_COHSNR
-DNON_BE_FIX_807_MASA_DTX_BRSW
-DNON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL
-DFIX_828_PORT_1152_FROM_FLT_REPO
-DNONE_BE_FIX_816_LFE_PLC_FLOAT
-DFIX_835_PARAMMC_BUFFER_VALUES
-DNONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST
-DFIX_903_ZERO_OUT_IMDCT_BUFFERS_FOR_MCT_IGNORE
-DFIX_853_DECODE_MASA_ISM_AZIMUTH_PREC_FP
-DBASOP_NOGLOB
-UDEBUGGING
-UWMOPS_PER_FRAME
-UWMOPS_DETAIL
-UWMOPS_WC_FRAME_ANALYSIS
-UDISABLE_DFT_STEREO_ASSERT
-UDEBUG_MODE_INFO
-UDEBUG_MODE_ACELP
-UDEBUG_MODE_TCX
-UDEBUG_MODE_DFT
-UDEBUG_MODE_TD
-UDEBUG_MODE_DIRAC
-UDEBUG_MODE_MDCT
-UDEBUG_MODE_PARAM_MC
-UDEBUG_MODE_PARAM_ISM
-UDEBUG_MODE_INFO_TWEAK
-UDEBUG_MODE_INFO_PLC
-UDEBUG_MODE_INFO_ALLRAD
-UDEBUG_MODE_LFE
-UDEBUG_PLOT_BITS
-UENABLE_BITRATE_VERIFICATION
-UDEBUG_PLOT
-UALLOW_BYTE_EP
-UWRAP_AS_EIDXOR
-UDEBUG_FORCE_MDCT_STEREO_MODE
-UDEBUG_STEREO_DFT_NOCORE
-UDEBUG_STEREO_DFT_NOSTEREO
-UDEBUG_STEREO_DFT_NOQRES
-UDEBUG_STEREO_DFT_OUTRESPRED
-UDEBUG_DISABLE_DIRAC_DELAY_COMP
-UDEBUG_BS_READ_WRITE
-UDEBUG_MODE_DIRAC_NOCORE
-UDEBUG_MODE_QMETADATA
-UDEBUG_FORCE_MCT_CP
-UDEBUG_SINGLE_CODE_OMNI
-UDEBUG_NO_TONAL_PLC
-UDEBUG_NO_TD_TCX_PLC
-UDEBUG_FORCE_TD_TCX_CONCEALMENT
-UDEBUG_PLC_INFO
-UDEBUG_EFAP_POLY_TOFILE
-UTDREND_HRTF_TABLE_METHODS
-UTDREND_STANDALONE
-UDEBUG_SBA
-UDEBUG_LBR_SBA
-UDEBUG_SBA_AUDIO_DUMP
-UDEBUG_SBA_MD_DUMP
-UDEBUG_SPAR_MD_TARGET_TUNING
-UDEBUG_SPAR_BYPASS_EVS_CODEC
-UDEBUG_SPAR_WRITE_OUT_COV
-UDEBUG_SPAR_DIRAC_WRITE_OUT_PRED_PARS
-UDEBUG_AGC
-USPAR_HOA_DBG
-UDEBUG_OSBA
-UDEBUG_BINAURAL_FILTER_DESIGN
-UDEBUG_AGC_ENCODER_CMD_OPTION
-UDEBUG_JBM_CMD_OPTION
-UVARIABLE_SPEED_DECODING
-UDBG_WAV_WRITER
-USPLIT_POSE_CORRECTION_DEBUG
-USPLIT_MD_CODING_DEBUG
+167 −0
Original line number Diff line number Diff line
#!/bin/bash

#
#   (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
#   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
#   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
#   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
#   contributors to this repository. All Rights Reserved.
#
#   This software is protected by copyright law and by international treaties.
#   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
#   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
#   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
#   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
#   contributors to this repository retain full ownership rights in their respective contributions in
#   the software. This notice grants no license of any kind, including but not limited to patent
#   license, nor is any license granted by implication, estoppel or otherwise.
#
#   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
#   contributions.
#
#   This software is provided "AS IS", without any express or implied warranties. The software is in the
#   development stage. It is intended exclusively for experts who have experience with such software and
#   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
#   and fitness for a particular purpose are hereby disclaimed and excluded.
#
#   Any dispute, controversy or claim arising under or in relation to providing this software shall be
#   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
#   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
#   the United Nations Convention on Contracts on the International Sales of Goods.
#

help=0
coan=0
opt_cnt=0

while getopts "hc" OPT; do
  case "$OPT" in
    h) help=1;;
    c) coan=1;let opt_cnt++;;
    *) # getopts produces error
       exit 1;;
  esac
done

let max_args="1+$opt_cnt"
if [ $# -ne $max_args ] || [ $help -ne 0 ]; then
  echo "Usage: $0 [-c] inputfile"
  echo "       -c: coan syntax at output"
  exit
fi

infile=$BASH_ARGV 

activeSwitches=( );
inactiveSwitches=( );

if_lev=0
comment_lev=0
comment_incr_post=0
comment_decr_post=0

declare -i active_code=( "1" );

while read line
do

  #check, whether we are in a comment block
  comment_incr=`echo "$line" | grep -o "\(\/\*\|\*\/\)" | grep "\/\*" | wc -l`
  comment_decr=`echo "$line" | grep -o "\(\/\*\|\*\/\)" | grep "\*\/" | wc -l`
  tmp=`echo "$line" | grep -c "^\ *#"`
  if [ $comment_incr -gt $comment_decr -a $tmp -gt 0 ]; then
      let comment_incr--
      comment_incr_post_tmp=1
  fi
  if [ $comment_decr -gt $comment_incr -a $tmp -gt 0 ]; then
      let comment_decr--
      comment_decr_post_tmp=1
  fi
  let incr=comment_incr+comment_incr_post
  let comment_lev+=incr
  let decr=comment_decr+comment_decr_post
  let comment_lev-=decr
  comment_incr_post=$comment_incr_post_tmp
  comment_decr_post=$comment_decr_post_tmp

  if [ $comment_lev -eq 0 ]; then 

    if [ `echo "$line" | grep -c "^\ *#if"` -gt 0 ]; then
      is_active=${active_code[$if_lev]}
      let if_lev++
      tmp=1
      if [ $is_active -eq 1 ]; then
        if [ `echo "$line" | grep -c "#if\ *0"` -gt 0 ]; then
            tmp=0
        fi

        if [ `echo "$line" | grep -c "#ifdef"` -gt 0 ]; then
          switch=`echo "$line" | sed -e "s/\(\ *#ifdef\ *\)\([a-zA-Z0-9_]*\)\(.*\)/\2/g"`
          if [[ " ${activeSwitches[@]} " =~ " ${switch} " ]]; then
            tmp=1
          else
            tmp=0
          fi
        fi

        if [ `echo "$line" | grep -c "#ifndef"` -gt 0 ]; then
          switch=`echo "$line" | sed -e "s/\(\ *#ifndef\ *\)\([a-zA-Z0-9_]*\)\(.*\)/\2/g"`
          if [[ " ${activeSwitches[@]} " =~ " ${switch} " ]]; then
            tmp=0
          else
            tmp=1
          fi
        fi        

        if [ `echo "$line" | grep -c "#if\ *[!(]*defined"` -gt 0 ]; then
          echo "$0: #if defined or similar expressions not supported. Aborting." 1>&2
          exit -1;
        fi

      else
        tmp=0
      fi
      active_code=( ${active_code[@]} $tmp )
    fi

    if [ `echo "$line" | grep -c "#endif"` -gt 0 ]; then
      unset active_code[$if_lev]
      let if_lev--
    fi

  fi

  active=`echo "$line" | grep '^\ *#define' | sed -e "s/\(\ *#define\ *\)\([a-zA-Z0-9_]*\)\(.*\)/\2/g" | sed -e "/OPTIONS_H/d" | sed -e "/DEBUGGING/d"`
  # support both, /* ... */ and // style comments
  inactive=`echo "$line" | grep '^\ *\(\/\*\|\/\/\)\{1,\}\ *#define' | sed -e "s/\(.*#define\ *\)\([a-zA-Z0-9_]*\)\(.*\)/\2/g" | sed -e '/^WMOPS$/d'`

  if [ ${comment_lev} -eq 0 -a ${active_code[$if_lev]} -eq 1 ]; then
      activeSwitches=( "${activeSwitches[@]}" $active )
  elif [[ ! " ${activeSwitches[@]} " =~ "${active} "  ]]; then
      inactiveSwitches=( "${inactiveSwitches[@]}" $active )
  fi
  inactiveSwitches=( "${inactiveSwitches[@]}" $inactive )
done < $infile

keyActive="+"
keyInactive=""
if [ $coan -ne 0 ]; then
  keyActive="-D"
  keyInactive="-U"
fi

# print active switches
index=0
while [ "$index" -lt ${#activeSwitches[@]} ]
do    # List all the elements in the array.
  echo "${keyActive}${activeSwitches[index]}"
  let index++
done

# print inactive switches
index=0
while [ "$index" -lt ${#inactiveSwitches[@]} ]
do    # List all the elements in the array.
  echo "${keyInactive}${inactiveSwitches[index]}"
  let index++
done
+203 −0
Original line number Diff line number Diff line
#!/bin/bash

#
#   (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
#   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
#   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
#   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
#   contributors to this repository. All Rights Reserved.
#
#   This software is protected by copyright law and by international treaties.
#   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
#   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
#   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
#   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
#   contributors to this repository retain full ownership rights in their respective contributions in
#   the software. This notice grants no license of any kind, including but not limited to patent
#   license, nor is any license granted by implication, estoppel or otherwise.
#
#   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
#   contributions.
#
#   This software is provided "AS IS", without any express or implied warranties. The software is in the
#   development stage. It is intended exclusively for experts who have experience with such software and
#   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
#   and fitness for a particular purpose are hereby disclaimed and excluded.
#
#   Any dispute, controversy or claim arising under or in relation to providing this software shall be
#   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
#   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
#   the United Nations Convention on Contracts on the International Sales of Goods.
#

function usage {
    echo
    echo "Usage:"
    echo "      $(basename $0) [OPTIONS]"
    echo 
    echo "      -m MODE    one of [FULL|MEM_ONLY]"
    echo "      -p PROJECT one of [FLOAT|BASOP]"
    exit
}


# default values
MODE="MEM_ONLY"
PROJECT="BASOP"

while getopts "m:p:h" OPTIONS; do
    case ${OPTIONS} in
    m)
        MODE=${OPTARG^^}
        if [ "$MODE" != "FULL" -a "$MODE" != "MEM_ONLY" ]; then
            usage
        fi
        ;;
    p)
        PROJECT=${OPTARG^^}
        if [ "$PROJECT" != "FLOAT" -a "$PROJECT" != "BASOP" ]; then
            usage
        fi
        ;;
    h | *)
        usage
        ;;
    esac
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="Linux"
fi

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

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

if ! (coan_exists || cppp_exists); then
    echo "Neither coan (recommended) nor cppp could be found. Requires either coan or cppp to operate properly. Exiting."
    echo "Coan is available from http://coan2.sourceforge.net/; please make it available in your path"
    echo "cppp is available from https://homes.cs.washington.edu/~mernst/software/#cppp; please copy to directory scripts/cppp"
    exit -1
fi

targetdir=c-code_instrument

currdir=`pwd`
scriptdir=`dirname $0`
ifdef_list=ifdef_instrument.list
sourcedir=$scriptdir/..
cd $scriptdir

rm -Rf $targetdir
mkdir $targetdir

# copy files from source-dir
cp -R ../lib_* $targetdir
cp -R ../apps $targetdir
cp -R ../Makefile $targetdir
if [ "$PROJECT" = "FLOAT" ]; then
    cp -R ../CMakeLists.txt $targetdir
fi
cp -R ../Workspace_msvc $targetdir

# back up #ifdef-list
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=$(
        gcc -E -dM $targetdir/lib_lc3plus/defines.h -I $targetdir/lib_com -I $targetdir/lib_debug |
            sed '/^#define [[:alnum:]][[:alnum:]_]\+[[:space:]]*$/! d' |
            sed '/#define DEFINES_H/ d'
    )

    # 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'`
       if grep -wqF "$line" "$targetdir/lib_lc3plus/defines.h"; then
           lc3plus_defines_filtered+=$line$'\n'
       fi
    done <<< $lc3plus_defines

    # Append LC3plus defines to options.h
    echo "
    /* LC3plus switches */
    #ifndef OPTIONS_H_LC3_DEFINES
    #define OPTIONS_H_LC3_DEFINES
    $lc3plus_defines_filtered
    #endif /* OPTIONS_H_LC3_DEFINES */
    " >>$targetdir/lib_com/options.h
fi

# get switches from options.h and append it to $ifdef_list
parse_options_opt=""
if coan_exists; then
    echo "-UDEBUGGING" >> $ifdef_list
    parse_options_opt="-c"
else
    echo "DEBUGGING" >> $ifdef_list
fi
./parse_options_h.sh $parse_options_opt $targetdir/lib_com/options.h >> $ifdef_list
if [ $? -ne 0 ]; then
    exit -1
fi

# strip switches, to remove the macros (turn on extended globing to allow !(pattern*) matching)
shopt -s extglob
if coan_exists; then
    # remove WMOPS and MEM_COUNT_DETAILS from the list to preserve the options in the instrumented code
    sed -i "/-DWMOPS/d" $ifdef_list
	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]
        coan source --replace --no-transients -E -K --file $ifdef_list $targetdir/lib_lc3plus/fft/!(wmc_auto*).[hc]
    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
shopt -u extglob

# patch code before wmc_tool: replace hexadecimal unsigned long constants (0x...UL) by regular integer constant + cast to unsigned long
find $targetdir -name "*.[ch]" -exec sed -i.bak -e "s/\(0x[0-9a-fA-F]*\)UL/\(\(unsigned long\)\1\)/" \{\} \;

# run wmc_tool
"tools/$system/wmc_tool" $wmc_opt -m "$targetdir/apps/encoder.c" "$targetdir/lib_enc/*.c" "$targetdir/lib_com/*.c"  >> /dev/null
"tools/$system/wmc_tool" $wmc_opt -m "$targetdir/apps/decoder.c" "$targetdir/lib_dec/*.c" "$targetdir/lib_rend/*.c" >> /dev/null
# ISAR post-renderer and lc3plus sources only need to be instrumented in float code
if [ "$PROJECT" = "FLOAT" ]; then
    "tools/$system/wmc_tool" $wmc_opt -m "$targetdir/apps/renderer.c" "$targetdir/lib_rend/*.c" "$targetdir/lib_lc3plus/*.c" "$targetdir/lib_lc3plus/fft/*.c" >> /dev/null
    "tools/$system/wmc_tool" $wmc_opt -m "$targetdir/apps/isar_post_rend.c" "$targetdir/lib_isar/*.c" "$targetdir/lib_lc3plus/*.c" "$targetdir/lib_lc3plus/fft/*.c" >> /dev/null
else
    "tools/$system/wmc_tool" $wmc_opt -m "$targetdir/apps/renderer.c" "$targetdir/lib_rend/*.c" >> /dev/null
fi

# automatically enable #define WMOPS in options.h
sed -i.bak -e "s/\/\*[[:space:]]*\(#define[[:space:]]*WMOPS\)[[:space:]]*\*\//\1/g" $targetdir/lib_com/options.h
sed -i.bak -e "s/\/\/[[:space:]]*\(#define[[:space:]]*WMOPS\)/\1/g"        $targetdir/lib_com/options.h

# return to start dir
cd "$currdir"
+33 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading