(**************************************************************************) (* ___ *) (* ||M|| *) (* ||A|| A project by Andrea Asperti *) (* ||T|| *) (* ||I|| Developers: *) (* ||T|| The HELM team. *) (* ||A|| http://helm.cs.unibo.it *) (* \ / *) (* \ / This file is distributed under the terms of the *) (* v GNU General Public License Version 2 *) (* *) (**************************************************************************) include "ERTL/ERTL.ma". include "ERTLptr/ERTLptr.ma". include "joint/TranslateUtils.ma". definition seq_embed : ∀globals.(joint_seq ERTL globals) → (joint_seq ERTLptr globals) ≝ λglobals,s. match s with [COMMENT s ⇒ COMMENT ERTLptr … s |MOVE a ⇒ MOVE ERTLptr … a |POP a ⇒ POP ERTLptr … a |PUSH a ⇒ PUSH ERTLptr … a |ADDRESS i H reg1 reg2 ⇒ ADDRESS ERTLptr … i H reg1 reg2 |OPACCS op reg1 reg2 reg3 reg4 ⇒ OPACCS ERTLptr … op reg1 reg2 reg3 reg4 |OP1 op reg1 reg2 ⇒ OP1 ERTLptr … op reg1 reg2 |OP2 op reg1 reg2 arg ⇒ OP2 ERTLptr … op reg1 reg2 arg |CLEAR_CARRY ⇒ CLEAR_CARRY ERTLptr ? |SET_CARRY ⇒ SET_CARRY ERTLptr ? |LOAD reg1 reg2 reg3 ⇒ LOAD ERTLptr … reg1 reg2 reg3 |STORE arg1 arg2 reg ⇒ STORE ERTLptr … arg1 arg2 reg |extension_seq s ⇒ extension_seq ERTLptr … (ertlptr_ertl s) ]. definition translate_step: ∀globals. label →joint_step ERTL globals →bind_step_block ERTLptr globals ≝ λglobals.λl.λs. match s return λ_.bind_step_block ERTLptr globals with [ CALL called args dest ⇒ match called return λ_.bind_step_block ERTLptr globals with [inl id ⇒ bret … 〈[ ], λ_.CALL ERTLptr ? (inl … id) args dest, [ ]〉 |inr dest1 ⇒ νreg in bret ? (step_block ERTLptr globals) 〈[λl.(LOW_ADDRESS reg l : joint_seq ??); λ_.PUSH ERTLptr … (Reg … reg); λl.HIGH_ADDRESS reg l; λ_.PUSH ERTLptr … (Reg … reg)], λ_.CALL ERTLptr ? (inr … dest1) args dest, [ ]〉 ] |COST_LABEL c ⇒ bret … 〈[ ], λ_.COST_LABEL ERTLptr … c, [ ]〉 | COND reg l ⇒ bret … 〈[ ], λ_.COND ERTLptr ? reg l, [ ]〉 | step_seq x ⇒ bret … [seq_embed … x] ]. definition fin_step_embed: joint_fin_step ERTL → joint_fin_step ERTLptr ≝ λs. match s with [GOTO l ⇒ GOTO ERTLptr … l |RETURN ⇒ RETURN ERTLptr |TAILCALL H arg arg' ⇒ TAILCALL ERTLptr … H arg arg' ]. definition translate_fin_step: ∀globals. label →joint_fin_step ERTL →bind_fin_block ERTLptr globals ≝ λglobals.λl.λs.bret … 〈[ ], fin_step_embed … s〉. definition translate_data : ∀globals.joint_closed_internal_function ERTL globals → bind_new register (b_graph_translate_data ERTL ERTLptr globals) ≝ λglobals,def.bret … (mk_b_graph_translate_data … (* init_ret ≝ *) (joint_if_result … def) (* init_params ≝ *) (joint_if_params … def) (* init_stack_size ≝ *) (joint_if_stacksize … def) (* added_prologue ≝ *) [ ] (* new_regs ≝ *) [ ] (* f_step ≝ *) (translate_step globals) (* f_fin ≝ *) (translate_fin_step globals) ????). @hide_prf [ #l * [ #c' | * #f #args #dest | #a #ltrue | #s ] #c whd [3: #r1 ] #l' #EQ destruct try % cases s in EQ; whd in match ensure_step_block; normalize nodelta try #a try #b try #c try #d try #e try #f destruct | #l #c % ] #l * [ #l' whd %{I} %{I} %{I} %2 % % | whd %{I} %{I I} | #abs #called #args whd %{I} %{I I} | #c #l' whd %{I} %{I} %{I} % | * #called #args #dest whd in match translate_step; normalize nodelta whd [ #l' %{I} %{I} %{I} % | #r #l' whd %{I} % [2: whd %{I} whd in match step_forall_registers; normalize nodelta whd in match step_registers; whd in match get_used_registers_from_step; normalize nodelta normalize cases(\fst called) [#r1 | #b1] normalize nodelta cases(\snd called) [1,3: #r2 |*: #b2 ] normalize nodelta /2 by All_mp, I/ % // [1,3,4: %2 % %] % [%2 %2 % %] % | % [2: % [2: % [2: %{I} ]]] % try @I %{I} %1 % ] ] | #a #l_true whd #l %{I} %{I} % %{I} [ %2 ] %1 % | #s whd #l %{I} %{I} whd % [ @(All_mp … (In ? (step_labels … s))) [ #l' #H %2{H} ] cases s -s // ] cut (∀X,l1,l2.l1 = l2 → All X (In X l1) l2) [ #X #l1 #l2 #EQ destruct elim l2 [ % ] #hd #tl #IH % [ %1 % ] @(All_mp … IH) #x #H %2{H} ] #aux @aux cases s // ] qed. definition ertl_to_ertlptr: ertl_program → ertlptr_program ≝ b_graph_transform_program ERTL ERTLptr translate_data. % qed.