Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.6 KiB

  1. package O;
  2. use B qw(minus_c);
  3. use Carp;
  4. sub import {
  5. my ($class, $backend, @options) = @_;
  6. eval "use B::$backend ()";
  7. if ($@) {
  8. croak "use of backend $backend failed: $@";
  9. }
  10. my $compilesub = &{"B::${backend}::compile"}(@options);
  11. if (ref($compilesub) eq "CODE") {
  12. minus_c;
  13. eval 'END { &$compilesub() }';
  14. } else {
  15. die $compilesub;
  16. }
  17. }
  18. 1;
  19. __END__
  20. =head1 NAME
  21. O - Generic interface to Perl Compiler backends
  22. =head1 SYNOPSIS
  23. perl -MO=Backend[,OPTIONS] foo.pl
  24. =head1 DESCRIPTION
  25. This is the module that is used as a frontend to the Perl Compiler.
  26. =head1 CONVENTIONS
  27. Most compiler backends use the following conventions: OPTIONS
  28. consists of a comma-separated list of words (no white-space).
  29. The C<-v> option usually puts the backend into verbose mode.
  30. The C<-ofile> option generates output to B<file> instead of
  31. stdout. The C<-D> option followed by various letters turns on
  32. various internal debugging flags. See the documentation for the
  33. desired backend (named C<B::Backend> for the example above) to
  34. find out about that backend.
  35. =head1 IMPLEMENTATION
  36. This section is only necessary for those who want to write a
  37. compiler backend module that can be used via this module.
  38. The command-line mentioned in the SYNOPSIS section corresponds to
  39. the Perl code
  40. use O ("Backend", OPTIONS);
  41. The C<import> function which that calls loads in the appropriate
  42. C<B::Backend> module and calls the C<compile> function in that
  43. package, passing it OPTIONS. That function is expected to return
  44. a sub reference which we'll call CALLBACK. Next, the "compile-only"
  45. flag is switched on (equivalent to the command-line option C<-c>)
  46. and an END block is registered which calls CALLBACK. Thus the main
  47. Perl program mentioned on the command-line is read in, parsed and
  48. compiled into internal syntax tree form. Since the C<-c> flag is
  49. set, the program does not start running (excepting BEGIN blocks of
  50. course) but the CALLBACK function registered by the compiler
  51. backend is called.
  52. In summary, a compiler backend module should be called "B::Foo"
  53. for some foo and live in the appropriate directory for that name.
  54. It should define a function called C<compile>. When the user types
  55. perl -MO=Foo,OPTIONS foo.pl
  56. that function is called and is passed those OPTIONS (split on
  57. commas). It should return a sub ref to the main compilation function.
  58. After the user's program is loaded and parsed, that returned sub ref
  59. is invoked which can then go ahead and do the compilation, usually by
  60. making use of the C<B> module's functionality.
  61. =head1 AUTHOR
  62. Malcolm Beattie, C<[email protected]>
  63. =cut