<commit_before>#!/usr/bin/env bash

device="hx8k"
package="ct256"
family=
pcf=
dry=
aproject=
atoolchain=
verbose=
onfail=true
out_prefix=build

usage() {
    echo "Exhaustively try project-toolchain combinations"
    echo "usage: exaust.sh [args]"
    echo "--device <device>         device (default: hx8k)"
    echo "--package <package>       device package (default: ct256)"
    echo "--family <family>         device family"
    echo "--project <project>       run given project only (default: all)"
    echo "--toolchain <toolchain>   run given toolchain only (default: all)"
    echo "--pcf <pcf>               pin constraint file (default: none)"
    echo "--sdc <xdc>               constraint file (default: none)"
    echo "--xdc <xdc>               constraint file (default: none)"
    echo "--out-prefix <dir>        output directory prefix (default: build)"
    echo "--dry                     print commands, don't invoke"
    echo "--fail                    fail on error"
    echo "--verbose                 verbose output"
}

ARGS=()
while [[ $# -gt 0 ]]; do
    case "$1" in
    --device)
        device=$2
        shift
        shift
        ;;
    --package)
        package=$2
        shift
        shift
        ;;
    --family)
        family=$2
        shift
        shift
        ;;
    --pcf)
        pcf=$2
        shift
        shift
        ;;
    --sdc)
        sdc=$2
        shift
        shift
        ;;
    --xdc)
        xdc=$2
        shift
        shift
        ;;

    --dry)
        dry=echo
        shift
        ;;
    --project)
        aproject=$2
        shift
        shift
        ;;
    --toolchain)
        atoolchain=$2
        shift
        shift
        ;;
    --out-prefix)
        out_prefix=$2
        shift
        shift
        ;;
    --fail)
        onfail=false
        shift
        ;;
    --verbose)
        verbose=--verbose
        shift
        ;;
    -h|--help)
        usage
        exit 0
        ;;
    *)
        echo "Unrecognized argument"
        usage
        exit 1
        ;;
    esac
done

set -x
set -e

function run2() {
    $dry python3 fpgaperf.py --toolchain $toolchain --project "$project" --device "$device" --family "$family" --package "$package" $pcf_arg $sdc_arg $xdc_arg --out-prefix "$out_prefix" $verbose || $onfail
}

function run() {
    toolchain=$1
    project=$2

    if [ "$pcf" = "" ] ; then
        pcf_arg=""
    else
        pcf_arg="--pcf $pcf"
    fi

    if [ "$sdc" = "" ] ; then
        sdc_arg=""
    else
        sdc_arg="--sdc $sdc"
    fi

    if [ "$xdc" = "" ] ; then<commit_msg>exhaust: add logic for choosing appropriate constraint file<commit_after>#!/usr/bin/env bash

device="hx8k"
package="ct256"
family=
pcf=
dry=
aproject=
atoolchain=
verbose=
onfail=true
out_prefix=build

usage() {
    echo "Exhaustively try project-toolchain combinations"
    echo "usage: exaust.sh [args]"
    echo "--device <device>         device (default: hx8k)"
    echo "--package <package>       device package (default: ct256)"
    echo "--family <family>         device family"
    echo "--project <project>       run given project only (default: all)"
    echo "--toolchain <toolchain>   run given toolchain only (default: all)"
    echo "--pcf <pcf>               pin constraint file (default: none)"
    echo "--sdc <xdc>               constraint file (default: none)"
    echo "--xdc <xdc>               constraint file (default: none)"
    echo "--out-prefix <dir>        output directory prefix (default: build)"
    echo "--dry                     print commands, don't invoke"
    echo "--fail                    fail on error"
    echo "--verbose                 verbose output"
}

ARGS=()
while [[ $# -gt 0 ]]; do
    case "$1" in
    --device)
        device=$2
        shift
        shift
        ;;
    --package)
        package=$2
        shift
        shift
        ;;
    --family)
        family=$2
        shift
        shift
        ;;
    --pcf)
        pcf=$2
        shift
        shift
        ;;
    --sdc)
        sdc=$2
        shift
        shift
        ;;
    --xdc)
        xdc=$2
        shift
        shift
        ;;

    --dry)
        dry=echo
        shift
        ;;
    --project)
        aproject=$2
        shift
        shift
        ;;
    --toolchain)
        atoolchain=$2
        shift
        shift
        ;;
    --out-prefix)
        out_prefix=$2
        shift
        shift
        ;;
    --fail)
        onfail=false
        shift
        ;;
    --verbose)
        verbose=--verbose
        shift
        ;;
    -h|--help)
        usage
        exit 0
        ;;
    *)
        echo "Unrecognized argument"
        usage
        exit 1
        ;;
    esac
done

set -x
set -e

function run2() {
    $dry python3 fpgaperf.py --toolchain $toolchain --project "$project" --device "$device" --family "$family" --package "$package" $pcf_arg $sdc_arg $xdc_arg --out-prefix "$out_prefix" $verbose || $onfail
}

function run() {
    toolchain=$1
    project=$2

    if [ "$family" = "ice40" ] ; then
        echo "$family family currently not supported by exhaust.sh"
        exit 1
    fi

    if [ "$toolchain" != vivado ] && [ "$toolchain" != vpr ] ; then
        echo "Currently testing only vivado and vpr toolchains,  not $toolchain"
        return
    fi

    if [ "$pcf" = "" ] ; then
        if [ "$family" = "xc7" ] ; then
            if [[ "$device" == "z010" ]] ; then
                if [ "$project" = "oneblink" ] ; then
                    pcf="project/oneblink-zybo-z7.xdc"
                else
                    echo "Combination $toolchain/$family/$device/$project doesn't have PCF file defined"
                    return 0
                fi
            elif [[ "$device" == "a35t"* ]] ; then
                if [ "$project" = "oneblink" ] ; then
                    pcf="project/oneblink-arty.xdc"
                elif [ "$project" = "litex-linux" ] ; then
                    if [ "$toolchain" = "vivado" ] ; then
                        pcf="src/baselitex/baselitex_arty_vivado.xdc"
                    else
                        pcf="src/baselitex/baselitex_arty.xdc"
                    fi
                else
                    pcf="src/baselitex/arty.sdc"
                fi
            fi
        fi
    fi

    if [ "$pcf" = "" ] ; then
        pcf_arg=""
    else
        pcf_arg="--pcf $pcf"
    fi

    if [ "$sdc" = "" ] ; then
        sdc_arg=""
    else
        sdc_arg="--sdc $sdc"
    fi

    if [ "$xdc" = "" ] ; then
{'fraction_non_alphanumeric': 0.1270378345124577, 'fraction_numerical': 0.00938172869886189, 'mean_word_length': 1.3476534296028881, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3971812', 'n_tokens_mistral': 2072, 'n_tokens_neox': 1959, 'n_words': 528}