-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgiraph.ml
36 lines (32 loc) · 1.32 KB
/
giraph.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
(* Authors:
Daniel Benett deb2174
Seth Benjamin sjb2190
Jennifer Bi jb3495
Jessie Liu jll2219
*)
(* Top-level of the Giraph compiler: scan & parse the input,
check the resulting AST and generate SAST, generate LLVM IR,
and dump the module *)
module StringMap = Map.Make(String)
type action = Ast | LLVM_IR | Compile
let _ =
let action = ref Compile in
let set_action a () = action := a in
let speclist = [
("-a", Arg.Unit (set_action Ast), "Print the SAST");
("-l", Arg.Unit (set_action LLVM_IR), "Print the generated LLVM IR");
("-c", Arg.Unit (set_action Compile),
"Check and print the generated LLVM IR (default)");
] in
let usage_msg = "usage: ./giraph.native [-a|-l|-c] [file.gir]" in
let channel = ref stdin in
Arg.parse speclist (fun filename -> channel := open_in filename) usage_msg;
let lexbuf = Lexing.from_channel !channel in
let ast = Parser.program Scanner.token lexbuf in
let sast = Semant.check ast in
match !action with
Ast -> (*print_string (Ast.string_of_program ast)*) print_string (Sast.string_of_sprogram sast)
| LLVM_IR -> print_string (Llvm.string_of_llmodule (Codegen.translate sast))
| Compile -> let m = Codegen.translate sast in
Llvm_analysis.assert_valid_module m;
print_string (Llvm.string_of_llmodule m)