line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/local/bin/perl -w |
2
|
|
|
|
|
|
|
################################################################################ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Copyright (c) 2002-2020 Marcus Holland-Moritz. All rights reserved. |
5
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
6
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
################################################################################ |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#=============================================================================== |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Parse perl's header files and play around with the types they define. |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
#=============================================================================== |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
959
|
use Convert::Binary::C; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
55
|
|
17
|
1
|
|
|
1
|
|
733
|
use Data::Dumper; |
|
1
|
|
|
|
|
7302
|
|
|
1
|
|
|
|
|
77
|
|
18
|
1
|
|
|
1
|
|
546
|
use File::Spec::Functions qw(rel2abs); |
|
1
|
|
|
|
|
898
|
|
|
1
|
|
|
|
|
64
|
|
19
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1719
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
3
|
my $base; |
22
|
1
|
|
33
|
|
|
29
|
-d "$_/include" and $base = rel2abs("$_/include") and last for qw( tests ../tests ); |
|
|
|
50
|
|
|
|
|
23
|
1
|
50
|
|
|
|
51
|
defined $base or die <
|
24
|
|
|
|
|
|
|
Please run this script from either the 'examples' directory |
25
|
|
|
|
|
|
|
or the distribution base directory. |
26
|
|
|
|
|
|
|
MSG |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#------------------------------------- |
29
|
|
|
|
|
|
|
# Create an object, set configuration. |
30
|
|
|
|
|
|
|
#------------------------------------- |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
602
|
my $cfg = require "$base/config.pl"; |
33
|
1
|
|
|
|
|
109
|
my $c = new Convert::Binary::C %$cfg; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#------------------ |
36
|
|
|
|
|
|
|
# Parse the C file. |
37
|
|
|
|
|
|
|
#------------------ |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
5
|
eval { $c->parse_file( "$base/include.c" ) }; |
|
1
|
|
|
|
|
19028
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#----------------------- |
42
|
|
|
|
|
|
|
# Check for parse error. |
43
|
|
|
|
|
|
|
#----------------------- |
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
|
|
10
|
if( $@ ) { |
46
|
0
|
|
|
|
|
0
|
die "Parse error: $@"; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#---------------------------- |
50
|
|
|
|
|
|
|
# Dump out the configuration. |
51
|
|
|
|
|
|
|
#---------------------------- |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
70
|
print Dumper( $c->configure ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#---------------------------- |
56
|
|
|
|
|
|
|
# Print all the enumerations. |
57
|
|
|
|
|
|
|
#---------------------------- |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
473
|
my @enums = $c->enum_names; |
60
|
1
|
|
|
|
|
7
|
print "\nenums: @enums\n\n"; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
63
|
|
|
|
|
|
|
# Print all structs, sorted by size; skip all structs smaller than 50 bytes. |
64
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
3
|
print "large structs:\n\n"; |
67
|
|
|
|
|
|
|
|
68
|
8
|
|
|
|
|
28
|
my @structs = sort { $c->sizeof( $b ) <=> $c->sizeof( $a ) } |
69
|
1
|
|
|
|
|
23
|
grep { $c->sizeof( $_ ) >= 50 } |
|
19
|
|
|
|
|
108
|
|
70
|
|
|
|
|
|
|
$c->struct_names; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
5
|
for my $struct ( @structs ) { |
73
|
6
|
|
|
|
|
28
|
printf "struct %-20s => %4d bytes\n", $struct, $c->sizeof( $struct ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
3
|
print "\n"; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#----------------------------------------------- |
79
|
|
|
|
|
|
|
# Dump the definition of the __socket_type enum |
80
|
|
|
|
|
|
|
#----------------------------------------------- |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
8
|
print Data::Dumper->Dump( [$c->enum('__socket_type')], ['__socket_type'] ); |