#!/bin/sh set -eu : "${CPU_AS:?}" TMP="${TMPDIR:-/tmp}/libcpu-imm-$$" trap 'rm -f "$TMP".s "$TMP".o "$TMP".err "$TMP".out' EXIT HUP INT TERM cat > "$TMP.s" <<'EOS' .text LDR r4096@0x00000, 3.14243987129849274029174912694696912849214e-286 HALT EOS if "$CPU_AS" -o "$TMP.o" "$TMP.s" >"$TMP.out" 2>"$TMP.err"; then echo "cpu-as unexpectedly accepted inexact wide LDR" >&2 exit 1 fi grep -F "$TMP.s:2: error:" "$TMP.err" >/dev/null grep -F 'LDR immediate is not exactly representable as real64;' "$TMP.err" >/dev/null grep -F 'use .real , value in DATA and LOAD' "$TMP.err" >/dev/null cat > "$TMP.s" <<'EOS' .text LDR r32@0x00000, 0.1 HALT EOS if "$CPU_AS" -o "$TMP.o" "$TMP.s" >"$TMP.out" 2>"$TMP.err"; then echo "cpu-as unexpectedly accepted inexact real32 LDR" >&2 exit 1 fi grep -F 'LDR immediate is not exactly representable as real32;' "$TMP.err" >/dev/null cat > "$TMP.s" <<'EOS' .text LDC c128@0x00000, 0.1r0+32.0j0 HALT EOS if "$CPU_AS" -o "$TMP.o" "$TMP.s" >"$TMP.out" 2>"$TMP.err"; then echo "cpu-as unexpectedly accepted inexact complex immediate" >&2 exit 1 fi grep -F 'LDC immediate component is not exactly representable as real32;' "$TMP.err" >/dev/null grep -F 'use .complex , real, imag in DATA and LOAD' "$TMP.err" >/dev/null cat > "$TMP.s" <<'EOS' .text LDI r8@0x00000, 255 HALT EOS if "$CPU_AS" -o "$TMP.o" "$TMP.s" >"$TMP.out" 2>"$TMP.err"; then echo "cpu-as unexpectedly accepted lossy narrow integer immediate" >&2 exit 1 fi grep -F 'LDI immediate is not exactly representable as integer8;' "$TMP.err" >/dev/null grep -F 'use .integer , value in DATA and LOAD' "$TMP.err" >/dev/null cat > "$TMP.s" <<'EOS' .text LDI r128@0x00000, 9223372036854775808 HALT EOS if "$CPU_AS" -o "$TMP.o" "$TMP.s" >"$TMP.out" 2>"$TMP.err"; then echo "cpu-as unexpectedly accepted integer wider than IMM64" >&2 exit 1 fi grep -F 'LDI immediate is not exactly representable as integer64;' "$TMP.err" >/dev/null echo 'libcpu immediate exactness runner regression: PASS'