2 # Get function prototypes
3 require 'regen_lib.pl';
5 #use Fatal qw(open close rename chmod unlink);
9 open DESC, 'regcomp.sym';
12 my (@name,@rest,@type,@code,@args,@longj);
13 my ($desc,$lastregop);
24 ($name[$ind], $desc, $rest[$ind]) = split /\t+/, $_, 3;
25 ($type[$ind], $code[$ind], $args[$ind], $longj[$ind])
26 = split /[,\s]\s*/, $desc, 4;
28 my ($type,@lists)=split /\s*\t+\s*/, $_;
29 die "No list? $type" if !@lists;
30 foreach my $list (@lists) {
31 my ($names,$special)=split /:/, $list , 2;
33 foreach my $name (split /,/,$names) {
34 my $real= $name eq 'resume'
40 } elsif ($special=~/\d/) {
41 @suffix=(1..$special);
42 } elsif ($special eq 'FAIL') {
45 die "unknown :type ':$special'";
47 foreach my $suffix (@suffix) {
49 $name[$ind]="$real$suffix";
51 $rest[$ind]="state for $type";
58 # use fixed width to keep the diffs between regcomp.pl recompiles
59 # as small as possible.
60 my ($width,$rwidth,$twidth)=(22,12,9);
64 die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!"
67 my $tmp_h = 'tmp_reg.h';
69 unlink $tmp_h if -f $tmp_h;
71 my $out = safer_open($tmp_h);
74 /* -*- buffer-read-only: t -*-
75 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
76 This file is built by regcomp.pl from regcomp.sym.
77 Any changes made here will be lost!
80 /* Regops and State definitions */
86 -$width, REGNODE_MAX => $lastregop - 1,
87 -$width, REGMATCH_STATE_MAX => $tot - 1
91 for ($ind=1; $ind <= $lastregop ; $ind++) {
93 printf $out "#define\t%*s\t%d\t/* %#04x %s */\n",
94 -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind];
96 print $out "\t/* ------------ States ------------- */\n";
97 for ( ; $ind <= $tot ; $ind++) {
98 printf $out "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n",
99 -$width, $name[$ind], $ind - $lastregop, $rest[$ind];
104 /* PL_regkind[] What type of regop or state is this. */
107 EXTCONST U8 PL_regkind[];
109 EXTCONST U8 PL_regkind[] = {
113 while (++$ind <= $tot) {
114 printf $out "\t%*s\t/* %*s */\n",
115 -1-$twidth, "$type[$ind],", -$width, $name[$ind];
116 print $out "\t/* ------------ States ------------- */\n"
117 if $ind == $lastregop and $lastregop != $tot;
124 /* regarglen[] - How large is the argument part of the node (in regnodes) */
127 static const U8 regarglen[] = {
131 while (++$ind <= $lastregop) {
133 $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
135 printf $out "\t%*s\t/* %*s */\n",
136 -37, "$size,",-$rwidth,$name[$ind];
142 /* reg_off_by_arg[] - Which argument holds the offset to the next node */
144 static const char reg_off_by_arg[] = {
148 while (++$ind <= $lastregop) {
149 my $size = $longj[$ind] || 0;
151 printf $out "\t%d,\t/* %*s */\n",
152 $size, -$rwidth, $name[$ind]
158 #endif /* REG_COMP_C */
160 /* reg_name[] - Opcode/state names in string form, for debugging */
163 EXTCONST char * PL_reg_name[];
165 EXTCONST char * const PL_reg_name[] = {
171 while (++$ind <= $tot) {
172 my $size = $longj[$ind] || 0;
174 printf $out "\t%*s\t/* $sym%#04x */\n",
175 -3-$width,qq("$name[$ind]",), $ind - $ofs;
176 if ($ind == $lastregop and $lastregop != $tot) {
177 print $out "\t/* ------------ States ------------- */\n";
179 $sym = 'REGNODE_MAX +';
188 /* PL_reg_extflags_name[] - Opcode/state names in string form, for debugging */
191 EXTCONST char * PL_reg_extflags_name[];
193 EXTCONST char * const PL_reg_extflags_name[] = {
196 open my $fh,"<","regexp.h" or die "Can't read regexp.h: $!";
201 if (/#define\s+(RXf_\w+)\s+(0x[A-F\d]+)/i) {
202 my $newval = eval $2;
204 die sprintf "Both $1 and $reverse{$newval} use %08X", $newval;
208 $reverse{$newval} = $1;
211 my %vrxf=reverse %rxfv;
212 printf $out "\t/* Bits in extflags defined: %032b */\n",$val;
214 my $n=$vrxf{2**$_}||"UNUSED_BIT_$_";
215 $n=~s/^RXf_(PMf_)?//;
216 printf $out qq(\t%-20s/* 0x%08x */\n),
228 rename_if_different $tmp_h, 'regnodes.h';