Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fa0bc5d
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.merlin | ||
_build | ||
*.install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# ocaml-print-intf | ||
|
||
Pretty prints a compiled interface file into the corresponding human-readable | ||
OCaml signature. | ||
|
||
This is a convenient alternative to `ocamlc -i` which does this on source .ml | ||
files. | ||
|
||
## Example | ||
|
||
On this repository: | ||
|
||
``` | ||
$ dune build | ||
$ dune exec -- ocaml-print-intf ./_build/default/.ocaml_print_intf.eobjs/byte/dune__exe__Ocaml_print_intf.cmt | ||
val print_intf : string -> unit | ||
val version : unit -> string | ||
val usage : unit -> unit | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(executable | ||
(name ocaml_print_intf) | ||
(public_name ocaml-print-intf) | ||
(libraries compiler-libs.common dune-build-info)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(lang dune 2.0) | ||
(generate_opam_files true) | ||
(name ocaml-print-intf) | ||
|
||
(source (github avsm/ocaml-print-intf)) | ||
(license ISC) | ||
(authors "Anil Madhavapeddy") | ||
(maintainers "anil@recoil.org") | ||
|
||
(package | ||
(name ocaml-print-intf) | ||
(synopsis "Display human-readable OCaml interface from a compiled .cmi") | ||
(description "This tool parses a compiled .cmi interface file and outputs | ||
the corresponding textual .mli file. This can be useful to quickly generate | ||
a skeleton interface file to then annotate with comments or add abstraction.") | ||
(depends | ||
(ocaml (>= 4.03)) | ||
compiler-libs.common | ||
dune-build-info)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This file is generated by dune, edit dune-project instead | ||
opam-version: "2.0" | ||
synopsis: "Display human-readable OCaml interface from a compiled .cmi" | ||
description: """ | ||
This tool parses a compiled .cmi interface file and outputs | ||
the corresponding textual .mli file. This can be useful to quickly generate | ||
a skeleton interface file to then annotate with comments or add abstraction.""" | ||
maintainer: ["anil@recoil.org"] | ||
authors: ["Anil Madhavapeddy"] | ||
license: "ISC" | ||
homepage: "https://github.com/avsm/ocaml-print-intf" | ||
bug-reports: "https://github.com/avsm/ocaml-print-intf/issues" | ||
depends: [ | ||
"dune" {>= "2.0"} | ||
"ocaml" {>= "4.03"} | ||
"compiler-libs.common" | ||
"dune-build-info" | ||
] | ||
build: [ | ||
["dune" "subst"] {pinned} | ||
[ | ||
"dune" | ||
"build" | ||
"-p" | ||
name | ||
"-j" | ||
jobs | ||
"@install" | ||
"@runtest" {with-test} | ||
"@doc" {with-doc} | ||
] | ||
] | ||
dev-repo: "git+https://github.com/avsm/ocaml-print-intf.git" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
(* Copyright (c) 2020 Anil Madhavapeddy <anil@recoil.org> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*) | ||
|
||
open Format | ||
|
||
let print_intf f = | ||
let {Cmi_format.cmi_sign;_} = Cmi_format.read_cmi f in | ||
Printtyp.signature std_formatter cmi_sign; | ||
print_flush (); | ||
print_newline (); | ||
flush stdout | ||
|
||
let version () = | ||
match Build_info.V1.version () with | ||
| None -> "n/a" | ||
| Some v -> Build_info.V1.Version.to_string v | ||
|
||
let usage () = | ||
eprintf "%s <file>\n<file> can be a .cmi or .cmt or .cmti compiled with OCaml %s\n" | ||
Sys.argv.(0) Sys.ocaml_version | ||
|
||
let () = | ||
match Sys.argv with | ||
| [| _; "--version" |] -> print_endline (version ()) | ||
| [| _; file |] -> begin | ||
try print_intf file | ||
with Sys_error err -> prerr_endline err; exit 1 | ||
| Cmi_format.Error _ -> prerr_endline "Error: not a valid .cmi .cmt or .cmti file"; exit 1 | ||
end | ||
| _ -> usage (); exit 1 |