minor udpate

This commit is contained in:
Blaise Tine 2024-08-17 04:11:16 -07:00
parent 20b82fd34d
commit 8fe02093e2

View file

@ -1,18 +1,20 @@
#!/bin/bash
# Copyright © 2019-2023
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
defines=()
includes=()
externs=()
@ -21,40 +23,47 @@ output_file=""
define_header=""
top_module=""
copy_folder=""
prepropressor=0
preprocessor=0
defines_str=""
params_str=""
includes_str=""
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Helper function to append options
add_option() {
if [ -n "$1" ]; then
echo "$1 $2"
else
echo "$2"
fi
}
# parse command arguments
# Parse command arguments
while getopts D:G:T:I:J:O:H:C:Ph flag
do
case "${flag}" in
D) defines+=( ${OPTARG} )
defines_str+="-D${OPTARG} "
defines_str=$(add_option "$defines_str" "-D${OPTARG}")
;;
G) params_str+="-G${OPTARG} "
G) params_str=$(add_option "$params_str" "-G${OPTARG}")
;;
T) top_module=( ${OPTARG} )
T) top_module="${OPTARG}"
;;
I) includes+=( ${OPTARG} )
includes_str+="-I${OPTARG} "
includes_str=$(add_option "$includes_str" "-I${OPTARG}")
;;
J) externs+=( ${OPTARG} )
includes_str+="-I${OPTARG} "
includes_str=$(add_option "$includes_str" "-I${OPTARG}")
;;
O) output_file=( ${OPTARG} )
O) output_file="${OPTARG}"
;;
H) define_header=( ${OPTARG} )
H) define_header="${OPTARG}"
;;
C) copy_folder=( ${OPTARG} )
C) copy_folder="${OPTARG}"
;;
P) prepropressor=1
P) preprocessor=1
;;
h) echo "Usage: [-D<macro>] [-G<param>=<value>] [-T<top-module>] [-I<include-path>] [-J<external-path>] [-O<output-file>] [-C<dest-folder>: copy to] [-H<define_header>] [-P: macro prepropressing] [-h help]"
h) echo "Usage: [-D<macro>] [-G<param>=<value>] [-T<top-module>] [-I<include-path>] [-J<external-path>] [-O<output-file>] [-C<dest-folder>: copy to] [-H<define_header>] [-P: macro preprocessing] [-h help]"
exit 0
;;
\?) echo "Invalid option: -$OPTARG" 1>&2
@ -70,33 +79,32 @@ if [ "$define_header" != "" ]; then
# dump defines into a header file
for value in ${defines[@]}; do
arrNV=(${value//=/ })
if (( ${#arrNV[@]} > 1 ));
then
if (( ${#arrNV[@]} > 1 )); then
echo "\`define ${arrNV[0]} ${arrNV[1]}"
else
echo "\`define $value"
fi
fi
done
} > $define_header
} > "$define_header"
fi
if [ "$copy_folder" != "" ]; then
# copy source files
mkdir -p $copy_folder
# copy source files
mkdir -p "$copy_folder"
for dir in ${includes[@]}; do
find "$dir" -maxdepth 1 -type f | while read -r file; do
file_ext="${file##*.}"
file_name=$(basename -- $file)
if [ $prepropressor != 0 ] && { [ "$file_ext" == "v" ] || [ "$file_ext" == "sv" ]; }; then
file_name=$(basename -- "$file")
if [ $preprocessor != 0 ] && { [ "$file_ext" == "v" ] || [ "$file_ext" == "sv" ]; }; then
if [[ -n "$params_str" && $file_name == "$top_module."* ]]; then
temp_file=$(mktemp)
$script_dir/repl_params.py $params_str -T$top_module $file > $temp_file
verilator $defines_str $includes_str -E -P $temp_file > $copy_folder/$file_name
"$SCRIPT_DIR/repl_params.py" "$params_str" -T"$top_module" "$file" > "$temp_file"
verilator "$defines_str" "$includes_str" -E -P "$temp_file" > "$copy_folder/$file_name"
else
verilator $defines_str $includes_str -E -P $file > $copy_folder/$file_name
fi
verilator "$defines_str" "$includes_str" -E -P "$file" > "$copy_folder/$file_name"
fi
else
cp $file $copy_folder
cp "$file" "$copy_folder"
fi
done
done
@ -112,7 +120,7 @@ if [ "$output_file" != "" ]; then
fi
for dir in ${externs[@]}; do
echo "+incdir+$(realpath $dir)"
echo "+incdir+$(realpath "$dir")"
done
for dir in ${externs[@]}; do
@ -124,24 +132,24 @@ if [ "$output_file" != "" ]; then
if [ "$copy_folder" != "" ]; then
# dump include directories
echo "+incdir+$(realpath $copy_folder)"
echo "+incdir+$(realpath "$copy_folder")"
# dump source files
find "$(realpath $copy_folder)" -maxdepth 1 -type f -name "*_pkg.sv" -print
find "$(realpath $copy_folder)" -maxdepth 1 -type f \( -name "*.v" -o -name "*.sv" \) ! -name "*_pkg.sv" -print
find "$(realpath "$copy_folder")" -maxdepth 1 -type f -name "*_pkg.sv" -print
find "$(realpath "$copy_folder")" -maxdepth 1 -type f \( -name "*.v" -o -name "*.sv" \) ! -name "*_pkg.sv" -print
else
# dump include directories
for dir in ${includes[@]}; do
echo "+incdir+$(realpath $dir)"
echo "+incdir+$(realpath "$dir")"
done
# dump source files
for dir in ${includes[@]}; do
find "$(realpath $dir)" -maxdepth 1 -type f -name "*_pkg.sv" -print
find "$(realpath "$dir")" -maxdepth 1 -type f -name "*_pkg.sv" -print
done
for dir in ${includes[@]}; do
find "$(realpath $dir)" -maxdepth 1 -type f \( -name "*.v" -o -name "*.sv" \) ! -name "*_pkg.sv" -print
find "$(realpath "$dir")" -maxdepth 1 -type f \( -name "*.v" -o -name "*.sv" \) ! -name "*_pkg.sv" -print
done
fi
} > $output_file
fi
} > "$output_file"
fi