#
# These tests should be valid on all targets.
#

# I think currently all targets fail this one when listings are enabled.
gas_test "p2425.s" ""   "" "pcrel values in assignment"

# p1480.s uses a ".space" directive which for most assemblers means
# "allocate some space".  On the PA it means "switch into this space".
#
# Therefore this test (as it is currently written) is completely bogus
# for any PA target.  Do not bother trying to run it and just claim
# it fails.
#
# The C54x uses ".space" to allocate bits, and requires absolute expressions;
# The ".space" directive is taken care of in the C54x-specific tests, so fail
#  here 
#
if { [istarget hppa*-*-*] || [istarget *c54x*-*-*] } then {
    setup_xfail *-*-*
    fail "simplifiable double subtraction"
} else {
    gas_test "p1480.s" "" "-a>" "simplifiable double subtraction"
}

# No floating point support in assembly code for CRIS.
if ![istarget cris-*-*] then {
    gas_test "float.s" ""   "" "simple FP constants"
}

# This test is meaningless for the PA; the difference of two undefined
# symbols is something that is (and must be) supported on the PA.
if ![istarget hppa*-*-*] then {
    gas_test_error "diff1.s" "" "difference of two undefined symbols"
}

proc do_comment {} {
    set testname "comment.s: comments in listings"
    set x1 0
    set x2 0
    set x3 0
    set white {[ \t]*}
    gas_start "comment.s" "-al"
    while 1 {
# Apparently CRLF is received when using ptys for subprocesses; hence the
# \r\n for line 3.
	expect {
	    -re "^ +1\[ \t\]+# This\[^\n\]*\n"		{ set x1 1 }
	    -re "^ +2\[ \t\]+# correctly\[^\n\]*\n"	{ set x2 1 }
	    -re "^ +3\[ \t\]+/. C comments too. ./\r?\n" { set x3 1 }
	    -re "\[^\n\]*\n"				{ }
	    timeout				{ perror "timeout\n"; break }
	    eof					{ break }
	}
    }
    gas_finish
    if [all_ones $x1 $x2 $x3] then { pass $testname } else { fail $testname }
}

do_comment

#
# Test x930509a -- correct assembly of differences involving forward
# references.
#

proc do_930509a {} {
    set testname "difference between forward references"
    set x 0
    gas_start "x930509.s" "-al"
    while 1 {
# We need to accomodate both byte orders here.
# If ".long" means an 8-byte value on some target someday, this test will have
# to be fixed.
	expect {
	    -re "^ +1 .... 00 ?00 ?00 ?00" { fail $testname; set x 1 }
	    -re "^ +1 .... 04 ?00 ?00 ?00" { pass $testname; set x 1 }
	    -re "^ +1 .... 00 ?00 ?00 ?04" { pass $testname; set x 1 }
	    -re "\[^\n\]*\n" { }
	    timeout { perror "timeout\n"; break }
	    eof { break }
	}
    }
    gas_finish
    if !$x then { fail $testname }
}

# This test is meaningless for the PA; the difference of two symbols
# must not be resolved by the assembler.
# C54x assembler (for compatibility) does not allow differences between
# forward references
# C30 counts a four byte offset as a difference of one.
if { ![istarget hppa*-*-*] &&
     ![istarget *c30*-*-*] &&
     ![istarget *c4x*-*-*] &&
     ![istarget *c54x*-*-*] } then {
    # the vax fails because VMS can apparently actually handle this
    # case in relocs, so gas doesn't handle it itself.
    setup_xfail "h8300*-*-elf*" "mn10200*-*-*" "mn10300*-*-*" "vax*-*-vms*"
    do_930509a
}

# ".struct" and ".align" have different meanings on c54x
# These directives are done in the c54x-specific tests instead
case $target_triplet in {
    { hppa*-*-* } { }
    { *c4x*-*-* } { }
    { *c54x*-*-* } { }
    default {
	run_dump_test struct
	run_dump_test align
	run_dump_test align2
    }
}

# This test is for any COFF target.
# We omit m88k COFF because it uses weird pseudo-op names.
# We omit the ARM toolchains because they define locals to
#  start with '.', which eliminates .eos, .text etc from the output.
# Omit c54x, since .tag and .def mean something different on that target
if {   ([istarget *-*-coff*] && ![istarget m88*-*-*] && ![istarget *arm*-*-coff] && ![istarget thumb*-*-coff] && ![istarget xscale-*-coff] && ![istarget *c4x*-*-coff] && ![istarget *c54x*-*-coff]) \
     ||([istarget *-*-pe*] && ![istarget arm*-*-pe*] && ![istarget thumb*-*-pe*]) \
     || [istarget a29k-*-udi*] \
     || [istarget a29k-*-ebmon*] \
     || [istarget a29k-*-sym*] \
     || [istarget a29k-*-vxworks*] \
     || [istarget i*86-*-aix*] \
     || [istarget i*86-*-sco*] \
     || [istarget i*86-*-isc*] \
     || [istarget i*86-*-go32*] \
     || [istarget i*86-*-cygwin*] \
     || [istarget i*86-*-*nt] \
     || [istarget i*86-*-interix*] \
     || ([istarget i960-*-vxworks5.*] && ![istarget i960-*-vxworks5.0*]) } {
    run_dump_test cofftag
}

# Test omitting conditionals from listings.
proc test_cond {} {
    global comp_output
    global srcdir
    global subdir

    set testname "conditional listings"
    gas_run cond.s "-alc" ">dump.out"
    if ![string match "" $comp_output] {
	send_log "$comp_output\n"
	fail $testname
    } else {
	if { [regexp_diff dump.out $srcdir/$subdir/cond.d] } {
	    fail $testname
	} else {
	    pass $testname
	}
    }
}

# This test is not suitable for the PA for various reasons
# not limited to the fact that it depends on specific section
# names appearing in the output file.
# again, p2align doesn't work on c54x target
case $target_triplet in {
    { hppa*-*-* } { }
    { *c4x*-*-* } { }
    { *c54x*-*-* } { }
    default {
        test_cond
        run_dump_test incbin
    }
}

if {   [istarget "i*86-*-*pe*"] \
    || [istarget "i*86-*-cygwin*"] \
    || [istarget "i*86-*-mingw32*"] } {
  gas_test "fastcall.s" ""   "" "fastcall labels"
}
