File: ocamlsize

package info (click to toggle)
ocaml 5.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,384 kB
  • sloc: ml: 370,196; ansic: 52,820; sh: 27,419; asm: 5,462; makefile: 3,684; python: 974; awk: 278; javascript: 273; perl: 59; fortran: 21; cs: 9
file content (79 lines) | stat: -rwxr-xr-x 2,869 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl

#**************************************************************************
#*                                                                        *
#*                                 OCaml                                  *
#*                                                                        *
#*             Xavier Leroy, projet Cristal, INRIA Rocquencourt           *
#*                                                                        *
#*   Copyright 2002 Institut National de Recherche en Informatique et     *
#*     en Automatique.                                                    *
#*                                                                        *
#*   All rights reserved.  This file is distributed under the terms of    *
#*   the GNU Lesser General Public License version 2.1, with the          *
#*   special exception on linking described in the file LICENSE.          *
#*                                                                        *
#**************************************************************************

foreach $f (@ARGV) {
    open(FILE, $f) || die("Cannot open $f");
    read(FILE, $header, 2);
    if ($header eq '#!') {
      $path = <FILE>;
      if ($path = '/bin/sh') {
        # exec form of the shebang header
        $path = <FILE>;
        if ($path =~ s/^exec '(.*)' "\$0" "\$@\"$/$1/ > 0) {
          $path =~ s/'\\''/'/g;
        } else {
          undef $path;
        }
      }
    };
    seek(FILE, -16, 2);
    $num_sections = &read_int();
    read(FILE, $magic, 12);
    seek(FILE, -16 - 8 * $num_sections, 2);
    @secname = ();
    @seclength = ();
    %length = ();
    for ($i = 0; $i < $num_sections; $i++) {
        read(FILE, $sec, 4);
        $secname[$i] = $sec;
        $seclength[$i] = &read_int();
        $length{$sec} = $seclength[$i];
    }
    print $f, ":\n" if ($#ARGV > 0);
    if (not defined $path) {
      $path =
          $length{'RNTM'} > 0 ?
              substr(&read_section('RNTM'), 0, -1) :
              "(custom runtime)";
    };
    printf ("\tcode: %-7d data: %-7d symbols: %-7d debug: %-7d\n",
            $length{'CODE'}, $length{'DATA'},
            $length{'SYMB'}, $length{'DBUG'});
    printf ("\tmagic number: %s  runtime system: %s\n",
            $magic, $path);
    close(FILE);
}

sub read_int {
    read(FILE, $buff, 4) == 4 || die("Truncated bytecode file $f");
    @int = unpack("C4", $buff);
    return ($int[0] << 24) + ($int[1] << 16) + ($int[2] << 8) + $int[3];
}

sub read_section {
    local ($sec) = @_;
    local ($i, $ofs, $data);
    for ($i = $num_sections - 1; $i >= 0; $i--) {
        $ofs += $seclength[$i];
        if ($secname[$i] eq $sec) {
            seek(FILE, -16 - 8 * $num_sections - $ofs, 2);
            read(FILE, $data, $seclength[$i]);
            return $data;
        }
    }
    return '';
}