This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: Sync Time::Local in blead to 1.13 on CPAN
[perl5.git] / regcomp.pl
1 BEGIN {
2     # Get function prototypes
3     require 'regen_lib.pl';
4 }
5 #use Fatal qw(open close rename chmod unlink);
6 open DESC, 'regcomp.sym';
7 $ind = 0;
8
9 while (<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 }
17 close DESC;
18 $tot = $ind;
19 die "Too many regexp opcodes! Maximum is 256, but there are $tot in file!"
20     if $tot>256;
21
22 $tmp_h = 'tmp_reg.h';
23
24 unlink $tmp_h if -f $tmp_h;
25
26 open OUT, ">$tmp_h";
27 binmode OUT;
28
29 print OUT <<EOP;
30 /* -*- buffer-read-only: t -*-
31    !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
32    This file is built by regcomp.pl from regcomp.sym.
33    Any changes made here will be lost!
34 */
35
36 EOP
37
38 $ind = 0;
39 while (++$ind <= $tot) {
40   $oind = $ind - 1;
41   $hind = sprintf "%#4x", $oind;
42   print OUT <<EOP;
43 #define $name[$ind]     $oind   /* $hind $rest[$ind] */
44 EOP
45 }
46
47 print OUT <<EOP;
48 #define REGNODE_MAX $oind
49
50 #ifndef DOINIT
51 EXTCONST U8 PL_regkind[];
52 #else
53 EXTCONST U8 PL_regkind[] = {
54 EOP
55
56 $ind = 0;
57 while (++$ind <= $tot) {
58   print OUT <<EOP;
59         $type[$ind],            /* $name[$ind] */
60 EOP
61 }
62
63 print OUT <<EOP;
64 };
65 #endif
66
67
68 #ifdef REG_COMP_C
69 static const U8 regarglen[] = {
70 EOP
71
72 $ind = 0;
73 while (++$ind <= $tot) {
74   $size = 0;
75   $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
76   
77   print OUT <<EOP;
78         $size,          /* $name[$ind] */
79 EOP
80 }
81
82 print OUT <<EOP;
83 };
84
85 static const char reg_off_by_arg[] = {
86 EOP
87
88 $ind = 0;
89 while (++$ind <= $tot) {
90   $size = $longj[$ind] || 0;
91
92   print OUT <<EOP;
93         $size,          /* $name[$ind] */
94 EOP
95 }
96
97 print OUT <<EOP;
98 };
99
100 #ifdef DEBUGGING
101 static const char * const reg_name[] = {
102 EOP
103
104 $ind = 0;
105 while (++$ind <= $tot) {
106   $hind = sprintf "%#4x", $ind-1;
107   $size = $longj[$ind] || 0;
108
109   print OUT <<EOP;
110         "$name[$ind]",          /* $hind */
111 EOP
112 }
113
114 print OUT <<EOP;
115 };
116
117 static const int reg_num = $tot;
118
119 #endif /* DEBUGGING */
120 #endif /* REG_COMP_C */
121
122 /* ex: set ro: */
123 EOP
124
125 close OUT or die "close $tmp_h: $!";
126
127 safer_rename $tmp_h, 'regnodes.h';