raz / test / a64 / expect.sh

33 lines · 1.4 KiB · raw · history · last change 489d8810

1#!/bin/sh
2# Makes test/a64/Encode.expect, what Encode.raz must print, from Apple's
3# assembler: Asm.txt, A64's assembler's part, turned into Apple's syntax
4# (raz's comments dropped, 10H as 0x10, `adr x0, v` as the adrp and add
5# it stands for, a name as its symbol, _v, db and dd as .byte and .long,
6# and ; between instructions as a new line, since ; begins a comment
7# there), then Api.s, the instructions of Encode.raz's calls of A64.
8# Each word of the object's code, a run of nop as one line, then its
9# relocations, sorted, as Encode.raz prints its fixups.
10# Run on an arm64 Mac, from the repository's root: sh test/a64/expect.sh
11set -e
12d=test/a64
13t=$(mktemp -d)
14trap 'rm -rf "$t"' EXIT
15{
16 echo Lstart:
17 sed -E -e '/^\(\*/,/\*\)/d' -e '/^end$/d' \
18 -e 's/([0-9][0-9A-F]*)H/0x\1/g' \
19 -e 's/adr (x[0-9]+), (glob|proc1)/adrp \1, _\2@PAGE; add \1, \1, _\2@PAGEOFF/g' \
20 -e 's/(b|bl) proc1/\1 _proc1/g' \
21 -e 's/(fcmp [ds][0-9]+, #0);/\1.0;/g' \
22 -e 's/^db /.byte /; s/; dd /; .long /' $d/Asm.txt
23 cat $d/Api.s
24} | tr ';' '\n' > $t/all.s
25cc -c -arch arm64 $t/all.s -o $t/all.o
26objdump -d $t/all.o | awk '
27 /^ *[0-9a-f]+:/ {
28 if ($2 == "d503201f") { nops++; next }
29 if (nops) { print "nop * " nops; nops = 0 }
30 print $2
31 }
32 END { if (nops) print "nop * " nops }' > $d/Encode.expect
33objdump -r $t/all.o | awk '/ARM64_RELOC/ { print "reloc", $1, $2, $3 }' | sort >> $d/Encode.expect