Asm-C

 view release on metacpan or  search on metacpan

lib/Asm/C.pm  view on Meta::CPAN


3 L<extractCFieldSize|/extractCFieldSize> - Extract the size of a field in a structure in a C file

4 L<extractCFieldType|/extractCFieldType> - Extract the type of a field in a structure in a C file

5 L<extractCStructure|/extractCStructure> - Extract the details of a structure

6 L<extractCStructureFields|/extractCStructureFields> - Extract the names of the fields in a C structure

7 L<extractCStructureSize|/extractCStructureSize> - Extract the size of a C structure

8 L<extractMacroDefinitionFromCHeaderFile|/extractMacroDefinitionFromCHeaderFile> - Extract a macro definitions found in a C header file using gcc

9 L<extractMacroDefinitionsFromCHeaderFile|/extractMacroDefinitionsFromCHeaderFile> - Extract the macro definitions found in a C header file using gcc

=head1 Installation

This module is written in 100% Pure Perl and, thus, it is easy to read,
comprehend, use, modify and install via B<cpan>:

  sudo cpan install Asm::C

=head1 Author

L<philiprbrenan@gmail.com|mailto:philiprbrenan@gmail.com>

L<http://www.appaapps.com|http://www.appaapps.com>

=head1 Copyright

Copyright (c) 2016-2021 Philip R Brenan.

This module is free software. It may be used, redistributed and/or modified
under the same terms as Perl itself.

=cut



# Tests and documentation

sub test
 {my $p = __PACKAGE__;
  binmode($_, ":utf8") for *STDOUT, *STDERR;
  return if eval "eof(${p}::DATA)";
  my $s = eval "join('', <${p}::DATA>)";
  $@ and die $@;
  eval $s;
  $@ and die $@;
  1
 }

test unless caller;

1;
# podDocumentation
__DATA__
use Time::HiRes qw(time);
use Test::More;

my $localTest = ((caller(1))[0]//'Asm::C') eq "Asm::C";                         # Local testing mode

Test::More->builder->output("/dev/null") if $localTest;                         # Reduce number of confirmation messages during testing

if ($^O =~ m(bsd|linux)i)
  {if (confirmHasCommandLineCommand(q(gcc))
   &&  confirmHasCommandLineCommand(q(readelf)))
    {plan tests => 17
    }
  else
   {plan skip_all =>qq(gcc or readelf missing on: $^O);
   }
 }
else
 {plan skip_all =>qq(Not supported on: $^O);
 }

my $start = time;                                                               # Tests

if (1)                                                                          #TextractCField #TextractCStructureFields #TextractCStructureSize  #TextractCFieldLoc #TextractCFieldSize #TextractCFieldType
 {my $input = writeTempFile <<END;
struct S
 {int a;
  int b;
  int c;
 } s;
void main() {}
END

  is_deeply extractCStructure($input),                                          #TextractCStructure
{ S => bless({
      fields => {
        a => bless({ field => "a", loc => 0, size => 4, type => "int" }, "field"),
        b => bless({ field => "b", loc => 4, size => 4, type => "int" }, "field"),
        c => bless({ field => "c", loc => 8, size => 4, type => "int" }, "field"),
      },
      size => 12,
    }, "structure")};

  is_deeply extractCField($input, q(S), q(a)),
    bless({ field => "a", loc => 0, size => 4, type => "int" }, "field");

  is_deeply extractCField($input, q(S), q(b)),
    bless({ field => "b", loc => 4, size => 4, type => "int" }, "field");

  is_deeply extractCField($input, q(S), q(c)),
    bless({ field => "c", loc => 8, size => 4, type => "int" }, "field");

  is_deeply [extractCStructureFields($input, q(S))], [qw(a b c)];

  is_deeply extractCStructureSize($input, q(S)), 12;

  is_deeply extractCFieldLoc ($input, q(S), q(a)), 0;
  is_deeply extractCFieldLoc ($input, q(S), q(b)), 4;
  is_deeply extractCFieldLoc ($input, q(S), q(c)), 8;

  is_deeply extractCFieldSize($input, q(S), q(a)), 4;
  is_deeply extractCFieldSize($input, q(S), q(b)), 4;
  is_deeply extractCFieldSize($input, q(S), q(c)), 4;

  is_deeply extractCFieldType($input, q(S), q(a)), q(int);



( run in 2.175 seconds using v1.01-cache-2.11-cpan-5735350b133 )