annotate ppc/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
mike@0 1 (* ppc/main.ml *)
mike@0 2 (* Copyright (c) 2017 J. M. Spivey *)
mike@0 3
mike@0 4 open Print
mike@0 5 open Mach
mike@0 6 open Source
mike@0 7
mike@0 8 let debug = ref 0
mike@0 9
mike@0 10 let usage = "Usage: ppc [-b] [-d n] [-O] file.p"
mike@0 11
mike@0 12 let spec =
mike@0 13 Arg.align
mike@0 14 ["-b", Arg.Unit (function () -> Kgen.boundchk := true),
mike@0 15 " enable bound checks";
mike@0 16 "-d", Arg.Int (function x -> debug := x), "n set debug level";
mike@0 17 "-O", Arg.Set Kgen.optflag, " enable peephole optimiser"]
mike@0 18
mike@0 19 let main () =
mike@0 20 let fns = ref [] in
mike@0 21 Arg.parse spec (function s -> fns := !fns @ [s]) usage;
mike@0 22 if List.length !fns <> 1 then begin
mike@0 23 fprintf stderr "$\n" [fStr usage]; exit 2
mike@0 24 end;
mike@0 25 let in_file = List.hd !fns in
mike@0 26 let in_chan = open_in in_file in
mike@0 27 let lexbuf = Lexing.from_channel in_chan in
mike@0 28 Source.init in_file in_chan;
mike@0 29 Peepopt.debug := !debug;
mike@0 30 ignore (Parsing.set_trace (!debug > 2));
mike@0 31
mike@0 32 let prog =
mike@0 33 try Parser.program Lexer.token lexbuf with
mike@0 34 Parsing.Parse_error ->
mike@0 35 let tok = Lexing.lexeme lexbuf in
mike@0 36 Source.err_message "syntax error at token '$'" [fStr tok] !Lexer.lineno;
mike@0 37 exit 1 in
mike@0 38
mike@0 39 if !debug > 0 then Tree.print_tree stdout "" prog;
mike@0 40
mike@0 41 begin try Check.annotate prog with
mike@0 42 Check.Sem_error (fmt, args, ln) ->
mike@0 43 Source.err_message fmt args ln;
mike@0 44 exit 1
mike@0 45 end;
mike@0 46
mike@0 47 printf "MODULE Main 0 0\n" [];
mike@0 48 printf "IMPORT Lib 0\n" [];
mike@0 49 printf "ENDHDR\n\n" [];
mike@0 50 Kgen.translate prog;
mike@0 51 printf "! End\n" [];
mike@0 52 exit 0
mike@0 53
mike@0 54 let ppc = main ()