This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
When testing the case sensitivity settings of the process
[perl5.git] / regcomp.pl
... / ...
CommitLineData
1BEGIN {
2 # Get function prototypes
3 require 'regen_lib.pl';
4}
5#use Fatal qw(open close rename chmod unlink);
6use strict;
7use warnings;
8
9open DESC, 'regcomp.sym';
10
11my $ind = 0;
12my (@name,@rest,@type,@code,@args,@longj);
13my ($desc,$lastregop);
14while (<DESC>) {
15 s/#.*$//;
16 next if /^\s*$/;
17 s/\s*\z//;
18 if (/^-+\s*$/) {
19 $lastregop= $ind;
20 next;
21 }
22 unless ($lastregop) {
23 $ind++;
24 ($name[$ind], $desc, $rest[$ind]) = split /\t+/, $_, 3;
25 ($type[$ind], $code[$ind], $args[$ind], $longj[$ind])
26 = split /[,\s]\s*/, $desc, 4;
27 } else {
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;
32 $special ||= "";
33 foreach my $name (split /,/,$names) {
34 my $real= $name eq 'resume'
35 ? "resume_$type"
36 : "${type}_$name";
37 my @suffix;
38 if (!$special) {
39 @suffix=("");
40 } elsif ($special=~/\d/) {
41 @suffix=(1..$special);
42 } elsif ($special eq 'FAIL') {
43 @suffix=("","_fail");
44 } else {
45 die "unknown :type ':$special'";
46 }
47 foreach my $suffix (@suffix) {
48 $ind++;
49 $name[$ind]="$real$suffix";
50 $type[$ind]=$type;
51 $rest[$ind]="state for $type";
52 }
53 }
54 }
55
56 }
57}
58# use fixed width to keep the diffs between regcomp.pl recompiles
59# as small as possible.
60my ($width,$rwidth,$twidth)=(22,12,9);
61$lastregop ||= $ind;
62my $tot = $ind;
63close DESC;
64die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!"
65 if $lastregop>256;
66
67my $tmp_h = 'tmp_reg.h';
68
69unlink $tmp_h if -f $tmp_h;
70
71my $out = safer_open($tmp_h);
72
73printf $out <<EOP,
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!
78*/
79
80/* Regops and State definitions */
81
82#define %*s\t%d
83#define %*s\t%d
84
85EOP
86 -$width, REGNODE_MAX => $lastregop - 1,
87 -$width, REGMATCH_STATE_MAX => $tot - 1
88;
89
90
91for ($ind=1; $ind <= $lastregop ; $ind++) {
92 my $oind = $ind - 1;
93 printf $out "#define\t%*s\t%d\t/* %#04x %s */\n",
94 -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind];
95}
96print $out "\t/* ------------ States ------------- */\n";
97for ( ; $ind <= $tot ; $ind++) {
98 printf $out "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n",
99 -$width, $name[$ind], $ind - $lastregop, $rest[$ind];
100}
101
102print $out <<EOP;
103
104/* PL_regkind[] What type of regop or state is this. */
105
106#ifndef DOINIT
107EXTCONST U8 PL_regkind[];
108#else
109EXTCONST U8 PL_regkind[] = {
110EOP
111
112$ind = 0;
113while (++$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;
118}
119
120print $out <<EOP;
121};
122#endif
123
124/* regarglen[] - How large is the argument part of the node (in regnodes) */
125
126#ifdef REG_COMP_C
127static const U8 regarglen[] = {
128EOP
129
130$ind = 0;
131while (++$ind <= $lastregop) {
132 my $size = 0;
133 $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
134
135 printf $out "\t%*s\t/* %*s */\n",
136 -37, "$size,",-$rwidth,$name[$ind];
137}
138
139print $out <<EOP;
140};
141
142/* reg_off_by_arg[] - Which argument holds the offset to the next node */
143
144static const char reg_off_by_arg[] = {
145EOP
146
147$ind = 0;
148while (++$ind <= $lastregop) {
149 my $size = $longj[$ind] || 0;
150
151 printf $out "\t%d,\t/* %*s */\n",
152 $size, -$rwidth, $name[$ind]
153}
154
155print $out <<EOP;
156};
157
158#endif /* REG_COMP_C */
159
160/* reg_name[] - Opcode/state names in string form, for debugging */
161
162#ifndef DOINIT
163EXTCONST char * PL_reg_name[];
164#else
165EXTCONST char * const PL_reg_name[] = {
166EOP
167
168$ind = 0;
169my $ofs = 1;
170my $sym = "";
171while (++$ind <= $tot) {
172 my $size = $longj[$ind] || 0;
173
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";
178 $ofs = $lastregop;
179 $sym = 'REGNODE_MAX +';
180 }
181
182}
183
184print $out <<EOP;
185};
186#endif /* DOINIT */
187
188/* PL_reg_extflags_name[] - Opcode/state names in string form, for debugging */
189
190#ifndef DOINIT
191EXTCONST char * PL_reg_extflags_name[];
192#else
193EXTCONST char * const PL_reg_extflags_name[] = {
194EOP
195
196open my $fh,"<","regexp.h" or die "Can't read regexp.h: $!";
197my %rxfv;
198my $val = 0;
199my %reverse;
200while (<$fh>) {
201 if (/#define\s+(RXf_\w+)\s+(0x[A-F\d]+)/i) {
202 my $newval = eval $2;
203 if($val & $newval) {
204 die sprintf "Both $1 and $reverse{$newval} use %08X", $newval;
205 }
206 $val|=$newval;
207 $rxfv{$1}= $newval;
208 $reverse{$newval} = $1;
209 }
210}
211my %vrxf=reverse %rxfv;
212printf $out "\t/* Bits in extflags defined: %032b */\n",$val;
213for (0..31) {
214 my $n=$vrxf{2**$_}||"UNUSED_BIT_$_";
215 $n=~s/^RXf_(PMf_)?//;
216 printf $out qq(\t%-20s/* 0x%08x */\n),
217 qq("$n",),2**$_;
218}
219
220print $out <<EOP;
221};
222#endif /* DOINIT */
223
224/* ex: set ro: */
225EOP
226safer_close($out);
227
228rename_if_different $tmp_h, 'regnodes.h';