Explorar o código

factor out parts of `create_dumpfile`

Simon Krajewski %!s(int64=9) %!d(string=hai) anos
pai
achega
2c7fddf996
Modificáronse 1 ficheiros con 14 adicións e 10 borrados
  1. 14 10
      codegen.ml

+ 14 - 10
codegen.ml

@@ -1500,22 +1500,26 @@ let make_valid_filename s =
 	let r = Str.regexp "[^A-Za-z0-9_\\-\\.,]" in
 	Str.global_substitute r (fun s -> "_") s
 
-(*
-	Make a dump of the full typed AST of all types
-*)
-let rec create_dumpfile acc = function
+let rec create_file ext acc = function
 	| [] -> assert false
 	| d :: [] ->
 		let d = make_valid_filename d in
-		let ch = open_out (String.concat "/" (List.rev (d :: acc)) ^ ".dump") in
-		let buf = Buffer.create 0 in
-		buf, (fun () ->
-			output_string ch (Buffer.contents buf);
-			close_out ch)
+		let ch = open_out (String.concat "/" (List.rev (d :: acc)) ^ ext) in
+		ch
 	| d :: l ->
 		let dir = String.concat "/" (List.rev (d :: acc)) in
 		if not (Sys.file_exists dir) then Unix.mkdir dir 0o755;
-		create_dumpfile (d :: acc) l
+		create_file ext (d :: acc) l
+
+(*
+	Make a dump of the full typed AST of all types
+*)
+let create_dumpfile acc l =
+	let ch = create_file ".dump" acc l in
+	let buf = Buffer.create 0 in
+	buf, (fun () ->
+		output_string ch (Buffer.contents buf);
+		close_out ch)
 
 let dump_types com =
 	let s_type = s_type (Type.print_context()) in