OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [lib/] [scanasm.exp] - Blame information for rev 729

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 701 jeremybenn
# Copyright (C) 2000, 2002, 2003, 2007, 2008, 2010, 2011, 2012
2
# Free Software Foundation, Inc.
3
 
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with GCC; see the file COPYING3.  If not see
16
# .
17
 
18
# Various utilities for scanning assembler output, used by gcc-dg.exp and
19
# g++-dg.exp.
20
 
21
# Utility for scanning compiler result, invoked via dg-final.
22
 
23
# Transform newline and similar characters into their escaped form.
24
proc make_pattern_printable { pattern } {
25
    return [string map {\t \\t \n \\n \r \\r \\ \\\\} $pattern]
26
}
27
 
28
# Scan the OUTPUT_FILE for a pattern.  If it is present and POSITIVE
29
# is non-zero, or it is not present and POSITIVE is zero, the test
30
# passes.  The ORIG_ARGS is the list of arguments provided by dg-final
31
# to scan-assembler.  The first element in ORIG_ARGS is the regular
32
# expression to look for in the file.  The second element, if present,
33
# is a DejaGNU target selector.
34
 
35
proc dg-scan { name positive testcase output_file orig_args } {
36
    if { [llength $orig_args] < 1 } {
37
        error "$name: too few arguments"
38
        return
39
    }
40
    if { [llength $orig_args] > 2 } {
41
        error "$name: too many arguments"
42
        return
43
    }
44
    if { [llength $orig_args] >= 2 } {
45
        switch [dg-process-target [lindex $orig_args 1]] {
46
            "S" { }
47
            "N" { return }
48
            "F" { setup_xfail "*-*-*" }
49
            "P" { }
50
        }
51
    }
52
 
53
    set pattern [lindex $orig_args 0]
54
    set printable_pattern [make_pattern_printable $pattern]
55
 
56
    if { [is_remote host] } {
57
        remote_upload host "$output_file"
58
    }
59
    set files [glob -nocomplain $output_file]
60
    if { $files == "" } {
61
        verbose -log "$testcase: output file does not exist"
62
        unresolved "$testcase $name $printable_pattern"
63
        return
64
    }
65
    set fd [open $output_file r]
66
    set text [read $fd]
67
    close $fd
68
 
69
    set match [regexp -- $pattern $text]
70
    if { $match == $positive } {
71
        pass "$testcase $name $printable_pattern"
72
    } else {
73
        fail "$testcase $name $printable_pattern"
74
    }
75
}
76
 
77
# Look for a pattern in the .s file produced by the compiler.  See
78
# dg-scan for details.
79
 
80
proc scan-assembler { args } {
81
    upvar 2 name testcase
82
    set testcase [lindex $testcase 0]
83
    set output_file "[file rootname [file tail $testcase]].s"
84
 
85
    dg-scan "scan-assembler" 1 $testcase $output_file $args
86
}
87
 
88
proc scan-assembler_required_options { args } {
89
    global gcc_force_conventional_output
90
    return $gcc_force_conventional_output
91
}
92
 
93
# Check that a pattern is not present in the .s file produced by the
94
# compiler.  See dg-scan for details.
95
 
96
proc scan-assembler-not { args } {
97
    upvar 2 name testcase
98
    set testcase [lindex $testcase 0]
99
    set output_file "[file rootname [file tail $testcase]].s"
100
 
101
    dg-scan "scan-assembler-not" 0 $testcase $output_file $args
102
}
103
 
104
proc scan-assembler-not_required_options { args } {
105
    global gcc_force_conventional_output
106
    return $gcc_force_conventional_output
107
}
108
 
109
# Return the scan for the assembly for hidden visibility.
110
 
111
proc hidden-scan-for { symbol } {
112
 
113
    set objformat [gcc_target_object_format]
114
 
115
    switch $objformat {
116
        elf      { return "hidden\[ \t_\]*$symbol" }
117
        mach-o   { return "private_extern\[ \t_\]*_?$symbol" }
118
        default  { return "" }
119
    }
120
 
121
}
122
 
123
 
124
# Check that a symbol is defined as a hidden symbol in the .s file
125
# produced by the compiler.
126
 
127
proc scan-hidden { args } {
128
    upvar 2 name testcase
129
    set testcase [lindex $testcase 0]
130
    set output_file "[file rootname [file tail $testcase]].s"
131
 
132
    set symbol [lindex $args 0]
133
 
134
    set hidden_scan [hidden-scan-for $symbol]
135
 
136
    set args [lreplace $args 0 0 "$hidden_scan"]
137
 
138
    dg-scan "scan-hidden" 1 $testcase $output_file $args
139
}
140
 
141
# Check that a symbol is not defined as a hidden symbol in the .s file
142
# produced by the compiler.
143
 
144
proc scan-not-hidden { args } {
145
    upvar 2 name testcase
146
    set testcase [lindex $testcase 0]
147
    set output_file "[file rootname [file tail $testcase]].s"
148
 
149
    set symbol [lindex $args 0]
150
    set hidden_scan [hidden-scan-for $symbol]
151
 
152
    set args [lreplace $args 0 0 "$hidden_scan"]
153
 
154
    dg-scan "scan-not-hidden" 0 $testcase $output_file $args
155
}
156
 
157
# Look for a pattern in OUTPUT_FILE.  See dg-scan for details.
158
 
159
proc scan-file { output_file args } {
160
    upvar 2 name testcase
161
    set testcase [lindex $testcase 0]
162
    dg-scan "scan-file" 1 $testcase $output_file $args
163
}
164
 
165
# Check that a pattern is not present in the OUTPUT_FILE.  See dg-scan
166
# for details.
167
 
168
proc scan-file-not { output_file args } {
169
    upvar 2 name testcase
170
    set testcase [lindex $testcase 0]
171
    dg-scan "scan-file-not" 0 $testcase $output_file $args
172
}
173
 
174
# Look for a pattern in the .su file produced by the compiler.  See
175
# dg-scan for details.
176
 
177
proc scan-stack-usage { args } {
178
    upvar 2 name testcase
179
    set testcase [lindex $testcase 0]
180
    set output_file "[file rootname [file tail $testcase]].su"
181
 
182
    dg-scan "scan-file" 1 $testcase $output_file $args
183
}
184
 
185
# Check that a pattern is not present in the .su file produced by the
186
# compiler.  See dg-scan for details.
187
 
188
proc scan-stack-usage-not { args } {
189
    upvar 2 name testcase
190
    set testcase [lindex $testcase 0]
191
    set output_file "[file rootname [file tail $testcase]].su"
192
 
193
    dg-scan "scan-file-not" 0 $testcase $output_file $args
194
}
195
 
196
# Call pass if pattern is present given number of times, otherwise fail.
197
proc scan-assembler-times { args } {
198
    if { [llength $args] < 2 } {
199
        error "scan-assembler: too few arguments"
200
        return
201
    }
202
    if { [llength $args] > 3 } {
203
        error "scan-assembler: too many arguments"
204
        return
205
    }
206
    if { [llength $args] >= 3 } {
207
        switch [dg-process-target [lindex $args 2]] {
208
            "S" { }
209
            "N" { return }
210
            "F" { setup_xfail "*-*-*" }
211
            "P" { }
212
        }
213
    }
214
 
215
    # This assumes that we are two frames down from dg-test, and that
216
    # it still stores the filename of the testcase in a local variable "name".
217
    # A cleaner solution would require a new dejagnu release.
218
    upvar 2 name testcase
219
    set testcase [lindex $testcase 0]
220
 
221
    set pattern [lindex $args 0]
222
    set pp_pattern [make_pattern_printable $pattern]
223
 
224
    # This must match the rule in gcc-dg.exp.
225
    set output_file "[file rootname [file tail $testcase]].s"
226
 
227
    set files [glob -nocomplain $output_file]
228
    if { $files == "" } {
229
        verbose -log "$testcase: output file does not exist"
230
        unresolved "$testcase scan-assembler-times $pp_pattern [lindex $args 1]"
231
        return
232
    }
233
 
234
    set fd [open $output_file r]
235
    set text [read $fd]
236
    close $fd
237
 
238
    if { [llength [regexp -inline -all -- $pattern $text]] == [lindex $args 1]} {
239
        pass "$testcase scan-assembler-times $pp_pattern [lindex $args 1]"
240
    } else {
241
        fail "$testcase scan-assembler-times $pp_pattern [lindex $args 1]"
242
    }
243
}
244
 
245
# Utility for scanning demangled compiler result, invoked via dg-final.
246
# Call pass if pattern is present, otherwise fail.
247
proc scan-assembler-dem { args } {
248
    global cxxfilt
249
    global base_dir
250
 
251
    if { [llength $args] < 1 } {
252
        error "scan-assembler-dem: too few arguments"
253
        return
254
    }
255
    if { [llength $args] > 2 } {
256
        error "scan-assembler-dem: too many arguments"
257
        return
258
    }
259
    if { [llength $args] >= 2 } {
260
        switch [dg-process-target [lindex $args 1]] {
261
            "S" { }
262
            "N" { return }
263
            "F" { setup_xfail "*-*-*" }
264
            "P" { }
265
        }
266
    }
267
 
268
    # Find c++filt like we find g++ in g++.exp.
269
    if ![info exists cxxfilt]  {
270
        set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
271
                     $base_dir/../../../binutils/cxxfilt \
272
                     [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
273
                      [findfile $base_dir/c++filt $base_dir/c++filt \
274
                       [transform c++filt]]]]
275
        verbose -log "c++filt is $cxxfilt"
276
    }
277
 
278
    upvar 2 name testcase
279
    set testcase [lindex $testcase 0]
280
    set pattern [lindex $args 0]
281
    set pp_pattern [make_pattern_printable $pattern]
282
    set output_file "[file rootname [file tail $testcase]].s"
283
 
284
    set files [glob -nocomplain $output_file]
285
    if { $files == "" } {
286
        verbose -log "$testcase: output file does not exist"
287
        unresolved "$testcase scan-assembler-dem $pp_pattern"
288
        return
289
    }
290
 
291
    set output [remote_exec host "$cxxfilt" "" "$output_file"]
292
    set text [lindex $output 1]
293
 
294
    if [regexp -- $pattern $text] {
295
        pass "$testcase scan-assembler-dem $pp_pattern"
296
    } else {
297
        fail "$testcase scan-assembler-dem $pp_pattern"
298
    }
299
}
300
 
301
# Call pass if demangled pattern is not present, otherwise fail.
302
proc scan-assembler-dem-not { args } {
303
    global cxxfilt
304
    global base_dir
305
 
306
    if { [llength $args] < 1 } {
307
        error "scan-assembler-dem-not: too few arguments"
308
        return
309
    }
310
    if { [llength $args] > 2 } {
311
        error "scan-assembler-dem-not: too many arguments"
312
        return
313
    }
314
    if { [llength $args] >= 2 } {
315
        switch [dg-process-target [lindex $args 1]] {
316
            "S" { }
317
            "N" { return }
318
            "F" { setup_xfail "*-*-*" }
319
            "P" { }
320
        }
321
    }
322
 
323
    # Find c++filt like we find g++ in g++.exp.
324
    if ![info exists cxxfilt]  {
325
        set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
326
                     $base_dir/../../../binutils/cxxfilt \
327
                     [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
328
                      [findfile $base_dir/c++filt $base_dir/c++filt \
329
                       [transform c++filt]]]]
330
        verbose -log "c++filt is $cxxfilt"
331
    }
332
 
333
    upvar 2 name testcase
334
    set testcase [lindex $testcase 0]
335
    set pattern [lindex $args 0]
336
    set pp_pattern [make_pattern_printable $pattern]
337
    set output_file "[file rootname [file tail $testcase]].s"
338
 
339
    set files [glob -nocomplain $output_file]
340
    if { $files == "" } {
341
        verbose -log "$testcase: output file does not exist"
342
        unresolved "$testcase scan-assembler-dem-not $pp_pattern"
343
        return
344
    }
345
 
346
    set output [remote_exec host "$cxxfilt" "" "$output_file"]
347
    set text [lindex $output 1]
348
 
349
    if ![regexp -- $pattern $text] {
350
        pass "$testcase scan-assembler-dem-not $pp_pattern"
351
    } else {
352
        fail "$testcase scan-assembler-dem-not $pp_pattern"
353
    }
354
}
355
 
356
# Call pass if object size is ok, otherwise fail.
357
# example: /* { dg-final { object-size text <= 54 } } */
358
proc object-size { args } {
359
    global size
360
    global base_dir
361
 
362
    if { [llength $args] < 3 } {
363
        error "object-size: too few arguments"
364
        return
365
    }
366
    if { [llength $args] > 4 } {
367
        error "object-size: too many arguments"
368
        return
369
    }
370
    if { [llength $args] >= 4 } {
371
        switch [dg-process-target [lindex $args 3]] {
372
            "S" { }
373
            "N" { return }
374
            "F" { setup_xfail "*-*-*" }
375
            "P" { }
376
        }
377
    }
378
 
379
    # Find size like we find g++ in g++.exp.
380
    if ![info exists size]  {
381
        set size [findfile $base_dir/../../../binutils/size \
382
                  $base_dir/../../../binutils/size \
383
                  [findfile $base_dir/../../size $base_dir/../../size \
384
                   [findfile $base_dir/size $base_dir/size \
385
                    [transform size]]]]
386
        verbose -log "size is $size"
387
    }
388
 
389
    upvar 2 name testcase
390
    set testcase [lindex $testcase 0]
391
 
392
    set what [lindex $args 0]
393
    set where [lsearch { text data bss total } $what]
394
    if { $where == -1 } {
395
        error "object-size: illegal argument: $what"
396
        return
397
    }
398
    set cmp [lindex $args 1]
399
    if { [lsearch { < > <= >= == != } $cmp] == -1 } {
400
        error "object-size: illegal argument: $cmp"
401
        return
402
    }
403
    set with [lindex $args 2]
404
    if ![string is integer $with ] {
405
        error "object-size: illegal argument: $with"
406
        return
407
    }
408
 
409
    set output_file "[file rootname [file tail $testcase]].o"
410
    if ![file_on_host exists $output_file] {
411
        verbose -log "$testcase: $output_file does not exist"
412
        unresolved "$testcase object-size $what $cmp $with"
413
        return
414
    }
415
    set output [remote_exec host "$size" "$output_file"]
416
    set status [lindex $output 0]
417
    if { $status != 0 } {
418
        verbose -log "$testcase object-size: $size failed"
419
        unresolved "$testcase object-size $what $cmp $with"
420
        return
421
    }
422
 
423
    set text [lindex $output 1]
424
    set lines [split $text "\n"]
425
 
426
    set line0 [lindex $lines 0]
427
    if ![regexp {^\s*text\s+data\s+bss\s+dec\s+hex\s+filename\s*$} $line0] {
428
        verbose -log "$testcase object-size: $size did not produce expected first line: $line0"
429
        unresolved "$testcase object-size $what $cmp $with"
430
        return
431
    }
432
 
433
    set line1 [lindex $lines 1]
434
    if ![regexp {^\s*\d+\s+\d+\s+\d+\s+\d+\s+[\da-fA-F]+\s+} $line1] {
435
        verbose -log "$testcase object-size: $size did not produce expected second line: $line1"
436
        unresolved "$testcase object-size $what $cmp $with"
437
        return
438
    }
439
 
440
    set actual [lindex $line1 $where]
441
    verbose -log "$what size is $actual"
442
 
443
    if [expr $actual $cmp $with] {
444
        pass "$testcase object-size $what $cmp $with"
445
    } else {
446
        fail "$testcase object-size $what $cmp $with"
447
    }
448
}
449
 
450
# Utility for testing that a function is defined on the current line.
451
# Call pass if so, otherwise fail.  Invoked directly; the file must
452
# have been compiled with -g -dA.
453
#
454
# Argument 0 is the current line, passed implicitly by dejagnu
455
# Argument 1 is the function to check
456
# Argument 2 handles expected failures and the like
457
# Argument 3 is "." to match the current line, or an integer to match
458
# an explicit line.
459
proc dg-function-on-line { args } {
460
    # Upvar from dg-final:
461
    upvar dg-final-code final-code
462
 
463
    set line [lindex $args 0]
464
    set symbol [lindex $args 1]
465
    set failures [lindex $args 2]
466
 
467
    if { [llength $args] >= 4 } {
468
        switch [lindex $args 3] {
469
            "." { }
470
            "default" { set line [lindex $args 3] }
471
        }
472
    }
473
 
474
    if { [istarget hppa*-*-*] } {
475
        set pattern [format {\t;[^:]+:%d\n(\t[^\t]+\n)+%s:\n\t.PROC} \
476
                     $line $symbol]
477
    } elseif { [istarget mips*-*-*] } {
478
        set pattern [format {\t\.loc [0-9]+ %d 0( [^\n]*)?\n(\t.cfi_startproc[^\t]*\n)*\t\.set\t(no)?mips16\n\t\.ent\t%s\n\t\.type\t%s, @function\n%s:\n} \
479
                     $line $symbol $symbol $symbol]
480
    } else {
481
        set pattern [format {%s:[^\t]*(\t.(fnstart|frame|mask|file)[^\t]*)*\t[^:]+:%d\n} \
482
                     $symbol $line]
483
    }
484
 
485
    # The lack of spaces around $pattern is important, since they'd
486
    # become part of the regex scan-assembler tries to match.
487
    set cmd "scan-assembler {$pattern}"
488
    if { [llength $args] >= 3 } {
489
        set cmd "$cmd {$failures}"
490
    }
491
 
492
    append final-code "$cmd\n"
493
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.