Ticket #1075: detect_llvm.diff
File detect_llvm.diff, 11.1 KB (added by jkeenan, 12 years ago) |
---|
-
lib/Parrot/Configure/Step/List.pm
41 41 auto::arch 42 42 auto::jit 43 43 auto::frames 44 auto::llvm 44 45 auto::cpu 45 46 auto::cgoto 46 47 auto::inline -
MANIFEST
1 1 # ex: set ro: 2 2 # $Id$ 3 3 # 4 # generated by tools/dev/mk_manifest_and_skip.pl Wed Sep 30 22:16:162009 UT4 # generated by tools/dev/mk_manifest_and_skip.pl Wed Oct 7 21:06:54 2009 UT 5 5 # 6 6 # See below for documentation on the format of this file. 7 7 # … … 257 257 config/auto/isreg.pm [] 258 258 config/auto/isreg/test_c.in [] 259 259 config/auto/jit.pm [] 260 config/auto/llvm.pm [] 261 config/auto/llvm/hello.c [] 260 262 config/auto/memalign.pm [] 261 263 config/auto/memalign/test2_c.in [] 262 264 config/auto/memalign/test_c.in [] … … 1931 1933 t/steps/auto/inline-01.t [test] 1932 1934 t/steps/auto/isreg-01.t [test] 1933 1935 t/steps/auto/jit-01.t [test] 1936 t/steps/auto/llvm-01.t [test] 1934 1937 t/steps/auto/memalign-01.t [test] 1935 1938 t/steps/auto/msvc-01.t [test] 1936 1939 t/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 6 use strict; 7 use warnings; 8 use Test::More tests => 27; 9 use Carp; 10 use lib qw( lib t/configure/testlib ); 11 use_ok('config::init::defaults'); 12 use_ok('config::inter::progs'); 13 use_ok('config::auto::llvm'); 14 use Parrot::Configure; 15 use Parrot::Configure::Options qw( process_options ); 16 use Parrot::Configure::Test qw( 17 test_step_thru_runstep 18 rerun_defaults_for_testing 19 test_step_constructor_and_description 20 ); 21 use IO::CaptureOutput qw( capture ); 22 23 ########## regular ########## 24 25 my ($args, $step_list_ref) = process_options( { 26 argv => [ ], 27 mode => q{configure}, 28 } ); 29 30 my $conf = Parrot::Configure->new; 31 32 my $serialized = $conf->pcfreeze(); 33 34 test_step_thru_runstep($conf, q{init::defaults}, $args); 35 test_step_thru_runstep($conf, q{inter::progs}, $args); 36 37 my $pkg = q{auto::llvm}; 38 39 $conf->add_steps($pkg); 40 $conf->options->set( %{$args} ); 41 my $step = test_step_constructor_and_description($conf); 42 my $ret = $step->runstep($conf); 43 ok( $ret, "runstep() returned true value" ); 44 like( $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 } ); 55 rerun_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 80 pass("Completed all tests in $0"); 81 82 ################### DOCUMENTATION ################### 83 84 =head1 NAME 85 86 t/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 94 This file holds tests for auto::llvm. 95 96 =head1 AUTHOR 97 98 James 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 6 config/auto/llvm - Check whether the Low Level Virtual Machine is present 7 8 =head1 DESCRIPTION 9 10 Determines whether the Low Level Virtual Machine (LLVM) is installed and 11 functional on the system. It is OK when it 12 doesn't exist. 13 14 =cut 15 16 package auto::llvm; 17 18 use strict; 19 use warnings; 20 21 use base qw(Parrot::Configure::Step); 22 23 use Parrot::Configure::Utils ':auto'; 24 25 sub _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 38 sub 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 157 sub _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 } 169 1; 170 171 =head1 AUTHOR 172 173 James 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 3 int main() { 4 printf("hello world\n"); 5 return 0; 6 }