#!/bin/bash # This script builds and runs the DEC64 tests for an ARM64 Android device. It # takes no arguments. # DEC64's ARM source must be tweaked slightly to make it compatible with # the Android NDK's clang: # 0. Comments start with a double slash, not a semicolon. # 1. The global directive, like all directives, is preceeded by a period. # 2. The area directive is not supported. We do, however, align. # 3. Labels must be suffixed with a colon. # 4. An 8 byte constant is declared with .quad rather than dcq. # 5. When shifting an address offset, an extra comma is required. # 6. The end directive is unnecessary. sed \ -E \ -e "s_;_//_g" \ -e "s/global ([a-z0-9_]+) \\[func\\]/.global \1/g" \ -e "s/area dec64, align=8, code, readonly/.align 8/g" \ -e "s/^([a-z0-9_]+)/\1:/g" \ -e "s/dcq/.quad/g" \ -e "s/x([0-9]) lsl 3/x\1, lsl 3/g" \ -e "/ end/d" \ dec64.android.s \ || exit build_and_run() { # Compile, assemble and link a source file into a binary executable, then # transfer and run that executable on a connected Android device. src=$1 bin=$2 # The tests shift negative integers on purpose, so we suppress that warning. "NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android32-clang" \ -Wno-shift-negative-value \ -o $bin \ dec64_string.c \ dec64_math.c \ dec64.android.s \ $src \ && adb push ./$bin /data/local/tmp/$bin \ && adb shell /data/local/tmp/$bin } build_and_run dec64_test.c dec64_test \ && build_and_run dec64_string_test.c dec64_string_test \ && build_and_run dec64_math_test.c dec64_math_test \ || exit # This script has been tested on a Samsung A52 5G device running Android 12, # using the Android NDK r25b.