RISC-V: Refactor Dynamic LMUL codes
[official-gcc.git] / gcc / testsuite / lib / gm2.exp
blob82915e35f5c8180ec8b0fb8fcff42dd83bb94e77
1 # Copyright (C) 2003-2023 Free Software Foundation, Inc.
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.
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.
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/>.
17 # This file was written by Gaius Mulley (gaius.mulley@southwales.ac.uk)
18 # for GNU Modula-2.
20 # we want to use libgloss so we can get find_gcc.
21 load_lib libgloss.exp
22 load_lib prune.exp
23 load_lib gcc-defs.exp
24 load_lib target-libpath.exp
25 load_lib timeout.exp
26 load_lib timeout-dg.exp
29 if {[info exists individual_timeout]} {
30 set gm2_previous_timeout $individual_timeout
31 } else {
32 set gm2_previous_timeout 10
36 # set gm2_previous_timeout $individual_timeout
38 # We should be able to complete any test in 10 seconds.
39 dg-timeout S 10
42 # only push one level.
44 proc gm2_push_timeout { secs } {
45 global individual_timeout
46 set individual_timeout $secs
50 proc gm2_pop_timeout { } {
51 global individual_timeout
52 global gm2_previous_timeout
53 set individual_timeout $gm2_previous_timeout
58 # GCC_UNDER_TEST is the compiler under test.
62 # default_gcc_version -- extract and print the version number of the compiler
65 proc default_gcc_version { } {
66 global GCC_UNDER_TEST
68 gm2_init
70 # ignore any arguments after the command
71 set compiler [lindex $GCC_UNDER_TEST 0]
73 if ![is_remote host] {
74 set compiler_name [which $compiler]
75 } else {
76 set compiler_name $compiler
79 # verify that the compiler exists
80 if { $compiler_name != 0 } then {
81 set tmp [remote_exec host "$compiler --version"]
82 set status [lindex $tmp 0]
83 set output [lindex $tmp 1]
84 regexp "version.*$" $output version
85 if { $status == 0 && [info exists version] } then {
86 clone_output "$compiler_name $version\n"
87 } else {
88 clone_output "Couldn't determine version of $compiler_name: $output\n"
90 } else {
91 # compiler does not exist (this should have already been detected)
92 warning "$compiler does not exist"
97 # gcc_version -- Call default_gcc_version, so we can override it if needed.
100 proc gcc_version { } {
101 default_gcc_version
105 # gm2_init -- called at the start of each .exp script.
107 # There currently isn't much to do, but always using it allows us to
108 # make some enhancements without having to go back and rewrite the scripts.
111 set gm2_initialized 0
112 set gm2_compile_method "default"
113 set gm2_link_path ""
114 set gm2_link_libraries "m2pim m2iso"
115 set gm2_link_objects ""
117 proc gm2_set_compile_method { arg } {
118 global gm2_compile_method
120 send_log "********************************************\n"
121 send_log "**** setting gm2_compile_method to $arg ****\n"
122 send_log "********************************************\n"
123 set gm2_compile_method $arg
127 proc gm2_init { args } {
128 global tmpdir
129 global objdir
130 global rootme
131 global base_dir
132 global tool_root_dir
133 global gluefile wrap_flags
134 global gm2_initialized
135 global GCC_UNDER_TEST
136 global TOOL_EXECUTABLE
137 global gm2_link_libraries
138 global gm2_link_objects
139 global gm2_link_path
140 global HAVE_LIBSTDCXX_V3
142 if { $gm2_initialized == 1 } { return }
144 set gm2_link_objects ""
145 set GCC_UNDER_TEST [lookfor_file $rootme gm2]
146 append GCC_UNDER_TEST " " -B[file dirname $rootme]/gcc " " ${args}
147 append GCC_UNDER_TEST " " -fno-diagnostics-show-caret
148 append GCC_UNDER_TEST " " -fno-diagnostics-show-line-numbers
149 append GCC_UNDER_TEST " " -fdiagnostics-color=never
150 send_log "GCC_UNDER_TEST is ${GCC_UNDER_TEST}\n"
152 if ![info exists tmpdir] then {
153 set tmpdir /tmp
155 if {[target_info needs_status_wrapper] != "" && \
156 [target_info needs_status_wrapper] != "0" && \
157 ![info exists gluefile]} {
158 set gluefile ${tmpdir}/gcc-testglue.o
159 set result [build_wrapper $gluefile]
160 if { $result != "" } {
161 set gluefile [lindex $result 0]
162 set wrap_flags [lindex $result 1]
163 } else {
164 unset gluefile
168 set gm2_link_path "[gm2_link_flags [get_multilibs]]"
169 verbose $gm2_link_path 1
171 # Set the default timeout value, larger tests can override
172 # this if necessary.
173 dg-timeout S 10
178 # gm2_target_compile_default -- compile a source file
181 proc gm2_target_compile_default { source dest type options } {
182 global gluefile wrap_flags
183 global GCC_UNDER_TEST
184 global TOOL_OPTIONS
185 global TEST_ALWAYS_FLAGS
186 global gm2_link_objects
187 global gm2_link_libraries
188 global gm2_link_path
190 if {[target_info needs_status_wrapper] != "" && \
191 [target_info needs_status_wrapper] != "0" && \
192 [info exists gluefile] } {
193 lappend options "libs=${gluefile}"
194 lappend options "ldflags=$wrap_flags"
197 # TEST_ALWAYS_FLAGS are flags that should be passed to every
198 # compilation. They are passed first to allow individual
199 # tests to override them.
200 if [info exists TEST_ALWAYS_FLAGS] {
201 set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
204 global TEST_EXTRA_LIBS
205 if [info exists TEST_EXTRA_LIBS] {
206 lappend options "ldflags=$TEST_EXTRA_LIBS"
209 if [target_info exists gcc,stack_size] {
210 lappend options "additional_flags=-DSTACK_SIZE=[target_info gcc,stack_size]"
212 if [target_info exists gcc,no_trampolines] {
213 lappend options "additional_flags=-DNO_TRAMPOLINES"
215 if [target_info exists gcc,no_label_values] {
216 lappend options "additional_flags=-DNO_LABEL_VALUES"
218 if [info exists TOOL_OPTIONS] {
219 lappend options "additional_flags=$TOOL_OPTIONS"
221 if [istarget *-*-solaris2*] {
222 lappend options "ldflags=-lnsl -lsocket"
224 if [istarget "powerpc-*-*"] {
225 lappend options "-mabi=ieeelongdouble"
228 lappend options "timeout=[timeout_value]"
229 lappend options "compiler=$GCC_UNDER_TEST"
230 # puts stderr "options = $options\n"
231 # puts stderr "***** target_compile: $source $dest $type $options\n"
232 return [target_compile $source $dest $type $options]
237 # gm2_target_compile -- compile a source file
240 proc gm2_target_compile { source dest type options } {
241 global gm2_compile_method
243 return [gm2_target_compile_${gm2_compile_method} $source $dest $type $options]
248 # gm2_link_lib - allows tests to specify link libraries.
249 # This _must_ be called before gm2_init.
252 proc gm2_link_lib { libraries } {
253 global gm2_link_libraries
255 set gm2_link_libraries $libraries
260 # gm2_link_obj - allows tests to specify link with objects.
263 proc gm2_link_obj { objects } {
264 global gm2_link_objects
266 set gm2_link_objects $objects
271 # gm2_link_flags - detects the whereabouts of libraries (-lstdc++).
274 proc gm2_link_flags { paths } {
275 global srcdir
276 global ld_library_path
277 global gccpath
278 global gm2_link_libraries
280 set gccpath ${paths}
281 set libio_dir ""
282 set flags ""
283 set ld_library_path "."
285 set shlib_ext [get_shlib_extension]
286 verbose "shared lib extension: $shlib_ext"
288 if [istarget "powerpc-*-*"] {
289 lappend flags "-mabi=ieeelongdouble"
291 if { $gccpath == "" } {
292 global tool_root_dir
294 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
295 if { $libstdcpp != "" } {
296 append flags "-L${libstdcpp} "
297 append ld_library_path ":${libstdcpp}"
299 } else {
300 if [file exists "${gccpath}/lib/libstdc++.a"] {
301 append ld_library_path ":${gccpath}/lib"
303 if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
304 append flags "-L${gccpath}/libstdc++ "
305 append ld_library_path ":${gccpath}/libstdc++"
307 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
308 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
309 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
311 # Look for libstdc++.${shlib_ext}.
312 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
313 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
314 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
317 # puts stderr "${gm2_link_libraries} before foreach"
318 foreach d [list {*}${gm2_link_libraries}] {
319 # puts stderr "${d} XXXX"
320 send_log "ld_library_path was ${ld_library_path}\n"
321 send_log "looking for ${gccpath}/lib${d}/.libs/lib${d}.a\n"
322 if [file exists "${gccpath}/libgm2/lib${d}/.libs/lib${d}.a"] {
323 send_log "good found ${gccpath}/libgm2/lib${d}/.libs/lib${d}.a\n"
324 # append flags " -L${gccpath}/libgm2/lib${d}/.libs -l${d}"
325 append flags " ${gccpath}/libgm2/lib${d}/.libs/lib${d}.a"
326 append ld_library_path ":${gccpath}/libgm2/lib${d}/.libs"
328 send_log "ld_library_path is ${ld_library_path}\n"
331 global GCC_UNDER_TEST
332 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
335 set_ld_library_path_env_vars
336 return "$flags"
341 # gm2_init_pimx - set the default libraries to choose PIM and then ISO.
342 # choose Modula-2, dialect.
346 proc gm2_init_pimx { dialect paths args } {
347 global srcdir
348 global gccpath
350 set gm2src ${srcdir}/../m2
353 send_log "srcdir is $srcdir\n"
354 send_log "gccpath is $gccpath\n"
355 send_log "gm2src is $gm2src\n"
357 set theIpath -fm2-pathname=m2pim
358 lappend theIpath -I${gccpath}/libgm2/libm2pim
359 lappend theIpath -fm2-pathname=m2log
360 lappend theIpath -I${gm2src}/gm2-libs-log
362 # NOTE:
363 lappend theIpath -fm2-pathname=m2pim
364 lappend theIpath -I${gm2src}/gm2-libs
366 set theLpath -L${gccpath}/libgm2/libm2pim/.libs
368 lappend theIpath -fm2-pathname=m2iso
369 lappend theIpath -I${gccpath}/libgm2/libm2iso
370 lappend theIpath -I${gm2src}/gm2-libs-iso
372 lappend theLpath -L${gccpath}/libgm2/libm2iso/.libs
374 lappend theIpath -fm2-pathname=-
375 foreach p $paths {
376 lappend theIpath -I$p
378 lappend theIpath -fm2-pathname=-
380 gm2_link_lib "m2pim m2iso"
381 lappend args -fno-libs=-
382 gm2_init {*}${theIpath} {*}${dialect} {*}${theLpath} {*}${args}
386 # gm2_init_pim - set the default libraries to choose PIM and then ISO.
390 proc gm2_init_pim { paths args } {
391 gm2_init_pimx -fpim $paths {*}${args}
396 # gm2_init_pim2 - set the default libraries to choose PIM and then ISO.
397 # It uses the PIM2 dialect.
400 proc gm2_init_pim2 { paths args } {
401 gm2_init_pimx -fpim2 $paths {*}${args}
406 # gm2_init_pim3 - set the default libraries to choose PIM and then ISO.
407 # It uses the PIM3 dialect.
410 proc gm2_init_pim3 { paths args } {
411 gm2_init_pimx -fpim3 $paths {*}${args}
416 # gm2_init_pim4 - set the default libraries to choose PIM and then ISO.
417 # It uses the PIM4 dialect.
420 proc gm2_init_pim4 { paths args } {
421 gm2_init_pimx -fpim4 $paths {*}${args}
426 # gm2_init_iso - set the default libraries to choose ISO and then PIM.
429 proc gm2_init_iso { paths args } {
430 global srcdir
431 global gccpath
433 set gm2src ${srcdir}/../m2
435 set theIpath -fm2-pathname=m2iso
436 lappend theIpath -I${gccpath}/libgm2/libm2iso
437 lappend theIpath -I${gm2src}/gm2-libs-iso
439 set theLpath -L${gccpath}/libgm2/libm2iso/.libs
441 lappend theIpath -fm2-pathname=m2pim
442 lappend theIpath -I${gccpath}/libgm2/libm2pim
444 lappend theIpath -fm2-pathname=m2log
445 lappend theIpath -I${gm2src}/gm2-libs-log
447 # NOTE:
448 lappend theIpath -fm2-pathname=m2pim
449 lappend theIpath -I${gm2src}/gm2-libs
451 lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs
453 lappend theIpath -fm2-pathname=m2cor
454 lappend theIpath -I${gccpath}/libgm2/libm2cor
455 lappend theIpath -I${gm2src}/gm2-libs-coroutines
457 lappend theLpath -L${gccpath}/libgm2/libm2cor/.libs
459 lappend theIpath -fm2-pathname=-
460 foreach p $paths {
461 lappend theIpath -I$p
463 lappend theIpath -fm2-pathname=-
465 gm2_link_lib "m2iso m2pim m2cor"
466 lappend args -fno-libs=-
467 gm2_init {*}${theIpath} -fiso {*}${theLpath} {*}${args}
471 # gm2_init_ulm - set the default libraries to choose the ULM and PIM libraries.
474 proc gm2_init_ulm { paths args } {
475 global srcdir
476 global gccpath
478 set gm2src ${srcdir}/../m2
480 set theIpath -fm2-pathname=m2ulm
481 lappend theIpath -I${gccpath}/libgm2/libm2ulm
482 lappend theIpath -I${gm2src}/ulm-lib-gm2/std
483 lappend theIpath -I${gm2src}/ulm-lib-gm2/sys
485 set theLpath -L${gccpath}/libgm2/libm2ulm/.libs
487 lappend theIpath -fm2-pathname=m2pim
488 lappend theIpath -I${gccpath}/libgm2/libm2pim
489 lappend theIpath -fm2-pathname=m2log
490 lappend theIpath -I${gm2src}/gm2-libs-log
492 # NOTE:
493 lappend theIpath -fm2-pathname=m2pim
494 lappend theIpath -I${gm2src}/gm2-libs
496 lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs
498 lappend theIpath -fm2-pathname=-
499 foreach p $paths {
500 lappend theIpath -I$p
502 lappend theIpath -fm2-pathname=-
504 gm2_link_lib "m2ulm m2pim"
505 lappend args -fno-libs=-
506 gm2_init {*}${theIpath} -fpim {*}${theLpath} {*}${args}
511 # gm2_init_log - set the default libraries to choose LOG and then PIM.
515 proc gm2_init_log { paths args } {
516 global srcdir
517 global gccpath
519 set gm2src ${srcdir}/../m2
521 send_log "srcdir is $srcdir\n"
522 send_log "gccpath is $gccpath\n"
523 send_log "gm2src is $gm2src\n"
525 # FIXME: this seems to interleave the library defs.
526 set theIpath -fm2-pathname=m2log
527 lappend theIpath -I${gccpath}/libgm2/libm2log
528 lappend theIpath -I${gm2src}/gm2-libs-log
530 set theLpath -L${gccpath}/libgm2/libm2log/.libs
532 lappend theIpath -fm2-pathname=m2pim
533 lappend theIpath -I${gccpath}/libgm2/libm2pim
534 lappend theIpath -I${gm2src}/gm2-libs
536 lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs
538 lappend theIpath -fm2-pathname=m2iso
539 lappend theIpath -I${gccpath}/libgm2/libm2iso
540 lappend theIpath -I${gm2src}/gm2-libs-iso
541 # ??? lappend theIpath -I${gm2src}/gm2-libs
543 lappend theLpath -L${gccpath}/libgm2/libm2iso/.libs
545 lappend theIpath -fm2-pathname=-
546 foreach p $paths {
547 lappend theIpath -I$p
549 lappend theIpath -fm2-pathname=-
551 gm2_link_lib "m2log m2pim m2iso"
552 lappend args -fno-libs=-
553 gm2_init {*}${theIpath} -fpim {*}${theLpath} {*}${args}
557 # gm2_init_cor - set the default libraries to choose COR and then PIM.
561 proc gm2_init_cor { paths args } {
562 global srcdir
563 global gccpath
564 global gm2_link_libraries
566 set gm2src ${srcdir}/../m2
568 send_log "srcdir is $srcdir\n"
569 send_log "gccpath is $gccpath\n"
570 send_log "gm2src is $gm2src\n"
572 set theIpath -fm2-pathname=m2cor
573 lappend theIpath -I${gccpath}/libgm2/libm2cor
574 lappend theIpath -I${gm2src}/gm2-libs-coroutines
576 set theLpath -L${gccpath}/libgm2/libm2cor/.libs
578 lappend theIpath -fm2-pathname=m2pim
579 lappend theIpath -I${gccpath}/libgm2/libm2pim
581 lappend theIpath -fm2-pathname=m2log
582 lappend theIpath -I${gm2src}/gm2-libs-log
584 lappend theIpath -fm2-pathname=m2pim
585 lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs
587 lappend theIpath -fm2-pathname=m2log
588 lappend theIpath -I${gccpath}/libgm2/libm2log
590 lappend theIpath -fm2-pathname=m2pim
591 lappend theIpath -I${gm2src}/gm2-libs
593 lappend theIpath -fm2-pathname=m2log
594 lappend theLpath -L${gccpath}/libgm2/libm2log/.libs
596 lappend theIpath -fm2-pathname=m2iso
597 lappend theIpath -I${gccpath}/libgm2/libm2iso
598 lappend theIpath -I${gm2src}/gm2-libs-iso
600 lappend theLpath -L${gccpath}/libgm2/libm2iso/.libs
602 lappend theIpath -fm2-pathname=-
603 foreach p $paths {
604 lappend theIpath -I$p
606 lappend theIpath -fm2-pathname=-
608 gm2_link_lib "m2cor m2pim m2log m2iso"
609 append args " -fno-libs=- "
610 gm2_init {*}${theIpath} -fpim {*}${theLpath} {*}${args}
615 # gm2_init_minx - set the default libraries to choose MIN library and
616 # choose Modula-2, dialect.
620 proc gm2_init_minx { dialect paths args } {
621 global srcdir
622 global gccpath
623 set gm2src ${srcdir}/../m2
625 send_log "srcdir is $srcdir\n"
626 send_log "gccpath is $gccpath\n"
627 send_log "gm2src is $gm2src\n"
629 set theIpath -fm2-pathname=m2min
630 lappend theIpath -I${gccpath}/libgm2/libm2min
631 lappend theIpath -I${gm2src}/gm2-libs-min
633 set theLpath -L${gccpath}/libgm2/libm2min/.libs
635 lappend theIpath -fm2-pathname=-
636 foreach p $paths {
637 lappend theIpath -I$p
639 lappend theIpath -fm2-pathname=-
641 gm2_link_lib "m2min"
642 lappend args -fno-exceptions
643 lappend args -fno-libs=-
644 gm2_init {*}${theIpath} {*}${dialect} {*}${theLpath} {*}${args}
648 # gm2_init_min - set the default libraries to choose MIN libraries
649 # and pim dialect.
652 proc gm2_init_min { paths args } {
653 gm2_init_minx -fpim $paths {*}${args}