📄 cris.exp
字号:
# Copyright 1999, 2000, 2002 Free Software Foundation, Inc.# This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.# # This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# # You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Please email any bugs, comments, and/or additions to this file to:# hp@axis.com# Written by Axis Communications AB.# --- This function copied from arc.exp and rewritten to fit CRIS ---## Test an insn from a template .s/.d.# The best way to create the .d file is to run the tests without it, let# dejagnu crash, run as.new on the just built .s file, run objdump -dr on# the result of that, copy the result into the .d file, and edit in the# necessary patterns (@OC@, etc.). Sounds complicated but it's easy. The# catch is that we assume a working assembler is used to build it. That's# obviously not entirely kosher, but once the .d file is created one can# verify it's contents over time.## Template patterns:# @OC@ - placeholder for the opcode# @OR@ - placeholder for extra replacement to distinguish similar# testcases.# @IR+????@ - placeholder for (e.g.) register-operand insn code# @IM+????@ - placeholder for (e.g.) memory-operand insn code.proc test_template_insn_reg_mem { args } { # tmpl opcode ircode imcode avoid_regex dname ircode0 # imcode0 [regex replace OR_replace] global srcdir subdir objdir set tmpl [lindex $args 0] set opcode [lindex $args 1] set ircode [lindex $args 2] set imcode [lindex $args 3] set avoid_regex [lindex $args 4] set dname [lindex $args 5] set ircode0 [lindex $args 6] set imcode0 [lindex $args 7] if { [llength $args] >= 10 } { set replace_regex [lindex $args 8] set replacement [lindex $args 9] } else { set replace_regex "" } # Any extra replacements (like modifying the test name to something # else than the @OC@ modification). Replaces occurences of @OR@. if { [llength $args] >= 11 } then { set extra_OR_replace [lindex $args 10] } else { set extra_OR_replace "" } # Get the parts that we will wedge into the insn. if [regexp "(.)(.)(.)" $imcode junk imcode3 imcode2 imcode1] { set imcode3 [expr "0x$imcode3" ] } else { regexp "(.)(.)" $imcode junk imcode2 imcode1 set imcode3 0 } set imcode1 [expr "0x$imcode1" ] set imcode2 [expr "0x$imcode2" ] if [regexp "(.)(.)(.)" $ircode junk ircode3 ircode2 ircode1] { set ircode3 [expr "0x$ircode3" ] } else { regexp "(.)(.)" $ircode junk ircode2 ircode1 set ircode3 0 } set ircode1 [expr "0x$ircode1" ] set ircode2 [expr "0x$ircode2" ] # To avoid fiddling with the generated .d-file, we have a # parameter saying what ircode, imcode to subtract. if [regexp "(.)(.)(.)" $imcode0 junk imcode03 imcode02 imcode01] { set imcode03 [expr "0x$imcode03" ] } else { regexp "(.)(.)" $imcode0 junk imcode02 imcode01 set imcode03 0 } set imcode01 [expr "0x$imcode01" ] set imcode02 [expr "0x$imcode02" ] if [regexp "(.)(.)(.)" $ircode0 junk ircode03 ircode02 ircode01] { set ircode03 [expr "0x$ircode03" ] } else { regexp "(.)(.)" $ircode0 junk ircode02 ircode01 set ircode03 0 } set ircode01 [expr "0x$ircode01" ] set ircode02 [expr "0x$ircode02" ] # The output template may be in another file than what the # source template is. if [string match $dname ""] { set dname $tmpl } # Change @OC@ in the template file to $opcode set in_fd [open $srcdir/$subdir/$tmpl.s r] set out_fd [open $objdir/$opcode-test.s w] # FIXME: check return codes while { [gets $in_fd line] >= 0 } { if { [string match "" "$avoid_regex"] \ || ![regexp "$avoid_regex" $line] } { # verbose "Keeping $line for $opcode" # If caller passed a replacement regex, use it. if ![string match "" "$replace_regex"] { # verbose "Replacing $line with ..." regsub $replace_regex $line $replacement line # verbose "... $line" } regsub "@OC@" $line $opcode line puts $out_fd $line } else { # verbose "Skipping $line for $opcode" } } close $in_fd close $out_fd # Create output template. set in_fd [open $srcdir/$subdir/$dname.d r] set out_fd [open $objdir/$opcode-test.d w] # FIXME: check return codes while { [gets $in_fd line] >= 0 } { regsub "@OC@" $line $opcode line #send_user "$line\n" regsub "@OR@" $line $extra_OR_replace line if [string match "*@IM+????@*" $line] { # Insert the memory opcode. imcode2 occupies the high four bits # of the first (presented as leftmost) byte of the # IC parameter, and imcode1 the low four bits of the second # (rightmost) byte. regexp "^(.*)@IM\\+(.)(.)(.)(.)@(.*)$" \ $line junk leftpart n1 n2 n3 n4 rightpart # verbose "IM $n1 $n2 $n3 $n4 ($imcode1 $imcode2 $imcode3 $imcode01 $imcode02 $imcode03)" set n1 [expr 0x$n1 - $imcode01 ] set n3 [expr 0x$n3 - $imcode03 ] set n4 [expr 0x$n4 - $imcode02 ] set n [expr ($imcode1 << 12) + ($n1 << 12) + (0x$n2 << 8) \ + ($n3 << 4) + ($imcode3 << 4) + $n4 + $imcode2 ] set n [format "%04x" $n] puts $out_fd "$leftpart$n$rightpart" } elseif [string match "*@IR+????@*" $line] { # As IM, but use the register opcode. regexp "^(.*)@IR\\+(.)(.)(.)(.)@(.*)$" \ $line junk leftpart n1 n2 n3 n4 rightpart # verbose "IR $n1 $n2 $n3 $n4 ($ircode1 $ircode2 $ircode3 $ircode01 $ircode02 $ircode03)" set n1 [expr 0x$n1 - $ircode01 ] set n3 [expr 0x$n3 - $ircode03 ] set n4 [expr 0x$n4 - $ircode02 ] set n [expr ($ircode1 << 12) + ($n1 << 12) + (0x$n2 << 8) \ + ($n3 << 4) + ($ircode3 << 4) + $n4 + $ircode2 ] set n [format "%04x" $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-test # "make clean" won't delete these, so for now we must. catch "exec rm -f $objdir/$opcode-test.s $objdir/$opcode-test.d"}# --- End of arc.exp borrow ---proc test_template_insn_reg { args } {# tmpl opcode ircode avoid_regex dname ircode0 [regex replace OR_replace] if { [llength $args] == 6 } { test_template_insn_reg_mem [lindex $args 0] [lindex $args 1] \ [lindex $args 2] 00 [lindex $args 3] [lindex $args 4] \ [lindex $args 5] 00 } elseif { [llength $args] == 9 } { test_template_insn_reg_mem [lindex $args 0] [lindex $args 1] \ [lindex $args 2] 00 [lindex $args 3] [lindex $args 4] \ [lindex $args 5] 00 [lindex $args 6] [lindex $args 7] \ [lindex $args 8] } else { test_template_insn_reg_mem [lindex $args 0] [lindex $args 1] \ [lindex $args 2] 00 [lindex $args 3] [lindex $args 4] \ [lindex $args 5] 00 [lindex $args 6] [lindex $args 7] }}# For insn with only memory operands.proc test_template_insn_mem { args } {# tmpl opcode imcode avoid_regex dname imcode0 [regex replace] if { [llength $args] == 6 } { test_template_insn_reg_mem [lindex $args 0] [lindex $args 1] 00 \ [lindex $args 2] [lindex $args 3] [lindex $args 4] 00 \ [lindex $args 5] } else { test_template_insn_reg_mem [lindex $args 0] [lindex $args 1] 00 \ [lindex $args 2] [lindex $args 3] [lindex $args 4] 00 \ [lindex $args 5] [lindex $args 6] [lindex $args 7] }}# For insn without substitutions in the output pattern.proc test_template_insn_single { tmpl opcode avoid_regex dname } { test_template_insn_reg_mem $tmpl $opcode 00 00 "$avoid_regex" $dname 00 00}# For iteration over special registers. Spec reg name in "regname",# number in "regno". Type (size) in "regtype". Size-patterns to avoid# in input_avoid.proc to_sreg { regname regno regtype input_avoid } { test_template_insn_reg_mem binop move \ [format "%0x63" $regno] [format "%0xa3" $regno] \ ",r\[0-9\]+,r\[0-9\]|@OC@\[^\\.\]|$input_avoid" \ "x-to-$regtype-sreg" 063 0a3 \ "@OC@\[^ \]+ (.*),r\[0-9\]+" [format "@OC@ \\1,%s" $regname] \ $regname}# As to_sreg, but using unop, since we don't need to test constants.proc sreg_to { regname regno regtype input_avoid } { test_template_insn_reg_mem unop move \ [format "%0x67" $regno] [format "%0xa7" $regno] \ "@OC@\\." "sreg-to-x" 067 0a7 \ "@OC@ (.*)" [format "@OC@ %s,\\1" $regname] $regname}# Replace registers in pushpopproc push_pop { regname regno regtype input_avoid } { test_template_insn_reg_mem pushpop pushpop-sreg \ 00 [format "%0x00" $regno] \ "$input_avoid" "pushpop-$regtype-sreg" 00 000 \ "(\\.\[bwd\])? ((\[^, \]*,)?)r\[0-9\]+((,.*)?)" " \\2$regname\\4" $regname}## Iterate over spec reg names and spec reg numbers.#proc do_spec_regs { inner_function spec_reg_list } { for { set i 0 } { $i < [llength $spec_reg_list] } { incr i } { set regname [lindex [lindex $spec_reg_list $i] 0] set regno [lindex [lindex $spec_reg_list $i] 1] set regtype [lindex [lindex $spec_reg_list $i] 2] set input_avoid [lindex [lindex $spec_reg_list $i] 3] # verbose "$regname $regno $regtype $input_avoid" $inner_function $regname $regno $regtype $input_avoid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -