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