include "Clight/label.ma". include "Clight/SimplifyCasts.ma". include "Clight/switchRemoval.ma". include "Clight/toCminor.ma". include "Cminor/initialisation.ma". include "Cminor/toRTLabs.ma". definition front_end : clight_program → res (clight_program × RTLabs_program) ≝ λp. let p' ≝ clight_label p in let p ≝ simplify_program p' in let p ≝ program_switch_removal p in ! p ← clight_to_cminor p; ! p ← cminor_to_rtlabs p; return 〈p',p〉. include "RTLabs/RTLabsToRTL.ma". include "RTL/RTLToERTL.ma". include "ERTL/ERTLToLTL.ma". include "LTL/LTLToLIN.ma". include "LIN/LINToASM.ma". axiom the_fixpoint : fixpoint. axiom build : ∀valuation. coloured_graph valuation. definition back_end : RTLabs_program → pseudo_assembly_program ≝ λp. let p ≝ rtlabs_to_rtl p in let p ≝ rtl_to_ertl p in let p ≝ ertl_to_ltl p in (* TODO: abstract over colouring *) let p ≝ ltl_to_lin p in lin_to_asm p. include "ASM/Assembly.ma". include "ASM/Policy.ma". axiom Jump_expansion_failed : String. include "ASM/ASMCostsSplit.ma". definition assembler : pseudo_assembly_program → res (object_code × costlabel_map) ≝ λp. let 〈preamble, list_instr〉 ≝ p in (* TODO: fail if p is too large. *) let p' ≝ 〈preamble, list_instr〉 in ! sigma_pol ← opt_to_res ? (msg Jump_expansion_failed) (jump_expansion' p'); let sigma ≝ λppc. \fst (sigma_pol ppc) in let pol ≝ λppc. \snd (sigma_pol ppc) in OK ? (assembly p sigma pol). cases daemon qed. include "RTLabs/semantics.ma". axiom RTLabs_abstract_status : genv → abstract_status. include "joint/semantics.ma". axiom joint_abstract_status : ∀globals.∀p:params globals.genv globals p → abstract_status. include "common/StructuredTraces.ma". include "ASM/Fetch.ma". (* For load_code_memory only *) definition in_clight_program : costlabel → Prop ≝ λ_.True. definition lift_cost_map_back_to_front : ∀code_memory, lbls. (∀l. (∃pc.as_label_of_pc (ASM_abstract_status code_memory lbls) pc = Some … l) + ¬(∃pc.as_label_of_pc (ASM_abstract_status code_memory lbls) pc = Some … l)) → as_cost_map (ASM_abstract_status code_memory lbls) → (Σl : costlabel.in_clight_program l) → ℕ ≝ λcode_memory,lbls,dec,k,l_sig. match dec l_sig with [ inl prf ⇒ k «l_sig, prf» | inr _ ⇒ 0 (* labels not present in out code get 0 *) ]. definition compile : clight_program → res (object_code × costlabel_map × clight_program × ((Σl.in_clight_program l) → ℕ)) ≝ λp. ! 〈p',p〉 ← front_end p; let p ≝ back_end p in ! p ← assembler p; let k ≝ ASM_cost_map p ? in let k' ≝ lift_cost_map_back_to_front (load_code_memory (\fst p)) (\snd p) ? k in return 〈p, p', k'〉. cases daemon qed.