This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add patch that generates regnodes.h via regcomp.pl
[perl5.git] / regcomp.pl
CommitLineData
d09b2d29
IZ
1#use Fatal qw(open close rename chmod unlink);
2open DESC, 'regcomp.sym';
3$ind = 0;
4
5while (<DESC>) {
6 next if /^\s*($|\#)/;
7 $ind++;
8 chomp;
9 ($name[$ind], $desc, $rest[$ind]) = split /\t+/, $_, 3;
10 ($type[$ind], $code[$ind], $args[$ind], $longj[$ind])
11 = split /[,\s]\s*/, $desc, 4;
12}
13close DESC;
14$tot = $ind;
15
16$tmp_h = 'tmp_reg.h';
17
18unlink $tmp_h if -f $tmp_h;
19
20open OUT, ">$tmp_h";
21
22print OUT <<EOP;
23/* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
24 This file is built by regcomp.pl from regcomp.sym.
25 Any changes made here will be lost!
26*/
27
28EOP
29
30$ind = 0;
31while (++$ind <= $tot) {
32 $oind = $ind - 1;
33 $hind = sprintf "%#4x", $oind;
34 print OUT <<EOP;
35#define $name[$ind] $oind /* $hind $rest[$ind] */
36EOP
37}
38
39print OUT <<EOP;
40
41#ifndef DOINIT
42EXTCONST U8 regkind[];
43#else
44EXTCONST U8 regkind[] = {
45EOP
46
47$ind = 0;
48while (++$ind <= $tot) {
49 print OUT <<EOP;
50 $type[$ind], /* $name[$ind] */
51EOP
52}
53
54print OUT <<EOP;
55};
56#endif
57
58
59#ifdef REG_COMP_C
60const static U8 regarglen[] = {
61EOP
62
63$ind = 0;
64while (++$ind <= $tot) {
65 $size = 0;
66 $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
67
68 print OUT <<EOP;
69 $size, /* $name[$ind] */
70EOP
71}
72
73print OUT <<EOP;
74};
75
76const static char reg_off_by_arg[] = {
77EOP
78
79$ind = 0;
80while (++$ind <= $tot) {
81 $size = $longj[$ind] || 0;
82
83 print OUT <<EOP;
84 $size, /* $name[$ind] */
85EOP
86}
87
88print OUT <<EOP;
89};
90#endif /* REG_COMP_C */
91
92EOP
93
94close OUT;
95
96chmod 0666, 'regnodes.h';
97unlink 'regnodes.h';
98rename $tmp_h, 'regnodes.h';