]> git.saurik.com Git - apple/javascriptcore.git/blame - create_jit_stubs
JavaScriptCore-7600.1.4.17.5.tar.gz
[apple/javascriptcore.git] / create_jit_stubs
CommitLineData
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
21use strict;
4e4e5a6f
A
22use File::Basename;
23use Getopt::Long;
f9bf01c6 24
81345200 25my $usage = basename($0) . " --prefix prefix --header header file";
4e4e5a6f
A
26
27my $rtype_template = quotemeta("#rtype#");
4e4e5a6f
A
28my $op_template = quotemeta("#op#");
29
30my $prefix;
81345200 31my $header;
93a37866 32my $enable_dfg = 0;
4e4e5a6f
A
33my $file;
34
35my $getOptionsResult = GetOptions(
93a37866 36 'prefix=s' => \$prefix,
81345200 37 'header=s' => \$header,
93a37866 38 'dfg!' => \$enable_dfg
4e4e5a6f
A
39);
40
41$file = $ARGV[0];
42
81345200 43die "$usage\n" unless ($header and $prefix and $file);
f9bf01c6
A
44
45my $stub_template = "";
14957cd0 46my $output_end = "";
f9bf01c6
A
47my $stub = "";
48
49my $rtype = "";
50my $op = "";
93a37866
A
51my $if_counter = 0;
52my $dfg_begin = 0;
f9bf01c6 53
4e4e5a6f 54print STDERR "Creating JIT stubs for $file \n";
81345200
A
55open(IN, $header) or die "No such file $header";
56
57while ( $_ = <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
70close(IN);
f9bf01c6
A
71open(IN, $file) or die "No such file $file";
72
73while ( $_ = <IN> ) {
93a37866
A
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 }
f9bf01c6
A
86 if ( /^DEFINE_STUB_FUNCTION\((.*), (.*)\)/ ) {
87 $stub = $stub_template;
88 $rtype = quotemeta($1);
89 $op = quotemeta($2);
90 $stub =~ s/$rtype_template/$rtype/g;
91 $stub =~ s/$op_template/$op/g;
92 $stub =~ s/\\\*/\*/g;
93a37866
A
93 if ( $enable_dfg == 1 || $dfg_begin == 0 ) {
94 print $stub;
95 }
f9bf01c6
A
96 }
97}
98
14957cd0
A
99print $output_end;
100
f9bf01c6 101close(IN);