123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #!/bin/sh -e
- # SPDX-License-Identifier: GPL-3.0-or-later
- # Copyright © 2018-2019 Ariadne Devos
- set -e
- LC_ALL=C.UTF-8
- export LC_ALL
- type="$1"
- func="$2"
- source="$3"
- IFS=' '
- sizes='2 4 8 16 32 64'
- cat <<EOF
- #include <sHT/vector.h>
- EOF
- for size in $sizes; do
- cat <<EOF
- #if defined(sHT_target_${size}) && (${size} >= sHT_${type}_bytes)
- # define sHT_size ${size}
- # define sHT_target sHT_target_${size}
- # define ${func} ${func}_${size}
- # include "${source}"
- # undef ${func}
- # undef sHT_target
- # undef sHT_size
- #endif
- EOF
- done
- cat <<EOF
- /* musl doesn't allow GNU indirect functions.
- Do the portable thing: save a pointer. */
- #if 0
- EOF
- for size in $sizes; do
- cat <<EOF
- #elif defined(sHT_target_${size}) && (${size} >= sHT_${type}_bytes)
- typedef __typeof__(&${func}_${size}) ${func}_type;
- EOF
- done
- cat <<EOF
- #else
- # error impossible
- #endif
- static const ${func}_type ${func}_variants[] = {
- EOF
- for size in $sizes; do
- cat <<EOF
- #if defined(sHT_target_${size}) && (${size} >= sHT_${type}_bytes)
- ${func}_${size},
- #endif
- EOF
- done
- cat <<EOF
- };
- EOF
|