1 # Copyright 2016, The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 #!/bin/bash 16 17 ME=$0 18 19 function usage { 20 echo >&2 "$ME: $*: Expected [-d|--dump] [-t|--trace] <SPIRV_TOOLS_PATH> <SCRIPT_NAME> <OUTPUT_DIR>)" 21 exit 2 22 } 23 24 function dump { 25 if [[ -z "${DUMP:-}" ]] ; then 26 return 0 27 fi 28 eval rs2spirv "$output_folder/$script.spv" -print-as-words 29 return $? 30 } 31 32 DUMP= 33 TRACE= 34 35 while [[ "${1:-}" = -* ]] ; do 36 case "$1" in 37 -d|--dump) 38 DUMP=t 39 ;; 40 -t|--trace) 41 TRACE=t 42 ;; 43 *) 44 usage "Unexpected option \"$1\"" 45 ;; 46 esac 47 shift 48 done 49 50 if [[ $# -ne 3 ]] ; then 51 usage "Bad argument count (got $#)" 52 fi 53 54 if [[ -n "${TRACE:-}" ]] ; then 55 set -x 56 fi 57 58 AND_HOME=$ANDROID_BUILD_TOP 59 SPIRV_TOOLS_PATH=$1 60 61 script_name="$2" 62 script=`basename ${2%.*}` # Remove enclosing directories and extension. 63 64 output_folder="$3" 65 mkdir -p $output_folder 66 67 eval llvm-rs-cc -o "$output_folder" -S -emit-llvm -Wall -Werror -target-api 24 \ 68 -I "$AND_HOME/external/clang/lib/Headers" -I "$AND_HOME/frameworks/rs/script_api/include" \ 69 "$script_name" && 70 eval llvm-as "$output_folder/bc32/$script.ll" -o "$output_folder/$script.bc" && 71 eval rs2spirv "$output_folder/$script.bc" -o "$output_folder/$script.spv" && 72 dump && 73 eval "$SPIRV_TOOLS_PATH/spirv-val" "$output_folder/$script.spv" && 74 75 exit $? 76