File Coverage

File:config/auto/byteorder.pm
Coverage:98.0%

linestmtbrancondsubcode
1# Copyright (C) 2001-2003, Parrot Foundation.
2
3 - 11
=head1 NAME

config/auto/byteorder.pm - Native Byteorder

=head1 DESCRIPTION

Computes the native byteorder for Parrot's wordsize.

=cut
12
13package auto::byteorder;
14
15
2
2
2
use strict;
16
2
2
2
use warnings;
17
18
2
2
2
use Parrot::Configure::Step qw(:auto);
19
2
2
2
use base qw(Parrot::Configure::Step);
20
21
22sub _init {
23
4
    my $self = shift;
24
4
    my %data;
25
4
    $data{description} = q{Compute native byteorder for wordsize};
26
4
    $data{result} = q{};
27
4
    return \%data;
28}
29
30sub runstep {
31
1
    my ( $self, $conf ) = @_;
32
33
1
    my $byteorder = _probe_for_byteorder($conf);
34
35
1
    $self->_evaluate_byteorder($conf, $byteorder);
36
37
1
    return 1;
38}
39
40sub _probe_for_byteorder {
41
1
    my $conf = shift;
42
1
    $conf->cc_gen('config/auto/byteorder/test_c.in');
43
1
    $conf->cc_build();
44
1
    my $byteorder = $conf->cc_run()
45        or die "Can't run the byteorder testing program: $!";
46
1
    $conf->cc_clean();
47
1
    chomp $byteorder;
48
1
    return $byteorder;
49}
50
51sub _evaluate_byteorder {
52
5
    my ($self, $conf, $byteorder) = @_;
53
5
    if ( $byteorder =~ /^1234/ ) {
54
2
        $conf->data->set(
55            byteorder => $byteorder,
56            bigendian => 0
57        );
58
2
        $self->set_result('little-endian');
59    }
60    elsif ( $byteorder =~ /^(8765|4321)/ ) {
61
2
        $conf->data->set(
62            byteorder => $byteorder,
63            bigendian => 1
64        );
65
2
        $self->set_result('big-endian');
66    }
67    else {
68
1
        die "Unsupported byte-order [$byteorder]!";
69    }
70
4
    return 1;
71}
72
731;
74
75# Local Variables:
76# mode: cperl
77# cperl-indent-level: 4
78# fill-column: 100
79# End:
80# vim: expandtab shiftwidth=4: