caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Missing the cmi files required to use toplevellib.cma
@ 2009-10-01 12:09 rixed
  2009-10-01 13:54 ` [Caml-list] " Richard Jones
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: rixed @ 2009-10-01 12:09 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 933 bytes --]

While learning OCaml, I just coded a small program that dumps
the full content of a cmi file. I find this more usefull than
ocamlbrowser or to use the toplevel to have a small command line
driven dumper, and it was also a good pretext to have a look
under the cover.

The problem is : most of the usefull types and functions are
installed in the toplevellib.cma but I can't use this without
the proper cmi files (I need config.cmi for cmi_magic_number,
printtyp.cmi and typemod.cmi for printing signatures, but
env.cmi would be nice to have as well for read_signature).

Of course I can use those left in ocaml-3.11.1 directory after
compilation, but having them installed would help the creation
and distribution of such tools.

But maybe there is an other way to use toplevellib.cma that I'm
unaware of ? If not, then why not install these cmi files along
with toplevellib ?

Anyway, if anyone is interrested the tool is attached.

[-- Attachment #2: cmidump.ml --]
[-- Type: text/plain, Size: 2490 bytes --]

open Format

let want_magic = ref false
let want_crc = ref false
let want_name = ref false
let want_flags = ref false
let want_sig = ref false
let simplify_sig = ref false

(* Stolen from env.ml - would be great of exported *)
type flags = Rectypes

let print_flags flags =
	let flag_name = function
	| Rectypes -> "Rectypes" in
	printf "@[Flags@ =@ [@[" ;
	List.iter (fun f -> printf "%s@ " (flag_name f)) flags ;
	printf "]@]@]@."

let print_magic m =
	printf "@[Cmi magic number@ =@ %s (%s)@]@."
		m (if m = Config.cmi_magic_number then "OK" else "Wrong!")

let print_name name = printf "@[Name@ =@ %s@]@." name

let print_crcs crcs =
	let print_crc (modname, crc) = printf "@[%s [%s]@]@ " modname (String.escaped crc) in
	printf "@[CRCs = @[" ; List.iter print_crc crcs ; printf "@]@]@."

let print_sig sign =
	fprintf std_formatter "@[Signature@ =@ @[<1>%a@]@]@."
		Printtyp.signature
		(if !simplify_sig then (Typemod.simplify_signature sign) else sign)

(* Reading persistent structures from .cmi files - Stolen from typing/env.ml
 * We'd rather use this instead of Env.read_signature so that we get all
 * components of the cmi files, not just signature *)

let process_cmi_file filename =
	let show_sig = !want_sig ||
		(not !want_magic && not !want_crc && not !want_name && not !want_flags) in
	let ic = open_in_bin filename in
	let magic_len = String.length (Config.cmi_magic_number) in
	let buffer = String.create magic_len in
	really_input ic buffer 0 magic_len ;
	let (name, sign) = input_value ic in
	let crcs = input_value ic in
	let flags = input_value ic in
	close_in ic ;
	if !want_magic then print_magic buffer ;
	if !want_name  then print_name name ;
	if !want_crc   then print_crcs crcs ;
	if !want_flags then print_flags flags ;
	if show_sig    then print_sig sign

let process_file fname =
	if Filename.check_suffix fname "cmi" then process_cmi_file fname
	else printf "Don't know what to do with file '%s'\n" fname

let _ =
	Arg.parse [
		"-magic",    Arg.Set want_magic,   " Display cmi magic number" ;
		"-name",     Arg.Set want_name,    " Display module name" ;
		"-crc",      Arg.Set want_crc,     " Display CRC" ;
		"-flags",    Arg.Set want_flags,   " Display flags" ;
		"-sig",      Arg.Set want_sig,     " Display signature" ;
		"-simplify", Arg.Set simplify_sig, " Do not simplify the signature" ]
		process_file
		"Syntax :
	cmidump [options] files...
Shows the content of cmi files.
If no option is given, shows only the signature.
Possible options :
"

[-- Attachment #3: Makefile --]
[-- Type: text/plain, Size: 690 bytes --]

OCAMLC   = ocamlfind ocamlc
OCAMLDEP = ocamlfind ocamldep
OCAMLFLAGS    = -w Ae -g

EXTCMI = env.cmi printtyp.cmi typemod.cmi config.cmi

.PHONY: all clean install uninstall

all: checkcmi cmidump

cmidump: cmidump.cmo
	$(OCAMLC) -o $@ /usr/local/lib/ocaml/toplevellib.cma $(OCAMLFLAGS) $^

checkcmi:
	@for i in $(EXTCMI) ; do if ! test -f $$i ; then echo "Ocamlc will fail if it cant access $$i" ; fi ; done

# Common rules
.SUFFIXES: .ml .mli .cmo .cmi .cmx

.ml.cmo:
	$(OCAMLC) $(OCAMLFLAGS) -I /usr/local/lib/ocaml -c $<

.mli.cmi:
	$(OCAMLC) $(OCAMLFLAGS) -c $<

# Clean up
clean:
	rm -f cmidump.cmi *.cmo *.s

# Dependencies
.depend: *.ml
	$(OCAMLDEP) *.ml > .depend

include .depend

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Missing the cmi files required to use toplevellib.cma
  2009-10-01 12:09 Missing the cmi files required to use toplevellib.cma rixed
@ 2009-10-01 13:54 ` Richard Jones
  2009-10-01 16:03   ` rixed
  2009-10-01 14:02 ` Mehdi Dogguy
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Richard Jones @ 2009-10-01 13:54 UTC (permalink / raw)
  To: rixed; +Cc: caml-list

On Thu, Oct 01, 2009 at 02:09:46PM +0200, rixed@happyleptic.org wrote:
> While learning OCaml, I just coded a small program that dumps
> the full content of a cmi file. I find this more usefull than
> ocamlbrowser or to use the toplevel to have a small command line
> driven dumper, and it was also a good pretext to have a look
> under the cover.

You might also want to look at 'cmigrep'.

> The problem is : most of the usefull types and functions are
> installed in the toplevellib.cma but I can't use this without
> the proper cmi files (I need config.cmi for cmi_magic_number,
> printtyp.cmi and typemod.cmi for printing signatures, but
> env.cmi would be nice to have as well for read_signature).
> 
> Of course I can use those left in ocaml-3.11.1 directory after
> compilation, but having them installed would help the creation
> and distribution of such tools.

This is really a packaging issue.  I believe that Debian already ship
the compiled sources to OCaml as a separate package, mostly for this
reason.  (Fedora doesn't, but probably we should follow Debian in this
respect).

Rich.

-- 
Richard Jones
Red Hat


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Missing the cmi files required to use toplevellib.cma
  2009-10-01 12:09 Missing the cmi files required to use toplevellib.cma rixed
  2009-10-01 13:54 ` [Caml-list] " Richard Jones
@ 2009-10-01 14:02 ` Mehdi Dogguy
  2009-10-01 16:06   ` rixed
  2009-10-01 14:07 ` Gerd Stolpmann
  2009-10-01 15:35 ` David Allsopp
  3 siblings, 1 reply; 7+ messages in thread
From: Mehdi Dogguy @ 2009-10-01 14:02 UTC (permalink / raw)
  To: rixed; +Cc: caml-list

rixed@happyleptic.org wrote:
> While learning OCaml, I just coded a small program that dumps
> the full content of a cmi file.

Have you tried ocamlobjinfo? We install it along with OCaml in Debian.
(tools/objinfo.ml in OCaml source code)

Cheers,

-- 
Mehdi Dogguy مهدي الدڤي
http://www.pps.jussieu.fr/~dogguy
Tel.: (+33).1.44.27.28.38


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Missing the cmi files required to use toplevellib.cma
  2009-10-01 12:09 Missing the cmi files required to use toplevellib.cma rixed
  2009-10-01 13:54 ` [Caml-list] " Richard Jones
  2009-10-01 14:02 ` Mehdi Dogguy
@ 2009-10-01 14:07 ` Gerd Stolpmann
  2009-10-01 15:35 ` David Allsopp
  3 siblings, 0 replies; 7+ messages in thread
From: Gerd Stolpmann @ 2009-10-01 14:07 UTC (permalink / raw)
  To: rixed; +Cc: caml-list

GODI installs the required cmi's. One can easily compile your utility
with

ocamlc -o cmidump -I /opt/godi-3.11/lib/ocaml/compiler-lib/
       toplevellib.cma cmidump.ml 

For docs.camlcity.org I converted all cmi's to a readable format by a
little script that does apply "ocamlc -i" on the program "include M"
where M is the module to print. That gives finally a nice view on all
information, like in

http://docs.camlcity.org/docs/godipkg/3.11/godi-lwt/lib/ocaml/pkg-lib/lwt/lwt.cmi_pretty

You can switch between the pretty-printed cmi, the mli, and the source
files. Ideal for exploring software.

Gerd

Am Donnerstag, den 01.10.2009, 14:09 +0200 schrieb
rixed@happyleptic.org:
> While learning OCaml, I just coded a small program that dumps
> the full content of a cmi file. I find this more usefull than
> ocamlbrowser or to use the toplevel to have a small command line
> driven dumper, and it was also a good pretext to have a look
> under the cover.
> 
> The problem is : most of the usefull types and functions are
> installed in the toplevellib.cma but I can't use this without
> the proper cmi files (I need config.cmi for cmi_magic_number,
> printtyp.cmi and typemod.cmi for printing signatures, but
> env.cmi would be nice to have as well for read_signature).
> 
> Of course I can use those left in ocaml-3.11.1 directory after
> compilation, but having them installed would help the creation
> and distribution of such tools.
> 
> But maybe there is an other way to use toplevellib.cma that I'm
> unaware of ? If not, then why not install these cmi files along
> with toplevellib ?
> 
> Anyway, if anyone is interrested the tool is attached.
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
-- 
------------------------------------------------------------
Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [Caml-list] Missing the cmi files required to use toplevellib.cma
  2009-10-01 12:09 Missing the cmi files required to use toplevellib.cma rixed
                   ` (2 preceding siblings ...)
  2009-10-01 14:07 ` Gerd Stolpmann
@ 2009-10-01 15:35 ` David Allsopp
  3 siblings, 0 replies; 7+ messages in thread
From: David Allsopp @ 2009-10-01 15:35 UTC (permalink / raw)
  To: rixed, caml-list

> The problem is : most of the usefull types and functions are installed
> in the toplevellib.cma but I can't use this without the proper cmi
> files (I need config.cmi for cmi_magic_number, printtyp.cmi and
> typemod.cmi for printing signatures, but env.cmi would be nice to have
> as well for read_signature).

You could add them to http://caml.inria.fr/mantis/view.php?id=4653 ... but
as that was requested for 3.11.0 and didn't make it to 3.11.1, I wouldn't
hold your breath!


David


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Missing the cmi files required to use toplevellib.cma
  2009-10-01 13:54 ` [Caml-list] " Richard Jones
@ 2009-10-01 16:03   ` rixed
  0 siblings, 0 replies; 7+ messages in thread
From: rixed @ 2009-10-01 16:03 UTC (permalink / raw)
  To: caml-list

> You might also want to look at 'cmigrep'.

I did not know this tool. Looks very usefull !

> This is really a packaging issue.  I believe that Debian already ship
> the compiled sources to OCaml as a separate package, mostly for this
> reason.

Ok ; I installed ocaml with inria's Makefile which does not install
them. Apparently, from cmigrep Makefile, it seams that godi have them
installed as well. So they are more commonly installed than I though and
I have no reason to worries any more. 

Thank you !


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Missing the cmi files required to use toplevellib.cma
  2009-10-01 14:02 ` Mehdi Dogguy
@ 2009-10-01 16:06   ` rixed
  0 siblings, 0 replies; 7+ messages in thread
From: rixed @ 2009-10-01 16:06 UTC (permalink / raw)
  To: caml-list

> Have you tried ocamlobjinfo? We install it along with OCaml in Debian.
> (tools/objinfo.ml in OCaml source code)

I saw it once, then forget completely about it. I'm going to
have a look, thank you !


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-10-01 16:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-01 12:09 Missing the cmi files required to use toplevellib.cma rixed
2009-10-01 13:54 ` [Caml-list] " Richard Jones
2009-10-01 16:03   ` rixed
2009-10-01 14:02 ` Mehdi Dogguy
2009-10-01 16:06   ` rixed
2009-10-01 14:07 ` Gerd Stolpmann
2009-10-01 15:35 ` David Allsopp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).