#!/bin/bash -ex

LIBCXX_DIR="$1"

[[ -e "$LIBCXX_DIR/include/__config" ]]
[[ -e "$LIBCXX_DIR/include/experimental/__config" ]]
[[ -e "$LIBCXX_DIR/include/experimental/simd" ]]

echo '/* DO NOT MODIFY: auto-generated by migrate_libcxx_simd.sh.
   This file mirrors libcxx <experimental/simd>. By far it is still
   under code review, but all tests passed and performance is
   verified. We early-adopt this because (1) the API is published
   in the C++ parallelism v2 TS, (2) it takes long time to review,
   (3) we already have a lot of experience with the implementation.

   https://reviews.llvm.org/D44665 is the last patch under review.
   One can navigate all patches through the review system dependency
   management.  */
'

cat "$LIBCXX_DIR/include/__config" \
  "$LIBCXX_DIR/include/experimental/__config" \
  "$LIBCXX_DIR/include/experimental/simd" \
| sed 's/\b_LIBCPP_/_DIMSUM_/g' \
| sed 's/\b_DIMSUM_EXPERIMENTAL_SIMD\b/_LIBCPP_EXPERIMENTAL_SIMD/' \
| sed 's/\bstd::index_sequence\b/dimsum::index_sequence/g' \
| sed 's/\bstd::make_index_sequence\b/dimsum::make_index_sequence/g' \
| sed 's|#include <__config>||g' \
| sed 's|#include <experimental/__config>|#include "index_sequence.h"|g'
