aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Chambers <[email protected]>2021-10-06 05:22:38 +1300
committerAndrew Chambers <[email protected]>2021-10-06 05:22:38 +1300
commite0ff42fe7eb739d4320ec9f089eaa247bfca9fc8 (patch)
treeea8ed9d97688d8b391eed1c7c6fee14d21076d55 /test
parent513cfa84f2e6b06e2ac8133cf1d3432fdbaf2f20 (diff)
More opcodes.
Diffstat (limited to 'test')
-rw-r--r--test/test.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/test.sh b/test/test.sh
new file mode 100644
index 0000000..cd174e7
--- /dev/null
+++ b/test/test.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+set -eu
+
+tmps="$(mktemp --suffix .s)"
+tmpo="$(mktemp --suffix .o)"
+tmpb="$(mktemp --suffix .bin)"
+
+trap "rm -f \"$tmps\" \"$tmpo\" \"$tmpb\"" EXIT
+
+t () {
+ echo "$1" > "$tmps"
+ clang -Wno-everything -c -s "$tmps" -o "$tmpo"
+ objcopy -j ".text" -O binary "$tmpo" "$tmpb"
+ want="$(xxd -ps "$tmpb" | head -n 1 | cut -d ' ' -f 2-)"
+ ./minias < "$tmps" > "$tmpo"
+ objcopy -j ".text" -O binary "$tmpo" "$tmpb"
+ got="$(xxd -ps "$tmpb" | head -n 1 | cut -d ' ' -f 2-)"
+ if test "$got" != "$want"
+ then
+ echo ""
+ echo "want: $1 -> $want"
+ echo "got: $1 -> $got"
+ exit 1
+ fi
+ echo -n "."
+}
+
+t "nop"
+t "ret"
+t "leave"
+t "addq %rax, %rax"
+t "addl %eax, %eax"
+t "subq %rax, %rax"
+t "subl %eax, %eax"
+t "addq %rax, %rbx"
+t "addl %eax, %ebx"
+t "addq %rax, (%rax)"
+t "addq %rax, (%rbx)"
+t "addl %eax, (%rax)"
+t "addl %eax, (%r9)"
+t "addl %ebx, (%r9)"
+
+t "xorq %rax, %rax"
+t "xorq %rax, (%rax)"
+t "xorl %eax, %eax"
+
+t "andq %rax, %rax"
+t "andq %rax, (%rax)"
+t "andl %eax, %eax"
+
+
+
+#t "addq %rbp, (%rax)"
+
+
+#t "addq %rax, %rbx"
+#t "addl %eax, %ebx"