Permalink
Browse files

implement -c for B::C and B::CC - fixes issue 99

  • Loading branch information...
1 parent 6a80f4e commit ceead941972f37db9d3d44be3d28c3ec91258266 Reini Urban committed Apr 30, 2012
Showing with 32 additions and 3 deletions.
  1. +19 −1 lib/B/C.pm
  2. +13 −2 lib/B/CC.pm
View
@@ -14,6 +14,7 @@ use strict;
our $VERSION = '1.43';
my %debug;
+our $check;
my $eval_pvs = '';
package B::C::Section;
@@ -61,6 +62,7 @@ sub output {
my ( $section, $fh, $format ) = @_;
my $sym = $section->symtable || {};
my $default = $section->default;
+ return if $B::C::check;
my $i = 0;
my $dodbg = 1 if $debug{flags} and $section->[-1]{dbg};
foreach ( @{ $section->[-1]{values} } ) {
@@ -148,6 +150,7 @@ sub output {
my ( $section, $fh, $format, $init_name ) = @_;
my $sym = $section->symtable || {};
my $default = $section->default;
+ return if $B::C::check;
push @{ $section->[-1]{chunks} }, $section->[-1]{current};
my $name = "aaaa";
@@ -4333,6 +4336,7 @@ sub B::SV::save {
sub output_all {
my $init_name = shift;
my $section;
+ return if $check;
my @sections = (
$opsect, $unopsect, $binopsect, $logopsect, $condopsect,
@@ -5884,6 +5888,7 @@ sub save_main_rest {
force_saving_xsloader() if $use_xsloader;
fixup_ppaddr();
+ return if $check;
warn "Writing output\n" if $verbose;
output_boilerplate();
@@ -6032,6 +6037,9 @@ OPTION:
if ( $opt eq "w" ) {
$warn_undefined_syms = 1;
}
+ if ( $opt eq "c" ) {
+ $check = 1;
+ }
elsif ( $opt eq "D" ) {
$arg ||= shift @options;
if ($arg eq 'full') {
@@ -6068,7 +6076,11 @@ OPTION:
elsif ( $opt eq "o" ) {
$arg ||= shift @options;
$outfile = $arg;
- open( STDOUT, ">", $arg ) or return "$arg: $!\n";
+ if ($check) {
+ warn "Warning: -o argument ignored with -c\n";
+ } else {
+ open( STDOUT, ">", $arg ) or return "$arg: $!\n";
+ }
}
elsif ( $opt eq "s" and $arg eq "taticxs" ) {
$outfile = "perlcc" unless $outfile;
@@ -6195,6 +6207,12 @@ Without extra arguments, it saves the main program.
Output to filename instead of STDOUT
+=item B<-c>
+
+Check and abort.
+
+Compiles and prints only warnings, but does not emit C code.
+
=item B<-m>I<Packagename> I<(NYI)>
Prepare to compile a module with all dependent code to a single shared
View
@@ -42,6 +42,12 @@ Without extra arguments, it saves the main program.
Output to filename instead of STDOUT
+=item B<-c>
+
+Check and abort.
+
+Compiles and prints only warnings, but does not emit C code.
+
=item B<-v>
Verbose compilation (prints a few compilation stages).
@@ -313,7 +319,7 @@ my %need_curcop; # ops which need PL_curcop
my $package_pv; # sv->pv of previous op for method_named
my %lexstate; # state of padsvs at the start of a bblock
-my $verbose;
+my ( $verbose, $check );
my ( $entertry_defined, $vivify_ref_defined );
my ( $init_name, %debug, $strict );
@@ -2905,7 +2911,7 @@ sub cc_main {
$end_av = end_av->save;
}
cc_recurse();
- return if $errors;
+ return if $errors or $check;
if ( !defined($module) ) {
my $amagic_generate = amagic_generation;
@@ -2999,6 +3005,10 @@ OPTION:
$arg ||= shift @options;
open( STDOUT, ">$arg" ) or return "open '>$arg': $!\n";
}
+ elsif ( $opt eq "c" ) {
+ $check = 1;
+ $B::C::check = 1;
+ }
elsif ( $opt eq "v" ) {
$verbose = 1;
B::C::verbose(1); # crashed in C _save_common_middle(B::FAKEOP)
@@ -3181,6 +3191,7 @@ sub compile {
my $warner = $SIG{__WARN__};
save_sig($warner);
fixup_ppaddr();
+ return if $check;
output_boilerplate();
print "\n";
output_all( $init_name || "init_module" );

0 comments on commit ceead94

Please sign in to comment.