This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Module::CoreList 2.09:
[perl5.git] / regcomp.pl
CommitLineData
36bb303b
NC
1BEGIN {
2 # Get function prototypes
9ad884cb 3 require 'regen_lib.pl';
36bb303b 4}
d09b2d29 5#use Fatal qw(open close rename chmod unlink);
03363afd
YO
6use strict;
7use warnings;
8
d09b2d29 9open DESC, 'regcomp.sym';
d09b2d29 10
03363afd
YO
11my $ind = 0;
12my (@name,@rest,@type,@code,@args,@longj);
13my ($desc,$lastregop);
d09b2d29 14while (<DESC>) {
03363afd
YO
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]="Regmatch state for $type";
52 }
53 }
54 }
55
56 }
57}
58my ($width,$rwidth,$twidth)=(0,0,0);
59for (1..@name) {
60 $width=length($name[$_]) if $name[$_] and $width<length($name[$_]);
61 $twidth=length($type[$_]) if $type[$_] and $twidth<length($type[$_]);
62 $rwidth=$width if $_ == $lastregop;
d09b2d29 63}
03363afd
YO
64$lastregop ||= $ind;
65my $tot = $ind;
d09b2d29 66close DESC;
03363afd
YO
67die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!"
68 if $lastregop>256;
d09b2d29 69
03363afd 70my $tmp_h = 'tmp_reg.h';
d09b2d29
IZ
71
72unlink $tmp_h if -f $tmp_h;
73
74open OUT, ">$tmp_h";
03363afd 75#*OUT=\*STDOUT;
dfb1454f 76binmode OUT;
d09b2d29 77
03363afd 78printf OUT <<EOP,
37442d52
RGS
79/* -*- buffer-read-only: t -*-
80 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
9b155405 81 This file is built by regcomp.pl from regcomp.sym.
d09b2d29
IZ
82 Any changes made here will be lost!
83*/
84
03363afd
YO
85#define %*s\t%d
86#define %*s\t%d
87
d09b2d29 88EOP
f9f4320a
YO
89 -$width, REGNODE_MAX => $lastregop - 1,
90 -$width, REGMATCH_STATE_MAX => $tot - 1
91;
d09b2d29
IZ
92
93$ind = 0;
94while (++$ind <= $tot) {
03363afd 95 my $oind = $ind - 1;
f9f4320a 96 printf OUT "#define\t%*s\t%d\t/* %#04x %s */\n",
03363afd
YO
97 -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind];
98 print OUT "\n\t/* ------------ States ------------- */\n\n"
99 if $ind == $lastregop and $lastregop != $tot;
d09b2d29
IZ
100}
101
102print OUT <<EOP;
03363afd 103
d09b2d29
IZ
104
105#ifndef DOINIT
22c35a8c 106EXTCONST U8 PL_regkind[];
d09b2d29 107#else
22c35a8c 108EXTCONST U8 PL_regkind[] = {
d09b2d29
IZ
109EOP
110
111$ind = 0;
112while (++$ind <= $tot) {
03363afd
YO
113 printf OUT "\t%*s\t/* %*s */\n",
114 -1-$twidth, "$type[$ind],", -$width, $name[$ind];
115 print OUT "\t/* ------------ States ------------- */\n"
116 if $ind == $lastregop and $lastregop != $tot;
d09b2d29
IZ
117}
118
119print OUT <<EOP;
120};
121#endif
122
123
124#ifdef REG_COMP_C
29de9391 125static const U8 regarglen[] = {
d09b2d29
IZ
126EOP
127
128$ind = 0;
03363afd
YO
129while (++$ind <= $lastregop) {
130 my $size = 0;
d09b2d29
IZ
131 $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
132
03363afd
YO
133 printf OUT "\t%*s\t/* %*s */\n",
134 -37, "$size,",-$rwidth,$name[$ind];
d09b2d29
IZ
135}
136
137print OUT <<EOP;
138};
139
29de9391 140static const char reg_off_by_arg[] = {
d09b2d29
IZ
141EOP
142
143$ind = 0;
03363afd
YO
144while (++$ind <= $lastregop) {
145 my $size = $longj[$ind] || 0;
9b155405 146
03363afd
YO
147 printf OUT "\t%d,\t/* %*s */\n",
148 $size, -$rwidth, $name[$ind]
d09b2d29
IZ
149}
150
151print OUT <<EOP;
152};
9b155405
IZ
153
154#ifdef DEBUGGING
6d9c9890 155const char * reg_name[] = {
9b155405
IZ
156EOP
157
158$ind = 0;
159while (++$ind <= $tot) {
03363afd 160 my $size = $longj[$ind] || 0;
9b155405 161
03363afd
YO
162 printf OUT "\t%*s\t/* %#04x */\n",
163 -3-$width,qq("$name[$ind]",),$ind-1;
164 print OUT "\t/* ------------ States ------------- */\n"
165 if $ind == $lastregop and $lastregop != $tot;
9b155405
IZ
166}
167
168print OUT <<EOP;
169};
9b155405 170#endif /* DEBUGGING */
03363afd
YO
171#else
172#ifdef DEBUGGING
6d9c9890 173extern const char * reg_name[];
03363afd 174#endif
d09b2d29
IZ
175#endif /* REG_COMP_C */
176
37442d52 177/* ex: set ro: */
d09b2d29
IZ
178EOP
179
36bb303b 180close OUT or die "close $tmp_h: $!";
d09b2d29 181
36bb303b 182safer_rename $tmp_h, 'regnodes.h';