tagged release 0.7.1
[parrot.git] / compilers / ncigen / nci_gen.pl
blobeb6d6a3a32ded6191146d1e5cb8e724554386459
1 #! perl
2 # Copyright (C) 2008, The Perl Foundation.
3 # $Id$
5 use strict;
6 use warnings;
8 use Getopt::Long;
9 use Pod::Usage;
10 use File::Temp;
11 use File::Spec;
12 use IPC::Run3;
14 my $man = 0;
15 my $help = 0;
16 my $PARROT = "../../parrot";
17 my ($incpaths,$libname,$nsname);
19 GetOptions('help|?' => \$help,
20 man => \$man,
21 libname => \$libname,
22 nsname => \$nsname,
23 "I=s@" => \$incpaths) or pod2usage(2);
24 pod2usage(1) if $help;
25 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
27 #sub usage()
29 sub cc_preprocess {
30 my ($file) = @_;
31 my ($volume, $directories, $fileonly) = File::Spec->splitpath( $file );
32 print "$fileonly\n";
34 my $ofile = mktemp( $fileonly . "_XXXX");
35 #execit("gcc -x c -fdirectives-only -E $file > $ofile");
36 execit("gcc -x c -E $file > $ofile");
37 return $ofile;
40 sub dump_parse_tree {
41 my ( $file, $more_args ) = @_;
42 return execit("make; $PARROT c99.pbc $more_args $file");
45 sub execit {
46 my ($cmd) = @_;
47 print "$cmd\n";
48 my $output = `$cmd`;
49 return $output;
52 sub main {
53 my $more_args = "";
54 $ARGV[0] = 't/spi.c' unless $ARGV[0];
55 $libname = "libexamplelib" unless $libname;
56 $nsname = "CLIB::examplelib" unless $nsname;
58 #$more_args = "--target=parse --libname=fred --nsname=GO::Mojo";
59 $more_args = "--libname=$libname --nsname=$nsname";
60 my $preproc_fn = cc_preprocess($ARGV[0]);
62 my $parse_tree = dump_parse_tree($preproc_fn, $more_args);
63 unlink($preproc_fn);
64 print $parse_tree;
65 print "$preproc_fn\n";
68 main();
70 __END__
72 =head1 NAME
74 sample - Using nci_gen.pl
76 =head1 SYNOPSIS
78 nci_gen [options] [file ...]
80 Options:
81 -help brief help message
82 -man full documentation
84 =head1 OPTIONS
86 =over 8
88 =item B<-help>
90 Print a brief help message and exits.
92 =item B<-man>
94 Prints the manual page and exits.
96 =back
98 =head1 DESCRIPTION
100 B<nci_gen> will read the given input file c header file and create a pir interface file.
102 =cut