Skip to content

Commit b19af03

Browse files
authored
Asmgen changes for Flambda 2 (#105)
1 parent af63498 commit b19af03

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

backend/asmgen.ml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,9 @@ let compile_unit ~output_prefix ~asm_filename ~keep_asm ~obj_filename gen =
203203
if create_asm && not keep_asm then remove_file asm_filename
204204
)
205205

206-
let end_gen_implementation ?toplevel ~ppf_dump
207-
(clambda : Clambda.with_constants) =
206+
let end_gen_implementation0 ?toplevel ~ppf_dump make_cmm =
208207
emit_begin_assembly ();
209-
clambda
210-
++ Profile.record "cmm" Cmmgen.compunit
208+
make_cmm ()
211209
++ Profile.record "compile_phrases" (List.iter (compile_phrase ~ppf_dump))
212210
++ (fun () -> ());
213211
(match toplevel with None -> () | Some f -> compile_genfuns ~ppf_dump f);
@@ -224,6 +222,10 @@ let end_gen_implementation ?toplevel ~ppf_dump
224222
!Translmod.primitive_declarations));
225223
emit_end_assembly ()
226224

225+
let end_gen_implementation ?toplevel ~ppf_dump clambda =
226+
end_gen_implementation0 ?toplevel ~ppf_dump (fun () ->
227+
Profile.record "cmm" Cmmgen.compunit clambda)
228+
227229
type middle_end =
228230
backend:(module Backend_intf.S)
229231
-> filename:string
@@ -249,6 +251,32 @@ let compile_implementation ?toplevel ~backend ~filename ~prefixname ~middle_end
249251
in
250252
end_gen_implementation ?toplevel ~ppf_dump clambda_with_constants)
251253

254+
type middle_end_flambda2 =
255+
ppf_dump:Format.formatter
256+
-> prefixname:string
257+
-> backend:(module Flambda2__Flambda_backend_intf.S)
258+
-> filename:string
259+
-> module_ident:Ident.t
260+
-> module_block_size_in_words:int
261+
-> module_initializer:Lambda.lambda
262+
-> Flambda2__Flambda_middle_end.middle_end_result
263+
264+
let compile_implementation_flambda2 ?toplevel ~backend ~filename ~prefixname
265+
~size:module_block_size_in_words ~module_ident ~module_initializer
266+
~(middle_end : middle_end_flambda2) ~flambda2_to_cmm ~ppf_dump
267+
~required_globals () =
268+
compile_unit ~output_prefix:prefixname
269+
~asm_filename:(asm_filename prefixname) ~keep_asm:!keep_asm_file
270+
~obj_filename:(prefixname ^ ext_obj)
271+
(fun () ->
272+
Ident.Set.iter Compilenv.require_global required_globals;
273+
let middle_end_result =
274+
middle_end ~backend ~module_block_size_in_words ~filename ~prefixname
275+
~ppf_dump ~module_ident ~module_initializer
276+
in
277+
let cmm_phrases = flambda2_to_cmm middle_end_result in
278+
end_gen_implementation0 ?toplevel ~ppf_dump (fun () -> cmm_phrases))
279+
252280
let linear_gen_implementation filename =
253281
let open Linear_format in
254282
let linear_unit_info, _ = restore filename in

backend/asmgen.mli

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@ val compile_implementation
3535
-> Lambda.program
3636
-> unit
3737

38+
(** The type of converters from Lambda to Flambda 2 programs. *)
39+
type middle_end_flambda2 =
40+
ppf_dump:Format.formatter
41+
-> prefixname:string
42+
-> backend:(module Flambda2__Flambda_backend_intf.S)
43+
-> filename:string
44+
-> module_ident:Ident.t
45+
-> module_block_size_in_words:int
46+
-> module_initializer:Lambda.lambda
47+
-> Flambda2__Flambda_middle_end.middle_end_result
48+
49+
(** Compile an implementation from Lambda using Flambda 2.
50+
The Flambda 2 middle end does not use the Clambda language nor the
51+
Cmmgen pass. Instead it emits Cmm directly. *)
52+
val compile_implementation_flambda2
53+
: ?toplevel:(string -> bool)
54+
-> backend:(module Flambda2__Flambda_backend_intf.S)
55+
-> filename:string
56+
-> prefixname:string
57+
-> size:int
58+
-> module_ident:Ident.t
59+
-> module_initializer:Lambda.lambda
60+
-> middle_end:middle_end_flambda2
61+
-> flambda2_to_cmm:(
62+
Flambda2__Flambda_middle_end.middle_end_result
63+
-> Cmm.phrase list)
64+
-> ppf_dump:Format.formatter
65+
-> required_globals:Ident.Set.t
66+
-> unit
67+
-> unit
68+
3869
val compile_implementation_linear :
3970
string -> progname:string -> unit
4071

0 commit comments

Comments
 (0)