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
(** Copyright 2025-2026, Georgiy Belyanin, Ignat Sergeev *)

(** SPDX-License-Identifier: LGPL-3.0-or-later *)

open DOOML
module Map = Base.Map.Poly

let failf fmt = Format.kasprintf failwith fmt

let parse input =
  let code = In_channel.with_open_text input In_channel.input_all in
  match Fe.parse code with
  | Error msg -> Error msg
  | Ok ast_list ->
    Ok
      (ast_list
       |> Cc.cc
       (*|> fun asts ->
   Format.printf
     "CC: %a\n\n"
     (Format.pp_print_list ~pp_sep:Format.pp_print_newline Ast.pp_top_level)
     asts;
   asts*)
       |> Ll.ll
       (*|> fun asts ->
   Format.printf
     "LL: %a\n\n"
     (Format.pp_print_list ~pp_sep:Format.pp_print_newline Ast.pp_top_level)
     asts;
   asts*)
       (*Cc.cc |> Ll.ll *)
       |> Anf.anf
          (*|> fun asts ->
   Format.printf
     "ANF %a\n\n"
     (Format.pp_print_list ~pp_sep:Format.pp_print_newline Anf.pp_decl)
     asts;
   asts
          *))
;;

let () =
  match parse Sys.argv.(1) with
  | Error msg -> failf "%s" msg
  | Ok anf_list -> Format.printf "%a\n" Riscv.pp_code (Riscv.riscv anf_list)
;;