2
0
Эх сурвалжийг харах

changed --dead-code-elimination to --dce [no|std|full], added haxe_ver for 3.0+

Nicolas Cannasse 13 жил өмнө
parent
commit
26d40f4ee8
4 өөрчлөгдсөн 34 нэмэгдсэн , 18 устгасан
  1. 11 3
      common.ml
  2. 3 3
      interp.ml
  3. 19 11
      main.ml
  4. 1 1
      parser.ml

+ 11 - 3
common.ml

@@ -144,6 +144,7 @@ module Define = struct
 		| CoreApi
 		| CoreApi
 		| NoCOpt
 		| NoCOpt
 		| Haxe3
 		| Haxe3
+		| HaxeVer
 		| CheckXmlProxy
 		| CheckXmlProxy
 		| DocGen
 		| DocGen
 		| Vcproj
 		| Vcproj
@@ -179,7 +180,7 @@ module Define = struct
 		| PhpPrefix
 		| PhpPrefix
 		| Dump
 		| Dump
 		| DumpDependencies
 		| DumpDependencies
-		| NoDce
+		| Dce
 
 
 		| Last (* must be last *)
 		| Last (* must be last *)
 
 
@@ -192,6 +193,7 @@ module Define = struct
 		| CoreApi -> ("core_api","Defined in the core api context")
 		| CoreApi -> ("core_api","Defined in the core api context")
 		| NoCOpt -> ("no_copt","Disable completion optimization (for debug purposes)")
 		| NoCOpt -> ("no_copt","Disable completion optimization (for debug purposes)")
 		| Haxe3 -> ("haxe3","Enable Haxe3 transition mode")
 		| Haxe3 -> ("haxe3","Enable Haxe3 transition mode")
+		| HaxeVer -> ("haxe_ver","The current Haxe version value")
 		| CheckXmlProxy -> ("check_xml_proxy","Check the used fields of the xml proxy")
 		| CheckXmlProxy -> ("check_xml_proxy","Check the used fields of the xml proxy")
 		| DocGen -> ("doc_gen","Do not perform any removal/change in order to correctly generate documentation")
 		| DocGen -> ("doc_gen","Do not perform any removal/change in order to correctly generate documentation")
 		| Vcproj -> ("vcproj","GenCPP internal")
 		| Vcproj -> ("vcproj","GenCPP internal")
@@ -227,7 +229,7 @@ module Define = struct
 		| PhpPrefix -> ("php_prefix","Compiled with --php-prefix")
 		| PhpPrefix -> ("php_prefix","Compiled with --php-prefix")
 		| Dump -> ("dump","Dump the complete typed AST for internal debugging")
 		| Dump -> ("dump","Dump the complete typed AST for internal debugging")
 		| DumpDependencies -> ("dump_dependencies","Dump the classes dependencies")
 		| DumpDependencies -> ("dump_dependencies","Dump the classes dependencies")
-		| NoDce -> ("no_dce","Entirely disable dead code elimination")
+		| Dce -> ("dce","The current DCE mode")
 		| Last -> assert false
 		| Last -> assert false
 
 
 end
 end
@@ -483,9 +485,12 @@ let raw_defined ctx v =
 let defined ctx v =
 let defined ctx v =
 	raw_defined ctx (fst (Define.infos v))
 	raw_defined ctx (fst (Define.infos v))
 
 
-let defined_value ctx k =
+let raw_defined_value ctx k =
 	PMap.find k ctx.defines
 	PMap.find k ctx.defines
 
 
+let defined_value ctx v =
+	raw_defined_value ctx (fst (Define.infos v))
+
 let raw_define ctx v =
 let raw_define ctx v =
 	let k,v = try ExtString.String.split v "=" with _ -> v,"1" in
 	let k,v = try ExtString.String.split v "=" with _ -> v,"1" in
 	ctx.defines <- PMap.add k v ctx.defines;
 	ctx.defines <- PMap.add k v ctx.defines;
@@ -493,6 +498,9 @@ let raw_define ctx v =
 	ctx.defines <- PMap.add k v ctx.defines;
 	ctx.defines <- PMap.add k v ctx.defines;
 	ctx.defines_signature <- None
 	ctx.defines_signature <- None
 
 
+let define_value ctx k v =
+	raw_define ctx (fst (Define.infos k) ^ "=" ^ v)
+	
 let define ctx v =
 let define ctx v =
 	raw_define ctx (fst (Define.infos v))
 	raw_define ctx (fst (Define.infos v))
 
 

+ 3 - 3
interp.ml

@@ -1829,8 +1829,8 @@ let reg_lib =
 		raise Builtin_error
 		raise Builtin_error
 	in
 	in
 	(* try to load regexp first : we might fail if pcre is not installed *)
 	(* try to load regexp first : we might fail if pcre is not installed *)
-	let neko = (match neko with 
-		| None -> None 
+	let neko = (match neko with
+		| None -> None
 		| Some neko ->
 		| Some neko ->
 			(try ignore(neko.load "regexp@regexp_new_options" 2); Some neko with _ -> None)
 			(try ignore(neko.load "regexp@regexp_new_options" 2); Some neko with _ -> None)
 	) in
 	) in
@@ -2058,7 +2058,7 @@ let macro_lib =
 		);
 		);
 		"defined_value", Fun1 (fun s ->
 		"defined_value", Fun1 (fun s ->
 			match s with
 			match s with
-			| VString s -> (try VString (Common.defined_value (ccom()) s) with Not_found -> VNull)
+			| VString s -> (try VString (Common.raw_defined_value (ccom()) s) with Not_found -> VNull)
 			| _ -> error();
 			| _ -> error();
 		);
 		);
 		"get_type", Fun1 (fun s ->
 		"get_type", Fun1 (fun s ->

+ 19 - 11
main.ml

@@ -690,12 +690,16 @@ try
 	let force_typing = ref false in
 	let force_typing = ref false in
 	let pre_compilation = ref [] in
 	let pre_compilation = ref [] in
 	let interp = ref false in
 	let interp = ref false in
-	let full_dce = ref false in
-	if version >= 300 then Common.define com Define.Haxe3;
-	for i = 0 to (if version < 300 then 4 else version - 300) do
-		let v = version - i in
-		Common.raw_define com ("haxe_" ^ string_of_int v);
-	done;
+	if version < 300 then begin
+		for i = 0 to 4 do
+			let v = version - i in
+			Common.raw_define com ("haxe_" ^ string_of_int v);
+		done;
+	end else begin
+		Common.define com Define.Haxe3;
+		Common.define_value com Define.HaxeVer (string_of_float (float_of_int version /. 100.));
+	end;
+	Common.define_value com Define.Dce "std";
 	com.warning <- (fun msg p -> message ctx ("Warning : " ^ msg) p);
 	com.warning <- (fun msg p -> message ctx ("Warning : " ^ msg) p);
 	com.error <- error ctx;
 	com.error <- error ctx;
 	Parser.display_error := (fun e p -> com.error (Parser.error_msg e) p);
 	Parser.display_error := (fun e p -> com.error (Parser.error_msg e) p);
@@ -773,7 +777,7 @@ try
 		),"<library[:version]> : use a haxelib library");
 		),"<library[:version]> : use a haxelib library");
 		("-D",Arg.String (fun var ->
 		("-D",Arg.String (fun var ->
 			if var = fst (Define.infos Define.UseRttiDoc) then Parser.use_doc := true;
 			if var = fst (Define.infos Define.UseRttiDoc) then Parser.use_doc := true;
-			if var = fst (Define.infos Define.NoOpt) then com.foptimize <- false;			
+			if var = fst (Define.infos Define.NoOpt) then com.foptimize <- false;
 			if List.mem var reserved_flags then raise (Arg.Bad (var ^ " is a reserved compiler flag and cannot be defined from command line"));
 			if List.mem var reserved_flags then raise (Arg.Bad (var ^ " is a reserved compiler flag and cannot be defined from command line"));
 			Common.raw_define com var
 			Common.raw_define com var
 		),"<var> : define a conditional compilation flag");
 		),"<var> : define a conditional compilation flag");
@@ -907,9 +911,12 @@ try
 			force_typing := true;
 			force_typing := true;
 			config_macros := e :: !config_macros
 			config_macros := e :: !config_macros
 		)," : call the given macro before typing anything else");
 		)," : call the given macro before typing anything else");
-		("--dead-code-elimination", Arg.Unit (fun () ->
-			full_dce := true
-		)," : remove unused methods");
+		("--dce", Arg.String (fun mode ->
+			(match mode with
+			| "std" | "full" | "no" -> ()
+			| _ -> raise (Arg.Bad "Invalid DCE mode"));
+			Common.define_value com Define.Dce mode
+		),"[std|full|no] : set the dead code elimination mode");
 		("--wait", Arg.String (fun hp ->
 		("--wait", Arg.String (fun hp ->
 			let host, port = (try ExtString.String.split hp ":" with _ -> "127.0.0.1", hp) in
 			let host, port = (try ExtString.String.split hp ":" with _ -> "127.0.0.1", hp) in
 			wait_loop com host (try int_of_string port with _ -> raise (Arg.Bad "Invalid port"))
 			wait_loop com host (try int_of_string port with _ -> raise (Arg.Bad "Invalid port"))
@@ -1054,7 +1061,8 @@ try
 		Codegen.post_process_end();
 		Codegen.post_process_end();
 		List.iter (fun f -> f()) (List.rev com.filters);
 		List.iter (fun f -> f()) (List.rev com.filters);
 		List.iter (Codegen.save_class_state tctx) com.types;
 		List.iter (Codegen.save_class_state tctx) com.types;
-		if not (!gen_as3 || Common.defined com Define.NoDce || Common.defined com Define.DocGen) then Dce.run com main (!full_dce && not !interp);
+		let dce_mode = (try Common.defined_value com Define.Dce with _ -> "no") in
+		if not (!gen_as3 || dce_mode = "no" || Common.defined com Define.DocGen) then Dce.run com main (dce_mode = "full" && not !interp);
 		let type_filters = [
 		let type_filters = [
 			Codegen.check_private_path;
 			Codegen.check_private_path;
 			Codegen.remove_generic_base;
 			Codegen.remove_generic_base;

+ 1 - 1
parser.ml

@@ -991,7 +991,7 @@ let parse ctx code =
 		in
 		in
 		let rec loop (e,p) =
 		let rec loop (e,p) =
 			match e with
 			match e with
-			| EConst (Ident i) -> (try TString (Common.defined_value ctx i) with Not_found -> TNull)
+			| EConst (Ident i) -> (try TString (Common.raw_defined_value ctx i) with Not_found -> TNull)
 			| EConst (String s) -> TString s
 			| EConst (String s) -> TString s
 			| EConst (Int i) -> TFloat (float_of_string i)
 			| EConst (Int i) -> TFloat (float_of_string i)
 			| EConst (Float f) -> TFloat (float_of_string f)
 			| EConst (Float f) -> TFloat (float_of_string f)