summaryrefslogtreecommitdiff
path: root/embed.pl
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2005-04-23 13:57:41 +0000
committerNicholas Clark <nick@ccl4.org>2005-04-23 13:57:41 +0000
commitda4ddda1308ab0218fa0865029c9475e5cfe8bc6 (patch)
tree08cee6c734b1965eb455eb12cd2e19bbbf587cfa /embed.pl
parentca46b8ee06bde4bff70dee92de161b97200c8d19 (diff)
downloadperl-da4ddda1308ab0218fa0865029c9475e5cfe8bc6.tar.gz
Save state when auto-generating #ifdef PERL_CORE and PERL_CORE/PERL_EXT
reducing embed.h by about 10%. p4raw-id: //depot/perl@24308
Diffstat (limited to 'embed.pl')
-rwxr-xr-xembed.pl59
1 files changed, 52 insertions, 7 deletions
diff --git a/embed.pl b/embed.pl
index 1d816b1b4e..612e19c445 100755
--- a/embed.pl
+++ b/embed.pl
@@ -344,8 +344,19 @@ print EM do_not_edit ("embed.h"), <<'END';
END
+# Try to elimiate lots of repeated
+# #ifdef PERL_CORE
+# foo
+# #endif
+# #ifdef PERL_CORE
+# bar
+# #endif
+# by tracking state and merging foo and bar into one block.
+my $ifdef_state = '';
+
walk_table {
my $ret = "";
+ my $new_ifdef_state = '';
if (@_ == 1) {
my $arg = shift;
$ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
@@ -362,15 +373,31 @@ walk_table {
}
if ($ret ne '' && $flags !~ /A/) {
if ($flags =~ /E/) {
- $ret = "#if defined(PERL_CORE) || defined(PERL_EXT)\n$ret#endif\n";
- } else {
- $ret = "#ifdef PERL_CORE\n$ret#endif\n";
+ $new_ifdef_state
+ = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
+ }
+ else {
+ $new_ifdef_state = "#ifdef PERL_CORE\n";
+ }
+
+ if ($new_ifdef_state ne $ifdef_state) {
+ $ret = $new_ifdef_state . $ret;
}
}
}
+ if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
+ # Close the old one ahead of opening the new one.
+ $ret = "#endif\n$ret";
+ }
+ # Remember the new state.
+ $ifdef_state = $new_ifdef_state;
$ret;
} \*EM, "";
+if ($ifdef_state) {
+ print EM "#endif\n";
+}
+
for $sym (sort keys %ppsym) {
$sym =~ s/^Perl_//;
print EM hide($sym, "Perl_$sym");
@@ -384,8 +411,10 @@ END
my @az = ('a'..'z');
+$ifdef_state = '';
walk_table {
my $ret = "";
+ my $new_ifdef_state = '';
if (@_ == 1) {
my $arg = shift;
$ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
@@ -420,17 +449,33 @@ walk_table {
$ret .= $alist . ")\n";
}
}
- unless ($flags =~ /A/) {
+ unless ($flags =~ /A/) {
if ($flags =~ /E/) {
- $ret = "#if defined(PERL_CORE) || defined(PERL_EXT)\n$ret#endif\n";
- } else {
- $ret = "#ifdef PERL_CORE\n$ret#endif\n";
+ $new_ifdef_state
+ = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
+ }
+ else {
+ $new_ifdef_state = "#ifdef PERL_CORE\n";
+ }
+
+ if ($new_ifdef_state ne $ifdef_state) {
+ $ret = $new_ifdef_state . $ret;
}
}
}
+ if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
+ # Close the old one ahead of opening the new one.
+ $ret = "#endif\n$ret";
+ }
+ # Remember the new state.
+ $ifdef_state = $new_ifdef_state;
$ret;
} \*EM, "";
+if ($ifdef_state) {
+ print EM "#endif\n";
+}
+
for $sym (sort keys %ppsym) {
$sym =~ s/^Perl_//;
if ($sym =~ /^ck_/) {