Reputation: 1747
I know ocamlc can compiler ocaml source file .ml and .mli
I am reading the compiler source code 4.07,in driver/pparse.ml,the function file_aux will use ocamlyacc to got the ast Parsetree.
in line 169:
File: d:\src\ocaml-4.07.0\driver\pparse.ml
169: let (ic, is_ast_file) = open_and_check_magic inputfile ast_magic in
will check is the file is a ast file.I want to know what file will be the astfile?
I can write this code to cheak it:
Printf.printf "%b" is_ast_file
but when i use both .ml and .mli file,all got false.Is the astfile means .cmt file?
I think the astfile here is the .cmt file.I can use ocamlc option -bin-annot to got a .cmt file.Is it the .cmt file?but I can't use ocamlc to compiler a .cmt file.Thanks!
Upvotes: 1
Views: 74
Reputation: 6144
It is not the .cmt
file. A .cmt
file contains more information than just the AST.
This AST magic is used for preprocessors that allow to write alternative syntaxes to the language. See the description of the -pp
option in the OCaml manual. See Camlp4 for an example of use of this functionality.
Note that the file produced by the call of -pp
will only be a temporary one (unless there is an error).
To answer the question in your title, the file extensions the ocamlc
compiler can read are .ml
, .mli
, .cmo
(compiled module), .cmi
(compiled interface) and .cma
(compiled library).
Upvotes: 1