<commit_before># Copyright (C) 2001-2008, Parrot Foundation.
# $Id$

=head1 NAME

config/gen/platform.pm - Platform Files

=head1 DESCRIPTION

Moves the various platform-specific files into place.

=cut

package gen::platform;

use strict;
use warnings;

use base qw(Parrot::Configure::Step);

use Parrot::Configure::Utils ':gen';

sub _init {
    my $self = shift;
    my %data;
    $data{description} = q{Move platform files into place};
    $data{result}      = q{};
    $data{platform_interface} = q{config/gen/platform/platform_interface.h};
    $data{coda} = <<'CODA';
/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
CODA
    return \%data;
}

sub runstep {
    my ( $self, $conf ) = @_;

    my $verbose     = $conf->options->get('verbose');
    my $generated   = $self->_get_generated($conf, $verbose);


    # headers are merged into platform.h
    $self->_set_headers($conf, $verbose, $generated);

    # implementation files are merged into platform.c
    $self->_set_implementations($conf, $verbose, $generated);

    $self->_handle_asm($conf);

    # interface is the same for all platforms
    copy_if_diff( $self->{platform_interface},
        "include/parrot/platform_interface.h" );

    $self->_set_limits($conf, $verbose);

    return 1;
}

sub _get_generated {
    my $self = shift;
    my ($conf, $verbose) = @_;
    my $generated = $conf->data->get('TEMP_generated');
    $generated = '' unless defined $generated;
    print " ($generated) " if $verbose;
    return $generated;
}

sub _set_headers {
    my $self = shift;
    my ($conf, $verbose, $generated) = @_;
    my $platform = $conf->data->get('platform');
    my @headers = qw/
        io.h
        math.h
        misc.h
        dl.h
        signal.h
        stat.h
        threads.h
        string.h
        /;

    my $plat_h = q{include/parrot/platform.h};
    $conf->append_configure_log($plat_h);
    open my $PLATFORM_H, ">", $plat_h
        or die "Can't open $plat_h: $!";

    print {$PLATFORM_H} <<"END_HERE";
/* ex: set ro:
** !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
**
** This file is generated automatically by config/gen/platform.pm
*/
#ifndef PARROT_PLATFORM_H_GUARD
#define PARROT_PLATFORM_H_GUARD

/*
** platform.h [$platform version]
**
** DO NOT EDIT THIS FILE
**
** Generated by config/gen/platform.pm
*/

END_HERE

    foreach (@headers) {
        my $header_file = "config/gen/platform/generic/$_";
        if ( -e "config/gen/platform/$platform/$_" ) {
            $header_file = "config/gen/platform/$platform/$_";
        }

        if ( -e $header_file ) {
            local $/ = undef;
            print("\t$header_file\n") if $verbose;
            open my $IN_H, "<", "$header_file"
                or die "Can't open $header_file: $!";

            # slurp in the header file
            my $in_h = <$IN_H>;

            # remove the (in this case) superfluous coda
            $in_h =~ s{\Q$self->{coda}\E\n*\z}{}xgs;

            print {$PLATFORM_H} <<"END_HERE";
/*
** $header_file:
*/
#line 1 "$header_file"
END_HERE
            print {$PLATFORM_H} $in_h, "\n\n";
            close $IN_H;
        }

        # just fall through if file is missing; means neither this platform nor
        # generic has anything to contribute for this feature.  this might not
        # be desirable if porters don't see the appropriate file in generic/ and
        # shoehorn their function into the wrong file rather than creating the
        # correct one from the above list in their $platform/ dir (e.g. misc.c).
    }

    # finally append generated
    @headers = grep { /\.h$/ } split( m/,/, $generated );
    for my $h (@headers) {
        if ( -e $h ) {
            local $/ = undef;
            print("\t$h\n") if $verbose;
            open my $IN_H, "<", $h or die "Can't open $h: $!";
            print {$PLATFORM_H} <<"END_HERE";
/*
** $h
*/
#line 1 "$h"
END_HERE
            print {$PLATFORM_H} <$IN_H>, "\n\n";
            close $IN_H;
        }
        else {
            warn("Header file '$h' listed in TEMP_generated but not found\n");
        }
    }

    # Add the C-coda
    print $PLATFORM_H <<"END_HERE";
#endif /* PARROT_PLATFORM_H_GUARD */

$self->{coda}
END_HERE

    close $PLATFORM_H;
    return 1;
}

sub _set_limits {
    my $self = shift;
    my ($conf, $verbose) = @_;
    my $platform = $conf->data->get('platform');

    my $limits = "config/gen/platform/generic/platform_limits.h";
    if ( -e "config/gen/platform/$platform/platform_limits.h" ) {
        $limits = "config/gen/platform/$platform/platform_limits.h";
    }
    copy_if_diff( $limits, "include/parrot/platform_limits.h" );

    return;
}

sub _set_implementations {<commit_msg>No need to pass $verbose in internal sub _set_limits(), as no verbose output is provided.<commit_after># Copyright (C) 2001-2008, Parrot Foundation.
# $Id$

=head1 NAME

config/gen/platform.pm - Platform Files

=head1 DESCRIPTION

Moves the various platform-specific files into place.

=cut

package gen::platform;

use strict;
use warnings;

use base qw(Parrot::Configure::Step);

use Parrot::Configure::Utils ':gen';

sub _init {
    my $self = shift;
    my %data;
    $data{description} = q{Move platform files into place};
    $data{result}      = q{};
    $data{platform_interface} = q{config/gen/platform/platform_interface.h};
    $data{coda} = <<'CODA';
/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
CODA
    return \%data;
}

sub runstep {
    my ( $self, $conf ) = @_;

    my $verbose     = $conf->options->get('verbose');
    my $generated   = $self->_get_generated($conf, $verbose);


    # headers are merged into platform.h
    $self->_set_headers($conf, $verbose, $generated);

    # implementation files are merged into platform.c
    $self->_set_implementations($conf, $verbose, $generated);

    $self->_handle_asm($conf);

    # interface is the same for all platforms
    copy_if_diff( $self->{platform_interface},
        "include/parrot/platform_interface.h" );

    $self->_set_limits($conf, $verbose);

    return 1;
}

sub _get_generated {
    my $self = shift;
    my ($conf, $verbose) = @_;
    my $generated = $conf->data->get('TEMP_generated');
    $generated = '' unless defined $generated;
    print " ($generated) " if $verbose;
    return $generated;
}

sub _set_headers {
    my $self = shift;
    my ($conf, $verbose, $generated) = @_;
    my $platform = $conf->data->get('platform');
    my @headers = qw/
        io.h
        math.h
        misc.h
        dl.h
        signal.h
        stat.h
        threads.h
        string.h
        /;

    my $plat_h = q{include/parrot/platform.h};
    $conf->append_configure_log($plat_h);
    open my $PLATFORM_H, ">", $plat_h
        or die "Can't open $plat_h: $!";

    print {$PLATFORM_H} <<"END_HERE";
/* ex: set ro:
** !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
**
** This file is generated automatically by config/gen/platform.pm
*/
#ifndef PARROT_PLATFORM_H_GUARD
#define PARROT_PLATFORM_H_GUARD

/*
** platform.h [$platform version]
**
** DO NOT EDIT THIS FILE
**
** Generated by config/gen/platform.pm
*/

END_HERE

    foreach (@headers) {
        my $header_file = "config/gen/platform/generic/$_";
        if ( -e "config/gen/platform/$platform/$_" ) {
            $header_file = "config/gen/platform/$platform/$_";
        }

        if ( -e $header_file ) {
            local $/ = undef;
            print("\t$header_file\n") if $verbose;
            open my $IN_H, "<", "$header_file"
                or die "Can't open $header_file: $!";

            # slurp in the header file
            my $in_h = <$IN_H>;

            # remove the (in this case) superfluous coda
            $in_h =~ s{\Q$self->{coda}\E\n*\z}{}xgs;

            print {$PLATFORM_H} <<"END_HERE";
/*
** $header_file:
*/
#line 1 "$header_file"
END_HERE
            print {$PLATFORM_H} $in_h, "\n\n";
            close $IN_H;
        }

        # just fall through if file is missing; means neither this platform nor
        # generic has anything to contribute for this feature.  this might not
        # be desirable if porters don't see the appropriate file in generic/ and
        # shoehorn their function into the wrong file rather than creating the
        # correct one from the above list in their $platform/ dir (e.g. misc.c).
    }

    # finally append generated
    @headers = grep { /\.h$/ } split( m/,/, $generated );
    for my $h (@headers) {
        if ( -e $h ) {
            local $/ = undef;
            print("\t$h\n") if $verbose;
            open my $IN_H, "<", $h or die "Can't open $h: $!";
            print {$PLATFORM_H} <<"END_HERE";
/*
** $h
*/
#line 1 "$h"
END_HERE
            print {$PLATFORM_H} <$IN_H>, "\n\n";
            close $IN_H;
        }
        else {
            warn("Header file '$h' listed in TEMP_generated but not found\n");
        }
    }

    # Add the C-coda
    print $PLATFORM_H <<"END_HERE";
#endif /* PARROT_PLATFORM_H_GUARD */

$self->{coda}
END_HERE

    close $PLATFORM_H;
    return 1;
}

sub _set_limits {
    my ($self, $conf) = @_;
    my $platform = $conf->data->get('platform');

    my $limits = "config/gen/platform/generic/platform_limits.h";
    if ( -e "config/gen/platform/$platform/platform_limits.h" ) {
        $limits = "config/gen/platform/$platform/platform_limits.h";
    }
    copy_if_diff( $limits, "include/parrot/platform_limits.h" );

    return;
}

sub _set_implementations {
{'fraction_non_alphanumeric': 0.14973149415604928, 'fraction_numerical': 0.0031588922817731915, 'mean_word_length': 2.4513081395348837, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1034494', 'n_tokens_mistral': 3275, 'n_tokens_neox': 3191, 'n_words': 827}