laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 1 | #! /usr/bin/perl -w |
| 2 | # |
| 3 | # Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) |
eric@webkit.org | e8e340f | 2010-02-15 18:04:54 +0000 | [diff] [blame] | 4 | # Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> |
laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 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; |
eric@webkit.org | e8e340f | 2010-02-15 18:04:54 +0000 | [diff] [blame] | 22 | use File::Basename; |
| 23 | use Getopt::Long; |
laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 24 | |
paroga@webkit.org | 48deacd | 2013-08-06 10:03:30 +0000 | [diff] [blame] | 25 | my $usage = basename($0) . " --prefix prefix --header header file"; |
eric@webkit.org | e8e340f | 2010-02-15 18:04:54 +0000 | [diff] [blame] | 26 | |
| 27 | my $rtype_template = quotemeta("#rtype#"); |
eric@webkit.org | e8e340f | 2010-02-15 18:04:54 +0000 | [diff] [blame] | 28 | my $op_template = quotemeta("#op#"); |
| 29 | |
eric@webkit.org | 671c425 | 2010-02-19 19:30:55 +0000 | [diff] [blame] | 30 | my $prefix; |
paroga@webkit.org | 48deacd | 2013-08-06 10:03:30 +0000 | [diff] [blame] | 31 | my $header; |
paroga@webkit.org | 24c86b8 | 2012-07-16 20:06:15 +0000 | [diff] [blame] | 32 | my $enable_dfg = 0; |
eric@webkit.org | e8e340f | 2010-02-15 18:04:54 +0000 | [diff] [blame] | 33 | my $file; |
| 34 | |
| 35 | my $getOptionsResult = GetOptions( |
paroga@webkit.org | 24c86b8 | 2012-07-16 20:06:15 +0000 | [diff] [blame] | 36 | 'prefix=s' => \$prefix, |
paroga@webkit.org | 48deacd | 2013-08-06 10:03:30 +0000 | [diff] [blame] | 37 | 'header=s' => \$header, |
paroga@webkit.org | 24c86b8 | 2012-07-16 20:06:15 +0000 | [diff] [blame] | 38 | 'dfg!' => \$enable_dfg |
eric@webkit.org | e8e340f | 2010-02-15 18:04:54 +0000 | [diff] [blame] | 39 | ); |
| 40 | |
| 41 | $file = $ARGV[0]; |
| 42 | |
paroga@webkit.org | 48deacd | 2013-08-06 10:03:30 +0000 | [diff] [blame] | 43 | die "$usage\n" unless ($header and $prefix and $file); |
laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 44 | |
| 45 | my $stub_template = ""; |
commit-queue@webkit.org | d018810 | 2010-06-25 07:30:12 +0000 | [diff] [blame] | 46 | my $output_end = ""; |
laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 47 | my $stub = ""; |
| 48 | |
| 49 | my $rtype = ""; |
| 50 | my $op = ""; |
paroga@webkit.org | 24c86b8 | 2012-07-16 20:06:15 +0000 | [diff] [blame] | 51 | my $if_counter = 0; |
| 52 | my $dfg_begin = 0; |
laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 53 | |
mitz@apple.com | 6cf57f0 | 2011-10-26 16:30:50 +0000 | [diff] [blame] | 54 | print STDERR "Creating JIT stubs for $file \n"; |
paroga@webkit.org | 48deacd | 2013-08-06 10:03:30 +0000 | [diff] [blame] | 55 | open(IN, $header) or die "No such file $header"; |
| 56 | |
| 57 | while ( $_ = <IN> ) { |
| 58 | if ( /^$prefix\_BEGIN\((.*)\)/ ) { |
| 59 | $stub = $1; |
| 60 | print $stub . "\n"; |
| 61 | } |
| 62 | if ( /^$prefix\((.*)\)/ ) { |
| 63 | $stub_template .= $1 . "\n"; |
| 64 | } |
| 65 | if ( /^$prefix\_END\((.*)\)/ ) { |
| 66 | $output_end .= $1 . "\n"; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | close(IN); |
laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 71 | open(IN, $file) or die "No such file $file"; |
| 72 | |
| 73 | while ( $_ = <IN> ) { |
paroga@webkit.org | 24c86b8 | 2012-07-16 20:06:15 +0000 | [diff] [blame] | 74 | if ( /^#if (.*)/ ) { |
| 75 | $if_counter++; |
| 76 | if ( $1 eq "ENABLE(DFG_JIT)" ) { |
| 77 | $dfg_begin = $if_counter; |
| 78 | } |
| 79 | } |
| 80 | if ( /^#endif/ ) { |
| 81 | if ( $if_counter == $dfg_begin ) { |
| 82 | $dfg_begin = 0; |
| 83 | } |
| 84 | $if_counter--; |
| 85 | } |
laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 86 | if ( /^DEFINE_STUB_FUNCTION\((.*), (.*)\)/ ) { |
| 87 | $stub = $stub_template; |
| 88 | $rtype = quotemeta($1); |
| 89 | $op = quotemeta($2); |
laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 90 | $stub =~ s/$rtype_template/$rtype/g; |
| 91 | $stub =~ s/$op_template/$op/g; |
| 92 | $stub =~ s/\\\*/\*/g; |
paroga@webkit.org | 24c86b8 | 2012-07-16 20:06:15 +0000 | [diff] [blame] | 93 | if ( $enable_dfg == 1 || $dfg_begin == 0 ) { |
| 94 | print $stub; |
| 95 | } |
laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
commit-queue@webkit.org | d018810 | 2010-06-25 07:30:12 +0000 | [diff] [blame] | 99 | print $output_end; |
| 100 | |
laszlo.1.gombos@nokia.com | 32fb4ae | 2010-01-08 05:47:21 +0000 | [diff] [blame] | 101 | close(IN); |