ソースを参照

defined "dce" and reactivated as3 unit tests (with DCE disabled)

Simon Krajewski 13 年 前
コミット
61f3c39e6c
6 ファイル変更14 行追加14 行削除
  1. 1 3
      common.ml
  2. 5 4
      main.ml
  3. 2 0
      tests/unit/Test.hx
  4. 4 5
      tests/unit/unit.hxml
  5. 1 1
      typeload.ml
  6. 1 1
      typer.ml

+ 1 - 3
common.ml

@@ -96,7 +96,6 @@ type context = {
 	mutable debug : bool;
 	mutable verbose : bool;
 	mutable foptimize : bool;
-	mutable dead_code_elimination : bool;
 	mutable platform : platform;
 	mutable config : platform_config;
 	mutable std_path : string list;
@@ -283,7 +282,6 @@ let create v args =
 		verbose = false;
 		foptimize = true;
 		features = Hashtbl.create 0;
-		dead_code_elimination = false;
 		platform = Cross;
 		config = default_config;
 		print = print_string;
@@ -411,7 +409,7 @@ let rec has_feature com f =
 			let r = (try
 				let path = List.rev pack, cl in
 				(match List.find (fun t -> t_path t = path && not (has_meta ":realPath" (t_infos t).mt_meta)) com.types with
-				| t when meth = "*" -> (not com.dead_code_elimination) || has_meta ":used" (t_infos t).mt_meta
+				| t when meth = "*" -> not (defined com "dce") || has_meta ":used" (t_infos t).mt_meta
 				| TClassDecl c -> PMap.exists meth c.cl_statics || PMap.exists meth c.cl_fields
 				| _ -> false)
 			with Not_found ->

+ 5 - 4
main.ml

@@ -535,7 +535,7 @@ and wait_loop boot_com host port =
 		in
 		try
 			let m = Hashtbl.find cache.c_modules (mpath,sign) in
-			if com2.dead_code_elimination then raise Not_found;
+			if Common.defined com2 "dce" then raise Not_found;
 			if not (check m) then begin
 				if verbose then print_endline ("Skipping cached module " ^ Ast.s_type_path mpath ^ (match !dep with None -> "" | Some m -> "(" ^ Ast.s_type_path m.m_path ^ ")"));
 				raise Not_found;
@@ -566,7 +566,7 @@ and wait_loop boot_com host port =
 				read_loop()
 		in
 		let rec cache_context com =
-			if not com.dead_code_elimination && not com.display then begin
+			if not (Common.defined com "dce") && not com.display then begin
 				List.iter cache_module com.modules;
 				if verbose then print_endline ("Cached " ^ string_of_int (List.length com.modules) ^ " modules");
 			end;
@@ -740,6 +740,7 @@ try
 			gen_as3 := true;
 			Common.define com "as3";
 			Common.define com "no_inline";
+			if defined com "dce" then com.defines <- PMap.remove "dce" com.defines;		
 		),"<directory> : generate AS3 code into target directory");
 		("-neko",Arg.String (set_platform Neko),"<file> : compile code to Neko Binary");
 		("-php",Arg.String (fun dir ->
@@ -905,7 +906,7 @@ try
 			config_macros := e :: !config_macros
 		)," : call the given macro before typing anything else");
 		("--dead-code-elimination", Arg.Unit (fun () ->
-			com.dead_code_elimination <- true;
+			if not (Common.defined com "as3") then Common.define com "dce"
 		)," : remove unused methods");
 		("--wait", Arg.String (fun hp ->
 			let host, port = (try ExtString.String.split hp ":" with _ -> "127.0.0.1", hp) in
@@ -1026,7 +1027,7 @@ try
 		end;
 		let t = Common.timer "filters" in
 		let main, types, modules = Typer.generate tctx in
-		let types,modules = if ctx.com.dead_code_elimination then Dce.run tctx main types modules else types,modules in
+		let types,modules = if Common.defined ctx.com "dce" then Dce.run tctx main types modules else types,modules in
 		com.main <- main;
 		com.types <- types;
 		com.modules <- modules;

+ 2 - 0
tests/unit/Test.hx

@@ -205,7 +205,9 @@ package unit;
 			#if java
 			new TestJava(),
 			#end
+			#if dce
 			new TestDCE(),
+			#end
 			//new TestUnspecified(),
 			//new TestRemoting(),
 		];

+ 4 - 5
tests/unit/unit.hxml

@@ -51,13 +51,12 @@ unit.Test
 -php php
 
 #as3
-#--next
-#-main unit.Test
-#-as3 as3
-#-cmd mxmlc -static-link-runtime-shared-libraries=true -debug as3/__main__.as --output unit9_as3.swf
+--next
+-main unit.Test
+-as3 as3
+-cmd mxmlc -static-link-runtime-shared-libraries=true -debug as3/__main__.as --output unit9_as3.swf
 
 #cpp
-
 --next
 -main unit.Test
 -cpp cpp

+ 1 - 1
typeload.ml

@@ -865,7 +865,7 @@ let init_class ctx c p herits fields =
 		c.cl_extern <- true;
 		List.filter (fun f -> List.mem AStatic f.cff_access) fields, []
 	end else fields, herits in
-	if core_api && not (ctx.com.display || ctx.com.dead_code_elimination) then delay ctx (fun() -> init_core_api ctx c);
+	if core_api && not (ctx.com.display || Common.defined ctx.com "dce") then delay ctx (fun() -> init_core_api ctx c);
 	let tthis = TInst (c,List.map snd c.cl_types) in
 	let rec extends_public c =
 		List.exists (fun (c,_) -> c.cl_path = (["haxe"],"Public") || extends_public c) c.cl_implements ||

+ 1 - 1
typer.ml

@@ -2769,13 +2769,13 @@ let get_macro_context ctx p =
 		com2.package_rules <- PMap.empty;
 		com2.main_class <- None;
 		com2.display <- false;
-		com2.dead_code_elimination <- false;
 		List.iter (fun p -> com2.defines <- PMap.remove (platform_name p) com2.defines) platforms;
 		com2.defines_signature <- None;
 		com2.class_path <- List.filter (fun s -> not (ExtString.String.exists s "/_std/")) com2.class_path;
 		com2.class_path <- List.map (fun p -> p ^ "neko" ^ "/_std/") com2.std_path @ com2.class_path;
 		com2.defines <- PMap.foldi (fun k _ acc ->
 			match k with
+			| "dce"
 			| "no_traces" -> acc
 			| _ when List.exists (fun (_,d) -> "flash" ^ d = k) Common.flash_versions -> acc
 			| _ -> PMap.add k () acc