]>
Commit | Line | Data |
---|---|---|
f9bf01c6 A |
1 | #! /usr/bin/perl -w |
2 | # | |
3 | # Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) | |
4e4e5a6f | 4 | # Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> |
f9bf01c6 A |
5 | # |
6 | # This library is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU Library General Public | |
8 | # License as published by the Free Software Foundation; either | |
9 | # version 2 of the License, or (at your option) any later version. | |
10 | # | |
11 | # This library is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | # Library General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU Library General Public License | |
17 | # along with this library; see the file COPYING.LIB. If not, write to | |
18 | # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
19 | # Boston, MA 02110-1301, USA. | |
20 | ||
21 | use strict; | |
4e4e5a6f A |
22 | use File::Basename; |
23 | use Getopt::Long; | |
f9bf01c6 | 24 | |
14957cd0 | 25 | my $usage = basename($0) . " --prefix prefix file"; |
4e4e5a6f A |
26 | |
27 | my $rtype_template = quotemeta("#rtype#"); | |
4e4e5a6f A |
28 | my $op_template = quotemeta("#op#"); |
29 | ||
30 | my $prefix; | |
93a37866 | 31 | my $enable_dfg = 0; |
4e4e5a6f A |
32 | my $file; |
33 | ||
34 | my $getOptionsResult = GetOptions( | |
93a37866 A |
35 | 'prefix=s' => \$prefix, |
36 | 'dfg!' => \$enable_dfg | |
4e4e5a6f A |
37 | ); |
38 | ||
39 | $file = $ARGV[0]; | |
40 | ||
41 | die "$usage\n" unless ($prefix and $file); | |
f9bf01c6 A |
42 | |
43 | my $stub_template = ""; | |
14957cd0 | 44 | my $output_end = ""; |
f9bf01c6 A |
45 | my $stub = ""; |
46 | ||
47 | my $rtype = ""; | |
48 | my $op = ""; | |
93a37866 A |
49 | my $if_counter = 0; |
50 | my $dfg_begin = 0; | |
f9bf01c6 | 51 | |
4e4e5a6f | 52 | print STDERR "Creating JIT stubs for $file \n"; |
f9bf01c6 A |
53 | open(IN, $file) or die "No such file $file"; |
54 | ||
55 | while ( $_ = <IN> ) { | |
93a37866 A |
56 | if ( /^#if (.*)/ ) { |
57 | $if_counter++; | |
58 | if ( $1 eq "ENABLE(DFG_JIT)" ) { | |
59 | $dfg_begin = $if_counter; | |
60 | } | |
61 | } | |
62 | if ( /^#endif/ ) { | |
63 | if ( $if_counter == $dfg_begin ) { | |
64 | $dfg_begin = 0; | |
65 | } | |
66 | $if_counter--; | |
67 | } | |
14957cd0 A |
68 | if ( /^$prefix\_BEGIN\((.*)\)/ ) { |
69 | $stub = $1; | |
70 | print $stub . "\n"; | |
71 | } | |
4e4e5a6f | 72 | if ( /^$prefix\((.*)\)/ ) { |
f9bf01c6 A |
73 | $stub_template .= $1 . "\n"; |
74 | } | |
14957cd0 A |
75 | if ( /^$prefix\_END\((.*)\)/ ) { |
76 | $output_end .= $1 . "\n"; | |
77 | } | |
f9bf01c6 A |
78 | if ( /^DEFINE_STUB_FUNCTION\((.*), (.*)\)/ ) { |
79 | $stub = $stub_template; | |
80 | $rtype = quotemeta($1); | |
81 | $op = quotemeta($2); | |
82 | $stub =~ s/$rtype_template/$rtype/g; | |
83 | $stub =~ s/$op_template/$op/g; | |
84 | $stub =~ s/\\\*/\*/g; | |
93a37866 A |
85 | if ( $enable_dfg == 1 || $dfg_begin == 0 ) { |
86 | print $stub; | |
87 | } | |
f9bf01c6 A |
88 | } |
89 | } | |
90 | ||
14957cd0 A |
91 | print $output_end; |
92 | ||
f9bf01c6 | 93 | close(IN); |