--- /dev/null
+# ARC gas testsuite
+
+# Test an insn from a template .s/.d.
+
+proc test_template_insn { tmpl opcode icode } {
+ global srcdir subdir objdir
+
+ # Change @OC@ in the template file to $opcode
+
+ set in_fd [open $srcdir/$subdir/$tmpl.s r]
+ set out_fd [open $objdir/$opcode.s w]
+ # FIXME: check return codes
+
+ while { [gets $in_fd line] >= 0 } {
+ regsub "@OC@" $line $opcode line
+ puts $out_fd $line
+ }
+
+ close $in_fd
+ close $out_fd
+
+ # Create output template.
+
+ set in_fd [open $srcdir/$subdir/$tmpl.d r]
+ set out_fd [open $objdir/$opcode.d w]
+ # FIXME: check return codes
+
+ while { [gets $in_fd line] >= 0 } {
+ regsub "@OC@" $line $opcode line
+ #send_user "$line\n"
+ if [string match "*@IC+?@*" $line] {
+ # Insert the opcode. It occupies the top 5 bits.
+ regexp "^(.*)@(IC\\+)(.)@(.*)$" $line junk leftpart icodepart n rightpart
+ set n [expr ($icode << 3) + $n]
+ set n [format "%02x" $n]
+ puts $out_fd "$leftpart$n$rightpart"
+ } else {
+ puts $out_fd $line
+ }
+ }
+
+ close $in_fd
+ close $out_fd
+
+ # Finally, run the test.
+
+ run_dump_test $objdir/$opcode
+}
+
+# Run the tests.
+
+if [istarget arc*-*-*] then {
+
+ test_template_insn math adc 9
+ test_template_insn math add 8
+ test_template_insn math and 12
+ test_template_insn math bic 14
+ test_template_insn math or 13
+ test_template_insn math sbc 11
+ test_template_insn math sub 10
+ test_template_insn math xor 15
+
+# test_shift "asl" 8
+# test_shift "asr" 3
+# test_shift "lsl" 8
+# test_shift "lsr" 3
+# test_shift "ror" 3
+# test_shift "rrc" 3
+
+# test_branch "b" 4
+# test_branch "bl" 5
+# test_branch "lp" 5
+
+ run_dump_test "j"
+
+# test_special "ext" 3
+# test_special "sex" 3
+
+# test_macro "mov" 12
+# test_macro "rlc" 9
+
+ run_dump_test "flag"
+# run_dump_test "ld"
+# run_dump_test "lr"
+# run_dump_test "nop"
+# run_dump_test "st"
+# run_dump_test "sr"
+
+}
--- /dev/null
+#objdump: -dr
+#name: @OC@
+
+# Test the @OC@ insn.
+
+.*: +file format elf32-.*arc
+
+Disassembly of section .text:
+00000000 @IC+0@008400 @OC@ r0,r1,r2
+00000004 @IC+3@4db800 @OC@ r26,fp,sp
+00000008 @IC+3@af3e00 @OC@ ilink1,ilink2,blink
+0000000c @IC+7@5df800 @OC@ r58,r59,lp_count
+00000010 @IC+0@00fe00 @OC@ r0,r1,0
+00000014 @IC+0@1f8400 @OC@ r0,0,r2
+00000018 @IC+7@e08400 @OC@ 0,r1,r2
+0000001c @IC+0@00ffff @OC@ r0,r1,511
+00000020 @IC+0@1f85ff @OC@ r0,511,r2
+00000024 @IC+7@e085ff @OC@ 511,r1,r2
+00000028 @IC+0@00feff @OC@ r0,r1,255
+0000002c @IC+0@1f84ff @OC@ r0,255,r2
+00000030 @IC+7@e084ff @OC@ 255,r1,r2
+00000034 @IC+0@00ff00 @OC@ r0,r1,256
+00000038 @IC+0@1f8500 @OC@ r0,256,r2
+0000003c @IC+7@e08500 @OC@ 256,r1,r2
+00000040 @IC+0@00fc00 @OC@ r0,r1,256
+00000048 @IC+0@1f0400 @OC@ r0,-257,r2
+00000050 @IC+7@c08400 @OC@ 511,r1,r2
+00000058 @IC+0@1f7c00 @OC@ r0,1111638594,1111638594
+00000060 @IC+7@df7c00 @OC@ 305419896,305419896,305419896
+00000068 @IC+0@1ffcff @OC@ r0,255,256
+00000070 @IC+0@1f7eff @OC@ r0,256,255
+00000078 @IC+7@e0fcff @OC@ 255,r1,256
+00000080 @IC+7@ff04ff @OC@ 255,256,r2
+00000088 @IC+7@c0feff @OC@ 256,r1,255
+00000090 @IC+7@df84ff @OC@ 256,255,r2
+00000098 @IC+0@00fc00 @OC@ r0,r1,0
+ RELOC: 0000009c R_ARC_32 foo
+000000a0 @IC+0@008400 @OC@ r0,r1,r2
+000000a4 @IC+0@620a00 @OC@ r3,r4,r5
+000000a8 @IC+0@c39001 @OC@.eq r6,r7,r8
+000000ac @IC+1@251601 @OC@.eq r9,r10,r11
+000000b0 @IC+1@869c02 @OC@.ne r12,r13,r14
+000000b4 @IC+1@e82202 @OC@.ne r15,r16,r17
+000000b8 @IC+2@49a803 @OC@.p r18,r19,r20
+000000bc @IC+2@ab2e03 @OC@.p r21,r22,r23
+000000c0 @IC+3@0cb404 @OC@.n r24,r25,r26
+000000c4 @IC+3@6e3a04 @OC@.n fp,sp,ilink1
+000000c8 @IC+3@cfc005 @OC@.c ilink2,blink,r32
+000000cc @IC+4@314605 @OC@.c r33,r34,r35
+000000d0 @IC+4@92cc05 @OC@.c r36,r37,r38
+000000d4 @IC+4@f45206 @OC@.nc r39,r40,r41
+000000d8 @IC+5@55d806 @OC@.nc r42,r43,r44
+000000dc @IC+5@b75e06 @OC@.nc r45,r46,r47
+000000e0 @IC+6@18e407 @OC@.v r48,r49,r50
+000000e4 @IC+6@7a6a07 @OC@.v r51,r52,r53
+000000e8 @IC+6@dbf008 @OC@.nv r54,r55,r56
+000000ec @IC+7@3d7608 @OC@.nv r57,r58,r59
+000000f0 @IC+7@9e7809 @OC@.gt lp_count,lp_count,lp_count
+000000f4 @IC+0@007c0a @OC@.ge r0,r0,0
+000000fc @IC+0@3f020b @OC@.lt r1,1,r1
+00000104 @IC+7@c1040c @OC@.le 2,r2,r2
+0000010c @IC+0@7f7c0d @OC@.hi r3,3,3
+00000114 @IC+7@df080e @OC@.ls 4,4,r4
+0000011c @IC+7@df7c0f @OC@.pnz 5,5,5
+00000124 @IC+0@008500 @OC@.f r0,r1,r2
+00000128 @IC+0@00fa01 @OC@.f r0,r1,1
+0000012c @IC+0@1e8401 @OC@.f r0,1,r2
+00000130 @IC+7@a08400 @OC@.f 0,r1,r2
+00000134 @IC+0@00fd00 @OC@.f r0,r1,512
+0000013c @IC+0@1f0500 @OC@.f r0,512,r2
+00000144 @IC+7@c08500 @OC@.f 512,r1,r2
+0000014c @IC+0@008501 @OC@.eq.f r0,r1,r2
+00000150 @IC+0@00fd02 @OC@.ne.f r0,r1,0
+00000158 @IC+0@1f050b @OC@.lt.f r0,0,r2
+00000160 @IC+7@c08509 @OC@.gt.f 0,r1,r2
+00000168 @IC+0@00fd0c @OC@.le.f r0,r1,512
+00000170 @IC+0@1f050a @OC@.ge.f r0,512,r2
+00000178 @IC+7@c08504 @OC@.n.f 512,r1,r2