source: src/RTL/RTL.ma

Last change on this file was 3263, checked in by tranquil, 7 years ago

moved callee saved saving and restoring to ERTL -> LTL pass (untrusted
colourer and interference graph creator still need to be updated)
joint now has the stack size split in three (referenced locals, params
and spilled)

File size: 4.5 KB
Line 
1include "joint/Joint.ma".
2
3inductive rtl_seq : Type[0] ≝
4  | rtl_stack_address: register → register → rtl_seq.
5 
6definition RTL_uns ≝ mk_unserialized_params
7    (* acc_a_reg ≝ *) register
8    (* acc_b_reg ≝ *) register
9    (* acc_a_arg ≝ *) psd_argument
10    (* acc_b_arg ≝ *) psd_argument
11    (* dpl_reg   ≝ *) register
12    (* dph_reg   ≝ *) register
13    (* dpl_arg   ≝ *) psd_argument
14    (* dph_arg   ≝ *) psd_argument
15    (* snd_arg   ≝ *) psd_argument
16    (* pair_move ≝ *) (register × psd_argument)
17    (* call_args ≝ *) (list psd_argument)
18    (* call_dest ≝ *) (list register)
19    (* ext_seq ≝ *) rtl_seq
20    (* ext_seq_labels ≝ *) (λ_.[])
21    (* has_tailcalls ≝ *) false
22    (* paramsT ≝ *) (list register).
23
24definition RTL_functs ≝ mk_get_pseudo_reg_functs RTL_uns
25(* acc_a_regs *) (λr.[r])
26(* acc_b_regs *) (λr.[r])
27(* acc_a_args *) (λa. match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]])
28(* acc_b_args *) (λa. match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]])
29(* dpl_regs *) (λr.[r])
30(* dph_regs *) (λr.[r])
31(* dpl_args *) (λa. match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]])
32(* dph_args *) (λa. match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]])
33(* snd_args *) (λa. match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]])
34(* pair_move_regs *) (λx.[\fst x] @ (match \snd x with [Reg r ⇒ [r] |Imm _ ⇒ [ ]]))
35(* f_call_args *) (λl.foldl ?? (λl1.λa.l1@(match a with [Reg r ⇒ [r] |Imm _ ⇒ [ ]])) [ ] l)
36(* f_call_dest *) (λx.x)
37(* ext_seq_regs *) (λext.match ext with [rtl_stack_address r1 r2 ⇒ [r1;r2]])
38(* params_regs *) (λx.x).
39
40definition RTL ≝ mk_graph_params (mk_uns_params RTL_uns RTL_functs).
41definition rtl_program ≝ joint_program RTL.
42unification hint 0 ≔ ⊢ rtl_program ≡ joint_program RTL.
43
44interpretation "move" 'mov r a = (MOVE RTL ? (mk_Prod ? psd_argument r a)).
45
46(* aid unification *)
47include "hints_declaration.ma".
48unification hint 0 ≔
49(*---------------*) ⊢
50acc_a_reg RTL ≡ register.
51unification hint 0 ≔
52(*---------------*) ⊢
53acc_b_reg RTL ≡ register.
54unification hint 0 ≔
55(*---------------*) ⊢
56acc_a_arg RTL ≡ psd_argument.
57unification hint 0 ≔
58(*---------------*) ⊢
59acc_b_arg RTL ≡ psd_argument.
60unification hint 0 ≔
61(*---------------*) ⊢
62dpl_reg RTL ≡ register.
63unification hint 0 ≔
64(*---------------*) ⊢
65dph_reg RTL ≡ register.
66unification hint 0 ≔
67(*---------------*) ⊢
68dpl_arg RTL ≡ psd_argument.
69unification hint 0 ≔
70(*---------------*) ⊢
71dph_arg RTL ≡ psd_argument.
72unification hint 0 ≔
73(*---------------*) ⊢
74snd_arg RTL ≡ psd_argument.
75unification hint 0 ≔
76(*---------------*) ⊢
77pair_move RTL ≡ register × psd_argument.
78unification hint 0 ≔
79(*---------------*) ⊢
80call_args RTL ≡ list psd_argument.
81unification hint 0 ≔
82(*---------------*) ⊢
83call_dest RTL ≡ list register.
84
85unification hint 0 ≔
86(*---------------*) ⊢
87ext_seq RTL ≡ rtl_seq.
88
89coercion reg_to_rtl_snd_argument : ∀r : register.snd_arg RTL ≝ psd_argument_from_reg
90  on _r : register to snd_arg RTL.
91coercion byte_to_rtl_snd_argument : ∀b : Byte.snd_arg RTL ≝ psd_argument_from_byte
92  on _b : Byte to snd_arg RTL.
93
94(* parameters for main need to be passed to the premain *)
95definition RTL_premain : ∀p : rtl_program.
96  joint_closed_internal_function RTL (prog_names … p) ≝
97λp.
98let l1 : label ≝ an_identifier … one in
99let l2 : label ≝ an_identifier … (p0 one) in
100let l3 : label ≝ an_identifier … (p1 one) in
101let rs : list register ≝
102  [ an_identifier … one ;
103    an_identifier … (p0 one) ;
104    an_identifier … (p1 one) ;
105    an_identifier … (p0 (p0 one)) ] in
106let res ≝
107  mk_joint_internal_function RTL (prog_names … p)
108  (mk_universe … (p0 (p0 one)))
109  (mk_universe … (p1 (p0 one)))
110  [ ] rs 0 0 0 (empty_map …) l1 in
111(* todo: args for main? *)
112let res ≝ add_graph … l1
113  (sequential … (COST_LABEL … (init_cost_label … p)) l2)
114  res in
115let res ≝ add_graph … l2
116  (sequential … (CALL RTL ? (inl … (prog_main … p)) [ ] rs) l3)
117  res in
118let res ≝ add_graph … l3
119  (GOTO ? l3)
120  res in
121res.
122%
123[ ** [2,3: * [2,3,5,6: #p ]] #s whd in ⊢ (??%?→?); #EQ destruct
124  %
125  [1,3,5: %{I} % whd in ⊢ (??%(??%)→?); #EQ destruct
126  |2: %
127  |4,6: % whd in ⊢ (??%%→?); #EQ destruct
128  ]
129| ** [2,3: * [2,3,5,6: #p ]] #s whd in ⊢ (??%?→?); #EQ destruct % try @I %{I I}
130| ** [2,3: * [2,3,5,6: #p ]] * whd whd in ⊢ (?%%); //
131| ** [2,3: * [2,3,5,6: #p ]] #s whd in ⊢ (??%%→?); #EQ destruct try @I
132  try % try % try % try % try % whd /2 by double_lt3/
133| %{l2} %{(init_cost_label … p)} %
134]
135qed.
Note: See TracBrowser for help on using the repository browser.