diff --git a/Deliverables/D2.2/8051/src/acc.ml b/Deliverables/D2.2/8051/src/acc.ml index 0a95ef0..56d0cb9 100644 --- a/Deliverables/D2.2/8051/src/acc.ml +++ b/Deliverables/D2.2/8051/src/acc.ml @@ -27,18 +27,20 @@ let process filename = let tgt_language = Options.get_target_language () in let is_lustre_file = Options.is_lustre_file () in let remove_lustre_externals = Options.is_remove_lustre_externals () in - let input_ast = - Languages.parse ~is_lustre_file ~remove_lustre_externals - src_language filename in - let input_ast = Languages.add_runtime input_ast in - let input_ast = Languages.labelize input_ast in let (exact_output, output_filename) = match Options.get_output_files () with | None -> (false, filename) | Some filename' -> (true, filename') in - let save ?(suffix="") ast = - Languages.save + let save ?(suffix="") ?(matita=false) ast = + Languages.save ~matita (Options.is_asm_pretty ()) exact_output output_filename suffix ast in + let input_ast = + Languages.parse ~is_lustre_file ~remove_lustre_externals + src_language filename in + if tgt_language = Languages.Clight && + Options.is_matita_output_enabled () then save ~matita:true input_ast; + let input_ast = Languages.add_runtime input_ast in + let input_ast = Languages.labelize input_ast in let target_asts = (** If debugging is enabled, the compilation function returns all the intermediate programs. *) @@ -49,6 +51,8 @@ let process filename = in let final_ast, intermediate_asts = Misc.ListExt.cut_last target_asts in save final_ast; + if tgt_language <> Languages.Clight && + Options.is_matita_output_enabled () then save ~matita:true final_ast; if Options.annotation_requested () then begin let (annotated_input_ast, cost_id, cost_incr, extern_cost_variables) = @@ -59,8 +63,11 @@ let process filename = extern_cost_variables); end; - if Options.is_debug_enabled () then + if Options.is_debug_enabled () then begin List.iter save intermediate_asts; + if Options.is_matita_output_enabled () then + List.iter (save ~matita:true) intermediate_asts + end; if Options.interpretations_requested () then begin diff --git a/Deliverables/D2.2/8051/src/clight/clightFromC.ml b/Deliverables/D2.2/8051/src/clight/clightFromC.ml index 0b54437..1c84dca 100644 --- a/Deliverables/D2.2/8051/src/clight/clightFromC.ml +++ b/Deliverables/D2.2/8051/src/clight/clightFromC.ml @@ -272,6 +272,8 @@ let ezero = Expr(Econst_int(0), Tint(I32, AST.Signed)) let rec convertExpr env e = let ty = convertTyp env e.etyp in match e.edesc with + | C.EConst(C.CInt(i, _, _)) when i = Int64.zero && ty = Tpointer Tvoid -> + Expr(Ecast (ty, Expr (Econst_int 0, Tint (I8, AST.Unsigned))), ty) | C.EConst(C.CInt(i, _, _)) -> Expr(Econst_int( convertInt i), ty) | C.EConst(C.CFloat(f, _, _)) -> diff --git a/Deliverables/D2.2/8051/src/driver.ml b/Deliverables/D2.2/8051/src/driver.ml index 759eafd..e0bfd69 100644 --- a/Deliverables/D2.2/8051/src/driver.ml +++ b/Deliverables/D2.2/8051/src/driver.ml @@ -4,9 +4,9 @@ module DataSize32 = struct - let alignment = Some 4 + let alignment = Some 1 let int_size = 4 - let ptr_size = 4 + let ptr_size = 2 end (* The target architecture: the Intel 8051. *) diff --git a/Deliverables/D2.2/8051/src/languages.ml b/Deliverables/D2.2/8051/src/languages.ml index 3048d99..ef7b876 100644 --- a/Deliverables/D2.2/8051/src/languages.ml +++ b/Deliverables/D2.2/8051/src/languages.ml @@ -257,7 +257,26 @@ let string_output asm_pretty = function else ["Pretty print not requested"]) @ [ASMPrinter.print_program p] -let save asm_pretty exact_output filename suffix ast = +let string_output_matita = function + | AstClight p -> + [ClightPrintMatita.print_program p] + | AstCminor p -> + [CminorMatitaPrinter.print_program p] + | AstRTLabs p -> + [RTLabsPrinter.print_program p] + (*[RTLabsMatitaPrinter.print_program p]*) + | AstRTL p -> + [RTLPrinter.print_program p] + | AstERTL p -> + [ERTLPrinter.print_program p] + | AstLTL p -> + [LTLPrinter.print_program p] + | AstLIN p -> + [LINPrinter.print_program p] + | AstASM p -> + [Pretty.print_program p ; ASMPrinter.print_program p] + +let save asm_pretty ?(matita=false) exact_output filename suffix ast = let ext_chopped_filename = if exact_output then filename else @@ -265,12 +284,16 @@ let save asm_pretty exact_output filename suffix ast = with Invalid_argument ("Filename.chop_extension") -> filename in let ext_chopped_filename = ext_chopped_filename ^ suffix in let ext_filenames = - List.map (fun ext -> ext_chopped_filename ^ "." ^ ext) + List.map (fun ext -> + if matita then ext_chopped_filename ^ "." ^ ext ^ ".ma" + else ext_chopped_filename ^ "." ^ ext) (extension (language_of_ast ast)) in let output_filenames = if exact_output then ext_filenames else List.map Misc.SysExt.alternative ext_filenames in - let output_strings = string_output asm_pretty ast in + let output_strings = + if matita then string_output_matita ast + else string_output asm_pretty ast in let f filename s = let cout = open_out filename in output_string cout s; diff --git a/Deliverables/D2.2/8051/src/languages.mli b/Deliverables/D2.2/8051/src/languages.mli index 26b5a0f..121c53f 100644 --- a/Deliverables/D2.2/8051/src/languages.mli +++ b/Deliverables/D2.2/8051/src/languages.mli @@ -90,7 +90,7 @@ val interpret : bool -> ast -> AST.trace whose extension is deduced from the language of the AST. If [exact_output] is false then the written file will be fresh. If [asm_pretty] is true, then an additional pretty-printed assembly file is output. *) -val save : bool -> bool -> string -> string -> ast -> unit +val save : bool -> ?matita:bool -> bool -> string -> string -> ast -> unit (** [save_cost exact_name filename cost_id cost_incr extern_cost_variables] prints the name [cost_id] of the cost variable, then the name [cost_incr] of diff --git a/Deliverables/D2.2/8051/src/options.ml b/Deliverables/D2.2/8051/src/options.ml index 77a7735..b4a2d05 100644 --- a/Deliverables/D2.2/8051/src/options.ml +++ b/Deliverables/D2.2/8051/src/options.ml @@ -98,6 +98,9 @@ let set_lustre_test_max_int = (:=) lustre_test_max_int let get_lustre_test_max_int () = !lustre_test_max_int +let matita_flag = ref false +let is_matita_output_enabled () = !matita_flag + (* let print_result_flag = ref false let set_print_result = (:=) print_result_flag @@ -233,4 +236,7 @@ let options = OptionsParsing.register [ "-dev", Arg.Set dev_test, " Playground for developers."; + + "-m", Arg.Set matita_flag, + " Output matita term (when available)."; ] diff --git a/Deliverables/D2.2/8051/src/options.mli b/Deliverables/D2.2/8051/src/options.mli index 2f75755..3af36c9 100644 --- a/Deliverables/D2.2/8051/src/options.mli +++ b/Deliverables/D2.2/8051/src/options.mli @@ -75,3 +75,6 @@ val is_print_result_enabled : unit -> bool (** {2 Developers' playground} *) val is_dev_test_enabled : unit -> bool + +(** {2 Output matita term when available} *) +val is_matita_output_enabled : unit -> bool