mirror of
https://github.com/apache/impala.git
synced 2025-12-19 09:58:28 -05:00
Change build files to generate and compile C++ file with LLVM IR as C array. The LLVM IR files are now generated as a dependency of the codegen module, rather than separately. The IR files are kept in the same location as before, but are not required at runtime. Also change suffix from .ll (which is meant to be for the human-readable text IR) to .bc (the correct extension for LLVM bitcode). Includes a modified script file2array.sh from the Apache-licensed Swift/T project that generates a valid C++ source file with binary data encoded as an array variable. Also enable and fix CMake rules to generate the IR metadata, instead of doing it in make_impala.sh. Change-Id: I432f5aa42f88b614af3339a465893c557192bbd5 Reviewed-on: http://gerrit.cloudera.org:8080/1387 Tested-by: Internal Jenkins Reviewed-by: Martin Grund <mgrund@cloudera.com>
104 lines
2.5 KiB
Bash
Executable File
104 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Copyright 2015 Cloudera Inc.
|
|
# Copyright 2013 University of Chicago and Argonne National Laboratory
|
|
#
|
|
# 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
|
|
|
|
# Convert file to a C array with provided name.
|
|
#
|
|
# Also produce length variable of type size_t with _len suffix.
|
|
#
|
|
# We add an extra null byte on the end of the array, which is not
|
|
# included in the length, to allow it to be used as a string if needed.
|
|
#
|
|
set -e
|
|
|
|
arrname=""
|
|
modifiers=""
|
|
null_terminate=0
|
|
|
|
usage () {
|
|
echo "Usage: $0 [options] [input file] " >&2
|
|
echo "Options:" >&2
|
|
echo " -v <c array variable name>" >&2
|
|
echo " Name of C variable in output file. Must be provided." >&2
|
|
echo " -m <array variable modifiers>" >&2
|
|
echo " Modifiers for C variable in output file. Default is const." >&2
|
|
echo " -n" >&2
|
|
echo " Add a trailing null byte, not included in length." >&2
|
|
exit 1
|
|
}
|
|
|
|
while getopts "m:nv:" opt; do
|
|
case $opt in
|
|
m)
|
|
if [[ $modifiers != "" ]]; then
|
|
echo "-m specified twice" >&2
|
|
usage
|
|
fi
|
|
modifiers=$OPTARG
|
|
;;
|
|
n)
|
|
null_terminate=1
|
|
;;
|
|
v)
|
|
if [[ $arrname != "" ]]; then
|
|
echo "-v specified twice" >&2
|
|
usage
|
|
fi
|
|
arrname=$OPTARG
|
|
;;
|
|
\?)
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
usage
|
|
esac
|
|
done
|
|
shift $((OPTIND - 1))
|
|
|
|
infile=$1
|
|
if [[ $# > 1 ]]; then
|
|
echo "Too many remaining arguments: $@" >&2
|
|
usage
|
|
fi
|
|
|
|
if [ -z "$arrname" ]; then
|
|
echo "-v not provided or empty." >&2
|
|
usage
|
|
fi
|
|
|
|
if [ -z "$modifiers" ]; then
|
|
# Default is const with global linking visibility
|
|
modifiers="const"
|
|
fi
|
|
|
|
echo "#include <stddef.h>" # For size_t
|
|
echo
|
|
# Preceding extern declaration guarantees external linkage in C++
|
|
echo "extern $modifiers unsigned char $arrname[];";
|
|
echo "extern $modifiers size_t ${arrname}_len;"
|
|
echo
|
|
echo "$modifiers unsigned char $arrname[] = {"
|
|
xxd -i < $infile
|
|
if [ ${null_terminate} = 1 ]; then
|
|
echo ", 0x0"
|
|
fi
|
|
echo "};"
|
|
|
|
echo -n "$modifiers size_t ${arrname}_len = "
|
|
if [ ${null_terminate} = 1 ]; then
|
|
echo "sizeof(${arrname}) - 1;"
|
|
else
|
|
echo "sizeof(${arrname});"
|
|
fi
|