Imported Upstream version 1.8.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: one-codegen [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   exit 255
38 }
39
40 function version()
41 {
42   $DRIVER_PATH/one-version one-codegen
43   exit 255
44 }
45
46 # Get command from command-line
47 BACKEND=$1
48 if [[ -z ${BACKEND} ]]; then
49   Usage
50 fi
51 shift
52
53 if [[ "${BACKEND}" == "--version" ]]; then
54   version
55 fi
56
57 BACKEND_DRIVER="${BACKEND}-compile"
58
59 BACKEND_DRIVER_CMD="${DRIVER_PATH}/${BACKEND_DRIVER}"
60
61 if [[ ! -f "${BACKEND_DRIVER_CMD}" ]]; then
62   echo "ERROR: '${BACKEND_DRIVER}' is not supported"
63   Usage
64 fi
65
66 "${BACKEND_DRIVER_CMD}" "$@"