OSDN Git Service

6a11b2d6e666f55bee529bce9c78ee0733d06fc0
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / mips / mips.exp
1 #   Copyright (C) 1997, 2007 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3.  If not see
15 # <http://www.gnu.org/licenses/>.
16
17 # GCC testsuite that uses the `dg.exp' driver.
18
19 # Exit immediately if this isn't a MIPS target.
20 if ![istarget mips*-*-*] {
21   return
22 }
23
24 # Load support procs.
25 load_lib gcc-dg.exp
26
27 # Find out which target is selected by the default compiler flags.
28 # Also remember which aspects of the target are forced on the command
29 # line (as opposed to being overridable defaults).
30 #
31 #    $mips_isa:          the ISA level specified by __mips
32 #    $mips_arch:         the architecture specified by _MIPS_ARCH
33 #    $mips_mips16:       true if MIPS16 mode is selected
34 #    $mips_mips64:       true if 64-bit output is selected
35 #    $mips_float:        "hard" or "soft"
36 #
37 #    $mips_forced_isa:   true if the command line uses -march=* or -mips*
38 #    $mips_forced_abi:   true if the command line uses -mabi=* or -mgp*
39 #    $mips_forced_float: true if the command line uses -mhard/soft-float
40 proc setup_mips_tests {} {
41     global mips_isa
42     global mips_arch
43     global mips_mips16
44     global mips_mips64
45     global mips_float
46
47     global mips_forced_isa
48     global mips_forced_abi
49     global mips_forced_float
50
51     global compiler_flags
52     global tool
53
54     set src dummy[pid].c
55     set f [open $src "w"]
56     puts $f {
57         int isa = __mips;
58         const char *arch = _MIPS_ARCH;
59         #ifdef __mips16
60         int mips16 = 1;
61         #endif
62         #ifdef __mips64
63         int mips64 = 1;
64         #endif
65         #ifdef __mips_hard_float
66         const char *float = "hard";
67         #else
68         const char *float = "soft";
69         #endif
70     }
71     close $f
72     set output [${tool}_target_compile $src "" preprocess ""]
73     file delete $src
74
75     regexp {isa = ([^;]*)} $output dummy mips_isa
76     regexp {arch = "([^"]*)} $output dummy mips_arch
77     set mips_mips16 [regexp {mips16 = 1} $output]
78     set mips_mips64 [regexp {mips64 = 1} $output]
79     regexp {float = "([^"]*)} $output dummy mips_float
80
81     set mips_forced_isa [regexp -- {(-mips|-march)} $compiler_flags]
82     set mips_forced_abi [regexp -- {(-mgp|-mfp|-mabi)} $compiler_flags]
83     set mips_forced_float [regexp -- {-m(hard|soft)-float} $compiler_flags]
84 }
85
86 # Return true if command-line option FLAG forces 32-bit code.
87 proc is_gp32_flag {flag} {
88     switch -glob -- $flag {
89         -msmartmips -
90         -march=mips32* -
91         -mgp32 { return 1 }
92         default { return 0 }
93     }
94 }
95
96 # Like dg-options, but treats certain MIPS-specific options specially:
97 #
98 #    -mgp32
99 #    -march=mips32*
100 #       Force 32-bit code.  Skip the test if the multilib flags force
101 #       a 64-bit ABI.
102 #
103 #    -mgp64
104 #       Force 64-bit code.  Also force a 64-bit target architecture
105 #       if the other flags don't do so.  Skip the test if the multilib
106 #       flags force a 32-bit ABI or a 32-bit architecture.
107 #
108 #    -mno-mips16
109 #       Skip the test for MIPS16 targets.
110 #
111 #    -march=*
112 #    -mips*
113 #       Select the target architecture.  Skip the test for MIPS16 targets
114 #       or if the multilib flags force a different architecture.
115 #
116 #    -msoft-float
117 #    -mhard-float
118 #       Select the given floating-point mode.  Skip the test if the
119 #       multilib flags force a different selection.
120 proc dg-mips-options {args} {
121     upvar dg-extra-tool-flags extra_tool_flags
122     upvar dg-do-what do_what
123
124     global mips_isa
125     global mips_arch
126     global mips_mips16
127     global mips_mips64
128     global mips_float
129
130     global mips_forced_isa
131     global mips_forced_abi
132     global mips_forced_float
133
134     set flags [lindex $args 1]
135     set matches 1
136
137     # First handle the -mgp* options.  Add an architecture option if necessary.
138     foreach flag $flags {
139         if {[is_gp32_flag $flag] && $mips_mips64} {
140             if {$mips_forced_abi} {
141                 set matches 0
142             } else {
143                 append flags " -mabi=32"
144             }
145         } elseif {$flag == "-mgp64" && !$mips_mips64} {
146             if {$mips_forced_abi} {
147                 set matches 0
148             } else {
149                 append flags " -mabi=o64"
150                 if {[lsearch -regexp $flags {^(-mips|-march)}] < 0} {
151                     append flags " -mips3"
152                 }
153             }
154         }
155     }
156     # Handle the other options.
157     foreach flag $flags {
158         if {$flag == "-mno-mips16"} {
159             if {$mips_mips16} {
160                 set matches 0
161             }
162         } elseif {$flag == "-mfp64"} {
163             if {$mips_isa < 33 || $mips_float != "hard"} {
164                 set matches 0
165             }
166         } elseif {[regexp -- {^-march=(.*)} $flag dummy arch]} {
167             if {$mips_mips16 || ($arch != $mips_arch && $mips_forced_isa)} {
168                 set matches 0
169             }
170         } elseif {[regexp -- {^-mips(.*)} $flag dummy isa] && $isa != 16} {
171             if {$mips_mips16 || ($isa != $mips_isa && $mips_forced_isa)} {
172                 set matches 0
173             }
174         } elseif {[regexp -- {^-m(hard|soft)-float} $flag dummy float]} {
175             if {$mips_float != $float && $mips_forced_float} {
176                 set matches 0
177             }
178         }
179     }
180     if {$matches} {
181         set extra_tool_flags $flags
182     } else {
183         set do_what [list [lindex $do_what 0] "N" "P"]
184     }
185 }
186
187 setup_mips_tests
188
189 dg-init
190 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c]] "" ""
191 dg-finish