aboutsummaryrefslogtreecommitdiffstats
path: root/fpga/usrp3/tools/scripts/launch_vlint.sh
blob: c8d9b1d630ed9b3593c2b0624264d34ea510f3b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash

#------------------------------------------
# Colorize
#------------------------------------------

# VIV_COLOR_SCHEME must be defined in the environment setup script
case "$VIV_COLOR_SCHEME" in
    default)
        CLR_OFF='tput sgr0'
        ERR_CLR='tput setaf 1'
        CRIWARN_CLR='tput setaf 1'
        WARN_CLR='tput setaf 3'
        ;;
    *)
        CLR_OFF=''
        ERR_CLR=$CLR_OFF
        CRIWARN_CLR=$CLR_OFF
        WARN_CLR=$CLR_OFF
esac

# Display output string colorized
function print_color {
    case $line in
        *Fatal:*)
            eval $ERR_CLR; echo "$line"; eval $CLR_OFF
            ;;
        *Error:*|*Error[[:space:]]\(suppressible\):*)
            eval $ERR_CLR; echo "$line"; eval $CLR_OFF
            ;;
        *Warning:*)
            eval $WARN_CLR; echo "$line"; eval $CLR_OFF
            ;;
        *)
            echo "$line"
    esac
}

#------------------------------------------
# Functions
#------------------------------------------

# Replace any directories with the files they include
function replace_dirs_with_source {
    for file in "$@"
    do
        if [ -d $file ]; then
            echo "$(realpath $(find $file -maxdepth 1 -type f)) "
        else
            echo "$file "
        fi
    done
}

#------------------------------------------
# Initialize Variables
#------------------------------------------

WORKING_DIR=$(pwd)

# Use specified modelsim.ini, if set
if [[ -z $VLINT_MODELSIM_INI ]]; then
    MODELSIMINI_ARG=""
else
    MODELSIMINI_ARG="-modelsimini $VLINT_MODELSIM_INI"
fi

# Define arguments to pass to the compile
SVLOG_ARGS="$VLINT_SVLOG_ARGS $MODELSIMINI_ARG -quiet +define+WORKING_DIR=$WORKING_DIR"
VLOG_ARGS="$VLINT_VLOG_ARGS $MODELSIMINI_ARG -quiet +define+WORKING_DIR=$WORKING_DIR"
VHDL_ARGS="$VLINT_VHDL_ARGS $MODELSIMINI_ARG -quiet"

# Define files in which to store all the compiler arguments
SV_ARGS_FILE=svlogarglist.txt
V_ARGS_FILE=vlogarglist.txt
VHD_ARGS_FILE=vcomarglist.txt

# Replace any directories with the sources they contain
SOURCES=
SOURCES+=$(replace_dirs_with_source $VLINT_INC_SRCS)
SOURCES+=$(replace_dirs_with_source $VLINT_DESIGN_SRCS)
SOURCES+=$(replace_dirs_with_source $VLINT_SIM_SRCS)

# Separate the files by type and determine include directories to use
V_FILES=
SV_FILES=
VHDL_FILES=
V_INC=
for file in $SOURCES
do
    if [[ ${file: -3} == ".sv" ]]; then
        SV_FILES+="$file "
        V_INC+="+incdir+${file%/*}/ "
    elif [[ ${file: -2} == ".v" ]]; then
        V_FILES+="$file "
        V_INC+="+incdir+${file%/*}/ "
    elif [[ ${file: -3} == ".vh" || ${file: -4} == ".svh" ]]; then
        V_INC+="+incdir+${file%/*}/ "
    elif [[ ${file: -4} == ".vhd" ]]; then
        VHD_FILES+="$file "
    fi
done

# Remove duplicates from the lists of files and directories
SV_FILES=$(printf '%s\n' $SV_FILES | awk '!a[$0]++')
V_FILES=$(printf '%s\n' $V_FILES | awk '!a[$0]++')
VHD_FILES=$(printf '%s\n' $VHD_FILES | awk '!a[$0]++')
V_INC=$(printf '%s\n' $V_INC | awk '!a[$0]++')

#------------------------------------------
# Compile HDL
#------------------------------------------

# Generate argument files
mkdir -p ./$VLINT_PROJ_DIR
cd ./$VLINT_PROJ_DIR

echo "/* Auto generated argument file for vlog -sv */" > $SV_ARGS_FILE
echo "-sv" >> $SV_ARGS_FILE
printf '%s\n'  $V_INC $SV_FILES >> $SV_ARGS_FILE

echo "/* Auto generated argument file for vlog -v */" > $V_ARGS_FILE
echo "-vlog01compat" >> $V_ARGS_FILE
printf '%s\n' $V_INC $V_FILES >> $V_ARGS_FILE

echo "/* Auto generated argument file for vcom */" > $VHD_ARGS_FILE
echo "-2008" >> $VHD_ARGS_FILE
printf '%s\n' $VHD_FILES >> $VHD_ARGS_FILE

# Run ModelSim compiler for each file type
if [[ -n "$SV_FILES" ]]; then
    echo "* Compiling SystemVerilog"
    vlog $SVLOG_ARGS -sv -f svlogarglist.txt 2>&1 | while IFS= read -r line; do
        print_color $line
    done
    exit_status=${PIPESTATUS[0]}
    if [ ${exit_status} -ne 0 ]; then exit ${exit_status}; fi
fi
if [[ -n "$V_FILES" ]]; then
    echo "* Compiling Verilog"
    vlog $VLOG_ARGS -f vlogarglist.txt 2>&1 | while IFS= read -r line; do
        print_color $line
    done
    exit_status=${PIPESTATUS[0]}
    if [ ${exit_status} -ne 0 ]; then exit ${exit_status}; fi
fi
if [[ -n "$VHD_FILES" ]]; then
    echo "* Compiling VHDL"
    vcom $VHDL_ARGS -f vcomarglist.txt 2>&1 | while IFS= read -r line; do
        print_color $line
    done
    exit_status=${PIPESTATUS[0]}
    if [ ${exit_status} -ne 0 ]; then exit ${exit_status}; fi
fi