Simon Krajewski 8 лет назад
Родитель
Сommit
918231c47f
3 измененных файлов с 20 добавлено и 20 удалено
  1. 1 18
      src/codegen/codegen.ml
  2. 18 1
      src/core/path.ml
  3. 1 1
      src/optimization/analyzer.ml

+ 1 - 18
src/codegen/codegen.ml

@@ -539,28 +539,11 @@ let rec constructor_side_effects e =
 			true
 
 module Dump = struct
-	let make_valid_filename s =
-		let r = Str.regexp "[^A-Za-z0-9_\\-\\.,]" in
-		Str.global_substitute r (fun s -> "_") s
-
-	let rec create_file ext acc = function
-		| [] -> assert false
-		| d :: [] ->
-			let d = make_valid_filename d in
-			let maxlen = 200 - String.length ext in
-			let d = if String.length d > maxlen then String.sub d 0 maxlen else d in
-			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_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 ch = Path.create_file false ".dump" acc l in
 		let buf = Buffer.create 0 in
 		buf, (fun () ->
 			output_string ch (Buffer.contents buf);

+ 18 - 1
src/core/path.ml

@@ -153,4 +153,21 @@ let find_directories target recursive paths =
 		with Sys_error _ ->
 			acc
 	in
-	List.fold_left (fun acc dir -> loop acc dir) [] paths
+	List.fold_left (fun acc dir -> loop acc dir) [] paths
+
+let make_valid_filename s =
+	let r = Str.regexp "[^A-Za-z0-9_\\-\\.,]" in
+	Str.global_substitute r (fun s -> "_") s
+
+let rec create_file bin ext acc = function
+	| [] -> assert false
+	| d :: [] ->
+		let d = make_valid_filename d in
+		let maxlen = 200 - String.length ext in
+		let d = if String.length d > maxlen then String.sub d 0 maxlen else d in
+		let ch = (if bin then open_out_bin else 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 (remove_trailing_slash dir)) then Unix.mkdir dir 0o755;
+		create_file bin ext (d :: acc) l

+ 1 - 1
src/optimization/analyzer.ml

@@ -804,7 +804,7 @@ module Debug = struct
 	let dot_debug ctx c cf =
 		let g = ctx.graph in
 		let start_graph ?(graph_config=[]) suffix =
-			let ch = Codegen.Dump.create_file suffix [] (get_dump_path ctx c cf) in
+			let ch = Path.create_file false suffix [] (get_dump_path ctx c cf) in
 			Printf.fprintf ch "digraph graphname {\n";
 			List.iter (fun s -> Printf.fprintf ch "%s;\n" s) graph_config;
 			ch,(fun () ->