This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Change docs display for PERL_UNUSED_foo
[perl5.git] / regen / genpacksizetables.pl
CommitLineData
78d46eaa
NC
1#!/usr/bin/perl -w
2# I'm assuming that you're running this on some kind of ASCII system, but
d8a38289 3# it will generate EBCDIC too. (TODO)
78d46eaa
NC
4use strict;
5use Encode;
3d7c117d 6require './regen/regen_lib.pl';
78d46eaa 7
a7a3cfaa
TH
8sub make_text {
9 my ($chrmap, $letter, $unpredictable, $nocsum, $size, $condition) = @_;
10 my $text = " /* $letter */ $size";
11 $text .= " | PACK_SIZE_UNPREDICTABLE" if $unpredictable;
12 $text .= " | PACK_SIZE_CANNOT_CSUM" if $nocsum;
13 $text .= ",";
78d46eaa 14
a7a3cfaa 15 if ($condition) {
a7a3cfaa
TH
16 $text = "#if $condition
17$text
18#else
19 0,
20#endif";
21 }
22 return $text;
78d46eaa
NC
23}
24
a7a3cfaa
TH
25sub make_tables {
26 my %arrays;
78d46eaa 27
a7a3cfaa
TH
28 my $chrmap = shift;
29 foreach (@_) {
30 my ($letter, $shriek, $unpredictable, $nocsum, $size, $condition) =
31 /^([A-Za-z])(!?)\t(\S*)\t(\S*)\t([^\t\n]+)(?:\t+(.*))?$/ or
32 die "Can't parse '$_'";
78d46eaa 33
a7a3cfaa 34 $size = "sizeof($size)" unless $size =~ s/^=//;
78d46eaa 35
a7a3cfaa
TH
36 $arrays{$shriek ? 'shrieking' : 'normal'}{ord $chrmap->{$letter}} =
37 make_text($chrmap, $letter,
38 $unpredictable, $nocsum, $size, $condition);
80a13697 39 }
a7a3cfaa 40
f43a9a31 41 my $text = "STATIC const packprops_t packprops[512] = {\n";
a7a3cfaa
TH
42 foreach my $arrayname (qw(normal shrieking)) {
43 my $array = $arrays{$arrayname} ||
44 die "No defined entries in $arrayname";
45 $text .= " /* $arrayname */\n";
46 for my $ch (0..255) {
47 $text .= $array->{$ch} || " 0,";
48 $text .= "\n";
49 }
7212898e 50 }
a7a3cfaa
TH
51 # Join "0," entries together
52 1 while $text =~ s/\b0,\s*\n\s*0,/0, 0,/g;
53 # But split them up again if the sequence gets too long
54 $text =~ s/((?:\b0, ){15}0,) /$1\n /g;
55 # Clean up final ,
56 $text =~ s/,$//;
57 $text .= "};";
58 return $text;
59}
78d46eaa 60
a7a3cfaa
TH
61my @lines = grep {
62 s/#.*//;
63 /\S/;
64} <DATA>;
78d46eaa 65
a7a3cfaa 66my %asciimap = map {chr $_, chr $_} 0..255;
43fdf692
KW
67
68# Currently, all things generated by this on EBCDIC are alphabetics, whose
69# positions are all the same regardless of code page, so any EBCDIC encoding
70# will work; just choose one
a7a3cfaa 71my %ebcdicmap = map {chr $_, Encode::encode("posix-bc", chr $_)} 0..255;
78d46eaa 72
4ad176ef 73my $fh = open_new('packsizetables.inc', '>', { by => $0, from => 'its data'});
78d46eaa 74
6b05cb81 75print $fh <<"EOC";
a7a3cfaa
TH
76#if TYPE_IS_SHRIEKING != 0x100
77 ++++shriek offset should be 256
78#endif
79
80typedef U8 packprops_t;
78d46eaa
NC
81#if 'J'-'I' == 1
82/* ASCII */
a7a3cfaa 83@{[make_tables (\%asciimap, @lines)]}
78d46eaa
NC
84#else
85/* EBCDIC (or bust) */
a7a3cfaa
TH
86@{[make_tables (\%ebcdicmap, @lines)]}
87#endif
78d46eaa 88EOC
78d46eaa 89
6b05cb81
NC
90read_only_bottom_close_and_rename($fh);
91
78d46eaa 92__DATA__
f337b084
TH
93#Symbol unpredictable
94# nocsum size
78d46eaa 95c char
e2add64b 96C unsigned char
f337b084
TH
97W * unsigned char
98U * char
78d46eaa
NC
99s! short
100s =SIZE16
101S! unsigned short
102v =SIZE16
103n =SIZE16
104S =SIZE16
f8e5a5db
NC
105v! =SIZE16
106n! =SIZE16
78d46eaa
NC
107i int
108i! int
109I unsigned int
110I! unsigned int
111j =IVSIZE
112J =UVSIZE
113l! long
114l =SIZE32
115L! unsigned long
116V =SIZE32
117N =SIZE32
f8e5a5db
NC
118V! =SIZE32
119N! =SIZE32
78d46eaa 120L =SIZE32
a72c271b 121p * char *
f337b084 122w * * char
1640b983
NC
123q Quad_t IVSIZE >= 8
124Q Uquad_t IVSIZE >= 8
78d46eaa
NC
125f float
126d double
127F =NVSIZE
1640b983 128D =LONG_DOUBLESIZE defined(HAS_LONG_DOUBLE) && defined(USE_LONG_DOUBLE)