浏览代码

factor out parts of `create_dumpfile`

Simon Krajewski 9 年之前
父节点
当前提交
2c7fddf996
共有 1 个文件被更改,包括 14 次插入10 次删除
  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