Commit | Line | Data |
36bb303b |
1 | BEGIN { |
2 | # Get function prototypes |
9ad884cb |
3 | require 'regen_lib.pl'; |
36bb303b |
4 | } |
d09b2d29 |
5 | #use Fatal qw(open close rename chmod unlink); |
03363afd |
6 | use strict; |
7 | use warnings; |
8 | |
d09b2d29 |
9 | open DESC, 'regcomp.sym'; |
d09b2d29 |
10 | |
03363afd |
11 | my $ind = 0; |
12 | my (@name,@rest,@type,@code,@args,@longj); |
13 | my ($desc,$lastregop); |
d09b2d29 |
14 | while (<DESC>) { |
03363afd |
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; |
24b23f37 |
51 | $rest[$ind]="state for $type"; |
03363afd |
52 | } |
53 | } |
54 | } |
55 | |
56 | } |
57 | } |
5d458dd8 |
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); |
03363afd |
61 | $lastregop ||= $ind; |
62 | my $tot = $ind; |
d09b2d29 |
63 | close DESC; |
03363afd |
64 | die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!" |
65 | if $lastregop>256; |
d09b2d29 |
66 | |
03363afd |
67 | my $tmp_h = 'tmp_reg.h'; |
d09b2d29 |
68 | |
69 | unlink $tmp_h if -f $tmp_h; |
70 | |
71 | open OUT, ">$tmp_h"; |
03363afd |
72 | #*OUT=\*STDOUT; |
dfb1454f |
73 | binmode OUT; |
d09b2d29 |
74 | |
03363afd |
75 | printf OUT <<EOP, |
37442d52 |
76 | /* -*- buffer-read-only: t -*- |
77 | !!!!!!! DO NOT EDIT THIS FILE !!!!!!! |
9b155405 |
78 | This file is built by regcomp.pl from regcomp.sym. |
d09b2d29 |
79 | Any changes made here will be lost! |
80 | */ |
81 | |
6bda09f9 |
82 | /* Regops and State definitions */ |
83 | |
03363afd |
84 | #define %*s\t%d |
85 | #define %*s\t%d |
86 | |
d09b2d29 |
87 | EOP |
f9f4320a |
88 | -$width, REGNODE_MAX => $lastregop - 1, |
89 | -$width, REGMATCH_STATE_MAX => $tot - 1 |
90 | ; |
d09b2d29 |
91 | |
24b23f37 |
92 | |
93 | for ($ind=1; $ind <= $lastregop ; $ind++) { |
03363afd |
94 | my $oind = $ind - 1; |
f9f4320a |
95 | printf OUT "#define\t%*s\t%d\t/* %#04x %s */\n", |
03363afd |
96 | -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind]; |
24b23f37 |
97 | } |
98 | print OUT "\t/* ------------ States ------------- */\n"; |
99 | for ( ; $ind <= $tot ; $ind++) { |
100 | printf OUT "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n", |
101 | -$width, $name[$ind], $ind - $lastregop, $rest[$ind]; |
d09b2d29 |
102 | } |
103 | |
104 | print OUT <<EOP; |
03363afd |
105 | |
6bda09f9 |
106 | /* PL_regkind[] What type of regop or state is this. */ |
d09b2d29 |
107 | |
108 | #ifndef DOINIT |
22c35a8c |
109 | EXTCONST U8 PL_regkind[]; |
d09b2d29 |
110 | #else |
22c35a8c |
111 | EXTCONST U8 PL_regkind[] = { |
d09b2d29 |
112 | EOP |
113 | |
114 | $ind = 0; |
115 | while (++$ind <= $tot) { |
03363afd |
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; |
d09b2d29 |
120 | } |
121 | |
122 | print OUT <<EOP; |
123 | }; |
124 | #endif |
125 | |
6bda09f9 |
126 | /* regarglen[] - How large is the argument part of the node (in regnodes) */ |
d09b2d29 |
127 | |
128 | #ifdef REG_COMP_C |
29de9391 |
129 | static const U8 regarglen[] = { |
d09b2d29 |
130 | EOP |
131 | |
132 | $ind = 0; |
03363afd |
133 | while (++$ind <= $lastregop) { |
134 | my $size = 0; |
d09b2d29 |
135 | $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind]; |
136 | |
03363afd |
137 | printf OUT "\t%*s\t/* %*s */\n", |
138 | -37, "$size,",-$rwidth,$name[$ind]; |
d09b2d29 |
139 | } |
140 | |
141 | print OUT <<EOP; |
142 | }; |
143 | |
6bda09f9 |
144 | /* reg_off_by_arg[] - Which argument holds the offset to the next node */ |
145 | |
29de9391 |
146 | static const char reg_off_by_arg[] = { |
d09b2d29 |
147 | EOP |
148 | |
149 | $ind = 0; |
03363afd |
150 | while (++$ind <= $lastregop) { |
151 | my $size = $longj[$ind] || 0; |
9b155405 |
152 | |
03363afd |
153 | printf OUT "\t%d,\t/* %*s */\n", |
154 | $size, -$rwidth, $name[$ind] |
d09b2d29 |
155 | } |
156 | |
157 | print OUT <<EOP; |
158 | }; |
9b155405 |
159 | |
13d6edb4 |
160 | #endif /* REG_COMP_C */ |
161 | |
6bda09f9 |
162 | /* reg_name[] - Opcode/state names in string form, for debugging */ |
163 | |
22429478 |
164 | #ifndef DOINIT |
13d6edb4 |
165 | EXTCONST char * PL_reg_name[]; |
22429478 |
166 | #else |
4764e399 |
167 | EXTCONST char * const PL_reg_name[] = { |
9b155405 |
168 | EOP |
169 | |
170 | $ind = 0; |
24b23f37 |
171 | my $ofs = 1; |
172 | my $sym = ""; |
9b155405 |
173 | while (++$ind <= $tot) { |
03363afd |
174 | my $size = $longj[$ind] || 0; |
9b155405 |
175 | |
24b23f37 |
176 | printf OUT "\t%*s\t/* $sym%#04x */\n", |
177 | -3-$width,qq("$name[$ind]",), $ind - $ofs; |
178 | if ($ind == $lastregop and $lastregop != $tot) { |
179 | print OUT "\t/* ------------ States ------------- */\n"; |
180 | $ofs = $lastregop; |
181 | $sym = 'REGNODE_MAX +'; |
182 | } |
183 | |
9b155405 |
184 | } |
185 | |
186 | print OUT <<EOP; |
187 | }; |
22429478 |
188 | #endif /* DOINIT */ |
d09b2d29 |
189 | |
f7819f85 |
190 | /* PL_reg_extflags_name[] - Opcode/state names in string form, for debugging */ |
191 | |
192 | #ifndef DOINIT |
193 | EXTCONST char * PL_reg_extflags_name[]; |
194 | #else |
195 | EXTCONST char * const PL_reg_extflags_name[] = { |
d09b2d29 |
196 | EOP |
197 | |
f7819f85 |
198 | open my $fh,"<","regexp.h" or die "Can't read regexp.h: $!"; |
199 | my %rxfv; |
200 | my $val; |
201 | while (<$fh>) { |
202 | if (/#define\s+(RXf_\w+)\s+(0x[A-F\d]+)/i) { |
203 | $rxfv{$1}= eval $2; |
204 | $val|=$rxfv{$1}; |
205 | } |
206 | } |
207 | my %vrxf=reverse %rxfv; |
208 | printf OUT "\t/* Bits in extflags defined: %032b */\n",$val; |
209 | for (0..31) { |
210 | my $n=$vrxf{2**$_}||"UNUSED_BIT_$_"; |
211 | $n=~s/^RXf_(PMf_)?//; |
212 | printf OUT qq(\t%-20s/* 0x%08x */\n), |
213 | qq("$n",),2**$_; |
214 | } |
215 | |
216 | print OUT <<EOP; |
217 | }; |
218 | #endif /* DOINIT */ |
219 | |
220 | /* ex: set ro: */ |
221 | EOP |
36bb303b |
222 | close OUT or die "close $tmp_h: $!"; |
d09b2d29 |
223 | |
36bb303b |
224 | safer_rename $tmp_h, 'regnodes.h'; |