浏览代码

[analyzer] allow `@:analyzer(full_debug)` to output exception information

Simon Krajewski 9 年之前
父节点
当前提交
7fc8d599b2
共有 2 个文件被更改,包括 24 次插入10 次删除
  1. 14 7
      src/optimization/analyzer.ml
  2. 10 3
      src/optimization/analyzerConfig.ml

+ 14 - 7
src/optimization/analyzer.ml

@@ -1184,12 +1184,7 @@ module Run = struct
 		| Some e when not (is_ignored cf.cf_meta) && not (Codegen.is_removable_field ctx cf) ->
 			let config = update_config_from_meta ctx.Typecore.com config cf.cf_meta in
 			let actx = create_analyzer_context ctx.Typecore.com config e in
-			let e = try
-				run_on_expr actx e
-			with
-			| Error _ | Abort _ as exc ->
-				raise exc
-			| exc ->
+			let debug() =
 				prerr_endline (Printf.sprintf "While analyzing %s.%s" (s_type_path c.cl_path) cf.cf_name);
 				List.iter (fun (s,e) ->
 					prerr_endline (Printf.sprintf "<%s>" s);
@@ -1198,10 +1193,22 @@ module Run = struct
 				) (List.rev actx.debug_exprs);
 				Debug.dot_debug actx c cf;
 				prerr_endline (Printf.sprintf "dot graph written to %s" (String.concat "/" (Debug.get_dump_path actx c cf)));
+			in
+			let e = try
+				run_on_expr actx e
+			with
+			| Error _ | Abort _ as exc ->
+				raise exc
+			| exc ->
+				debug();
 				raise exc
 			in
 			let e = Cleanup.reduce_control_flow ctx e in
-			if config.dot_debug then Debug.dot_debug actx c cf;
+			begin match config.debug_kind with
+				| DebugNone -> ()
+				| DebugDot -> Debug.dot_debug actx c cf;
+				| DebugFull -> debug()
+			end;
 			cf.cf_expr <- Some e;
 		| _ -> ()
 

+ 10 - 3
src/optimization/analyzerConfig.ml

@@ -21,6 +21,11 @@ open Ast
 open Type
 open Common
 
+type debug_kind =
+	| DebugNone
+	| DebugDot
+	| DebugFull
+
 type t = {
 	optimize : bool;
 	const_propagation : bool;
@@ -29,7 +34,7 @@ type t = {
 	local_dce : bool;
 	fusion : bool;
 	purity_inference : bool;
-	dot_debug : bool;
+	debug_kind : debug_kind;
 }
 
 let flag_const_propagation = "const_propagation"
@@ -40,6 +45,7 @@ let flag_fusion = "fusion"
 let flag_purity_inference = "purity_inference"
 let flag_ignore = "ignore"
 let flag_dot_debug = "dot_debug"
+let flag_full_debug = "full_debug"
 
 let all_flags =
 	List.fold_left (fun acc flag ->
@@ -79,7 +85,7 @@ let get_base_config com =
 		local_dce = not (Common.raw_defined com "analyzer-no-local-dce");
 		fusion = not (Common.raw_defined com "analyzer-no-fusion") && (match com.platform with Flash | Java -> false | _ -> true);
 		purity_inference = not (Common.raw_defined com "analyzer-no-purity-inference");
-		dot_debug = false;
+		debug_kind = DebugNone;
 	}
 
 let update_config_from_meta com config meta =
@@ -98,7 +104,8 @@ let update_config_from_meta com config meta =
 				| EConst (Ident s) when s = flag_fusion -> { config with fusion = true}
 				| EConst (Ident s) when s = "no_" ^ flag_purity_inference -> { config with purity_inference = false}
 				| EConst (Ident s) when s = flag_purity_inference -> { config with purity_inference = true}
-				| EConst (Ident s) when s = flag_dot_debug -> {config with dot_debug = true}
+				| EConst (Ident s) when s = flag_dot_debug -> {config with debug_kind = DebugDot}
+				| EConst (Ident s) when s = flag_full_debug -> {config with debug_kind = DebugFull}
 				| _ ->
 					let s = Ast.s_expr e in
 					com.warning (StringError.string_error s all_flags ("Unrecognized analyzer option: " ^ s)) (pos e);