include "joint/Joint.ma". inductive rtl_seq : Type[0] ≝ | rtl_stack_address: register → register → rtl_seq. definition RTL_uns ≝ mk_unserialized_params (* acc_a_reg ≝ *) register (* acc_b_reg ≝ *) register (* acc_a_arg ≝ *) psd_argument (* acc_b_arg ≝ *) psd_argument (* dpl_reg ≝ *) register (* dph_reg ≝ *) register (* dpl_arg ≝ *) psd_argument (* dph_arg ≝ *) psd_argument (* snd_arg ≝ *) psd_argument (* pair_move ≝ *) (register × psd_argument) (* call_args ≝ *) (list psd_argument) (* call_dest ≝ *) (list register) (* ext_seq ≝ *) rtl_seq (* ext_seq_labels ≝ *) (λ_.[]) (* has_tailcalls ≝ *) false (* paramsT ≝ *) (list register). definition RTL_functs ≝ mk_get_pseudo_reg_functs RTL_uns (* acc_a_regs *) (λr.[r]) (* acc_b_regs *) (λr.[r]) (* acc_a_args *) (λa. match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]]) (* acc_b_args *) (λa. match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]]) (* dpl_regs *) (λr.[r]) (* dph_regs *) (λr.[r]) (* dpl_args *) (λa. match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]]) (* dph_args *) (λa. match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]]) (* snd_args *) (λa. match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]]) (* pair_move_regs *) (λx.[\fst x] @ (match \snd x with [Reg r ⇒ [r] |Imm _ ⇒ [ ]])) (* f_call_args *) (λl.foldl ?? (λl1.λa.l1@(match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]])) [ ] l) (* f_call_dest *) (λx.x) (* ext_seq_regs *) (λext.match ext with [rtl_stack_address r1 r2 ⇒ [r1;r2]]) (* params_regs *) (λx.x). definition RTL ≝ mk_graph_params (mk_uns_params RTL_uns RTL_functs). definition rtl_program ≝ joint_program RTL. unification hint 0 ≔ ⊢ rtl_program ≡ joint_program RTL. interpretation "move" 'mov r a = (MOVE RTL ? (mk_Prod ? psd_argument r a)). (* aid unification *) include "hints_declaration.ma". unification hint 0 ≔ (*---------------*) ⊢ acc_a_reg RTL ≡ register. unification hint 0 ≔ (*---------------*) ⊢ acc_b_reg RTL ≡ register. unification hint 0 ≔ (*---------------*) ⊢ acc_a_arg RTL ≡ psd_argument. unification hint 0 ≔ (*---------------*) ⊢ acc_b_arg RTL ≡ psd_argument. unification hint 0 ≔ (*---------------*) ⊢ dpl_reg RTL ≡ register. unification hint 0 ≔ (*---------------*) ⊢ dph_reg RTL ≡ register. unification hint 0 ≔ (*---------------*) ⊢ dpl_arg RTL ≡ psd_argument. unification hint 0 ≔ (*---------------*) ⊢ dph_arg RTL ≡ psd_argument. unification hint 0 ≔ (*---------------*) ⊢ snd_arg RTL ≡ psd_argument. unification hint 0 ≔ (*---------------*) ⊢ pair_move RTL ≡ register × psd_argument. unification hint 0 ≔ (*---------------*) ⊢ call_args RTL ≡ list psd_argument. unification hint 0 ≔ (*---------------*) ⊢ call_dest RTL ≡ list register. unification hint 0 ≔ (*---------------*) ⊢ ext_seq RTL ≡ rtl_seq. coercion reg_to_rtl_snd_argument : ∀r : register.snd_arg RTL ≝ psd_argument_from_reg on _r : register to snd_arg RTL. coercion byte_to_rtl_snd_argument : ∀b : Byte.snd_arg RTL ≝ psd_argument_from_byte on _b : Byte to snd_arg RTL. (* parameters for main need to be passed to the premain *) definition RTL_premain : ∀p : rtl_program. joint_closed_internal_function RTL (prog_names … p) ≝ λp. let l1 : label ≝ an_identifier … one in let l2 : label ≝ an_identifier … (p0 one) in let l3 : label ≝ an_identifier … (p1 one) in let rs : list register ≝ [ an_identifier … one ; an_identifier … (p0 one) ; an_identifier … (p1 one) ; an_identifier … (p0 (p0 one)) ] in let res ≝ mk_joint_internal_function RTL (prog_names … p) (mk_universe … (p0 (p0 one))) (mk_universe … (p1 (p0 one))) [ ] rs 0 0 (empty_map …) l1 in (* todo: args for main? *) let res ≝ add_graph … l1 (sequential … (COST_LABEL … (init_cost_label … p)) l2) res in let res ≝ add_graph … l2 (sequential … (CALL RTL ? (inl … (prog_main … p)) [ ] rs) l3) res in let res ≝ add_graph … l3 (GOTO ? l3) res in res. % [ ** [2,3: * [2,3,5,6: #p ]] #s whd in ⊢ (??%?→?); #EQ destruct % [1,3,5: %{I} % whd in ⊢ (??%(??%)→?); #EQ destruct |2: % |4,6: % whd in ⊢ (??%%→?); #EQ destruct ] | ** [2,3: * [2,3,5,6: #p ]] #s whd in ⊢ (??%?→?); #EQ destruct % try @I %{I I} | ** [2,3: * [2,3,5,6: #p ]] * whd whd in ⊢ (?%%); // | ** [2,3: * [2,3,5,6: #p ]] #s whd in ⊢ (??%%→?); #EQ destruct try @I try % try % try % try % try % whd /2 by double_lt3/ | %{l2} %{(init_cost_label … p)} % ] qed.