aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/lib/gm2.exp
blob: da08a565fc53378b0881a1d47c0ed469454de5b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# Copyright (C) 2003-2023 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 3 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 GCC; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.

# This file was written by Gaius Mulley (gaius.mulley@southwales.ac.uk)
# for GNU Modula-2.

# we want to use libgloss so we can get find_gcc.
load_lib libgloss.exp
load_lib prune.exp
load_lib gcc-defs.exp
load_lib target-libpath.exp
load_lib timeout.exp
load_lib timeout-dg.exp


if {[info exists individual_timeout]} {
    set gm2_previous_timeout $individual_timeout
} else {
    set gm2_previous_timeout 10
}


# set gm2_previous_timeout $individual_timeout

# We should be able to complete any test in 10 seconds.
dg-timeout S 10


# only push one level.

proc gm2_push_timeout { secs } {
    global individual_timeout
    set individual_timeout $secs
}


proc gm2_pop_timeout { } {
    global individual_timeout
    global gm2_previous_timeout
    set individual_timeout $gm2_previous_timeout
}


#
# GCC_UNDER_TEST is the compiler under test.
#

#
# default_gcc_version -- extract and print the version number of the compiler
#

proc default_gcc_version { } {
    global GCC_UNDER_TEST

    gm2_init

    # ignore any arguments after the command
    set compiler [lindex $GCC_UNDER_TEST 0]

    if ![is_remote host] {
	set compiler_name [which $compiler]
    } else {
	set compiler_name $compiler
    }

    # verify that the compiler exists
    if { $compiler_name != 0 } then {
	set tmp [remote_exec host "$compiler --version"]
	set status [lindex $tmp 0]
	set output [lindex $tmp 1]
	regexp "version.*$" $output version
	if { $status == 0 && [info exists version] } then {
	    clone_output "$compiler_name $version\n"
	} else {
	    clone_output "Couldn't determine version of $compiler_name: $output\n"
	}
    } else {
	# compiler does not exist (this should have already been detected)
	warning "$compiler does not exist"
    }
}

#
# gcc_version -- Call default_gcc_version, so we can override it if needed.
#

proc gcc_version { } {
    default_gcc_version
}

#
# gm2_init -- called at the start of each .exp script.
#
# There currently isn't much to do, but always using it allows us to
# make some enhancements without having to go back and rewrite the scripts.
#

set gm2_initialized 0
set gm2_compile_method "default"
set gm2_link_path ""
set gm2_link_libraries "m2pim m2iso"
set gm2_link_objects ""

proc gm2_set_compile_method { arg } {
    global gm2_compile_method

    send_log "********************************************\n"
    send_log "**** setting gm2_compile_method to $arg ****\n"
    send_log "********************************************\n"
    set gm2_compile_method $arg
}


proc gm2_init { args } {
    global tmpdir
    global objdir
    global rootme
    global base_dir
    global tool_root_dir
    global gluefile wrap_flags
    global gm2_initialized
    global GCC_UNDER_TEST
    global TOOL_EXECUTABLE
    global gm2_link_libraries
    global gm2_link_objects
    global gm2_link_path
    global HAVE_LIBSTDCXX_V3

    if { $gm2_initialized == 1 } { return }

    set gm2_link_objects ""
    set GCC_UNDER_TEST [lookfor_file $rootme gm2]
    append GCC_UNDER_TEST " " -B[file dirname $rootme]/gcc " " ${args}
    append GCC_UNDER_TEST " " -fno-diagnostics-show-caret
    append GCC_UNDER_TEST " " -fno-diagnostics-show-line-numbers
    append GCC_UNDER_TEST " " -fdiagnostics-color=never
    send_log "GCC_UNDER_TEST is ${GCC_UNDER_TEST}\n"

    if ![info exists tmpdir] then {
	set tmpdir /tmp
    }
    if {[target_info needs_status_wrapper] != "" && \
	    [target_info needs_status_wrapper] != "0" && \
	    ![info exists gluefile]} {
	set gluefile ${tmpdir}/gcc-testglue.o
	set result [build_wrapper $gluefile]
	if { $result != "" } {
	    set gluefile [lindex $result 0]
	    set wrap_flags [lindex $result 1]
	} else {
	    unset gluefile
	}
    }

    set gm2_link_path "[gm2_link_flags [get_multilibs]]"
    verbose $gm2_link_path 1

    # Set the default timeout value, larger tests can override
    # this if necessary.
    dg-timeout S 10
}


#
# gm2_target_compile_default -- compile a source file
#

proc gm2_target_compile_default { source dest type options } {
    global gluefile wrap_flags
    global GCC_UNDER_TEST
    global TOOL_OPTIONS
    global TEST_ALWAYS_FLAGS
    global gm2_link_objects
    global gm2_link_libraries
    global gm2_link_path

    if {[target_info needs_status_wrapper] != "" && \
	    [target_info needs_status_wrapper] != "0" && \
	    [info exists gluefile] } {
	lappend options "libs=${gluefile}"
	lappend options "ldflags=$wrap_flags"
    }

    # TEST_ALWAYS_FLAGS are flags that should be passed to every
    # compilation.  They are passed first to allow individual
    # tests to override them.
    if [info exists TEST_ALWAYS_FLAGS] {
	set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
    }

    global TEST_EXTRA_LIBS
    if [info exists TEST_EXTRA_LIBS] {
	lappend options "ldflags=$TEST_EXTRA_LIBS"
    }

    if [target_info exists gcc,stack_size] {
	lappend options "additional_flags=-DSTACK_SIZE=[target_info gcc,stack_size]"
    }
    if [target_info exists gcc,no_trampolines] {
	lappend options "additional_flags=-DNO_TRAMPOLINES"
    }
    if [target_info exists gcc,no_label_values] {
	lappend options "additional_flags=-DNO_LABEL_VALUES"
    }
    if [info exists TOOL_OPTIONS] {
	lappend options "additional_flags=$TOOL_OPTIONS"
    }
    lappend options "timeout=[timeout_value]"
    lappend options "compiler=$GCC_UNDER_TEST"
    # puts stderr "options = $options\n"
    # puts stderr "***** target_compile: $source $dest $type $options\n"
    return [target_compile $source $dest $type $options]
}


#
# gm2_target_compile -- compile a source file
#

proc gm2_target_compile { source dest type options } {
    global gm2_compile_method

    return [gm2_target_compile_${gm2_compile_method} $source $dest $type $options]
}

#
#  gm2_link_lib - allows tests to specify link libraries.
#                  This _must_ be called before gm2_init.
#

proc gm2_link_lib { libraries } {
    global gm2_link_libraries

    set gm2_link_libraries $libraries
}


#
#  gm2_link_obj - allows tests to specify link with objects.
#

proc gm2_link_obj { objects } {
    global gm2_link_objects

    set gm2_link_objects $objects
}


#
#  gm2_link_flags - detects the whereabouts of libraries (-lstdc++).
#

proc gm2_link_flags { paths } {
    global srcdir
    global ld_library_path
    global gccpath
    global gm2_link_libraries

    set gccpath ${paths}
    set libio_dir ""
    set flags ""
    set ld_library_path "."

    set shlib_ext [get_shlib_extension]
    verbose "shared lib extension: $shlib_ext"

    if { $gccpath == "" } {
      global tool_root_dir

      set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
      if { $libstdcpp != "" } {
          append flags "-L${libstdcpp} "
          append ld_library_path ":${libstdcpp}"
      }
    } else {
	if [file exists "${gccpath}/lib/libstdc++.a"] {
	    append ld_library_path ":${gccpath}/lib"
	}
	if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
	    append flags "-L${gccpath}/libstdc++ "
	    append ld_library_path ":${gccpath}/libstdc++"
	}
	if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
	    append flags " -L${gccpath}/libstdc++-v3/src/.libs "
	    append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
	}
	# Look for libstdc++.${shlib_ext}.
	if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
	    append flags " -L${gccpath}/libstdc++-v3/src/.libs "
	    append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
	}

	# puts stderr "${gm2_link_libraries}  before foreach"
	foreach d [list {*}${gm2_link_libraries}] {
	    # puts stderr "${d}  XXXX"
	    send_log "ld_library_path was ${ld_library_path}\n"
	    send_log "looking for ${gccpath}/lib${d}/.libs/lib${d}.a\n"
	    if [file exists "${gccpath}/libgm2/lib${d}/.libs/lib${d}.a"] {
		send_log "good found ${gccpath}/libgm2/lib${d}/.libs/lib${d}.a\n"
		# append flags " -L${gccpath}/libgm2/lib${d}/.libs -l${d}"
		append flags " ${gccpath}/libgm2/lib${d}/.libs/lib${d}.a"
		append ld_library_path ":${gccpath}/libgm2/lib${d}/.libs"
	    }
	    send_log "ld_library_path is ${ld_library_path}\n"
	}

	global GCC_UNDER_TEST
	append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
    }

    set_ld_library_path_env_vars
    return "$flags"
}


#
#  gm2_init_pimx - set the default libraries to choose PIM and then ISO.
#                  choose Modula-2, dialect.
#
#

proc gm2_init_pimx { dialect paths args } {
    global srcdir
    global gccpath

    set gm2src ${srcdir}/../m2


    send_log "srcdir is $srcdir\n"
    send_log "gccpath is $gccpath\n"
    send_log "gm2src is $gm2src\n"

    set theIpath -I${gccpath}/libgm2/libm2pim
    lappend theIpath -I${gm2src}/gm2-libs-log

    # NOTE:
    lappend theIpath -I${gm2src}/gm2-libs

    set theLpath -L${gccpath}/libgm2/libm2pim/.libs

    lappend theIpath -I${gccpath}/libgm2/libm2iso
    lappend theIpath -I${gm2src}/gm2-libs-iso

    lappend theLpath -L${gccpath}/libgm2/libm2iso/.libs

    foreach p $paths {
	lappend theIpath -I$p
    }

    gm2_link_lib "m2pim m2iso"
    lappend args -fno-libs=-
    gm2_init {*}${theIpath} {*}${dialect} {*}${theLpath} {*}${args}
}

#
#  gm2_init_pim - set the default libraries to choose PIM and then ISO.
#
#

proc gm2_init_pim { paths args } {
    gm2_init_pimx -fpim $paths {*}${args}
}


#
#  gm2_init_pim2 - set the default libraries to choose PIM and then ISO.
#                  It uses the PIM2 dialect.
#

proc gm2_init_pim2 { paths args } {
    gm2_init_pimx -fpim2 $paths {*}${args}
}


#
#  gm2_init_pim3 - set the default libraries to choose PIM and then ISO.
#                  It uses the PIM3 dialect.
#

proc gm2_init_pim3 { paths args } {
    gm2_init_pimx -fpim3 $paths {*}${args}
}


#
#  gm2_init_pim4 - set the default libraries to choose PIM and then ISO.
#                  It uses the PIM4 dialect.
#

proc gm2_init_pim4 { paths args } {
    gm2_init_pimx -fpim4 $paths {*}${args}
}


#
#  gm2_init_iso - set the default libraries to choose ISO and then PIM.
#

proc gm2_init_iso { paths args } {
    global srcdir
    global gccpath

    set gm2src ${srcdir}/../m2

    set theIpath -I${gccpath}/libgm2/libm2iso
    lappend theIpath -I${gm2src}/gm2-libs-iso

    set theLpath -L${gccpath}/libgm2/libm2iso/.libs

    lappend theIpath -I${gccpath}/libgm2/libm2pim
    lappend theIpath -I${gm2src}/gm2-libs-log

    # NOTE:
    lappend theIpath -I${gm2src}/gm2-libs

    lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs

    lappend theIpath -I${gccpath}/libgm2/libm2cor
    lappend theIpath -I${gm2src}/gm2-libs-coroutines

    lappend theLpath -L${gccpath}/libgm2/libm2cor/.libs

    foreach p $paths {
	lappend theIpath -I$p
    }

    gm2_link_lib "m2iso m2pim m2cor"
    lappend args -fno-libs=-
    gm2_init {*}${theIpath} -fiso {*}${theLpath} {*}${args}
}

#
#  gm2_init_ulm - set the default libraries to choose the ULM and PIM libraries.
#

proc gm2_init_ulm { paths args } {
    global srcdir
    global gccpath

    set gm2src ${srcdir}/../m2

    set theIpath -I${gccpath}/libgm2/libm2ulm
    lappend theIpath -I${gm2src}/ulm-lib-gm2/std
    lappend theIpath -I${gm2src}/ulm-lib-gm2/sys

    set theLpath -L${gccpath}/libgm2/libm2ulm/.libs

    lappend theIpath -I${gccpath}/libgm2/libm2pim
    lappend theIpath -I${gm2src}/gm2-libs-log

    # NOTE:
    lappend theIpath -I${gm2src}/gm2-libs

    lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs

    foreach p $paths {
	lappend theIpath -I$p
    }

    gm2_link_lib "m2ulm m2pim"
    lappend args -fno-libs=-
    gm2_init {*}${theIpath} -fpim {*}${theLpath} {*}${args}
}


#
#  gm2_init_log - set the default libraries to choose LOG and then PIM.
#
#

proc gm2_init_log { paths args } {
    global srcdir
    global gccpath

    set gm2src ${srcdir}/../m2

    send_log "srcdir is $srcdir\n"
    send_log "gccpath is $gccpath\n"
    send_log "gm2src is $gm2src\n"

    # FIXME: this seems to interleave the library defs.
    set theIpath -I${gccpath}/libgm2/libm2log
    lappend theIpath -I${gm2src}/gm2-libs-log

    set theLpath -L${gccpath}/libgm2/libm2log/.libs

    lappend theIpath -I${gccpath}/libgm2/libm2pim
    lappend theIpath -I${gm2src}/gm2-libs

    lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs

    lappend theIpath -I${gccpath}/libgm2/libm2iso
    lappend theIpath -I${gm2src}/gm2-libs-iso
    # ??? lappend theIpath -I${gm2src}/gm2-libs

    lappend theLpath -L${gccpath}/libgm2/libm2iso/.libs

    foreach p $paths {
	lappend theIpath -I$p
    }

    gm2_link_lib "m2log m2pim m2iso"
    lappend args -fno-libs=-
    gm2_init {*}${theIpath} -fpim {*}${theLpath} {*}${args}
}

#
#  gm2_init_cor - set the default libraries to choose COR and then PIM.
#
#

proc gm2_init_cor { paths args } {
    global srcdir
    global gccpath
    global gm2_link_libraries

    set gm2src ${srcdir}/../m2

    send_log "srcdir is $srcdir\n"
    send_log "gccpath is $gccpath\n"
    send_log "gm2src is $gm2src\n"

    set theIpath -I${gccpath}/libgm2/libm2cor
    lappend theIpath -I${gm2src}/gm2-libs-coroutines

    set theLpath -L${gccpath}/libgm2/libm2cor/.libs

    lappend theIpath -I${gccpath}/libgm2/libm2pim
    lappend theIpath -I${gm2src}/gm2-libs-log

    lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs

    lappend theIpath -I${gccpath}/libgm2/libm2log
    lappend theIpath -I${gm2src}/gm2-libs

    lappend theLpath -L${gccpath}/libgm2/libm2log/.libs

    lappend theIpath -I${gccpath}/libgm2/libm2iso
    lappend theIpath -I${gm2src}/gm2-libs-iso

    lappend theLpath -L${gccpath}/libgm2/libm2iso/.libs

    foreach p $paths {
	lappend theIpath -I$p
    }

    gm2_link_lib "m2cor m2pim m2log m2iso"
    append args " -fno-libs=- "
    gm2_init {*}${theIpath} -fpim {*}${theLpath} {*}${args}
}


#
#  gm2_init_minx - set the default libraries to choose MIN library and
#                  choose Modula-2, dialect.
#
#

proc gm2_init_minx { dialect paths args } {
    global srcdir
    global gccpath
    set gm2src ${srcdir}/../m2

    send_log "srcdir is $srcdir\n"
    send_log "gccpath is $gccpath\n"
    send_log "gm2src is $gm2src\n"

    set theIpath -I${gccpath}/libgm2/libm2min
    lappend theIpath -I${gm2src}/gm2-libs-min

    set theLpath -L${gccpath}/libgm2/libm2min/.libs

    foreach p $paths {
	lappend theIpath -I$p
    }

    gm2_link_lib "m2min"
    lappend args -fno-exceptions
    lappend args -fno-libs=-
    gm2_init {*}${theIpath} {*}${dialect} {*}${theLpath} {*}${args}
}

#
#  gm2_init_min - set the default libraries to choose MIN libraries
#                 and pim dialect.
#

proc gm2_init_min { paths args } {
    gm2_init_minx -fpim $paths {*}${args}
}