This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don't set things to zero twice. Once is enough. (see also change 15255)
[perl5.git] / regcomp.pl
CommitLineData
36bb303b
NC
1BEGIN {
2 # Get function prototypes
9ad884cb 3 require 'regen_lib.pl';
36bb303b 4}
d09b2d29
IZ
5#use Fatal qw(open close rename chmod unlink);
6open DESC, 'regcomp.sym';
7$ind = 0;
8
9while (<DESC>) {
10 next if /^\s*($|\#)/;
11 $ind++;
12 chomp;
13 ($name[$ind], $desc, $rest[$ind]) = split /\t+/, $_, 3;
14 ($type[$ind], $code[$ind], $args[$ind], $longj[$ind])
15 = split /[,\s]\s*/, $desc, 4;
16}
17close DESC;
18$tot = $ind;
19
20$tmp_h = 'tmp_reg.h';
21
22unlink $tmp_h if -f $tmp_h;
23
24open OUT, ">$tmp_h";
dfb1454f 25binmode OUT;
d09b2d29
IZ
26
27print OUT <<EOP;
28/* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
9b155405 29 This file is built by regcomp.pl from regcomp.sym.
d09b2d29
IZ
30 Any changes made here will be lost!
31*/
32
33EOP
34
35$ind = 0;
36while (++$ind <= $tot) {
37 $oind = $ind - 1;
38 $hind = sprintf "%#4x", $oind;
39 print OUT <<EOP;
40#define $name[$ind] $oind /* $hind $rest[$ind] */
41EOP
42}
43
44print OUT <<EOP;
45
46#ifndef DOINIT
22c35a8c 47EXTCONST U8 PL_regkind[];
d09b2d29 48#else
22c35a8c 49EXTCONST U8 PL_regkind[] = {
d09b2d29
IZ
50EOP
51
52$ind = 0;
53while (++$ind <= $tot) {
54 print OUT <<EOP;
55 $type[$ind], /* $name[$ind] */
56EOP
57}
58
59print OUT <<EOP;
60};
61#endif
62
63
64#ifdef REG_COMP_C
29de9391 65static const U8 regarglen[] = {
d09b2d29
IZ
66EOP
67
68$ind = 0;
69while (++$ind <= $tot) {
70 $size = 0;
71 $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
72
73 print OUT <<EOP;
74 $size, /* $name[$ind] */
75EOP
76}
77
78print OUT <<EOP;
79};
80
29de9391 81static const char reg_off_by_arg[] = {
d09b2d29
IZ
82EOP
83
84$ind = 0;
85while (++$ind <= $tot) {
86 $size = $longj[$ind] || 0;
9b155405 87
d09b2d29
IZ
88 print OUT <<EOP;
89 $size, /* $name[$ind] */
90EOP
91}
92
93print OUT <<EOP;
94};
9b155405
IZ
95
96#ifdef DEBUGGING
29de9391 97static const char * const reg_name[] = {
9b155405
IZ
98EOP
99
100$ind = 0;
101while (++$ind <= $tot) {
102 $hind = sprintf "%#4x", $ind-1;
103 $size = $longj[$ind] || 0;
104
105 print OUT <<EOP;
106 "$name[$ind]", /* $hind */
107EOP
108}
109
110print OUT <<EOP;
111};
112
29de9391 113static const int reg_num = $tot;
9b155405
IZ
114
115#endif /* DEBUGGING */
d09b2d29
IZ
116#endif /* REG_COMP_C */
117
118EOP
119
36bb303b 120close OUT or die "close $tmp_h: $!";
d09b2d29 121
36bb303b 122safer_rename $tmp_h, 'regnodes.h';