3 # Test an insn from a template .s/.d.
5 proc test_template_insn { tmpl opcode icode } {
6 global srcdir subdir objdir
8 # Change @OC@ in the template file to $opcode
10 set in_fd [open $srcdir/$subdir/$tmpl.s r]
11 set out_fd [open $objdir/$opcode.s w]
12 # FIXME: check return codes
14 while { [gets $in_fd line] >= 0 } {
15 regsub "@OC@" $line $opcode line
22 # Create output template.
24 set in_fd [open $srcdir/$subdir/$tmpl.d r]
25 set out_fd [open $objdir/$opcode.d w]
26 # FIXME: check return codes
28 while { [gets $in_fd line] >= 0 } {
29 regsub "@OC@" $line $opcode line
31 if [string match "*@IC+?@*" $line] {
32 # Insert the opcode. It occupies the top 5 bits.
33 regexp "^(.*)@IC\\+(.)@(.*)$" $line junk leftpart n rightpart
34 set n [expr ($icode << 3) + $n]
35 set n [format "%02x" $n]
36 puts $out_fd "$leftpart$n$rightpart"
37 } elseif [string match "*@I3+??@*" $line] {
38 # Insert insn 3 code (register C field)
39 # b15=8/0, b8=1/0 (their respective hex values in the objdump)
40 regexp "^(.*)@I3\\+(.)(.)@(.*)$" $line junk leftpart b15 b8 rightpart
41 set n [expr ($icode << 1) + ($b15 << 4) + ($b8 << 0)]
42 set n [format "%02x" $n]
43 puts $out_fd "$leftpart$n$rightpart"
52 # Finally, run the test.
54 run_dump_test $objdir/$opcode
59 if [istarget arc*-*-*] then {
61 test_template_insn math adc 9
62 test_template_insn math add 8
63 test_template_insn math and 12
64 test_template_insn math bic 14
65 test_template_insn math or 13
66 test_template_insn math sbc 11
67 test_template_insn math sub 10
68 test_template_insn math xor 15
70 test_template_insn alias mov 12
71 test_template_insn alias rlc 9
72 test_template_insn alias asl 8
73 # `lsl' gets dumped as `asl' so this must be tested elsewhere.
74 # test_template_insn alias lsl 8
76 test_template_insn sshift asr 1
77 test_template_insn sshift lsr 2
78 test_template_insn sshift ror 3
79 test_template_insn sshift rrc 4
81 test_template_insn branch b 4
82 test_template_insn branch bl 5
83 test_template_insn branch lp 6
87 # test_special "ext" 3
88 # test_special "sex" 3