#!/usr/bin/env bash # Generates C byte-array headers (tests/rv32/embed/*.h) from a curated subset of # tests/corpus/seeds/*.chd, for embedding into the rv32 RAM-budget firmware # (tests/rv32/fw.c). Not committed - regenerated by CI / on demand. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SEEDS_DIR="$SCRIPT_DIR/../corpus/seeds" OUT_DIR="$SCRIPT_DIR/embed" mkdir -p "$OUT_DIR" # One representative CHD per decompressor the RAM-budget check cares about: # every HD/raw codec (small hunks) plus every CD sub-codec (large hunks, the # ones that pay for a subcode decompressor on top of the base one). FLAC is in # the list because its decoder holds the largest per-instance buffer of any # codec here - leaving it out is how an oversized allocation went unnoticed. FILES=(hd_zlib hd_zstd hd_lzma hd_huff hd_flac cd_cdzl cd_cdzs cd_cdlz cd_cdfl) for f in "${FILES[@]}"; do src="$SEEDS_DIR/${f}.chd" if [ ! -f "$src" ]; then echo "gen_embed.sh: missing corpus seed: $src" >&2 exit 1 fi xxd -i "$src" | sed \ -e "s/unsigned char [A-Za-z0-9_]*_chd\[\]/const unsigned char ${f}_chd[]/" \ -e "s/unsigned int [A-Za-z0-9_]*_chd_len/const unsigned int ${f}_chd_len/" \ > "$OUT_DIR/${f}.h" done echo "Generated ${#FILES[@]} embedded CHD headers in $OUT_DIR"