Repository navigation
Expand file tree
/
Copy pathmain.ml
More file actions
129 lines (114 loc) · 5.21 KB
/
Copy pathmain.ml
File metadata and controls
129 lines (114 loc) · 5.21 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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 rec iter_nonrec n e = (* 非再帰関数を無条件に展開 *)
Format.eprintf "iteration_norec %d@." n;
if n = 0 then e else
let e'=Elim.f (ConstFold.f (Inline_nonrec.f (Assoc.f (Beta.f e))))
in
if e = e' then e else
iter_nonrec (n - 1) e'
let lexbuf outchan oc_childe outchan2 outchan3 outchan4 l glb_l= (* バッファをコンパイルしてチャンネルへ出力する (caml2html: main_lexbuf) *)
Id.counter := 0;
Typing.extenv := M.empty;
Emit.f outchan
oc_childe
(RegAlloc.f
(Multosll.f
(Simm.f
(Virtual.f
(Emit_closure.f
outchan4
(Closure.f
(HpAlloc.f
(Emit_knormal.f
outchan3
(iter !limit
(iter_nonrec !limit
(Parallelize.f
(Emit_knormal.f
outchan3
(Unique_constdef.f
(For_check.f
(Assoc.f
(Alpha.f
(KNormal.f
(Emit_syntax.f
outchan2
(Typing.f
(Joinglb.f
(Parser.exp Lexer.token l)
(Parser.exp Lexer.token glb_l)))))))))))))))))))))
let string s glbchan = lexbuf stdout stdout stdout stdout stdout (Lexing.from_string s) (Lexing.from_channel glbchan) (* 文字列をコンパイルして標準出力に表示する (caml2html: main_string) *)
let file f = (* ファイルをコンパイルしてファイルに出力する (caml2html: main_file) *)
let catin = open_in (f ^ ".ml") in
let catout = open_out (f ^ ".mlo") in
let libin = open_in ("./mylib.ml") in
(let rec lib_sub () =
output_char catout (input_char libin);
lib_sub ()
in
(try lib_sub () with End_of_file -> ()));
(let rec cat_sub () =
output_char catout (input_char catin);
cat_sub ()
in
(try cat_sub () with End_of_file -> close_in catin; close_out catout));
let inchan = open_in (f ^ ".mlo") in
let glbchan = open_in ("globals.ml") in
let outchan = open_out (f ^ ".s") in
let oc_child = open_out (f^"child.s") in
let outchan2 = open_out (f ^ "_syn.txt") in
let outchan3 = open_out (f^"_k1.txt") in
let outchan4 = open_out (f^"_closure.txt") in
try
lexbuf outchan oc_child outchan2 outchan3 outchan4 (Lexing.from_channel inchan) (Lexing.from_channel glbchan);
close_in inchan;
close_out outchan;
close_out oc_child;
close_out outchan2;
close_out outchan3;
close_out outchan4;
with
|Typing.Error (t1,t2,pos)-> close_in inchan;
close_out outchan;
close_out outchan2;
close_out outchan3;
close_out outchan4;
let line = pos.Syntax.line in
let charnum= pos.Syntax.characters in
Printf.printf "line %d, from character %d~\n" line charnum;
Printf.printf "this expression has type\n";
Emit_syntax.print_type stdout t2;
Printf.printf "\nbut an expression was expected of type\n";
Emit_syntax.print_type stdout t1;
|Typing.Occur (t1,t2,pos)-> close_in inchan;
close_out outchan;
close_out outchan2;
close_out outchan3;
close_out outchan4;
let line = pos.Syntax.line in
let charnum= pos.Syntax.characters in
Printf.printf "line %d, from character %d~\n" line charnum;
Printf.printf "this expression has type\n";
Emit_syntax.print_type stdout t2;
Printf.printf "\nbut an expression was expected of type\n";
Emit_syntax.print_type stdout t1;
Printf.printf "\n this is occurcheck error"
|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 (*filesにあるファイルを先頭からコンパイル*)