Explorar o código

keep track of some positions through the analyzer

Simon Krajewski %!s(int64=9) %!d(string=hai) anos
pai
achega
71b2032449

+ 4 - 4
src/optimization/analyzer.ml

@@ -941,10 +941,10 @@ module Debug = struct
 		| SESubBlock(bb_sub,bb_next) ->
 			edge bb_sub "sub";
 			edge bb_next "next";
-		| SEIfThen(bb_then,bb_next) ->
+		| SEIfThen(bb_then,bb_next,_) ->
 			edge bb_then "then";
 			edge bb_next "next"
-		| SEIfThenElse(bb_then,bb_else,bb_next,_) ->
+		| SEIfThenElse(bb_then,bb_else,bb_next,_,_) ->
 			edge bb_then "then";
 			edge bb_else "else";
 			edge bb_next "next";
@@ -954,11 +954,11 @@ module Debug = struct
 			edge bb_next "next";
 		| SEMerge bb_next ->
 			edge bb_next "merge"
-		| SESwitch(bbl,bo,bb_next) ->
+		| SESwitch(bbl,bo,bb_next,_) ->
 			List.iter (fun (el,bb) -> edge bb ("case " ^ (String.concat " | " (List.map s_expr_pretty el)))) bbl;
 			(match bo with None -> () | Some bb -> edge bb "default");
 			edge bb_next "next";
-		| SETry(bb_try,_,bbl,bb_next) ->
+		| SETry(bb_try,_,bbl,bb_next,_) ->
 			edge bb_try "try";
 			List.iter (fun (_,bb_catch) -> edge bb_catch "catch") bbl;
 			edge bb_next "next";

+ 13 - 13
src/optimization/analyzerTexprTransformer.ml

@@ -320,7 +320,7 @@ let rec func ctx bb tf t p =
 			add_cfg_edge bb bb_then (CFGCondBranch (mk (TConst (TBool true)) ctx.com.basic.tbool e2.epos));
 			let bb_then_next = block bb_then e2 in
 			let bb_next = create_node BKNormal bb.bb_type bb.bb_pos in
-			set_syntax_edge bb (SEIfThen(bb_then,bb_next));
+			set_syntax_edge bb (SEIfThen(bb_then,bb_next,e.epos));
 			add_cfg_edge bb bb_next CFGCondElse;
 			close_node g bb;
 			add_cfg_edge bb_then_next bb_next CFGGoto;
@@ -337,11 +337,11 @@ let rec func ctx bb tf t p =
 			let bb_then_next = block bb_then e2 in
 			let bb_else_next = block bb_else e3 in
 			if bb_then_next == g.g_unreachable && bb_else_next == g.g_unreachable then begin
-				set_syntax_edge bb (SEIfThenElse(bb_then,bb_else,g.g_unreachable,e.etype));
+				set_syntax_edge bb (SEIfThenElse(bb_then,bb_else,g.g_unreachable,e.etype,e.epos));
 				g.g_unreachable
 			end else begin
 				let bb_next = create_node BKNormal bb.bb_type bb.bb_pos in
-				set_syntax_edge bb (SEIfThenElse(bb_then,bb_else,bb_next,e.etype));
+				set_syntax_edge bb (SEIfThenElse(bb_then,bb_else,bb_next,e.etype,e.epos));
 				add_cfg_edge bb_then_next bb_next CFGGoto;
 				add_cfg_edge bb_else_next bb_next CFGGoto;
 				close_node g bb_then_next;
@@ -375,14 +375,14 @@ let rec func ctx bb tf t p =
 					Some (bb_case)
 			in
 			if is_exhaustive && !reachable = [] then begin
-				set_syntax_edge bb (SESwitch(cases,def,g.g_unreachable));
+				set_syntax_edge bb (SESwitch(cases,def,g.g_unreachable,e.epos));
 				close_node g bb;
 				g.g_unreachable;
 			end else begin
 				let bb_next = create_node BKNormal bb.bb_type bb.bb_pos in
 				if not is_exhaustive then add_cfg_edge bb bb_next CFGGoto;
 				List.iter (fun bb -> add_cfg_edge bb bb_next CFGGoto) !reachable;
-				set_syntax_edge bb (SESwitch(cases,def,bb_next));
+				set_syntax_edge bb (SESwitch(cases,def,bb_next,e.epos));
 				close_node g bb;
 				bb_next
 			end
@@ -447,7 +447,7 @@ let rec func ctx bb tf t p =
 					close_node g bb_catch_next;
 					v,bb_catch
 				) catches in
-				set_syntax_edge bb (SETry(bb_try,bb_exc,catches,bb_next));
+				set_syntax_edge bb (SETry(bb_try,bb_exc,catches,bb_next,e.epos));
 				if bb_try_next != g.g_unreachable then add_cfg_edge bb_try_next bb_next CFGGoto;
 				close_node g bb_try_next;
 				bb_next
@@ -610,17 +610,17 @@ let rec block_to_texpr_el ctx bb =
 			| {eexpr = TWhile(e1,_,flag)} as e :: el,(SEWhile(_,bb_body,bb_next)) ->
 				let e2 = block bb_body in
 				Some bb_next,{e with eexpr = TWhile(e1,e2,flag)} :: el
-			| el,SETry(bb_try,_,bbl,bb_next) ->
-				Some bb_next,(mk (TTry(block bb_try,List.map (fun (v,bb) -> v,block bb) bbl)) ctx.com.basic.tvoid bb_try.bb_pos) :: el
+			| el,SETry(bb_try,_,bbl,bb_next,p) ->
+				Some bb_next,(mk (TTry(block bb_try,List.map (fun (v,bb) -> v,block bb) bbl)) ctx.com.basic.tvoid p) :: el
 			| e1 :: el,se ->
 				let e1 = Texpr.skip e1 in
-				let bb_next,e1_def,t = match se with
-					| SEIfThen(bb_then,bb_next) -> Some bb_next,TIf(e1,block bb_then,None),ctx.com.basic.tvoid
-					| SEIfThenElse(bb_then,bb_else,bb_next,t) -> Some bb_next,TIf(e1,block bb_then,Some (block bb_else)),t
-					| SESwitch(bbl,bo,bb_next) -> Some bb_next,TSwitch(e1,List.map (fun (el,bb) -> el,block bb) bbl,Option.map block bo),ctx.com.basic.tvoid
+				let bb_next,e1_def,t,p = match se with
+					| SEIfThen(bb_then,bb_next,p) -> Some bb_next,TIf(e1,block bb_then,None),ctx.com.basic.tvoid,p
+					| SEIfThenElse(bb_then,bb_else,bb_next,t,p) -> Some bb_next,TIf(e1,block bb_then,Some (block bb_else)),t,p
+					| SESwitch(bbl,bo,bb_next,p) -> Some bb_next,TSwitch(e1,List.map (fun (el,bb) -> el,block bb) bbl,Option.map block bo),ctx.com.basic.tvoid,p
 					| _ -> error (Printf.sprintf "Invalid node exit: %s" (s_expr_pretty e1)) bb.bb_pos
 				in
-				bb_next,(mk e1_def t e1.epos) :: el
+				bb_next,(mk e1_def t p) :: el
 			| [],_ ->
 				None,[]
 		in

+ 13 - 13
src/optimization/analyzerTypes.ml

@@ -63,15 +63,15 @@ module BasicBlock = struct
 	}
 
 	and syntax_edge =
-		| SEIfThen of t * t                                (* `if` with "then" and "next" *)
-		| SEIfThenElse of t * t * t * Type.t               (* `if` with "then", "else" and "next" *)
-		| SESwitch of (texpr list * t) list * t option * t (* `switch` with cases, "default" and "next" *)
-		| SETry of t * t * (tvar * t) list * t             (* `try` with "exc", catches and "next" *)
-		| SEWhile of t * t * t                             (* `while` with "head", "body" and "next" *)
-		| SESubBlock of t * t                              (* "sub" with "next" *)
-		| SEMerge of t                                     (* Merge to same block *)
-		| SEEnd                                            (* End of syntax *)
-		| SENone                                           (* No syntax exit *)
+		| SEIfThen of t * t * pos                                (* `if` with "then" and "next" *)
+		| SEIfThenElse of t * t * t * Type.t * pos               (* `if` with "then", "else" and "next" *)
+		| SESwitch of (texpr list * t) list * t option * t * pos (* `switch` with cases, "default" and "next" *)
+		| SETry of t * t * (tvar * t) list * t *  pos            (* `try` with "exc", catches and "next" *)
+		| SEWhile of t * t * t                                   (* `while` with "head", "body" and "next" *)
+		| SESubBlock of t * t                                    (* "sub" with "next" *)
+		| SEMerge of t                                           (* Merge to same block *)
+		| SEEnd                                                  (* End of syntax *)
+		| SENone                                                 (* No syntax exit *)
 
 	and t = {
 		bb_id : int;                          (* The unique ID of the block *)
@@ -478,18 +478,18 @@ module Graph = struct
 		let rec loop scopes bb =
 			bb.bb_scopes <- scopes;
 			begin match bb.bb_syntax_edge with
-				| SEIfThen(bb_then,bb_next) ->
+				| SEIfThen(bb_then,bb_next,_) ->
 					loop (next_scope scopes) bb_then;
 					loop scopes bb_next
-				| SEIfThenElse(bb_then,bb_else,bb_next,_) ->
+				| SEIfThenElse(bb_then,bb_else,bb_next,_,_) ->
 					loop (next_scope scopes) bb_then;
 					loop (next_scope scopes) bb_else;
 					loop scopes bb_next
-				| SESwitch(cases,bbo,bb_next) ->
+				| SESwitch(cases,bbo,bb_next,_) ->
 					List.iter (fun (_,bb_case) -> loop (next_scope scopes) bb_case) cases;
 					(match bbo with None -> () | Some bb -> loop (next_scope scopes) bb);
 					loop scopes bb_next;
-				| SETry(bb_try,bb_exc,catches,bb_next) ->
+				| SETry(bb_try,bb_exc,catches,bb_next,_) ->
 					let scopes' = next_scope scopes in
 					loop scopes' bb_try;
 					loop scopes' bb_exc;