This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
split by " \0" (const string staring with a SPACE followed by NULL)
[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
71open OUT, ">$tmp_h";
72#*OUT=\*STDOUT;
73binmode OUT;
74
75printf OUT <<EOP,
76/* -*- buffer-read-only: t -*-
77 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
78 This file is built by regcomp.pl from regcomp.sym.
79 Any changes made here will be lost!
80*/
81
82/* Regops and State definitions */
83
84#define %*s\t%d
85#define %*s\t%d
86
87EOP
88 -$width, REGNODE_MAX => $lastregop - 1,
89 -$width, REGMATCH_STATE_MAX => $tot - 1
90;
91
92
93for ($ind=1; $ind <= $lastregop ; $ind++) {
94 my $oind = $ind - 1;
95 printf OUT "#define\t%*s\t%d\t/* %#04x %s */\n",
96 -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind];
97}
98print OUT "\t/* ------------ States ------------- */\n";
99for ( ; $ind <= $tot ; $ind++) {
100 printf OUT "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n",
101 -$width, $name[$ind], $ind - $lastregop, $rest[$ind];
102}
103
104print OUT <<EOP;
105
106/* PL_regkind[] What type of regop or state is this. */
107
108#ifndef DOINIT
109EXTCONST U8 PL_regkind[];
110#else
111EXTCONST U8 PL_regkind[] = {
112EOP
113
114$ind = 0;
115while (++$ind <= $tot) {
116 printf OUT "\t%*s\t/* %*s */\n",
117 -1-$twidth, "$type[$ind],", -$width, $name[$ind];
118 print OUT "\t/* ------------ States ------------- */\n"
119 if $ind == $lastregop and $lastregop != $tot;
120}
121
122print OUT <<EOP;
123};
124#endif
125
126/* regarglen[] - How large is the argument part of the node (in regnodes) */
127
128#ifdef REG_COMP_C
129static const U8 regarglen[] = {
130EOP
131
132$ind = 0;
133while (++$ind <= $lastregop) {
134 my $size = 0;
135 $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
136
137 printf OUT "\t%*s\t/* %*s */\n",
138 -37, "$size,",-$rwidth,$name[$ind];
139}
140
141print OUT <<EOP;
142};
143
144/* reg_off_by_arg[] - Which argument holds the offset to the next node */
145
146static const char reg_off_by_arg[] = {
147EOP
148
149$ind = 0;
150while (++$ind <= $lastregop) {
151 my $size = $longj[$ind] || 0;
152
153 printf OUT "\t%d,\t/* %*s */\n",
154 $size, -$rwidth, $name[$ind]
155}
156
157print OUT <<EOP;
158};
159
160/* reg_name[] - Opcode/state names in string form, for debugging */
161
162#ifdef DEBUGGING
163const char * reg_name[] = {
164EOP
165
166$ind = 0;
167my $ofs = 1;
168my $sym = "";
169while (++$ind <= $tot) {
170 my $size = $longj[$ind] || 0;
171
172 printf OUT "\t%*s\t/* $sym%#04x */\n",
173 -3-$width,qq("$name[$ind]",), $ind - $ofs;
174 if ($ind == $lastregop and $lastregop != $tot) {
175 print OUT "\t/* ------------ States ------------- */\n";
176 $ofs = $lastregop;
177 $sym = 'REGNODE_MAX +';
178 }
179
180}
181
182print OUT <<EOP;
183};
184#endif /* DEBUGGING */
185#else
186#ifdef DEBUGGING
187extern const char * reg_name[];
188#endif
189#endif /* REG_COMP_C */
190
191/* ex: set ro: */
192EOP
193
194close OUT or die "close $tmp_h: $!";
195
196safer_rename $tmp_h, 'regnodes.h';