include "joint/Joint.ma". inductive move_dst: Type[0] ≝ | PSD: register → move_dst | HDW: Register → move_dst. definition move_src ≝ argument move_dst. definition move_src_from_dst : move_dst → move_src ≝ Reg move_dst. coercion move_dst_to_src : ∀r : move_dst.move_src ≝ move_src_from_dst on _r : move_dst to move_src. definition psd_argument_move_src : psd_argument → move_src ≝ λarg.match arg with [ Imm b ⇒ Imm ? b | Reg r ⇒ Reg ? (PSD r) ]. coercion psd_argument_to_move_src : ∀a:psd_argument.move_src ≝ psd_argument_move_src on _a : psd_argument to move_src. inductive ertl_seq : Type[0] ≝ | ertl_new_frame: ertl_seq | ertl_del_frame: ertl_seq | ertl_frame_size: register → ertl_seq. definition ERTL_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 ≝ *) (move_dst × move_src) (* call_args ≝ *) ℕ (* call_dest ≝ *) unit (* ext_seq ≝ *) ertl_seq (* ext_seq_labels ≝ *) (λ_.[]) (* has_tailcall ≝ *) false (* paramsT ≝ *) ℕ. definition regs_from_move_dst : move_dst → list register ≝ λm. match m with [PSD r ⇒ [r] | HDW _ ⇒ [ ] ]. definition regs_from_move_src : move_src → list register ≝ λm. match m with [Imm _ ⇒ [ ] | Reg r ⇒ match r with [PSD r1 ⇒ [r1] | HDW _ ⇒ [ ] ] ]. definition ertl_ext_seq_regs : ertl_seq → list register ≝ λs.match s with [ertl_frame_size r ⇒ [r] | _ ⇒ [ ]]. definition ERTL_functs ≝ mk_get_pseudo_reg_functs ERTL_uns (* acc_a_regs *) (λr.[r]) (* acc_b_regs *) (λr.[r]) (* acc_a_args *) (λarg.match arg with [ Imm _ ⇒ [ ] | Reg r ⇒ [r]]) (* acc_b_args *) (λarg.match arg with [ Imm _ ⇒ [ ] | Reg r ⇒ [r]]) (* dpl_regs *) (λr.[r]) (* dph_regs *) (λr.[r]) (* dpl_args *) (λarg.match arg with [ Imm _ ⇒ [ ] | Reg r ⇒ [r]]) (* dph_args *) (λarg.match arg with [ Imm _ ⇒ [ ] | Reg r ⇒ [r]]) (* snd_args *) (λarg.match arg with [ Imm _ ⇒ [ ] | Reg r ⇒ [r]]) (* pair_move_regs *) (λx.(regs_from_move_dst (\fst x)) @ (regs_from_move_src (\snd x))) (* f_call_args *) (λ_.[ ]) (* f_call_dest *) (λ_.[ ]) (* ext_seq_regs *) ertl_ext_seq_regs (* params_regs *) (λ_.[ ]). definition ERTL ≝ mk_graph_params (mk_uns_params ERTL_uns ERTL_functs). definition ertl_program ≝ joint_program ERTL. unification hint 0 ≔ ⊢ ertl_program ≡ joint_program ERTL. interpretation "move" 'mov r a = (MOVE ?? (mk_Prod move_dst move_src r a)). (* aid unification *) unification hint 0 ≔ (*---------------*) ⊢ pair_move ERTL ≡ move_dst × move_src. unification hint 0 ≔ (*---------------*) ⊢ acc_a_reg ERTL ≡ register. unification hint 0 ≔ (*---------------*) ⊢ acc_b_reg ERTL ≡ register. unification hint 0 ≔ (*---------------*) ⊢ acc_a_arg ERTL ≡ psd_argument. unification hint 0 ≔ (*---------------*) ⊢ acc_b_arg ERTL ≡ psd_argument. unification hint 0 ≔ (*---------------*) ⊢ dpl_reg ERTL ≡ register. unification hint 0 ≔ (*---------------*) ⊢ dph_reg ERTL ≡ register. unification hint 0 ≔ (*---------------*) ⊢ dpl_arg ERTL ≡ psd_argument. unification hint 0 ≔ (*---------------*) ⊢ dph_arg ERTL ≡ psd_argument. unification hint 0 ≔ (*---------------*) ⊢ snd_arg ERTL ≡ psd_argument. unification hint 0 ≔ (*---------------*) ⊢ call_args ERTL ≡ ℕ. unification hint 0 ≔ (*---------------*) ⊢ call_dest ERTL ≡ unit. unification hint 0 ≔ (*---------------*) ⊢ ext_seq ERTL ≡ ertl_seq. coercion reg_to_ertl_snd_argument : ∀r : register.snd_arg ERTL ≝ psd_argument_from_reg on _r : register to snd_arg ERTL. coercion byte_to_ertl_snd_argument : ∀b : Byte.snd_arg ERTL ≝ psd_argument_from_byte on _b : Byte to snd_arg ERTL. definition ertl_seq_joint ≝ extension_seq ERTL. coercion ertl_seq_to_joint_seq : ∀globals.∀s : ertl_seq.joint_seq ERTL globals ≝ ertl_seq_joint on _s : ertl_seq to joint_seq ERTL ?. definition ERTL_premain : ∀p : ertl_program.joint_closed_internal_function ERTL (prog_var_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 res ≝ mk_joint_internal_function ERTL (prog_var_names … p) (mk_universe … (p0 (p0 one))) (mk_universe … one) it 4 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 ERTL ? (inl … (prog_main … p)) 0 it) 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 @I | %{l2} %{(init_cost_label … p)} % ] qed.