+
+# The functions below create and manipulate an "architecture data
+# array" which contains entries for each MIPS architecture (or CPU)
+# known to these tests. The array contains the following information
+# for each architecture, indexed by the name of the architecture
+# described by the entry:
+#
+# displayname: The name of the entry to be used for pretty-printing.
+#
+# gprsize: The size in bits of General Purpose Registers provided by
+# the architecture (must be 32 or 64).
+#
+# props: A list of text strings which are associated with the
+# architecture. These include the architecture name as well as
+# information about what instructions the CPU supports. When matching
+# based on properties, an additional property is added to the normal
+# property list, "gpr<gprsize>" so that tests can match CPUs which
+# have GPRs of a specific size. The following properties are most
+# useful when matching properties for generic (i.e., not CPU-specific)
+# tests:
+#
+# mips1, mips2, mips3, mips4, mips5, mips32, mips64
+# The architecture includes the instructions defined
+# by that MIPS ISA.
+#
+# gpr_ilocks
+# The architecture interlocks GPRs accesses. (That is,
+# there are no load delay slots.)
+#
+# mips3d The architecture includes the MIPS-3D ASE.
+#
+# ror The architecture includes hardware rotate instructions.
+#
+# gpr32, gpr64
+# The architecture provides 32- or 64-bit General Purpose
+# Registers.
+#
+# as_flags: The assembler flags used when assembling tests for this
+# architecture.
+#
+# objdump_flags: The objdump flags used when disassembling tests for
+# this architecture.
+#
+# Most entries in the architecture array will have values in all of
+# the fields above. One entry, "default" represents the default CPU
+# based on the target of the assembler being built. If always has
+# empty "as_flags" and "objdump_flags."
+
+# mips_arch_init
+#
+# This function initializes the architecture data array ("mips_arches")
+# to be empty.
+proc mips_arch_init {} {
+ global mips_arches
+
+ # Catch becuase the variable won't be set the first time through.
+ catch {unset mips_arches}
+}
+
+# mips_arch_create ARCH GPRSIZE EXTENDS PROPS AS_FLAGS OBJDUMP_FLAGS \
+# (optional:) DEFAULT_FOR_TARGETS
+#
+# This function creates a new entry in the architecture data array,
+# for the architecture or CPU named ARCH, and fills in the entry
+# according to the rest of the arguments.
+#
+# The new entry's property list is initialized to contain ARCH, any
+# properties specified by PROPS, and the properties associated with
+# the entry specified by EXTENDS. (The new architecture is considered
+# to extend the capabilities provided by that architecture.)
+#
+# If DEFAULT_FOR_TARGETS is specified, it is a list of targets for which
+# this architecture is the default architecture. If "istarget" returns
+# true for any of the targets in the list, a "default" entry will be
+# added to the architecture array which indicates that ARCH is the default
+# architecture.
+proc mips_arch_create {arch gprsize extends props as_flags objdump_flags
+ {default_for_targets {}}} {
+ global mips_arches
+
+ if { [info exists mips_arches($arch)] } {
+ error "mips_arch_create: arch \"$arch\" already exists"
+ }
+ if { $gprsize != 32 && $gprsize != 64 } {
+ error "mips_arch_create: invalid GPR size $gprsize"
+ }
+
+ set archdata(displayname) $arch
+ set archdata(gprsize) $gprsize
+ set archdata(as_flags) $as_flags
+ set archdata(objdump_flags) $objdump_flags
+ set archdata(props) $arch
+ eval lappend archdata(props) $props
+ if { [string length $extends] != 0 } {
+ eval lappend archdata(props) [mips_arch_properties $extends 0]
+ }
+
+ set mips_arches($arch) [array get archdata]
+
+ # Set as default if appropriate.
+ foreach target $default_for_targets {
+ if { [istarget $target] } {
+ if { [info exists mips_arches(default)] } {
+ error "mips_arch_create: default arch already exists"
+ }
+
+ set archdata(displayname) "default = $arch"
+ set archdata(as_flags) ""
+ set archdata(objdump_flags) ""
+
+ set mips_arches(default) [array get archdata]
+ break
+ }
+ }
+}
+
+# mips_arch_list_all
+#
+# This function returns the list of all names of entries in the
+# architecture data array (including the default entry, if a default
+# is known).
+proc mips_arch_list_all {} {
+ global mips_arches
+ return [lsort -dictionary [array names mips_arches]]
+}
+
+# mips_arch_data ARCH
+#
+# This function returns the information associated with ARCH
+# in the architecture data array, in "array get" form.
+proc mips_arch_data {arch} {
+ global mips_arches
+
+ if { ! [info exists mips_arches($arch)] } {
+ error "mips_arch_data: unknown arch \"$arch\""
+ }
+ return $mips_arches($arch)
+}
+
+# mips_arch_displayname ARCH
+#
+# This function returns the printable name associated with ARCH in
+# the architecture data array.
+proc mips_arch_displayname {arch} {
+ array set archdata [mips_arch_data $arch]
+ return $archdata(displayname)
+}
+
+# mips_arch_properties ARCH (optional:) INCLUDE_GPRSIZE
+#
+# This function returns the property list associated with ARCH in the
+# architecture data array. If INCLUDE_GPRSIZE is non-zero, an additional
+# "gpr32" or "gpr64" property will be returned as part of the list based
+# on the architecture's GPR size.
+proc mips_arch_properties {arch {include_gprsize 1}} {
+ array set archdata [mips_arch_data $arch]
+ set props $archdata(props)
+ if { $include_gprsize } {
+ lappend props gpr$archdata(gprsize)
+ }
+ return $props
+}
+
+# mips_arch_as_flags ARCH
+#
+# This function returns the assembler flags associated with ARCH in
+# the architecture data array.
+proc mips_arch_as_flags {arch} {
+ array set archdata [mips_arch_data $arch]
+ return $archdata(as_flags)
+}
+
+# mips_arch_objdump_flags ARCH
+#
+# This function returns the objdump disassembly flags associated with
+# ARCH in the architecture data array.
+proc mips_arch_objdump_flags {arch} {
+ array set archdata [mips_arch_data $arch]
+ return $archdata(objdump_flags)
+}
+
+# mips_arch_matches ARCH PROPMATCHLIST
+#
+# This function returns non-zero if ARCH matches the set of properties
+# described by PROPMATCHLIST. Each entry in PROPMATCHLIST can either
+# be the name of a property which must be matched, or "!" followed by
+# the name of a property which must not be matched. ARCH matches
+# PROPMATCHLIST if and only if all of the conditions specified by
+# PROPMATCHLIST are satisfied.
+proc mips_arch_matches {arch propmatchlist} {
+ foreach pm $propmatchlist {
+ if { [string match {!*} $pm] } {
+ # fail if present.
+ set inverted 1
+ set p [string range $pm 1 end]
+ } {
+ # fail if not present.
+ set inverted 0
+ set p $pm
+ }
+
+ set loc [lsearch -exact [mips_arch_properties $arch] $p]
+
+ # required-absent and found, or required-present and not found: fail.
+ if { ($inverted && $loc != -1) || (! $inverted && $loc == -1) } {
+ return 0
+ }
+ }
+ return 1
+}
+
+# mips_arch_list_matching ARGS
+#
+# This function returns a list of all architectures which match
+# the conditions described by its arguments. Its arguments are
+# taken as a list and used as the PROPMATCHLIST in a call to
+# "mips_arch_matches" for each known architecture.
+proc mips_arch_list_matching {args} {
+ set l ""
+ foreach arch [mips_arch_list_all] {
+ # For now, don't match default arch until we know what its
+ # properties actually are.
+ if { [string compare $arch default] == 0
+ && [string length [mips_arch_properties default]] == 0} {
+ continue
+ }
+ if { [mips_arch_matches $arch $args] } {
+ lappend l $arch
+ }
+ }
+ return $l
+}
+
+
+# The functions below facilitate running various types of tests.
+
+# run_dump_test_arch NAME ARCH
+#
+# Invoke "run_dump_test" for test NAME, with extra assembler and
+# disassembler flags to test architecture ARCH.
+proc run_dump_test_arch { name arch } {
+ global subdir
+
+ if [catch {run_dump_test $name \
+ "{name {([mips_arch_displayname $arch])}}
+ {objdump {[mips_arch_objdump_flags $arch]}}
+ {as {[mips_arch_as_flags $arch]}}"} rv] {
+ perror "$rv"
+ untested "$subdir/$name ($arch)"
+ }
+}
+
+# run_dump_test_arches NAME ARCH_LIST
+#
+# Invoke "run_dump_test_arch" for test NAME, for each architecture
+# listed in ARCH_LIST.
+proc run_dump_test_arches { name arch_list } {
+ foreach arch $arch_list {
+ run_dump_test_arch "$name" "$arch"
+ }
+}
+
+# run_list_test NAME OPTS (optional): TESTNAME
+#
+# Assemble the file "NAME.d" and compare the assembler standard error
+# output against the regular expressions given in the file "NAME.l".
+# The assembler is passed the flags given in OPTS. If TESTNAME is
+# provided, it will be used as the name of the test.
+proc run_list_test { name opts {testname {}} } {