This repository has been archived on 2022-12-27. You can view files and clone it, but cannot push or open issues or pull requests.
compilateurMIPS/main.ml

25 lines
806 B
OCaml
Raw Normal View History

open Errors
2022-12-06 20:39:15 +01:00
let () =
2022-12-06 22:22:48 +01:00
if Array.length Sys.argv != 2
then (
Printf.eprintf "Usage: %s <file>\n" Sys.argv.(0);
exit 1);
2022-12-06 20:39:15 +01:00
let f = open_in Sys.argv.(1) in
let buf = Lexing.from_channel f in
try
let parsed = Parser.prog Lexer.token buf in
2022-12-06 22:22:48 +01:00
close_in f;
2022-12-10 14:57:14 +01:00
(* Test.debug_parser Stdlib.stderr parsed; *)
2022-12-06 20:39:15 +01:00
let ast = Semantics.analyze parsed in
(* Test.debug_semantics Stdlib.stderr ast; *)
2022-12-11 02:36:55 +01:00
let asm = Compiler.compile (Simplifier.simplify ast) in
2022-12-06 20:39:15 +01:00
Mips.emit Stdlib.stdout asm
with
| LexerError c ->
2022-12-08 19:54:57 +01:00
err (Printf.sprintf "Unrecognized char \"%c\"" c) (Lexing.lexeme_start_p buf)
2022-12-11 03:35:52 +01:00
| SyntaxError s -> err (Printf.sprintf "%s" s) (Lexing.lexeme_start_p buf)
2022-12-08 19:54:57 +01:00
| Parser.Error -> err "Syntax error" (Lexing.lexeme_start_p buf)
| SemanticsError (msg, pos) -> err msg pos
2022-12-06 22:22:48 +01:00
;;