Commit | Line | Data |
---|---|---|
36bb303b NC |
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 YO |
6 | use strict; |
7 | use warnings; | |
8 | ||
d09b2d29 | 9 | open DESC, 'regcomp.sym'; |
d09b2d29 | 10 | |
03363afd YO |
11 | my $ind = 0; |
12 | my (@name,@rest,@type,@code,@args,@longj); | |
13 | my ($desc,$lastregop); | |
d09b2d29 | 14 | while (<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; | |
24b23f37 | 51 | $rest[$ind]="state for $type"; |
03363afd YO |
52 | } |
53 | } | |
54 | } | |
55 | ||
56 | } | |
57 | } | |
58 | my ($width,$rwidth,$twidth)=(0,0,0); | |
59 | for (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; |
65 | my $tot = $ind; | |
d09b2d29 | 66 | close DESC; |
03363afd YO |
67 | die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!" |
68 | if $lastregop>256; | |
d09b2d29 | 69 | |
03363afd | 70 | my $tmp_h = 'tmp_reg.h'; |
d09b2d29 IZ |
71 | |
72 | unlink $tmp_h if -f $tmp_h; | |
73 | ||
74 | open OUT, ">$tmp_h"; | |
03363afd | 75 | #*OUT=\*STDOUT; |
dfb1454f | 76 | binmode OUT; |
d09b2d29 | 77 | |
03363afd | 78 | printf 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 | ||
6bda09f9 YO |
85 | /* Regops and State definitions */ |
86 | ||
03363afd YO |
87 | #define %*s\t%d |
88 | #define %*s\t%d | |
89 | ||
d09b2d29 | 90 | EOP |
f9f4320a YO |
91 | -$width, REGNODE_MAX => $lastregop - 1, |
92 | -$width, REGMATCH_STATE_MAX => $tot - 1 | |
93 | ; | |
d09b2d29 | 94 | |
24b23f37 YO |
95 | |
96 | for ($ind=1; $ind <= $lastregop ; $ind++) { | |
03363afd | 97 | my $oind = $ind - 1; |
f9f4320a | 98 | printf OUT "#define\t%*s\t%d\t/* %#04x %s */\n", |
03363afd | 99 | -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind]; |
24b23f37 YO |
100 | } |
101 | print OUT "\t/* ------------ States ------------- */\n"; | |
102 | for ( ; $ind <= $tot ; $ind++) { | |
103 | printf OUT "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n", | |
104 | -$width, $name[$ind], $ind - $lastregop, $rest[$ind]; | |
d09b2d29 IZ |
105 | } |
106 | ||
107 | print OUT <<EOP; | |
03363afd | 108 | |
6bda09f9 | 109 | /* PL_regkind[] What type of regop or state is this. */ |
d09b2d29 IZ |
110 | |
111 | #ifndef DOINIT | |
22c35a8c | 112 | EXTCONST U8 PL_regkind[]; |
d09b2d29 | 113 | #else |
22c35a8c | 114 | EXTCONST U8 PL_regkind[] = { |
d09b2d29 IZ |
115 | EOP |
116 | ||
117 | $ind = 0; | |
118 | while (++$ind <= $tot) { | |
03363afd YO |
119 | printf OUT "\t%*s\t/* %*s */\n", |
120 | -1-$twidth, "$type[$ind],", -$width, $name[$ind]; | |
121 | print OUT "\t/* ------------ States ------------- */\n" | |
122 | if $ind == $lastregop and $lastregop != $tot; | |
d09b2d29 IZ |
123 | } |
124 | ||
125 | print OUT <<EOP; | |
126 | }; | |
127 | #endif | |
128 | ||
6bda09f9 | 129 | /* regarglen[] - How large is the argument part of the node (in regnodes) */ |
d09b2d29 IZ |
130 | |
131 | #ifdef REG_COMP_C | |
29de9391 | 132 | static const U8 regarglen[] = { |
d09b2d29 IZ |
133 | EOP |
134 | ||
135 | $ind = 0; | |
03363afd YO |
136 | while (++$ind <= $lastregop) { |
137 | my $size = 0; | |
d09b2d29 IZ |
138 | $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind]; |
139 | ||
03363afd YO |
140 | printf OUT "\t%*s\t/* %*s */\n", |
141 | -37, "$size,",-$rwidth,$name[$ind]; | |
d09b2d29 IZ |
142 | } |
143 | ||
144 | print OUT <<EOP; | |
145 | }; | |
146 | ||
6bda09f9 YO |
147 | /* reg_off_by_arg[] - Which argument holds the offset to the next node */ |
148 | ||
29de9391 | 149 | static const char reg_off_by_arg[] = { |
d09b2d29 IZ |
150 | EOP |
151 | ||
152 | $ind = 0; | |
03363afd YO |
153 | while (++$ind <= $lastregop) { |
154 | my $size = $longj[$ind] || 0; | |
9b155405 | 155 | |
03363afd YO |
156 | printf OUT "\t%d,\t/* %*s */\n", |
157 | $size, -$rwidth, $name[$ind] | |
d09b2d29 IZ |
158 | } |
159 | ||
160 | print OUT <<EOP; | |
161 | }; | |
9b155405 | 162 | |
6bda09f9 YO |
163 | /* reg_name[] - Opcode/state names in string form, for debugging */ |
164 | ||
9b155405 | 165 | #ifdef DEBUGGING |
6d9c9890 | 166 | const char * reg_name[] = { |
9b155405 IZ |
167 | EOP |
168 | ||
169 | $ind = 0; | |
24b23f37 YO |
170 | my $ofs = 1; |
171 | my $sym = ""; | |
9b155405 | 172 | while (++$ind <= $tot) { |
03363afd | 173 | my $size = $longj[$ind] || 0; |
9b155405 | 174 | |
24b23f37 YO |
175 | printf OUT "\t%*s\t/* $sym%#04x */\n", |
176 | -3-$width,qq("$name[$ind]",), $ind - $ofs; | |
177 | if ($ind == $lastregop and $lastregop != $tot) { | |
178 | print OUT "\t/* ------------ States ------------- */\n"; | |
179 | $ofs = $lastregop; | |
180 | $sym = 'REGNODE_MAX +'; | |
181 | } | |
182 | ||
9b155405 IZ |
183 | } |
184 | ||
185 | print OUT <<EOP; | |
186 | }; | |
9b155405 | 187 | #endif /* DEBUGGING */ |
03363afd YO |
188 | #else |
189 | #ifdef DEBUGGING | |
6d9c9890 | 190 | extern const char * reg_name[]; |
03363afd | 191 | #endif |
d09b2d29 IZ |
192 | #endif /* REG_COMP_C */ |
193 | ||
37442d52 | 194 | /* ex: set ro: */ |
d09b2d29 IZ |
195 | EOP |
196 | ||
36bb303b | 197 | close OUT or die "close $tmp_h: $!"; |
d09b2d29 | 198 | |
36bb303b | 199 | safer_rename $tmp_h, 'regnodes.h'; |