annotate lab4/main.ml @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 (* lab4/main.ml *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 (* Copyright (c) 2017 J. M. Spivey *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 open Print
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 open Mach
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 open Source
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 let debug = ref 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 let usage = "Usage: ppc0 [-v] [-t] file"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 let spec =
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 Arg.align
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 ["-b", Arg.Unit (fun () -> Tgen.boundchk := true),
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 " enable bound checks";
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 "-d", Arg.Int (function x -> debug := x), "n set debug level";
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 "-O", Arg.Unit (fun () -> Tgen.optlevel := 1),
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 " enable optimiser (simplifier, jump opt)";
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 "-O2", Arg.Unit (fun () -> Tgen.optlevel := 2),
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 " more optimisation (common subexpressions)";
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 "-noregvars", Arg.Unit (fun () -> Check.regvars := false),
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 " disable register variables"]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 let main () =
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 let fns = ref [] in
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 Arg.parse spec (function s -> fns := !fns @ [s]) usage;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 if List.length !fns <> 1 then begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 fprintf stderr "$\n" [fStr usage]; exit 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 let in_file = List.hd !fns in
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 let in_chan = open_in in_file in
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 let lexbuf = Lexing.from_channel in_chan in
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 Source.init in_file in_chan;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 Tgen.debug := !debug;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 Tran.debug := !debug;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 ignore (Parsing.set_trace (!debug > 2));
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 (* Parse the program *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 let prog =
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 try Parser.program Lexer.token lexbuf with
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 Parsing.Parse_error ->
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 let tok = Lexing.lexeme lexbuf in
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 Source.err_message "syntax error at token '$'" [fStr tok] !Lexer.lineno;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 exit 1 in
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 if !debug > 2 then begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 printf "$Abstract syntax tree:\n" [fStr Mach.comment];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 Tree.print_tree stdout Mach.comment prog;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 printf "\n" []
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 (* Semantic analysis *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 begin try Check.annotate prog with
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 Check.Sem_error (fmt, args, ln) ->
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 Source.err_message fmt args ln;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 exit 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 (* Translate the program *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 Tgen.translate prog;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 exit 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 let ppc = main ()