From 889f7abc6f2c2dde2523f639e671ea4a2a804165 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Wed, 17 Oct 2018 02:24:32 -0700 Subject: [PATCH] [sledge] Dump program to file between frontend and backend Summary: `sledge -c foo.bc` generates a binary file `foo.bc.llair` which can be analyzed with `sledge foo.bc.llair`, and converted to textual form with `sledge -c foo.bc.llair -o foo.llair`. Binary files are not compatible between debug and release builds. Reviewed By: mbouaziz Differential Revision: D10389473 fbshipit-source-id: dfcabf33b --- sledge/src/import/import.ml | 1 + sledge/src/import/import.mli | 1 + sledge/src/sledge.ml | 13 +++++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sledge/src/import/import.ml b/sledge/src/import/import.ml index eb618de8b..757ce898f 100644 --- a/sledge/src/import/import.ml +++ b/sledge/src/import/import.ml @@ -22,6 +22,7 @@ include ( (* prematurely deprecated, remove and use Stdlib instead *) and module Filename := Base.Filename and module Format := Base.Format + and module Marshal := Base.Marshal and module Scanf := Base.Scanf and type ('ok, 'err) result := ('ok, 'err) Base.result) [@warning "-3"] diff --git a/sledge/src/import/import.mli b/sledge/src/import/import.mli index 955dac69a..9364f64c9 100644 --- a/sledge/src/import/import.mli +++ b/sledge/src/import/import.mli @@ -22,6 +22,7 @@ include module type of ( (* prematurely deprecated, remove and use Stdlib instead *) and module Filename := Base.Filename and module Format := Base.Format + and module Marshal := Base.Marshal and module Scanf := Base.Scanf and type ('ok, 'err) result := ('ok, 'err) Base.result) [@warning "-3"] diff --git a/sledge/src/sledge.ml b/sledge/src/sledge.ml index 5d717ca6b..9b412739e 100644 --- a/sledge/src/sledge.ml +++ b/sledge/src/sledge.ml @@ -9,8 +9,17 @@ let main ~input ~output ~compile_only = try - let program = Frontend.translate input in - Trace.flush () ; + let program = + if String.is_suffix input ~suffix:".llair" then + In_channel.with_file input ~f:(fun ic -> + (Marshal.from_channel ic : Llair.t) ) + else + let program = Frontend.translate input in + Trace.flush () ; + Out_channel.with_file (input ^ ".llair") ~f:(fun oc -> + Marshal.to_channel oc program [Marshal.Closures] ) ; + program + in Option.iter output ~f:(function | "-" -> Format.printf "%a@." Llair.pp program | filename ->