3 # Regenerate (overwriting only if changed):
7 # from information stored in
12 # Accepts the standard regen_lib -q and -v args.
14 # This script is normally invoked from regen.pl.
17 # Get function prototypes
18 require 'regen_lib.pl';
20 #use Fatal qw(open close rename chmod unlink);
24 open DESC, 'regcomp.sym';
27 my (@name,@rest,@type,@code,@args,@flags,@longj);
28 my ($desc,$lastregop);
39 ($name[$ind], $desc, $rest[$ind]) = /^(\S+)\s+([^\t]+)\s*;\s*(.*)/;
40 ($type[$ind], $code[$ind], $args[$ind], $flags[$ind], $longj[$ind])
41 = split /[,\s]\s*/, $desc;
43 my ($type,@lists)=split /\s+/, $_;
44 die "No list? $type" if !@lists;
45 foreach my $list (@lists) {
46 my ($names,$special)=split /:/, $list , 2;
48 foreach my $name (split /,/,$names) {
49 my $real= $name eq 'resume'
55 } elsif ($special=~/\d/) {
56 @suffix=(1..$special);
57 } elsif ($special eq 'FAIL') {
60 die "unknown :type ':$special'";
62 foreach my $suffix (@suffix) {
64 $name[$ind]="$real$suffix";
66 $rest[$ind]="state for $type";
73 # use fixed width to keep the diffs between regcomp.pl recompiles
74 # as small as possible.
75 my ($width,$rwidth,$twidth)=(22,12,9);
79 die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!"
83 my ($flag, $varname, $comment) = @_;
84 $comment = '' unless defined $comment;
88 while (++$ind <= $lastregop) {
89 push @selected, $name[$ind] if $flags[$ind] && $flags[$ind] eq $flag;
91 my $out_string = join ', ', @selected, 0;
92 $out_string =~ s/(.{1,70},) /$1\n /g;
93 return $comment . <<"EOP";
94 #define REGNODE_\U$varname\E(node) strchr((const char *)PL_${varname}, (node))
97 EXTCONST U8 PL_${varname}[];
99 EXTCONST U8 PL_${varname}[] = {
107 my $tmp_h = 'regnodes.h-new';
109 unlink $tmp_h if -f $tmp_h;
111 my $out = safer_open($tmp_h);
114 /* -*- buffer-read-only: t -*-
115 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
116 This file is built by regcomp.pl from regcomp.sym.
117 Any changes made here will be lost!
120 /* Regops and State definitions */
126 -$width, REGNODE_MAX => $lastregop - 1,
127 -$width, REGMATCH_STATE_MAX => $tot - 1
131 for ($ind=1; $ind <= $lastregop ; $ind++) {
133 printf $out "#define\t%*s\t%d\t/* %#04x %s */\n",
134 -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind];
136 print $out "\t/* ------------ States ------------- */\n";
137 for ( ; $ind <= $tot ; $ind++) {
138 printf $out "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n",
139 -$width, $name[$ind], $ind - $lastregop, $rest[$ind];
144 /* PL_regkind[] What type of regop or state is this. */
147 EXTCONST U8 PL_regkind[];
149 EXTCONST U8 PL_regkind[] = {
153 while (++$ind <= $tot) {
154 printf $out "\t%*s\t/* %*s */\n",
155 -1-$twidth, "$type[$ind],", -$width, $name[$ind];
156 print $out "\t/* ------------ States ------------- */\n"
157 if $ind == $lastregop and $lastregop != $tot;
164 /* regarglen[] - How large is the argument part of the node (in regnodes) */
167 static const U8 regarglen[] = {
171 while (++$ind <= $lastregop) {
173 $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
175 printf $out "\t%*s\t/* %*s */\n",
176 -37, "$size,",-$rwidth,$name[$ind];
182 /* reg_off_by_arg[] - Which argument holds the offset to the next node */
184 static const char reg_off_by_arg[] = {
188 while (++$ind <= $lastregop) {
189 my $size = $longj[$ind] || 0;
191 printf $out "\t%d,\t/* %*s */\n",
192 $size, -$rwidth, $name[$ind]
198 #endif /* REG_COMP_C */
200 /* reg_name[] - Opcode/state names in string form, for debugging */
203 EXTCONST char * PL_reg_name[];
205 EXTCONST char * const PL_reg_name[] = {
211 while (++$ind <= $tot) {
212 my $size = $longj[$ind] || 0;
214 printf $out "\t%*s\t/* $sym%#04x */\n",
215 -3-$width,qq("$name[$ind]",), $ind - $ofs;
216 if ($ind == $lastregop and $lastregop != $tot) {
217 print $out "\t/* ------------ States ------------- */\n";
219 $sym = 'REGNODE_MAX +';
228 /* PL_reg_extflags_name[] - Opcode/state names in string form, for debugging */
231 EXTCONST char * PL_reg_extflags_name[];
233 EXTCONST char * const PL_reg_extflags_name[] = {
236 open my $fh,"<","regexp.h" or die "Can't read regexp.h: $!";
241 if (/#define\s+(RXf_\w+)\s+(0x[A-F\d]+)/i) {
242 my $newval = eval $2;
244 die sprintf "Both $1 and $reverse{$newval} use %08X", $newval;
248 $reverse{$newval} = $1;
251 my %vrxf=reverse %rxfv;
252 printf $out "\t/* Bits in extflags defined: %032b */\n",$val;
254 my $n=$vrxf{2**$_}||"UNUSED_BIT_$_";
255 $n=~s/^RXf_(PMf_)?//;
256 printf $out qq(\t%-20s/* 0x%08x */\n),
266 print $out process_flags('V', 'varies', <<'EOC');
267 /* The following have no fixed length. U8 so we can do strchr() on it. */
270 print $out process_flags('S', 'simple', <<'EOC');
271 /* The following always have a length of 1. U8 we can do strchr() on it. */
272 /* (Note that length 1 means "one character" under UTF8, not "one octet".) */
280 rename_if_different $tmp_h, 'regnodes.h';