|
|
|
|
@ -40,10 +40,47 @@ if [[ ! -x "$compiler" ]]; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then
|
|
|
|
|
echo "未找到 aarch64-linux-gnu-gcc,无法汇编/链接。" >&2
|
|
|
|
|
now_ms() {
|
|
|
|
|
local ns
|
|
|
|
|
ns=$(date +%s%N 2>/dev/null || true)
|
|
|
|
|
if [[ "$ns" =~ ^[0-9]+$ ]]; then
|
|
|
|
|
printf '%s\n' "$((ns / 1000000))"
|
|
|
|
|
else
|
|
|
|
|
printf '%s000\n' "$(date +%s)"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
format_ms() {
|
|
|
|
|
local ms=$1
|
|
|
|
|
printf '%d.%03ds' "$((ms / 1000))" "$((ms % 1000))"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
link_aarch64() {
|
|
|
|
|
local asm_file=$1
|
|
|
|
|
local sylib=$2
|
|
|
|
|
local exe=$3
|
|
|
|
|
|
|
|
|
|
if command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then
|
|
|
|
|
if [[ -f "$sylib" ]]; then
|
|
|
|
|
aarch64-linux-gnu-gcc "$asm_file" "$sylib" -o "$exe"
|
|
|
|
|
else
|
|
|
|
|
aarch64-linux-gnu-gcc "$asm_file" -o "$exe"
|
|
|
|
|
fi
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if command -v clang >/dev/null 2>&1; then
|
|
|
|
|
if [[ -f "$sylib" ]]; then
|
|
|
|
|
clang --target=aarch64-linux-gnu "$asm_file" "$sylib" -o "$exe"
|
|
|
|
|
else
|
|
|
|
|
clang --target=aarch64-linux-gnu "$asm_file" -o "$exe"
|
|
|
|
|
fi
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "未找到 AArch64 链接工具:需要 aarch64-linux-gnu-gcc,或支持 --target=aarch64-linux-gnu 的 clang。" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mkdir -p "$out_dir"
|
|
|
|
|
base=$(basename "$input")
|
|
|
|
|
@ -60,11 +97,7 @@ SYLIB="$SCRIPT_DIR/../sylib/sylib.c"
|
|
|
|
|
"$compiler" --emit-asm "$input" > "$asm_file"
|
|
|
|
|
echo "汇编已生成: $asm_file"
|
|
|
|
|
|
|
|
|
|
if [[ -f "$SYLIB" ]]; then
|
|
|
|
|
aarch64-linux-gnu-gcc "$asm_file" "$SYLIB" -o "$exe"
|
|
|
|
|
else
|
|
|
|
|
aarch64-linux-gnu-gcc "$asm_file" -o "$exe"
|
|
|
|
|
fi
|
|
|
|
|
link_aarch64 "$asm_file" "$SYLIB" "$exe"
|
|
|
|
|
echo "可执行文件已生成: $exe"
|
|
|
|
|
|
|
|
|
|
if [[ "$run_exec" == true ]]; then
|
|
|
|
|
@ -75,11 +108,12 @@ if [[ "$run_exec" == true ]]; then
|
|
|
|
|
|
|
|
|
|
stdout_file="$out_dir/$stem.stdout"
|
|
|
|
|
actual_file="$out_dir/$stem.actual.out"
|
|
|
|
|
run_timeout="${SY_QEMU_TIMEOUT:-90}"
|
|
|
|
|
echo "运行 $exe ..."
|
|
|
|
|
run_timeout="${SY_QEMU_TIMEOUT:-600}"
|
|
|
|
|
echo "运行 $exe ... (timeout: ${run_timeout}s)"
|
|
|
|
|
set +e
|
|
|
|
|
ulimit -s unlimited 2>/dev/null || true
|
|
|
|
|
export QEMU_STACK_SIZE=67108864
|
|
|
|
|
run_start_ms=$(now_ms)
|
|
|
|
|
if command -v timeout >/dev/null 2>&1; then
|
|
|
|
|
if [[ -f "$stdin_file" ]]; then
|
|
|
|
|
timeout "${run_timeout}s" qemu-aarch64 -L /usr/aarch64-linux-gnu "$exe" < "$stdin_file" > "$stdout_file"
|
|
|
|
|
@ -94,11 +128,14 @@ if [[ "$run_exec" == true ]]; then
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
status=$?
|
|
|
|
|
run_end_ms=$(now_ms)
|
|
|
|
|
run_elapsed_ms=$((run_end_ms - run_start_ms))
|
|
|
|
|
set -e
|
|
|
|
|
if [[ $status -eq 124 ]]; then
|
|
|
|
|
echo "运行超时: ${run_timeout}s" >&2
|
|
|
|
|
echo "运行超时: ${run_timeout}s,耗时: $(format_ms "$run_elapsed_ms")" >&2
|
|
|
|
|
exit 124
|
|
|
|
|
fi
|
|
|
|
|
echo "运行耗时: $(format_ms "$run_elapsed_ms")"
|
|
|
|
|
cat "$stdout_file"
|
|
|
|
|
echo "退出码: $status"
|
|
|
|
|
{
|
|
|
|
|
|