Leaked source code of windows server 2003
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.

86 lines
2.7 KiB

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