| 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 | ▶ | use Convert::Binary::C; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use File::Spec::Functions qw(rel2abs); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | my $base; | |||||||||||||||||||||||||||
| 22 | 1 | ▶ | -d "$_/include" and $base = rel2abs("$_/include") and last for qw( tests ../tests ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d "$_/include" and $base = rel2abs("$_/include")
MC/DC0%0/2
-d "$_/include" and $base = rel2abs("$_/include")
-d "$_/include"
$base = rel2abs("$_/include")
Truth table33%1/3
A and B
A= -d "$_/include"B= $base = rel2abs("$_/include")
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | defined $base or die <<MSG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | my $cfg = require "$base/config.pl"; | |||||||||||||||||||||||||||
| 33 | 1 | my $c = new Convert::Binary::C %$cfg; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | #------------------ | ||||||||||||||||||||||||||||
| 36 | # Parse the C file. | ||||||||||||||||||||||||||||
| 37 | #------------------ | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | eval { $c->parse_file( "$base/include.c" ) }; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | #----------------------- | ||||||||||||||||||||||||||||
| 42 | # Check for parse error. | ||||||||||||||||||||||||||||
| 43 | #----------------------- | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | die "Parse error: $@"; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | #---------------------------- | ||||||||||||||||||||||||||||
| 50 | # Dump out the configuration. | ||||||||||||||||||||||||||||
| 51 | #---------------------------- | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | print Dumper( $c->configure ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | #---------------------------- | ||||||||||||||||||||||||||||
| 56 | # Print all the enumerations. | ||||||||||||||||||||||||||||
| 57 | #---------------------------- | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | my @enums = $c->enum_names; | |||||||||||||||||||||||||||
| 60 | 1 | 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 | print "large structs:\n\n"; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 8 | my @structs = sort { $c->sizeof( $b ) <=> $c->sizeof( $a ) } | |||||||||||||||||||||||||||
| 69 | 1 | grep { $c->sizeof( $_ ) >= 50 } | |||||||||||||||||||||||||||
| 70 | $c->struct_names; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | for my $struct ( @structs ) { | |||||||||||||||||||||||||||
| 73 | 6 | printf "struct %-20s => %4d bytes\n", $struct, $c->sizeof( $struct ); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | print "\n"; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | #----------------------------------------------- | ||||||||||||||||||||||||||||
| 79 | # Dump the definition of the __socket_type enum | ||||||||||||||||||||||||||||
| 80 | #----------------------------------------------- | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | print Data::Dumper->Dump( [$c->enum('__socket_type')], ['__socket_type'] ); | |||||||||||||||||||||||||||