source: src/ERTL/ERTL.ma @ 3037

Last change on this file since 3037 was 3037, checked in by tranquil, 7 years ago
  • ADDRESS joint instruction now has also an offset
  • corrected call to pointer (needed to clear the accumulator)
  • now we make sure globals contain also function names

LINToASM will be fixed in an upcoming commit

File size: 5.2 KB
Line 
1include "joint/Joint.ma".
2
3inductive move_dst: Type[0] ≝
4  | PSD: register → move_dst
5  | HDW: Register → move_dst.
6
7definition move_src ≝ argument move_dst.
8
9definition move_src_from_dst : move_dst → move_src ≝ Reg move_dst.
10coercion move_dst_to_src : ∀r : move_dst.move_src ≝ move_src_from_dst on _r : move_dst to move_src.
11
12definition psd_argument_move_src : psd_argument → move_src ≝
13  λarg.match arg with
14  [ Imm b ⇒ Imm ? b
15  | Reg r ⇒ Reg ? (PSD r)
16  ].
17coercion psd_argument_to_move_src : ∀a:psd_argument.move_src ≝
18  psd_argument_move_src on _a : psd_argument to move_src.
19
20inductive ertl_seq : Type[0] ≝
21  | ertl_new_frame: ertl_seq
22  | ertl_del_frame: ertl_seq
23  | ertl_frame_size: register → ertl_seq.
24
25definition ERTL_uns ≝ mk_unserialized_params
26    (* acc_a_reg ≝ *) register
27    (* acc_b_reg ≝ *) register
28    (* acc_a_arg ≝ *) psd_argument
29    (* acc_b_arg ≝ *) psd_argument
30    (* dpl_reg   ≝ *) register
31    (* dph_reg   ≝ *) register
32    (* dpl_arg   ≝ *) psd_argument
33    (* dph_arg   ≝ *) psd_argument
34    (* snd_arg   ≝ *) psd_argument
35    (* pair_move ≝ *) (move_dst × move_src)
36    (* call_args ≝ *) ℕ
37    (* call_dest ≝ *) unit
38    (* ext_seq ≝ *) ertl_seq
39    (* ext_seq_labels ≝ *) (λ_.[])
40    (* has_tailcall ≝ *) false
41    (* paramsT ≝ *) ℕ.
42
43definition regs_from_move_dst : move_dst → list register ≝
44λm. match m with [PSD r ⇒ [r] | HDW _ ⇒ [ ] ].
45
46definition regs_from_move_src : move_src → list register ≝
47λm. match m with [Imm _ ⇒ [ ] | Reg r ⇒ match r with [PSD r1 ⇒ [r1] | HDW _ ⇒ [ ] ] ].
48
49definition ertl_ext_seq_regs : ertl_seq → list register ≝
50λs.match s with [ertl_frame_size r ⇒ [r] | _ ⇒ [ ]].
51
52definition ERTL_functs ≝ mk_get_pseudo_reg_functs ERTL_uns
53(* acc_a_regs *) (λr.[r])
54(* acc_b_regs *) (λr.[r])
55(* acc_a_args *) (λarg.match arg with [ Imm _ ⇒ [ ] | Reg r ⇒ [r]])
56(* acc_b_args *) (λarg.match arg with [ Imm _ ⇒ [ ] | Reg r ⇒ [r]])
57(* dpl_regs *) (λr.[r])
58(* dph_regs *) (λr.[r])
59(* dpl_args *) (λarg.match arg with [ Imm _ ⇒ [ ] | Reg r ⇒ [r]])
60(* dph_args *) (λarg.match arg with [ Imm _ ⇒ [ ] | Reg r ⇒ [r]])
61(* snd_args *) (λarg.match arg with [ Imm _ ⇒ [ ] | Reg r ⇒ [r]])
62(* pair_move_regs *) (λx.(regs_from_move_dst (\fst x)) @ (regs_from_move_src (\snd x)))
63(* f_call_args *) (λ_.[ ])
64(* f_call_dest *) (λ_.[ ])
65(* ext_seq_regs *) ertl_ext_seq_regs
66(* params_regs *) (λ_.[ ]).
67
68definition ERTL ≝ mk_graph_params (mk_uns_params ERTL_uns ERTL_functs).
69definition ertl_program ≝ joint_program ERTL.
70unification hint 0 ≔ ⊢ ertl_program ≡ joint_program ERTL.
71
72interpretation "move" 'mov r a = (MOVE ?? (mk_Prod move_dst move_src r a)).
73
74(* aid unification *)
75unification hint 0 ≔
76(*---------------*) ⊢
77pair_move ERTL ≡ move_dst × move_src.
78unification hint 0 ≔
79(*---------------*) ⊢
80acc_a_reg ERTL ≡ register.
81unification hint 0 ≔
82(*---------------*) ⊢
83acc_b_reg ERTL ≡ register.
84unification hint 0 ≔
85(*---------------*) ⊢
86acc_a_arg ERTL ≡ psd_argument.
87unification hint 0 ≔
88(*---------------*) ⊢
89acc_b_arg ERTL ≡ psd_argument.
90unification hint 0 ≔
91(*---------------*) ⊢
92dpl_reg ERTL ≡ register.
93unification hint 0 ≔
94(*---------------*) ⊢
95dph_reg ERTL ≡ register.
96unification hint 0 ≔
97(*---------------*) ⊢
98dpl_arg ERTL ≡ psd_argument.
99unification hint 0 ≔
100(*---------------*) ⊢
101dph_arg ERTL ≡ psd_argument.
102unification hint 0 ≔
103(*---------------*) ⊢
104snd_arg ERTL ≡ psd_argument.
105unification hint 0 ≔
106(*---------------*) ⊢
107call_args ERTL ≡ ℕ.
108unification hint 0 ≔
109(*---------------*) ⊢
110call_dest ERTL ≡ unit.
111
112unification hint 0 ≔
113(*---------------*) ⊢
114ext_seq ERTL ≡ ertl_seq.
115
116coercion reg_to_ertl_snd_argument : ∀r : register.snd_arg ERTL ≝
117  psd_argument_from_reg
118  on _r : register to snd_arg ERTL.
119coercion byte_to_ertl_snd_argument : ∀b : Byte.snd_arg ERTL ≝
120  psd_argument_from_byte
121  on _b : Byte to snd_arg ERTL.
122 
123definition ertl_seq_joint ≝ extension_seq ERTL.
124coercion ertl_seq_to_joint_seq : ∀globals.∀s : ertl_seq.joint_seq ERTL globals ≝ ertl_seq_joint
125  on _s : ertl_seq to joint_seq ERTL ?.
126
127definition ERTL_premain : ∀p : ertl_program.
128  joint_closed_internal_function ERTL (prog_names … p) ≝
129λp.
130let l1 : label ≝ an_identifier … one in
131let l2 : label ≝ an_identifier … (p0 one) in
132let l3 : label ≝ an_identifier … (p1 one) in
133let res ≝
134  mk_joint_internal_function ERTL (prog_names … p)
135  (mk_universe … (p0 (p0 one)))
136  (mk_universe … one)
137  it 4 0 0 (empty_map …) l1 in
138(* todo: args for main? *)
139let res ≝ add_graph … l1
140  (sequential … (COST_LABEL … (init_cost_label … p)) l2)
141  res in
142let res ≝ add_graph … l2
143  (sequential … (CALL ERTL ? (inl … (prog_main … p)) 0 it) l3)
144  res in
145let res ≝ add_graph … l3
146  (GOTO ? l3)
147  res in
148res.
149%
150[ ** [2,3: * [2,3,5,6: #p ]] #s whd in ⊢ (??%?→?); #EQ destruct
151  %
152  [1,3,5: %{I} % whd in ⊢ (??%(??%)→?); #EQ destruct
153  |2: %
154  |4,6: % whd in ⊢ (??%%→?); #EQ destruct
155  ]
156| ** [2,3: * [2,3,5,6: #p ]] #s whd in ⊢ (??%?→?); #EQ destruct % try @I %{I I}
157| ** [2,3: * [2,3,5,6: #p ]] * whd whd in ⊢ (?%%); //
158| ** [2,3: * [2,3,5,6: #p ]] #s whd in ⊢ (??%%→?); #EQ destruct @I
159| %{l2} %{(init_cost_label … p)} %
160]
161qed.
Note: See TracBrowser for help on using the repository browser.