#
# opcode.h
# opnames.h
-# pp.sym
+# pp_proto.h
#
# from information stored in regen/opcodes, plus the
# values hardcoded into this script in @raw_alias.
require 'regen/regen_lib.pl';
}
-my $opcode_new = 'opcode.h-new';
-my $opname_new = 'opnames.h-new';
-my $oc = safer_open($opcode_new);
-my $on = safer_open($opname_new);
-select $oc;
+my $oc = open_new('opcode.h', '>',
+ {by => 'regen/opcode.pl', from => 'its data',
+ file => 'opcode.h', style => '*',
+ copyright => [1993 .. 2007]});
+
+my $on = open_new('opnames.h', '>',
+ { by => 'regen/opcode.pl', from => 'its data', style => '*',
+ file => 'opnames.h', copyright => [1999 .. 2008] });
# Read data.
$args = '' unless defined $args;
warn qq[Description "$desc" duplicates $seen{$desc}\n]
- if $seen{$desc} and $key ne "transr";
+ if $seen{$desc} and $key !~ "transr|(?:intro|clone)cv";
die qq[Opcode "$key" duplicates $seen{$key}\n] if $seen{$key};
+ die qq[Opcode "freed" is reserved for the slab allocator\n]
+ if $key eq 'freed';
$seen{$desc} = qq[description of opcode "$key"];
$seen{$key} = qq[opcode "$key"];
Perl_pp_goto => ['dump'],
Perl_pp_require => ['dofile'],
Perl_pp_untie => ['dbmclose'],
- Perl_pp_sysread => [qw(read recv)],
+ Perl_pp_sysread => {read => '', recv => '#ifdef HAS_SOCKET'},
Perl_pp_sysseek => ['seek'],
Perl_pp_ioctl => ['fcntl'],
- Perl_pp_ssockopt => ['gsockopt'],
- Perl_pp_getpeername => ['getsockname'],
+ Perl_pp_ssockopt => {gsockopt => '#ifdef HAS_SOCKET'},
+ Perl_pp_getpeername => {getsockname => '#ifdef HAS_SOCKET'},
Perl_pp_stat => ['lstat'],
Perl_pp_ftrowned => [qw(fteowned ftzero ftsock ftchr ftblk
ftfile ftdir ftpipe ftsuid ftsgid
Perl_pp_ftrread => [qw(ftrwrite ftrexec fteread ftewrite
fteexec)],
Perl_pp_shmwrite => [qw(shmread msgsnd msgrcv semop)],
- Perl_pp_send => ['syswrite'],
+ Perl_pp_syswrite => {send => '#ifdef HAS_SOCKET'},
Perl_pp_defined => [qw(dor dorassign)],
Perl_pp_and => ['andassign'],
Perl_pp_or => ['orassign'],
Perl_pp_rv2av => ['rv2hv'],
Perl_pp_akeys => ['avalues'],
Perl_pp_rkeys => [qw(rvalues reach)],
- Perl_pp_trans => ['transr'],
- Perl_pp_chop => ['chomp'],
- Perl_pp_schop => ['schomp'],
- Perl_pp_bind => ['connect'],
- Perl_pp_preinc => ['i_preinc'],
- Perl_pp_predec => ['i_predec'],
- Perl_pp_postinc => ['i_postinc'],
- Perl_pp_postdec => ['i_postdec'],
+ Perl_pp_trans => [qw(trans transr)],
+ Perl_pp_chop => [qw(chop chomp)],
+ Perl_pp_schop => [qw(schop schomp)],
+ Perl_pp_bind => {connect => '#ifdef HAS_SOCKET'},
+ Perl_pp_preinc => ['i_preinc', 'predec', 'i_predec'],
+ Perl_pp_postinc => ['i_postinc', 'postdec', 'i_postdec'],
+ Perl_pp_ehostent => [qw(enetent eprotoent eservent
+ spwent epwent sgrent egrent)],
+ Perl_pp_shostent => [qw(snetent sprotoent sservent)],
+ Perl_pp_aelemfast => ['aelemfast_lex'],
);
while (my ($func, $names) = splice @raw_alias, 0, 2) {
- foreach (@$names) {
- $alias{$_} = $func;
+ if (ref $names eq 'ARRAY') {
+ foreach (@$names) {
+ $alias{$_} = [$func, ''];
+ }
+ } else {
+ while (my ($opname, $cond) = each %$names) {
+ $alias{$opname} = [$func, $cond];
+ }
}
}
-# Emit defines.
+foreach my $sock_func (qw(socket bind listen accept shutdown
+ ssockopt getpeername)) {
+ $alias{$sock_func} = ["Perl_pp_$sock_func", '#ifdef HAS_SOCKET'],
+}
-print <<"END";
-/* -*- buffer-read-only: t -*-
- *
- * opcode.h
- *
- * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- * 2001, 2002, 2003, 2004, 2005, 2006, 2007 by Larry Wall and others
- *
- * You may distribute under the terms of either the GNU General Public
- * License or the Artistic License, as specified in the README file.
- *
- * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
- * This file is built by regen/opcode.pl from its data. Any changes made
- * here will be lost!
- */
+# Emit defines.
-#ifndef PERL_GLOBAL_STRUCT_INIT
+print $oc "#ifndef PERL_GLOBAL_STRUCT_INIT\n\n";
-END
+{
+ my $last_cond = '';
+ my @unimplemented;
-for (@ops) {
- print "#define Perl_pp_$_ $alias{$_}\n" if $alias{$_};
-}
-
-print <<'END';
+ sub unimplemented {
+ if (@unimplemented) {
+ print $oc "#else\n";
+ foreach (@unimplemented) {
+ print $oc "#define $_ Perl_unimplemented_op\n";
+ }
+ print $oc "#endif\n";
+ @unimplemented = ();
+ }
-PERL_PPDEF(Perl_unimplemented_op)
+ }
-END
+ for (@ops) {
+ my ($impl, $cond) = @{$alias{$_} || ["Perl_pp_$_", '']};
+ my $op_func = "Perl_pp_$_";
+
+ if ($cond ne $last_cond) {
+ # A change in condition. (including to or from no condition)
+ unimplemented();
+ $last_cond = $cond;
+ if ($last_cond) {
+ print $oc "$last_cond\n";
+ }
+ }
+ push @unimplemented, $op_func if $last_cond;
+ print $oc "#define $op_func $impl\n" if $impl ne $op_func;
+ }
+ # If the last op was conditional, we need to close it out:
+ unimplemented();
+}
-print $on <<"END";
-/* -*- buffer-read-only: t -*-
- *
- * opnames.h
- *
- * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
- * 2007, 2008 by Larry Wall and others
- *
- * You may distribute under the terms of either the GNU General Public
- * License or the Artistic License, as specified in the README file.
- *
- *
- * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
- * This file is built by regen/opcode.pl from its data. Any changes made
- * here will be lost!
- */
-
-typedef enum opcode {
-END
+print $on "typedef enum opcode {\n";
my $i = 0;
for (@ops) {
- # print $on "\t", &tab(3,"OP_\U$_,"), "/* ", $i++, " */\n";
- print $on "\t", &tab(3,"OP_\U$_"), " = ", $i++, ",\n";
+ print $on "\t", tab(3,"OP_\U$_"), " = ", $i++, ",\n";
}
-print $on "\t", &tab(3,"OP_max"), "\n";
+print $on "\t", tab(3,"OP_max"), "\n";
print $on "} opcode;\n";
print $on "\n#define MAXO ", scalar @ops, "\n";
+print $on "#define OP_FREED MAXO\n";
# Emit op names and descriptions.
-print <<END;
+print $oc <<'END';
START_EXTERN_C
#ifndef DOINIT
END
for (@ops) {
- print qq(\t"$_",\n);
+ print $oc qq(\t"$_",\n);
}
-print <<END;
+print $oc <<'END';
+ "freed",
};
#endif
-END
-
-print <<END;
#ifndef DOINIT
EXTCONST char* const PL_op_desc[];
#else
# Have to escape double quotes and escape characters.
$safe_desc =~ s/([\\"])/\\$1/g;
- print qq(\t"$safe_desc",\n);
+ print $oc qq(\t"$safe_desc",\n);
}
-print <<END;
+print $oc <<'END';
+ "freed op",
};
#endif
#endif /* !PERL_GLOBAL_STRUCT_INIT */
END
-# Emit function declarations.
-
-#for (sort keys %ckname) {
-# print "OP *\t", &tab(3,$_),"(pTHX_ OP* o);\n";
-#}
-#
-#print "\n";
-#
-#for (@ops) {
-# print "OP *\t", &tab(3, "pp_$_"), "(pTHX);\n";
-#}
-
# Emit ppcode switch array.
-print <<END;
+print $oc <<'END';
START_EXTERN_C
END
for (@ops) {
- if (my $name = $alias{$_}) {
- print "\t$name,\t/* Perl_pp_$_ */\n";
+ my $op_func = "Perl_pp_$_";
+ my $name = $alias{$_};
+ if ($name && $name->[0] ne $op_func) {
+ print $oc "\t$op_func,\t/* implemented by $name->[0] */\n";
}
else {
- print "\tPerl_pp_$_,\n";
+ print $oc "\t$op_func,\n";
}
}
-print <<END;
+print $oc <<'END';
}
#endif
#ifdef PERL_PPADDR_INITED
;
#endif
-END
-
-# Emit check routines.
-
-print <<END;
#ifdef PERL_GLOBAL_STRUCT_INIT
# define PERL_CHECK_INITED
static const Perl_check_t Gcheck[]
END
for (@ops) {
- print "\t", &tab(3, "Perl_$check{$_},"), "\t/* $_ */\n";
+ print $oc "\t", tab(3, "Perl_$check{$_},"), "\t/* $_ */\n";
}
-print <<END;
+print $oc <<'END';
}
#endif
#ifdef PERL_CHECK_INITED
;
#endif /* #ifdef PERL_CHECK_INITED */
-END
-
-# Emit allowed argument types.
-
-my $ARGBITS = 32;
-
-print <<END;
#ifndef PERL_GLOBAL_STRUCT_INIT
#ifndef DOINIT
EXTCONST U32 PL_opargs[] = {
END
+# Emit allowed argument types.
+
+my $ARGBITS = 32;
+
my %argnum = (
'S', 1, # scalar
'L', 2, # list
'u' => 128, # defaults to $_
);
-my %OP_IS_SOCKET;
-my %OP_IS_FILETEST;
-my %OP_IS_FT_ACCESS;
+my %OP_IS_SOCKET; # /Fs/
+my %OP_IS_FILETEST; # /F-/
+my %OP_IS_FT_ACCESS; # /F-+/
+my %OP_IS_NUMCOMPARE; # /S</
+my %OP_IS_DIRHOP; # /Fd/
+
my $OCSHIFT = 8;
my $OASHIFT = 12;
$argsum |= $opclass{$flags} << $OCSHIFT;
my $argshift = $OASHIFT;
for my $arg (split(' ',$args{$op})) {
+ if ($arg =~ s/^D//) {
+ # handle 1st, just to put D 1st.
+ $OP_IS_DIRHOP{$op} = $opnum{$op};
+ }
if ($arg =~ /^F/) {
# record opnums of these opnames
$OP_IS_SOCKET{$op} = $opnum{$op} if $arg =~ s/s//;
$OP_IS_FILETEST{$op} = $opnum{$op} if $arg =~ s/-//;
$OP_IS_FT_ACCESS{$op} = $opnum{$op} if $arg =~ s/\+//;
}
+ elsif ($arg =~ /^S</) {
+ $OP_IS_NUMCOMPARE{$op} = $opnum{$op} if $arg =~ s/<//;
+ }
my $argnum = ($arg =~ s/\?//) ? 8 : 0;
die "op = $op, arg = $arg\n"
unless exists $argnum{$arg};
$argshift += 4;
}
$argsum = sprintf("0x%08x", $argsum);
- print "\t", &tab(3, "$argsum,"), "/* $op */\n";
+ print $oc "\t", tab(3, "$argsum,"), "/* $op */\n";
}
-print <<END;
+print $oc <<'END';
};
#endif
#endif /* !PERL_GLOBAL_STRUCT_INIT */
END_EXTERN_C
-
END
# Emit OP_IS_* macros
-print $on <<EO_OP_IS_COMMENT;
-
-/* the OP_IS_(SOCKET|FILETEST) macros are optimized to a simple range
- check because all the member OPs are contiguous in opcode.pl
- <OPS> table. opcode.pl verifies the range contiguity. */
+print $on <<'EO_OP_IS_COMMENT';
+/* the OP_IS_* macros are optimized to a simple range check because
+ all the member OPs are contiguous in regen/opcodes table.
+ opcode.pl verifies the range contiguity, or generates an OR-equals
+ expression */
EO_OP_IS_COMMENT
gen_op_is_macro( \%OP_IS_SOCKET, 'OP_IS_SOCKET');
gen_op_is_macro( \%OP_IS_FILETEST, 'OP_IS_FILETEST');
gen_op_is_macro( \%OP_IS_FT_ACCESS, 'OP_IS_FILETEST_ACCESS');
+gen_op_is_macro( \%OP_IS_NUMCOMPARE, 'OP_IS_NUMCOMPARE');
+gen_op_is_macro( \%OP_IS_DIRHOP, 'OP_IS_DIRHOP');
sub gen_op_is_macro {
my ($op_is, $macname) = @_;
my $last = pop @rest; # @rest slurped, get its last
die "Invalid range of ops: $first .. $last\n" unless $last;
- print $on "#define $macname(op) \\\n\t(";
+ print $on "\n#define $macname(op) \\\n\t(";
# verify that op-ct matches 1st..last range (and fencepost)
# (we know there are no dups)
if ( $op_is->{$last} - $op_is->{$first} == scalar @rest + 1) {
# contiguous ops -> optimized version
- print $on "(op) >= OP_" . uc($first) . " && (op) <= OP_" . uc($last);
- print $on ")\n\n";
+ print $on "(op) >= OP_" . uc($first)
+ . " && (op) <= OP_" . uc($last);
}
else {
print $on join(" || \\\n\t ",
- map { "(op) == OP_" . uc() } sort keys %$op_is);
- print $on ")\n\n";
+ map { "(op) == OP_" . uc() } sort keys %$op_is);
}
+ print $on ")\n";
}
}
-print $oc "/* ex: set ro: */\n";
-print $on "/* ex: set ro: */\n";
-
-safer_close($oc);
-safer_close($on);
-
-rename_if_different $opcode_new, 'opcode.h';
-rename_if_different $opname_new, 'opnames.h';
-
-my $pp_sym_new = 'pp.sym-new';
-my $ppsym = safer_open($pp_sym_new);
-
-print $ppsym <<"END";
-# -*- buffer-read-only: t -*-
-#
-# !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
-# This file is built by regen/opcode.pl from its data. Any changes made
-# here will be lost!
-#
-
-END
-
-
-for (sort keys %ckname) {
- print $ppsym "Perl_$_\n";
-#OP *\t", &tab(3,$_),"(OP* o);\n";
-}
-
-for (@ops) {
- next if /^i_(pre|post)(inc|dec)$/;
- next if /^custom$/;
- print $ppsym "Perl_pp_$_\n";
-}
-print $ppsym "\n# ex: set ro:\n";
-
-safer_close($ppsym);
+my $pp = open_new('pp_proto.h', '>',
+ { by => 'opcode.pl', from => 'its data' });
-rename_if_different $pp_sym_new, 'pp.sym';
-
-END {
- foreach ('opcode.h', 'opnames.h', 'pp.sym') {
- 1 while unlink "$_-old";
- }
+{
+ my %funcs;
+ for (@ops) {
+ my $name = $alias{$_} ? $alias{$_}[0] : "Perl_pp_$_";
+ ++$funcs{$name};
+ }
+ print $pp "PERL_CALLCONV OP *$_(pTHX);\n" foreach sort keys %funcs;
}
-
-###########################################################################
-sub tab {
- my ($l, $t) = @_;
- $t .= "\t" x ($l - (length($t) + 1) / 8);
- $t;
+foreach ($oc, $on, $pp) {
+ read_only_bottom_close_and_rename($_);
}
-###########################################################################
# Some comments about 'T' opcode classifier: