Преглед изворни кода

[analyzer] add `@:analyzer(fusion_debug)`

Simon Krajewski пре 9 година
родитељ
комит
6df9f4c624
2 измењених фајлова са 9 додато и 4 уклоњено
  1. 4 0
      src/optimization/analyzerConfig.ml
  2. 5 4
      src/optimization/analyzerTexpr.ml

+ 4 - 0
src/optimization/analyzerConfig.ml

@@ -37,6 +37,7 @@ type t = {
 	debug_kind : debug_kind;
 	debug_kind : debug_kind;
 	detail_times : bool;
 	detail_times : bool;
 	user_var_fusion : bool;
 	user_var_fusion : bool;
+	fusion_debug : bool;
 }
 }
 
 
 let flag_const_propagation = "const_propagation"
 let flag_const_propagation = "const_propagation"
@@ -49,6 +50,7 @@ let flag_ignore = "ignore"
 let flag_dot_debug = "dot_debug"
 let flag_dot_debug = "dot_debug"
 let flag_full_debug = "full_debug"
 let flag_full_debug = "full_debug"
 let flag_user_var_fusion = "user_var_fusion"
 let flag_user_var_fusion = "user_var_fusion"
+let flag_fusion_debug = "fusion_debug"
 
 
 let all_flags =
 let all_flags =
 	List.fold_left (fun acc flag ->
 	List.fold_left (fun acc flag ->
@@ -91,6 +93,7 @@ let get_base_config com =
 		debug_kind = DebugNone;
 		debug_kind = DebugNone;
 		detail_times = Common.raw_defined com "analyzer-times";
 		detail_times = Common.raw_defined com "analyzer-times";
 		user_var_fusion = Common.raw_defined com "analyzer-user-var-fusion" || (not com.debug && not (Common.raw_defined com "analyzer-no-user-var-fusion"));
 		user_var_fusion = Common.raw_defined com "analyzer-user-var-fusion" || (not com.debug && not (Common.raw_defined com "analyzer-no-user-var-fusion"));
+		fusion_debug = false;
 	}
 	}
 
 
 let update_config_from_meta com config meta =
 let update_config_from_meta com config meta =
@@ -113,6 +116,7 @@ let update_config_from_meta com config meta =
 				| EConst (Ident s) when s = flag_full_debug -> {config with debug_kind = DebugFull}
 				| EConst (Ident s) when s = flag_full_debug -> {config with debug_kind = DebugFull}
 				| EConst (Ident s) when s = flag_user_var_fusion -> {config with user_var_fusion = true}
 				| EConst (Ident s) when s = flag_user_var_fusion -> {config with user_var_fusion = true}
 				| EConst (Ident s) when s = "no_" ^ flag_user_var_fusion -> {config with user_var_fusion = false}
 				| EConst (Ident s) when s = "no_" ^ flag_user_var_fusion -> {config with user_var_fusion = false}
+				| EConst (Ident s) when s = flag_fusion_debug -> {config with fusion_debug = true}
 				| _ ->
 				| _ ->
 					let s = Ast.s_expr e in
 					let s = Ast.s_expr e in
 					com.warning (StringError.string_error s all_flags ("Unrecognized analyzer option: " ^ s)) (pos e);
 					com.warning (StringError.string_error s all_flags ("Unrecognized analyzer option: " ^ s)) (pos e);

+ 5 - 4
src/optimization/analyzerTexpr.ml

@@ -438,7 +438,7 @@ module InterferenceReport = struct
 		let s_hashtbl f h =
 		let s_hashtbl f h =
 			String.concat ", " (Hashtbl.fold (fun k _ acc -> (f k) :: acc) h [])
 			String.concat ", " (Hashtbl.fold (fun k _ acc -> (f k) :: acc) h [])
 		in
 		in
-		Type.Printer.s_record_fields "" [
+		Type.Printer.s_record_fields "\t" [
 			"ir_var_reads",s_hashtbl string_of_int ir.ir_var_reads;
 			"ir_var_reads",s_hashtbl string_of_int ir.ir_var_reads;
 			"ir_var_writes",s_hashtbl string_of_int ir.ir_var_writes;
 			"ir_var_writes",s_hashtbl string_of_int ir.ir_var_writes;
 			"ir_field_reads",s_hashtbl (fun x -> x) ir.ir_field_reads;
 			"ir_field_reads",s_hashtbl (fun x -> x) ir.ir_field_reads;
@@ -591,7 +591,8 @@ module Fusion = struct
 				let found = ref false in
 				let found = ref false in
 				let blocked = ref false in
 				let blocked = ref false in
 				let ir = InterferenceReport.from_texpr e1 in
 				let ir = InterferenceReport.from_texpr e1 in
-				(*if e.epos.pfile = "src/Main.hx" then print_endline (Printf.sprintf "FUSION %s<%i> = %s\n\t%s\n\t%s" v1.v_name v1.v_id (s_expr_pretty e1) (s_expr_pretty (mk (TBlock el) t_dynamic null_pos)) (InterferenceReport.to_string ir));*)
+				if config.fusion_debug then print_endline (Printf.sprintf "FUSION\n\tvar %s<%i> = %s\n\t%s\n\t%s"
+					v1.v_name v1.v_id (s_expr_pretty e1) (InterferenceReport.to_string ir) (Type.s_expr_pretty true "" (s_type (print_context())) (mk (TBlock el) t_dynamic null_pos)));
 				let rec replace e =
 				let rec replace e =
 					let explore e =
 					let explore e =
 						let old = !blocked in
 						let old = !blocked in
@@ -728,10 +729,10 @@ module Fusion = struct
 					if not !found then raise Exit;
 					if not !found then raise Exit;
 					changed := true;
 					changed := true;
 					change_num_uses v1 (-1);
 					change_num_uses v1 (-1);
-					(*if e.epos.pfile = "src/Main.hx" then print_endline (Printf.sprintf "OK: %s" (s_expr_pretty e));*)
+					if config.fusion_debug then print_endline (Printf.sprintf "YES: %s" (s_expr_pretty (mk (TBlock el) t_dynamic null_pos)));
 					fuse acc el
 					fuse acc el
 				with Exit ->
 				with Exit ->
-					(*if e.epos.pfile = "src/Main.hx" then print_endline (Printf.sprintf "NOPE: %s" (Printexc.get_backtrace()));*)
+					if config.fusion_debug then print_endline (Printf.sprintf "NO: %s" (Printexc.get_backtrace()));
 					fuse (ev :: acc) el
 					fuse (ev :: acc) el
 				end
 				end
 			| {eexpr = TUnop((Increment | Decrement as op,Prefix,({eexpr = TLocal v} as ev)))} as e1 :: e2 :: el ->
 			| {eexpr = TUnop((Increment | Decrement as op,Prefix,({eexpr = TLocal v} as ev)))} as e1 :: e2 :: el ->