#!/bin/sh

# stop script at first fail
set -e

if [ "$#" -ne 1 ] ; then
  echo "usage: $0 file.vsl"
  exit 0
fi

name="`dirname $1`/`basename $1 .vsl`"

# translating from VSL to LLVM IR (.ll)
java -jar build/libs/TP2.jar < $name.vsl > $name.ll

# Check clang version
if command -v clang-20 2>&1 >/dev/null
then 
  cl=clang-20
else
if command -v clang-19 2>&1 >/dev/null
then 
  cl=clang-19
else 
if command -v clang-18 2>&1 >/dev/null
then 
  cl=clang-18
else 
if command -v clang-17 2>&1 >/dev/null
then 
  cl=clang-17
else 
  cl=clang
fi fi fi fi

# Compile using clang
$cl $name.ll -o $name