This repository has been archived by the owner on Nov 17, 2017. It is now read-only.
forked from esumii/min-caml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ml
45 lines (40 loc) · 1.54 KB
/
main.ml
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
let limit = ref 1000
let rec iter n e = (* 最適化処理をくりかえす (caml2html: main_iter) *)
Format.eprintf "iteration %d@." n;
if n = 0 then e else
let e' = Elim.f (ConstFold.f (Inline.f (Assoc.f (Beta.f e)))) in
if e = e' then e else
iter (n - 1) e'
let lexbuf outchan l = (* バッファをコンパイルしてチャンネルへ出力する (caml2html: main_lexbuf) *)
Id.counter := 0;
Typing.extenv := M.empty;
Emit.f outchan
(RegAlloc.f
(Simm.f
(Virtual.f
(Closure.f
(iter !limit
(Alpha.f
(KNormal.f
(Typing.f
(Parser.exp Lexer.token l)))))))))
let string s = lexbuf stdout (Lexing.from_string s) (* 文字列をコンパイルして標準出力に表示する (caml2html: main_string) *)
let file f = (* ファイルをコンパイルしてファイルに出力する (caml2html: main_file) *)
let inchan = open_in (f ^ ".ml") in
let outchan = open_out (f ^ ".s") in
try
lexbuf outchan (Lexing.from_channel inchan);
close_in inchan;
close_out outchan;
with e -> (close_in inchan; close_out outchan; raise e)
let () = (* ここからコンパイラの実行が開始される (caml2html: main_entry) *)
let files = ref [] in
Arg.parse
[("-inline", Arg.Int(fun i -> Inline.threshold := i), "maximum size of functions inlined");
("-iter", Arg.Int(fun i -> limit := i), "maximum number of optimizations iterated")]
(fun s -> files := !files @ [s])
("Mitou Min-Caml Compiler (C) Eijiro Sumii\n" ^
Printf.sprintf "usage: %s [-inline m] [-iter n] ...filenames without \".ml\"..." Sys.argv.(0));
List.iter
(fun f -> ignore (file f))
!files