@@ -28,16 +28,22 @@ let () = Sys.catch_break true
2828let gen_unit_filename dir u =
2929 Filename. concat dir (Printf. sprintf " %s.js" u.Cmo_format. cu_name)
3030
31+ let header formatter ~custom_header =
32+ match custom_header with
33+ | None -> ()
34+ | Some c -> Pretty_print. string formatter (c ^ " \n " )
35+
3136let jsoo_header formatter build_info =
3237 Pretty_print. string formatter " // Generated by js_of_ocaml\n " ;
3338 Pretty_print. string formatter (Build_info. to_string build_info)
3439
35- let output_gen ~build_info ~source_map output_file f =
40+ let output_gen ~standalone ~ custom_header ~ build_info ~source_map output_file f =
3641 let f chan k =
3742 let fmt = Pretty_print. to_out_channel chan in
3843 Driver. configure fmt;
44+ if standalone then header ~custom_header fmt;
3945 if Config.Flag. header () then jsoo_header fmt build_info;
40- let sm = f ~source_map: (Option. map ~f: snd source_map) (k, fmt) in
46+ let sm = f ~standalone ~ source_map: (Option. map ~f: snd source_map) (k, fmt) in
4147 match source_map, sm with
4248 | None , _ | _ , None -> ()
4349 | Some (output_file , _ ), Some sm ->
@@ -169,7 +175,7 @@ let run
169175 , noloc )
170176 ])
171177 in
172- let output (one : Parse_bytecode.one ) ~source_map ~ linkall ~ standalone output_file =
178+ let output (one : Parse_bytecode.one ) ~standalone ~ source_map ~ linkall output_file =
173179 check_debug one;
174180 let init_pseudo_fs = fs_external && standalone in
175181 let sm =
@@ -189,7 +195,6 @@ let run
189195 ~linkall
190196 ~wrap_with_fun
191197 ?source_map
192- ?custom_header
193198 fmt
194199 one.debug
195200 code
@@ -214,7 +219,6 @@ let run
214219 ~linkall
215220 ~wrap_with_fun
216221 ?source_map
217- ?custom_header
218222 fmt
219223 one.debug
220224 code
@@ -224,28 +228,23 @@ let run
224228 let instr = fs_instr2 in
225229 let code = Code. prepend Code. empty instr in
226230 let pfs_fmt = Pretty_print. to_out_channel chan in
227- Driver. f'
228- ~standalone
229- ?profile
230- ?custom_header
231- ~wrap_with_fun
232- pfs_fmt
233- one.debug
234- code));
231+ Driver. f' ~standalone ?profile ~wrap_with_fun pfs_fmt one.debug code));
235232 res
236233 in
237234 if times () then Format. eprintf " compilation: %a@." Timer. print t;
238235 sm
239236 in
240237 let output_partial
241238 (cmo : Cmo_format.compilation_unit )
239+ ~standalone
242240 ~source_map
243241 code
244242 ((_ , fmt ) as output_file ) =
243+ assert (not standalone);
245244 let uinfo = Unit_info. of_cmo cmo in
246245 Pretty_print. string fmt " \n " ;
247246 Pretty_print. string fmt (Unit_info. to_string uinfo);
248- output code ~source_map ~standalone: false ~linkall: false output_file
247+ output code ~source_map ~standalone ~linkall: false output_file
249248 in
250249 (if runtime_only
251250 then (
@@ -260,13 +259,15 @@ let run
260259 }
261260 in
262261 output_gen
262+ ~standalone: true
263+ ~custom_header
263264 ~build_info: (Build_info. create `Runtime )
264265 ~source_map
265266 (fst output_file)
266- (fun ~source_map ((_ , fmt ) as output_file ) ->
267+ (fun ~standalone ~ source_map ((_ , fmt ) as output_file ) ->
267268 Pretty_print. string fmt " \n " ;
268269 Pretty_print. string fmt (Unit_info. to_string uinfo);
269- output code ~source_map ~standalone: true ~linkall: true output_file))
270+ output code ~source_map ~standalone ~linkall: true output_file))
270271 else
271272 let kind, ic, close_ic, include_dirs =
272273 match input_file with
@@ -299,10 +300,12 @@ let run
299300 in
300301 if times () then Format. eprintf " parsing: %a@." Timer. print t1;
301302 output_gen
303+ ~standalone: true
304+ ~custom_header
302305 ~build_info: (Build_info. create `Exe )
303306 ~source_map
304307 (fst output_file)
305- (output code ~standalone: true ~ linkall )
308+ (output code ~linkall )
306309 | `Cmo cmo ->
307310 let output_file =
308311 match output_file, keep_unit_names with
@@ -327,6 +330,8 @@ let run
327330 in
328331 if times () then Format. eprintf " parsing: %a@." Timer. print t1;
329332 output_gen
333+ ~standalone: false
334+ ~custom_header
330335 ~build_info: (Build_info. create `Cmo )
331336 ~source_map
332337 output_file
@@ -355,12 +360,14 @@ let run
355360 if times ()
356361 then Format. eprintf " parsing: %a (%s)@." Timer. print t1 cmo.cu_name;
357362 output_gen
363+ ~standalone: false
364+ ~custom_header
358365 ~build_info: (Build_info. create `Cma )
359366 ~source_map
360367 (`Name output_file)
361368 (output_partial cmo code))
362369 | `Cma cma ->
363- let f ~source_map output =
370+ let f ~standalone ~ source_map output =
364371 List. fold_left cma.lib_units ~init: source_map ~f: (fun source_map cmo ->
365372 let t1 = Timer. make () in
366373 let code =
@@ -373,9 +380,15 @@ let run
373380 in
374381 if times ()
375382 then Format. eprintf " parsing: %a (%s)@." Timer. print t1 cmo.cu_name;
376- output_partial cmo ~source_map code output)
383+ output_partial cmo ~standalone ~ source_map code output)
377384 in
378- output_gen ~build_info: (Build_info. create `Cma ) ~source_map (fst output_file) f);
385+ output_gen
386+ ~standalone: false
387+ ~custom_header
388+ ~build_info: (Build_info. create `Cma )
389+ ~source_map
390+ (fst output_file)
391+ f);
379392 close_ic () );
380393 Debug. stop_profiling ()
381394
0 commit comments