Rudy Ges преди 2 години
родител
ревизия
9eeaa7b0f3
променени са 3 файла, в които са добавени 47 реда и са изтрити 5 реда
  1. 17 4
      src/compiler/args.ml
  2. 1 0
      src/compiler/compilationContext.ml
  3. 29 1
      src/compiler/generate.ml

+ 17 - 4
src/compiler/args.ml

@@ -46,6 +46,7 @@ let parse_args com =
 	let actx = {
 		classes = [([],"Std")];
 		xml_out = None;
+		hxb_out = None;
 		json_out = None;
 		cmds = [];
 		config_macros = [];
@@ -120,14 +121,26 @@ let parse_args com =
 		("Target",["--run"],[], Arg.Unit (fun() ->
 			raise (Arg.Bad "--run requires an argument: a Haxe module name")
 		), "<module> [args...]","interpret a Haxe module with command line arguments");
+		("Target",["--hxb"],[], Arg.String (fun file ->
+			actx.hxb_out <- Some file;
+		),"<file>", "generate haxe binary as target file");
 		("Compilation",["-p";"--class-path"],["-cp"],Arg.String (fun path ->
 			com.class_path <- Path.add_trailing_slash path :: com.class_path
 		),"<path>","add a directory to find source files");
 		("Compilation",["-m";"--main"],["-main"],Arg.String (fun cl ->
 			if com.main_class <> None then raise (Arg.Bad "Multiple --main classes specified");
-			let cpath = Path.parse_type_path cl in
-			com.main_class <- Some cpath;
-			actx.classes <- cpath :: actx.classes
+			begin match Path.file_extension cl with
+			| "hxb" ->
+				actx.pre_compilation <- (fun () ->
+					(* TODO: update hxb runner *)
+					(* HxbRunner.run com cl; *)
+					actx.did_something <- true
+				) :: actx.pre_compilation;
+			| _ ->
+				let cpath = Path.parse_type_path cl in
+				com.main_class <- Some cpath;
+				actx.classes <- cpath :: actx.classes
+			end
 		),"<class>","select startup class");
 		("Compilation",["-L";"--library"],["-lib"],Arg.String (fun _ -> ()),"<name[:ver]>","use a haxelib library");
 		("Compilation",["-D";"--define"],[],Arg.String (fun var ->
@@ -371,4 +384,4 @@ let parse_args com =
 	actx.raise_usage <- (fun () -> raise (Helper.HelpMessage (usage_string basic_args_spec usage)));
 	(* Handle CLI arguments *)
 	process com.args;
-	actx
+	actx

+ 1 - 0
src/compiler/compilationContext.ml

@@ -10,6 +10,7 @@ type server_mode =
 type arg_context = {
 	mutable classes : Globals.path list;
 	mutable xml_out : string option;
+	mutable hxb_out : string option;
 	mutable json_out : string option;
 	mutable cmds : string list;
 	mutable config_macros : string list;

+ 29 - 1
src/compiler/generate.ml

@@ -1,5 +1,24 @@
 open Globals
 open CompilationContext
+open TType
+
+let test_hxb com m =
+	if m.m_extra.m_kind = MCode then begin
+		let ch = IO.output_bytes() in
+		let anon_identification = new Genshared.tanon_identification ([],"") in
+		let writer = new HxbWriter.hxb_writer anon_identification (* cp *) in
+		writer#write_module m;
+		let bytes_module = IO.close_out ch in
+		let ch = IO.output_bytes() in
+		writer#export ch;
+		let bytes_cp = IO.close_out ch in
+		let path = m.m_path in
+		let l = ((Common.dump_path com) :: "hxb" :: (Common.platform_name_macro com) :: fst path @ [snd path]) in
+		let ch_file = Path.create_file true ".hxb" [] l in
+		output_bytes ch_file bytes_cp;
+		output_bytes ch_file bytes_module;
+		close_out ch_file
+	end
 
 let check_auxiliary_output com actx =
 	begin match actx.xml_out with
@@ -17,9 +36,18 @@ let check_auxiliary_output com actx =
 			Common.log com ("Generating json : " ^ file);
 			Path.mkdir_from_path file;
 			Genjson.generate com.types file
+	end;
+	begin match actx.hxb_out with
+		| None -> ()
+		| Some file ->
+				Common.log com ("Generating hxb : " ^ file);
+				Path.mkdir_from_path file;
+				let t = Timer.timer ["generate";"hxb"] in
+				(* HxbWriter.write com file; *)
+				List.iter (test_hxb com) com.modules;
+				t();
 	end
 
-
 let parse_swf_header ctx h = match ExtString.String.nsplit h ":" with
 		| [width; height; fps] ->
 			Some (int_of_string width,int_of_string height,float_of_string fps,0xFFFFFF)