create_jit_stubs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #! /usr/bin/perl -w
  2. #
  3. # Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
  4. # Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
  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. use strict;
  21. use File::Basename;
  22. use Getopt::Long;
  23. my $usage = basename($0) . " --prefix prefix file";
  24. my $rtype_template = quotemeta("#rtype#");
  25. my $op_template = quotemeta("#op#");
  26. my $prefix;
  27. my $enable_dfg = 0;
  28. my $file;
  29. my $getOptionsResult = GetOptions(
  30. 'prefix=s' => \$prefix,
  31. 'dfg!' => \$enable_dfg
  32. );
  33. $file = $ARGV[0];
  34. die "$usage\n" unless ($prefix and $file);
  35. my $stub_template = "";
  36. my $output_end = "";
  37. my $stub = "";
  38. my $rtype = "";
  39. my $op = "";
  40. my $if_counter = 0;
  41. my $dfg_begin = 0;
  42. print STDERR "Creating JIT stubs for $file \n";
  43. open(IN, $file) or die "No such file $file";
  44. while ( $_ = <IN> ) {
  45. if ( /^#if (.*)/ ) {
  46. $if_counter++;
  47. if ( $1 eq "ENABLE(DFG_JIT)" ) {
  48. $dfg_begin = $if_counter;
  49. }
  50. }
  51. if ( /^#endif/ ) {
  52. if ( $if_counter == $dfg_begin ) {
  53. $dfg_begin = 0;
  54. }
  55. $if_counter--;
  56. }
  57. if ( /^$prefix\_BEGIN\((.*)\)/ ) {
  58. $stub = $1;
  59. print $stub . "\n";
  60. }
  61. if ( /^$prefix\((.*)\)/ ) {
  62. $stub_template .= $1 . "\n";
  63. }
  64. if ( /^$prefix\_END\((.*)\)/ ) {
  65. $output_end .= $1 . "\n";
  66. }
  67. if ( /^DEFINE_STUB_FUNCTION\((.*), (.*)\)/ ) {
  68. $stub = $stub_template;
  69. $rtype = quotemeta($1);
  70. $op = quotemeta($2);
  71. $stub =~ s/$rtype_template/$rtype/g;
  72. $stub =~ s/$op_template/$op/g;
  73. $stub =~ s/\\\*/\*/g;
  74. if ( $enable_dfg == 1 || $dfg_begin == 0 ) {
  75. print $stub;
  76. }
  77. }
  78. }
  79. print $output_end;
  80. close(IN);