Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / one-cmds / one-codegen
1 #!/bin/bash
2
3 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #    http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 DRIVER_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
18
19 function Usage()
20 {
21   echo "Usage: $0 [BACKEND] ..."
22   echo "Available BACKEND drivers:"
23   backend_exist=0
24   for file in `find $DRIVER_PATH -name *-compile -type f`;
25   do
26     backend_driver=$(basename $file)
27     sub_length=8
28     driver_length=$(expr ${#backend_driver} - ${sub_length})
29     backend=${backend_driver:0:${driver_length}} # 8 is length of "-compile"
30     echo "  $backend"
31     backend_exist=1
32   done
33   if [ $backend_exist == 0 ]; then
34     echo "  (There is no available backend drivers)"
35   fi
36 }
37
38 # Get command from command-line
39 BACKEND=$1; shift
40 BACKEND_DRIVER="$BACKEND-compile"
41
42 if [[ -z "${BACKEND_DRIVER}" ]]; then
43   Usage
44   exit 255
45 fi
46
47 BACKEND_DRIVER_CMD="${DRIVER_PATH}/${BACKEND_DRIVER}"
48
49 if [[ ! -f "${BACKEND_DRIVER_CMD}" ]]; then
50   echo "ERROR: '${BACKEND_DRIVER}' is not supported"
51   Usage
52   exit 255
53 fi
54
55 "${BACKEND_DRIVER_CMD}" "$@"