7
8
%name_to_value, # just the names in the srl_protocol.h
8
9
%name_to_value_expanded, # names from srl_protocol, but with the LOW/HIGH data expanded
9
10
%value_to_name_expanded, # values from srl_protocol_expanded, mapping back, note value points at FIRST name
10
11
%value_to_comment_expanded # values from srl_protocol_expanded, with comments from file.
12
13
my $max_name_length= 0;
17
20
defined(my $ofs= $name_to_value_expanded{$pfx})
27
30
$meta[$value]{value}= $value;
28
31
$meta[$value]{type_name}= $pfx;
29
32
$meta[$value]{type_value}= $ofs;
34
push @{$range{$pfx}}, $meta[$value];
30
35
#$meta[$value]{comment}= $value_to_comment_expanded{ $ofs }
31
36
# if exists $value_to_comment_expanded{ $ofs };
33
38
$meta[$value]{masked_val}= $n;
34
39
$meta[$value]{masked}= 1;
41
#$define{"SRL_HDR_".$name}= $value;
37
43
$value_to_comment_expanded{ $name_to_value_expanded{$pfx . "_HIGH"} } = $value_to_comment_expanded{ $ofs };
45
if(m!^#define\s+SRL_HDR_(\S+)\s+\(\(char\)(\d+)\)\s*(?:/\*\s*(.*?)\s*\*/)?\s*\z!i) {
46
my ($name, $value, $comment)= ($1, $2, $3);
53
if(m!^#define\s+(SRL_HDR_(\S+))\s+\(\(U8\)(\d+)\)\s*(?:/\*\s*(.*?)\s*\*/)?\s*\z!i) {
54
my ($full_name, $name, $value, $comment)= ($1, $2, $3, $4);
48
56
$name_to_value{$name}= $value;
49
57
$name_to_value_expanded{$name}= $value;
51
59
$value_to_comment_expanded{$value} ||= $comment;
52
60
push @fill, $name if substr($name, -4) eq '_LOW';
62
if ( $value < 128 && !($name=~/_LOW/ or $name=~/_HIGH/)) {
55
63
$meta[$value]{name}= $name;
56
64
$meta[$value]{value}= $value;
57
65
$meta[$value]{type_name}= $name;
58
66
$meta[$value]{type_value}= $value;
59
67
$meta[$value]{comment}= $comment if defined $comment;
69
$define{$full_name}= $value;
70
} elsif (s!^#define (SRL_\w+)\s+!!) {
75
$define{$1} // die "Unknown define '$1'";
80
my $code= "\$val= $_; 1";
81
eval $code or die "Failed to eval $code (from $orig): $@";
83
$define_is_str{$def}= 1 if /[""]/;
64
fill_ranges($_) for @fill;
87
fill_range($_) for @fill;
65
88
foreach my $pfx (keys %name_to_value_expanded) {
66
89
$max_name_length= length($pfx) if $max_name_length < length($pfx);
91
#print Data::Dumper->new([\%define, \%define_is_str])->Useqq(1)->Sortkeys(1)->Dump();
81
105
sub replace_block {
82
106
my ($file,$blob)= @_;
83
107
my ($in,$out)= open_swap($file);
86
last if /^=for autoupdater start/ || /^# start autoupdated section/;
89
print $out "\n$blob\n\n";
91
if (/^=for autoupdater stop/ || /^# stop autoupdated section/) {
113
last if $gotit= (/^=for autoupdater start/ || /^# start autoupdated section/);
117
warn "didnt find autoupdater start!\n";
121
$blob =~ s/[ \t]+$//mg;
124
print $out "\n$blob\n\n";
127
if (/^=for autoupdater stop/ || /^# stop autoupdated section/) {
135
warn "didnt find autoupdater start!\n";
102
sub update_buildtools {
103
my $dump= Data::Dumper->new([\@meta],['*TAG_INFO_ARRAY'])->Indent(1)->Dump();
148
sub update_constants {
149
my $dump= Data::Dumper->new([\@meta],['*TAG_INFO_ARRAY'])->Sortkeys(1)->Useqq(1)->Indent(1)->Dump();
104
150
$dump =~ s/^(\s*)\{/$1# autoupdated by $0 do not modify directly!\n$1\{/mg;
105
return replace_block(
106
"Perl/shared/inc/Sereal/BuildTools.pm",
108
"our (%TAG_INFO_HASH, \@TAG_INFO_ARRAY);",
110
"\$TAG_INFO_HASH{chr \$_}= \$TAG_INFO_ARRAY[\$_] for 0 .. 127;",
111
"push \@EXPORT_OK, qw(%TAG_INFO_HASH \@TAG_INFO_ARRAY);",
151
my $defines= Data::Dumper->new([\%define],['*DEFINE'])->Sortkeys(1)->Useqq(1)->Indent(1)->Dump;
154
foreach my $mod_suffix (qw(Encoder Decoder)) {
156
"Perl/$mod_suffix/lib/Sereal/$mod_suffix/Constants.pm",
162
"use constant \\%DEFINE;",
163
"push \@EXPORT_OK, keys %DEFINE;",
165
"\$TAG_INFO_HASH{chr \$_}= \$TAG_INFO_ARRAY[\$_] for 0 .. 127;",
166
"push \@EXPORT_OK, qw(%TAG_INFO_HASH \@TAG_INFO_ARRAY);",
114
sub update_srl_decoder_h {
115
replace_block("Perl/Decoder/srl_decoder.h",
171
sub update_srl_taginfo_h {
172
replace_block("Perl/shared/srl_taginfo.h",
117
174
"* NOTE this section is autoupdated by $0",
119
177
"static const char * const tag_name[] = {",
121
179
my $str= Data::Dumper::qquote(chr($_));
124
182
$max_name_length+3, qq("$value_to_name_expanded{$_}") . ($_==127 ? " " : ","), $str, $_, $_, $_
188
sprintf "#define SRL_HDR_%-*s %3d",
189
$max_name_length+3, $_->{name}, $_->{value}
190
} grep { $_->{masked} } @meta
198
"#define CASE_SRL_HDR_$n",
200
map { "case SRL_HDR_$_->{name}" } @$v;
203
} sort keys %range ),
128
206
"* NOTE the above section is auto-updated by $0",
133
212
sub update_JavaSerealHeader {
134
213
my $declarations = "* NOTE this section is autoupdated by $0 */\n";
136
for my $name (sort { $name_to_value{$a} <=> $name_to_value{$b} } keys %name_to_value) {
215
for my $name (sort { $name_to_value{$a} <=> $name_to_value{$b} || $a cmp $b } keys %name_to_value) {
137
216
my $byte = $name_to_value{$name};
138
217
my $decl = sprintf("static final byte SRL_HDR_%-*s = (byte) %3d;", $max_name_length, $name, $byte);
139
218
$declarations .= sprintf("\t%s /* %3d 0x%02x 0b%08b %s */\n",