/
byteorder.pm
80 lines (62 loc) · 1.56 KB
/
byteorder.pm
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
# Copyright (C) 2001-2003, Parrot Foundation.
=head1 NAME
config/auto/byteorder.pm - Native Byteorder
=head1 DESCRIPTION
Computes the native byteorder for Parrot's wordsize.
=cut
package auto::byteorder;
use strict;
use warnings;
use Parrot::Configure::Step qw(:auto);
use base qw(Parrot::Configure::Step);
sub _init {
my $self = shift;
my %data;
$data{description} = q{Compute native byteorder for wordsize};
$data{result} = q{};
return \%data;
}
sub runstep {
my ( $self, $conf ) = @_;
my $byteorder = _probe_for_byteorder($conf);
$self->_evaluate_byteorder($conf, $byteorder);
return 1;
}
sub _probe_for_byteorder {
my $conf = shift;
$conf->cc_gen('config/auto/byteorder/test_c.in');
$conf->cc_build();
my $byteorder = $conf->cc_run()
or die "Can't run the byteorder testing program: $!";
$conf->cc_clean();
chomp $byteorder;
return $byteorder;
}
sub _evaluate_byteorder {
my ($self, $conf, $byteorder) = @_;
if ( $byteorder =~ /^1234/ ) {
$conf->data->set(
byteorder => $byteorder,
bigendian => 0
);
$self->set_result('little-endian');
}
elsif ( $byteorder =~ /^(?:8765|4321)/ ) {
$conf->data->set(
byteorder => $byteorder,
bigendian => 1
);
$self->set_result('big-endian');
}
else {
die "Unsupported byte-order [$byteorder]!";
}
return 1;
}
1;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: