summaryrefslogtreecommitdiff
path: root/test_marks_referencing.bash
blob: 1a178826838a12e464e800d5e3d8cc7665503c44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
#
# SPDX-License-Identifier: Unlicense
#
# Tests against m68k-none-elf-as.

AS=m68k-none-elf-as
OBJCOPY=m68k-none-elf-objcopy
LD="m68k-none-elf-ld -Ttest.ld"
DISASM="./cmake-build/m68k-disasm"
TEST_DIR=/tmp/m68k-disasm-tests-marks-referencing

set -e
CRED="\033[31m"
CGREEN="\033[32m"
CRST="\033[39m"

rm -rf ${TEST_DIR}
mkdir -p ${TEST_DIR}

run_test_r() {
  local test_name=$1
  local test_name_sanitized=${test_name//[^a-zA-Z0-9_\-]/-}
  local data=$2
  local args=$3
  local file_orig_bin=${TEST_DIR}/${test_name_sanitized}.orig.bin
  local file_asm=${TEST_DIR}/${test_name_sanitized}.S
  local file_as_o=${TEST_DIR}/${test_name_sanitized}.as.o
  local file_as_elf=${TEST_DIR}/${test_name_sanitized}.as.elf
  local file_as_bin=${TEST_DIR}/${test_name_sanitized}.as.bin
  echo -ne "Test \"${test_name}\"... "
  echo -ne "${data}" >${file_orig_bin}
  ${DISASM} $args -o ${file_asm} ${file_orig_bin}
  ${AS} -m68000 -o ${file_as_o} ${file_asm}
  ${LD} -o ${file_as_elf} ${file_as_o}
  ${OBJCOPY} ${file_as_elf} -O binary ${file_as_bin}
  if ! cmp ${file_orig_bin} ${file_as_bin}; then
    cat ${file_asm}
    echo -e "${CRED}FAIL${CRST}: output and input binaries do not match"
    hexdump -Cv ${file_orig_bin} >${file_orig_bin}.txt
    hexdump -Cv ${file_as_bin} >${file_as_bin}.txt
    echo ${file_orig_bin}
    echo ${file_as_bin}
    exit
  elif grep ".short" ${file_asm} >/dev/null 2>&1; then
    echo -e "${CRED}FAIL${CRST}: .short emitted"
    cat ${file_asm}
    exit
  fi
  local run_check=$4
  $run_check
  #cat ${file_asm}
  echo -e "${CGREEN}OK${CRST}"
}

run_check_rdisp() {
  if grep -e "\s\.\([+-]\+\|\s\+\|$\)" ${file_asm} >/dev/null 2>&1; then
    echo -e "${CRED}FAIL${CRST}: raw displacement emitted"
    cat ${file_asm}
    exit
  fi
}

run_check_r() {
  if grep -e "[^0-9a-zA-Z_][0-9]\+" ${file_asm} >/dev/null 2>&1; then
    echo -e "${CRED}FAIL${CRST}: raw number or displacement emitted"
    cat ${file_asm}
    exit
  fi
}

run_test_rdisp() {
  run_test_r "$1" "$2" "-fmarks -frel-marks" run_check_rdisp
}

run_test_rword() {
  run_test_r "$1" "$2" "-fmarks -fabs-marks" run_check_r
}

run_test_rlong() {
  run_test_r "$1" "$2" "-fmarks -fabs-marks" run_check_r
}

run_test_rpcrel() {
  run_test_r "$1" "$2" "-fmarks -frel-marks" run_check_r
}

run_test_rdisp "bras ." "\x60\xfe"
run_test_rdisp "bras .-2" "\x4e\x71\x60\xfc"
run_test_rdisp "bras .-1" "\x4e\x71\x60\xfd"
run_test_rdisp "braw .+2" "\x4e\x71\x60\x00\x00\x00"