#!/usr/bin/env bash
# Generate a lookup table function for interrupts of all supported chips
set -e
echo "// Autogenerated. Do not edit."
echo "pub fn lookup_vector(chip: &str, intr: &str) -> Option<usize> {"
echo " match chip {"
for intr_path in "$@"; do
chip="$(basename "${intr_path%.svd.patched}")"
echo " \"$chip\" => match intr {"
# toupper() to be compliant with svd2rust interrupts name
svd interrupts --no-gaps $intr_path | awk '{print " \""toupper(substr($2, 1, length($2)-1))"\"" " => Some(" $1"),"}'
echo " _ => None,"
echo " },"
done
echo " _ => None,"
echo " }"
echo "}"