Skip to content

Commit 3821d45

Browse files
committed
control write-shape
1 parent a73684d commit 3821d45

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

compiler/bin-js_of_ocaml/cmd_arg.ml

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type t =
5454
; wrap_with_fun : [ `Iife | `Named of string | `Anonymous ]
5555
; target_env : Target_env.t
5656
; shape_files : string list
57+
; shapes : bool
5758
; (* toplevel *)
5859
dynlink : bool
5960
; linkall : bool
@@ -107,6 +108,10 @@ let options =
107108
let doc = "load shape file [$(docv)]." in
108109
Arg.(value & opt_all string [] & info [ "load" ] ~docv:"FILE" ~doc)
109110
in
111+
let shapes =
112+
let doc = "Emit shape files" in
113+
Arg.(value & flag & info [ "shapes" ] ~doc)
114+
in
110115
let input_file =
111116
let doc =
112117
"Compile the bytecode program [$(docv)]. "
@@ -285,6 +290,7 @@ let options =
285290
input_file
286291
js_files
287292
shape_files
293+
shapes
288294
keep_unit_names =
289295
let inline_source_content = not sourcemap_don't_inline_content in
290296
let chop_extension s = try Filename.chop_extension s with Invalid_argument _ -> s in
@@ -348,6 +354,7 @@ let options =
348354
; source_map
349355
; keep_unit_names
350356
; shape_files
357+
; shapes
351358
}
352359
in
353360
let t =
@@ -379,6 +386,7 @@ let options =
379386
$ input_file
380387
$ js_files
381388
$ shape_files
389+
$ shapes
382390
$ keep_unit_names)
383391
in
384392
Term.ret t
@@ -576,6 +584,7 @@ let options_runtime_only =
576584
; source_map
577585
; keep_unit_names = false
578586
; shape_files = []
587+
; shapes = false
579588
}
580589
in
581590
let t =

compiler/bin-js_of_ocaml/cmd_arg.mli

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type t =
3838
]
3939
; target_env : Target_env.t
4040
; shape_files : string list
41+
; shapes : bool
4142
; (* toplevel *)
4243
dynlink : bool
4344
; linkall : bool

compiler/bin-js_of_ocaml/compile.ml

+23-7
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,28 @@ let source_map_enabled = function
4646
| No_sourcemap -> false
4747
| Inline | File _ -> true
4848

49-
let output_gen ~standalone ~custom_header ~build_info ~source_map output_file f =
49+
let output_gen
50+
~write_shapes
51+
~standalone
52+
~custom_header
53+
~build_info
54+
~source_map
55+
output_file
56+
f =
5057
let f chan k =
5158
let fmt = Pretty_print.to_out_channel chan in
5259
Driver.configure fmt;
5360
if standalone then header ~custom_header fmt;
5461
if Config.Flag.header () then jsoo_header fmt build_info;
5562
let sm, shapes = f ~standalone ~source_map (k, fmt) in
56-
(match output_file with
57-
| `Stdout -> ()
58-
| `Name name ->
59-
Shape.Store.save'
60-
(Filename.remove_extension name ^ Shape.Store.ext)
61-
(StringMap.bindings shapes));
63+
(if write_shapes
64+
then
65+
match output_file with
66+
| `Stdout -> ()
67+
| `Name name ->
68+
Shape.Store.save'
69+
(Filename.remove_extension name ^ Shape.Store.ext)
70+
(StringMap.bindings shapes));
6271
match source_map, sm with
6372
| No_sourcemap, _ | _, None -> ()
6473
| ((Inline | File _) as output), Some sm ->
@@ -164,6 +173,7 @@ let run
164173
; keep_unit_names
165174
; include_runtime
166175
; shape_files
176+
; shapes = write_shapes
167177
} =
168178
let source_map_base = Option.map ~f:snd source_map in
169179
let source_map =
@@ -378,6 +388,7 @@ let run
378388
}
379389
in
380390
output_gen
391+
~write_shapes
381392
~standalone:true
382393
~custom_header
383394
~build_info:(Build_info.create `Runtime)
@@ -426,6 +437,7 @@ let run
426437
in
427438
if times () then Format.eprintf " parsing: %a@." Timer.print t1;
428439
output_gen
440+
~write_shapes
429441
~standalone:true
430442
~custom_header
431443
~build_info:(Build_info.create `Exe)
@@ -464,6 +476,7 @@ let run
464476
in
465477
if times () then Format.eprintf " parsing: %a@." Timer.print t1;
466478
output_gen
479+
~write_shapes
467480
~standalone:false
468481
~custom_header
469482
~build_info:(Build_info.create `Cmo)
@@ -494,6 +507,7 @@ let run
494507
failwith "use [-o dirname/] or remove [--keep-unit-names]"
495508
in
496509
output_gen
510+
~write_shapes
497511
~standalone:false
498512
~custom_header
499513
~build_info:(Build_info.create `Runtime)
@@ -530,6 +544,7 @@ let run
530544
t1
531545
(Ocaml_compiler.Cmo_format.name cmo);
532546
output_gen
547+
~write_shapes
533548
~standalone:false
534549
~custom_header
535550
~build_info:(Build_info.create `Cma)
@@ -579,6 +594,7 @@ let run
579594
, shapes )
580595
in
581596
output_gen
597+
~write_shapes
582598
~standalone:false
583599
~custom_header
584600
~build_info:(Build_info.create `Cma)

compiler/lib/config.ml

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ module Flag = struct
102102

103103
let es6 = o ~name:"es6" ~default:false
104104

105+
let shapes = o ~name:"shapes" ~default:false
106+
105107
let load_shapes_auto = o ~name:"load-shapes-auto" ~default:false
106108
end
107109

compiler/lib/config.mli

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ module Flag : sig
7575

7676
val es6 : unit -> bool
7777

78+
val shapes : unit -> bool
79+
7880
val load_shapes_auto : unit -> bool
7981

8082
val enable : string -> unit

0 commit comments

Comments
 (0)