Ticket #1075: detect_llvm.diff

File detect_llvm.diff, 11.1 KB (added by jkeenan, 12 years ago)

svn diff  https://svn.parrot.org/parrot/trunk@41745  https://svn.parrot.org/parrot/branches/detect_llvm@HEAD

  • lib/Parrot/Configure/Step/List.pm

     
    4141    auto::arch 
    4242    auto::jit 
    4343    auto::frames 
     44    auto::llvm 
    4445    auto::cpu 
    4546    auto::cgoto 
    4647    auto::inline 
  • MANIFEST

     
    11# ex: set ro: 
    22# $Id$ 
    33# 
    4 # generated by tools/dev/mk_manifest_and_skip.pl Wed Sep 30 22:16:16 2009 UT 
     4# generated by tools/dev/mk_manifest_and_skip.pl Wed Oct  7 21:06:54 2009 UT 
    55# 
    66# See below for documentation on the format of this file. 
    77# 
     
    257257config/auto/isreg.pm                                        [] 
    258258config/auto/isreg/test_c.in                                 [] 
    259259config/auto/jit.pm                                          [] 
     260config/auto/llvm.pm                                         [] 
     261config/auto/llvm/hello.c                                    [] 
    260262config/auto/memalign.pm                                     [] 
    261263config/auto/memalign/test2_c.in                             [] 
    262264config/auto/memalign/test_c.in                              [] 
     
    19311933t/steps/auto/inline-01.t                                    [test] 
    19321934t/steps/auto/isreg-01.t                                     [test] 
    19331935t/steps/auto/jit-01.t                                       [test] 
     1936t/steps/auto/llvm-01.t                                      [test] 
    19341937t/steps/auto/memalign-01.t                                  [test] 
    19351938t/steps/auto/msvc-01.t                                      [test] 
    19361939t/steps/auto/neg_0-01.t                                     [test] 
  • t/steps/auto/llvm-01.t

     
     1#!perl 
     2# Copyright (C) 2001-2007, Parrot Foundation. 
     3# $Id$ 
     4# auto/llvm-01.t 
     5 
     6use strict; 
     7use warnings; 
     8use Test::More tests =>  27; 
     9use Carp; 
     10use lib qw( lib t/configure/testlib ); 
     11use_ok('config::init::defaults'); 
     12use_ok('config::inter::progs'); 
     13use_ok('config::auto::llvm'); 
     14use Parrot::Configure; 
     15use Parrot::Configure::Options qw( process_options ); 
     16use Parrot::Configure::Test qw( 
     17    test_step_thru_runstep 
     18    rerun_defaults_for_testing 
     19    test_step_constructor_and_description 
     20); 
     21use IO::CaptureOutput qw( capture ); 
     22 
     23########## regular ########## 
     24 
     25my ($args, $step_list_ref) = process_options( { 
     26    argv => [ ], 
     27    mode => q{configure}, 
     28} ); 
     29 
     30my $conf = Parrot::Configure->new; 
     31 
     32my $serialized = $conf->pcfreeze(); 
     33 
     34test_step_thru_runstep($conf, q{init::defaults}, $args); 
     35test_step_thru_runstep($conf, q{inter::progs},   $args); 
     36 
     37my $pkg = q{auto::llvm}; 
     38 
     39$conf->add_steps($pkg); 
     40$conf->options->set( %{$args} ); 
     41my $step = test_step_constructor_and_description($conf); 
     42my $ret = $step->runstep($conf); 
     43ok( $ret, "runstep() returned true value" ); 
     44like( $step->result(), qr/yes|no/, 
     45  "Result was either 'yes' or 'no'" ); 
     46 
     47$conf->replenish($serialized); 
     48 
     49########## --verbose ########## 
     50 
     51($args, $step_list_ref) = process_options( { 
     52    argv => [ q{--verbose} ], 
     53    mode => q{configure}, 
     54} ); 
     55rerun_defaults_for_testing($conf, $args ); 
     56$conf->add_steps($pkg); 
     57$conf->options->set( %{$args} ); 
     58$step = test_step_constructor_and_description($conf); 
     59{ 
     60    my $stdout; 
     61    my $ret = capture( 
     62        sub { $step->runstep($conf) }, 
     63        \$stdout 
     64    ); 
     65    ok( $ret, "runstep() returned true value" ); 
     66    like( $step->result(), qr/yes|no/, 
     67        "Result was either 'yes' or 'no'" ); 
     68    SKIP: { 
     69        skip 'No sense testing for verbose output if LLVM not present', 
     70        2 unless ( $step->result() =~ /yes/ ); 
     71        like( $stdout, qr/llvm-gcc/s, 
     72            "Got expected verbose output" ); 
     73        like( $stdout, qr/Low Level Virtual Machine/s, 
     74            "Got expected verbose output" ); 
     75    } 
     76} 
     77 
     78$conf->cc_clean(); 
     79 
     80pass("Completed all tests in $0"); 
     81 
     82################### DOCUMENTATION ################### 
     83 
     84=head1 NAME 
     85 
     86t/steps/auto/llvm-01.t - tests Parrot::Configure step auto::llvm 
     87 
     88=head1 SYNOPSIS 
     89 
     90    prove t/steps/auto/llvm-01.t 
     91 
     92=head1 DESCRIPTION 
     93 
     94This file holds tests for auto::llvm. 
     95 
     96=head1 AUTHOR 
     97 
     98James E Keenan 
     99 
     100=cut 
     101 
     102# Local Variables: 
     103#   mode: cperl 
     104#   cperl-indent-level: 4 
     105#   fill-column: 100 
     106# End: 
     107# vim: expandtab shiftwidth=4: 
  • config/auto/llvm.pm

    Property changes on: t/steps/auto/llvm-01.t
    ___________________________________________________________________
    Added: svn:eol-style
       + native
    Added: svn:mime-type
       + text/plain
    Added: svn:keywords
       + Author Date Id Revision
    
     
     1# Copyright (C) 2009, Parrot Foundation. 
     2# $Id$ 
     3 
     4=head1 NAME 
     5 
     6config/auto/llvm - Check whether the Low Level Virtual Machine is present 
     7 
     8=head1 DESCRIPTION 
     9 
     10Determines whether the Low Level Virtual Machine (LLVM) is installed and 
     11functional on the system.  It is OK when it 
     12doesn't exist. 
     13 
     14=cut 
     15 
     16package auto::llvm; 
     17 
     18use strict; 
     19use warnings; 
     20 
     21use base qw(Parrot::Configure::Step); 
     22 
     23use Parrot::Configure::Utils ':auto'; 
     24 
     25sub _init { 
     26    my $self = shift; 
     27    my %data; 
     28    $data{description} = q{Is LLVM installed}; 
     29    $data{result}      = q{}; 
     30    $data{llvm_components} = [ 
     31        [ 'llvm-gcc'    => 'llvm-gcc' ], 
     32        [ 'lli'         => 'Low Level Virtual Machine' ], 
     33        [ 'llc'         => 'Low Level Virtual Machine' ], 
     34    ]; 
     35    return \%data; 
     36} 
     37 
     38sub runstep { 
     39    my ( $self, $conf ) = @_; 
     40 
     41    my $verbose = $conf->options->get( 'verbose' ); 
     42 
     43    my $llvm_lacking = 0; 
     44    foreach my $prog ( @{ $self->{llvm_components} } ) { 
     45        my $output = capture_output( $prog->[0], '--version' ); 
     46        my $exp = $prog->[1]; 
     47        unless ( defined($output) and $output =~ m/$exp/s ) { 
     48            $llvm_lacking++; 
     49            print "Could not get expected '--version' output for $prog->[0]\n" 
     50                if $verbose; 
     51        } 
     52        else { 
     53            print $output, "\n" if $verbose; 
     54        } 
     55    } 
     56    my $output = q{}; 
     57    $output = capture_output( 'llvm-gcc', '--version' ); 
     58    if (! $output) { 
     59        $llvm_lacking++; 
     60    } 
     61    else { 
     62        my @line = split /\n+/, $output; 
     63        if ( $line[0] =~ m/\b(\d+)\.(\d+)\.(\d+)\b/ ) { 
     64            my @version = ($1, $2, $3); 
     65            if ($version[0] < 4) { 
     66                print "llvm-gcc must be at least major version 4\n" 
     67                    if $verbose; 
     68                $llvm_lacking++; 
     69            } 
     70        } 
     71        else { 
     72            print "Unable to extract llvm-gcc major, minor and patch versions\n" 
     73                if $verbose; 
     74            $llvm_lacking++; 
     75        } 
     76    } 
     77             
     78    if ( $llvm_lacking ) { 
     79        $self->_handle_result( $conf, 0 ); 
     80    } 
     81    else { 
     82 
     83        # Here we will take a simple C file, compile it into an LLVM bitcode 
     84        # file, execute it as bitcode, then compile it to native assembly 
     85        # using the LLC code generator, then assemble the native assembly 
     86        # language file into a program and execute it.  Cf.: 
     87        # http://llvm.org/releases/2.5/docs/GettingStarted.html#overview 
     88 
     89        my $stem = q|hello|; 
     90        my $cfile = qq|$stem.c|; 
     91        my $fullcfile = qq|config/auto/llvm/$cfile|; 
     92        my $bcfile = qq|$stem.bc|; 
     93        my $sfile = qq|$stem.s|; 
     94        my $nativefile = qq|$stem.native|; 
     95        eval { 
     96            system(qq{llvm-gcc -O3 -emit-llvm $fullcfile -c -o $bcfile}); 
     97        }; 
     98        if ($@) { 
     99            print "Unable to compile C file into LLVM bitcode file\n" 
     100                if $verbose; 
     101            $self->_handle_result( $conf, 0 ); 
     102        } 
     103        else { 
     104            my $output; 
     105            eval { 
     106                $output = capture_output( 'lli', $bcfile ); 
     107            }; 
     108            if ( $@ or $output !~ /hello world/ ) { 
     109                print "Unable to into LLVM bitcode file with 'lli'\n" 
     110                    if $verbose; 
     111                $self->_handle_result( $conf, 0 ); 
     112            } 
     113            else { 
     114                eval { 
     115                    system(qq{llc $bcfile -o $sfile}); 
     116                }; 
     117                if ( $@ or (! -e $sfile) ) { 
     118                    print "Unable to compile program to native assembly using 'llc'\n" 
     119                        if $verbose; 
     120                    $self->_handle_result( $conf, 0 ); 
     121                } 
     122                else { 
     123                    eval { 
     124                        my $cc = $conf->data->get('cc'); 
     125                        system(qq{$cc $sfile -o $nativefile}); 
     126                    }; 
     127                    if ( $@ or (! -e $nativefile) ) { 
     128                        print "Unable to assemble native assembly into program\n" 
     129                            if $verbose; 
     130                        $self->_handle_result( $conf, 0 ); 
     131                    } 
     132                    else { 
     133                        eval { 
     134                            $output = capture_output(qq{./$nativefile}); 
     135                        }; 
     136                        if ( $@ or ( $output !~ q/hello world/) ) { 
     137                            print "Unable to execute native assembly program successfuly\n" 
     138                                if $verbose; 
     139                            $self->_handle_result( $conf, 0 ); 
     140                        } 
     141                        else { 
     142                            $self->_handle_result( $conf, 1 ); 
     143                        } 
     144                    } 
     145                } 
     146            } 
     147        } 
     148        foreach my $f ( $bcfile, $sfile, $nativefile ) { 
     149          unlink $f if ( -e $f ); 
     150        } 
     151        $conf->cc_clean(); 
     152    } 
     153 
     154    return 1; 
     155} 
     156 
     157sub _handle_result { 
     158    my ($self, $conf, $result) = @_; 
     159    if ( $result ) { 
     160        $self->set_result('yes'); 
     161        $conf->data->set( has_llvm => 1 ); 
     162    } 
     163    else { 
     164        $self->set_result('no'); 
     165        $conf->data->set( has_llvm => '' ); 
     166    } 
     167    return 1; 
     168} 
     1691; 
     170 
     171=head1 AUTHOR 
     172 
     173James E Keenan 
     174 
     175=cut 
     176 
     177# Local Variables: 
     178#   mode: cperl 
     179#   cperl-indent-level: 4 
     180#   fill-column: 100 
     181# End: 
     182# vim: expandtab shiftwidth=4: 
     183 
  • config/auto/llvm/hello.c

    Property changes on: config/auto/llvm.pm
    ___________________________________________________________________
    Added: svn:eol-style
       + native
    Added: svn:keywords
       + Author Date Id Revision
    
     
     1#include <stdio.h> 
     2 
     3int main() { 
     4  printf("hello world\n"); 
     5  return 0; 
     6}