@@ -119,6 +119,82 @@ open bir_inst_liftingHelpersLib;
119119 arch_contract_thm
120120 end ;
121121
122+ fun get_arch_contract_thm arch_cont
123+ arch_lift_contract_thm arch_wf_varset_def arch_vars_def bir_post_bir_to_arch_def
124+ bir_ct init_addr_def end_addr_defs prog_bin_def arch_pre_def arch_post_def bir_prog_def bir_pre_defs
125+ bir_pre1_def arch_pre_imp_bir_pre_thm bir_post_defs
126+ arch_post_imp_bir_post_thm bir_is_lifted_prog_thm =
127+ let
128+ val prog_bin = (fst o dest_eq o concl) prog_bin_def;
129+ val arch_pre = (fst o dest_comb o lhs o snd o strip_forall o concl) arch_pre_def;
130+ val arch_post = (fst o dest_comb o lhs o snd o strip_forall o concl) arch_post_def;
131+ val init_addr = (fst o dest_eq o concl) init_addr_def;
132+ val end_addrs = pred_setSyntax.mk_set (map (fst o dest_eq o concl) end_addr_defs);
133+ val word_from_address = bir_immSyntax.dest_Imm64 o bir_programSyntax.dest_BL_Address;
134+ val bir_prog = get_bir_cont_prog bir_ct;
135+ val l = word_from_address (get_bir_cont_start_label bir_ct);
136+ val ls_set = get_bir_cont_ilist bir_ct;
137+ val ls = pred_setSyntax.mk_set (map word_from_address (pred_setSyntax.strip_set ls_set));
138+ val add_lift_thm =
139+ ISPECL [bir_prog,
140+ prog_bin,
141+ l,
142+ ls,
143+ (((el 2 ) o snd o strip_comb o concl) bir_is_lifted_prog_thm),
144+ arch_pre, arch_post,
145+ get_bir_cont_pre bir_ct,
146+ get_bir_cont_post bir_ct] arch_lift_contract_thm;
147+ (* Prove the arch triple by supplying the antecedents of lift_contract_thm *)
148+ val arch_contract_thm = prove (
149+ ``^arch_cont ^prog_bin ^init_addr ^end_addrs ^arch_pre ^arch_post``,
150+
151+ once_rewrite_tac (init_addr_def :: end_addr_defs) >>
152+ irule add_lift_thm >>
153+ REPEAT STRIP_TAC >| [
154+ (* 1. Prove that the union of variables in the program and precondition are a well-founded variable
155+ * set *)
156+ rewrite_tac [bir_prog_def] >>
157+ CONV_TAC (bir_convLib.bir_vars_of_program_CONV) >>
158+ rewrite_tac ([arch_wf_varset_def, arch_vars_def]@bir_pre_defs) >>
159+ CONV_TAC (bir_convLib.bir_vars_of_exp_CONV) >>
160+ CONV_TAC (
161+ LAND_CONV (pred_setLib.UNION_CONV bir_convLib.bir_var_EQ_CONV) THENC
162+ holba_convLib.SUBSET_CONV bir_convLib.bir_var_EQ_CONV
163+ ),
164+ (* 2. Starting address exists in program *)
165+ rewrite_tac [bir_prog_def] >>
166+ CONV_TAC (
167+ bir_convLib.bir_labels_of_program_CONV THENC
168+ RAND_CONV holba_convLib.LIST_TO_SET_CONV THENC
169+ pred_setLib.IN_CONV bir_convLib.bir_label_EQ_CONV
170+ ),
171+
172+ (* 3. Provide translation of the arch precondition to the BIR precondition *)
173+ FULL_SIMP_TAC std_ss [bir_pre1_def, arch_pre_imp_bir_pre_thm],
174+
175+ (* 4. Provide translation of the arch postcondition to BIR postcondition *)
176+ ASSUME_TAC (Q.ISPEC `{BL_Address (Imm64 ml') | ml' IN ^ls}` arch_post_imp_bir_post_thm) >>
177+ FULL_SIMP_TAC std_ss bir_post_defs >>
178+ FULL_SIMP_TAC (std_ss++pred_setLib.PRED_SET_ss) [bir_post_bir_to_arch_def] >>
179+ FULL_SIMP_TAC std_ss [],
180+
181+ (* 5. Provide the lifter theorem of the program *)
182+ FULL_SIMP_TAC std_ss [bir_is_lifted_prog_thm],
183+
184+ (* 6. Provide the BIR triple in the requisite format *)
185+ ASSUME_TAC bir_ct >>
186+ `{BL_Address (Imm64 ml') | ml' IN ^ls} = ^ls_set` suffices_by (
187+ FULL_SIMP_TAC std_ss []
188+ ) >>
189+ FULL_SIMP_TAC (std_ss++pred_setLib.PRED_SET_ss) [pred_setTheory.EXTENSION] >>
190+ METIS_TAC []
191+ ]
192+ );
193+
194+ in
195+ arch_contract_thm
196+ end ;
197+
122198 fun get_arm8_contract bir_ct prog_bin arm8_pre arm8_post bir_prog_def bir_pre_defs
123199 bir_pre1_def arm8_pre_imp_bir_pre_thm bir_post_defs
124200 arm8_post_imp_bir_post_thm bir_is_lifted_prog_thm =
@@ -128,18 +204,16 @@ open bir_inst_liftingHelpersLib;
128204 bir_pre_defs bir_pre1_def arm8_pre_imp_bir_pre_thm bir_post_defs
129205 arm8_post_imp_bir_post_thm bir_is_lifted_prog_thm;
130206
131- fun get_arm8_contract_thm bir_ct progbin_def arm8_pre_def arm8_post_def bir_prog_def bir_pre_defs
207+ fun get_arm8_contract_thm bir_ct init_addr_def end_addr_defs prog_bin_def
208+ arm8_pre_def arm8_post_def bir_prog_def bir_pre_defs
132209 bir_pre1_def arm8_pre_imp_bir_pre_thm bir_post_defs
133210 arm8_post_imp_bir_post_thm bir_is_lifted_prog_thm =
134- let
135- val prog_bin = (fst o dest_eq o concl) progbin_def;
136- val arm8_pre = (fst o dest_comb o lhs o snd o strip_forall o concl) arm8_pre_def;
137- val arm8_post = (fst o dest_comb o lhs o snd o strip_forall o concl) arm8_post_def;
138- in
139- get_arm8_contract bir_ct prog_bin arm8_pre arm8_post bir_prog_def bir_pre_defs
140- bir_pre1_def arm8_pre_imp_bir_pre_thm bir_post_defs
141- arm8_post_imp_bir_post_thm bir_is_lifted_prog_thm
142- end ;
211+ get_arch_contract_thm ``arm8_cont`` arm8_lift_contract_thm
212+ arm8_wf_varset_def arm8_vars_def bir_post_bir_to_arm8_def
213+ bir_ct init_addr_def end_addr_defs prog_bin_def
214+ arm8_pre_def arm8_post_def bir_prog_def
215+ bir_pre_defs bir_pre1_def arm8_pre_imp_bir_pre_thm bir_post_defs
216+ arm8_post_imp_bir_post_thm bir_is_lifted_prog_thm;
143217
144218 fun get_riscv_contract bir_ct prog_bin riscv_pre riscv_post bir_prog_def bir_pre_defs
145219 bir_pre1_def riscv_pre_imp_bir_pre_thm bir_post_defs
@@ -150,18 +224,16 @@ open bir_inst_liftingHelpersLib;
150224 bir_pre_defs bir_pre1_def riscv_pre_imp_bir_pre_thm bir_post_defs
151225 riscv_post_imp_bir_post_thm bir_is_lifted_prog_thm;
152226
153- fun get_riscv_contract_thm bir_ct progbin_def riscv_pre_def riscv_post_def bir_prog_def bir_pre_defs
227+ fun get_riscv_contract_thm bir_ct init_addr_def end_addr_defs prog_bin_def
228+ riscv_pre_def riscv_post_def bir_prog_def bir_pre_defs
154229 bir_pre1_def riscv_pre_imp_bir_pre_thm bir_post_defs
155230 riscv_post_imp_bir_post_thm bir_is_lifted_prog_thm =
156- let
157- val prog_bin = (fst o dest_eq o concl) progbin_def;
158- val riscv_pre = (fst o dest_comb o lhs o snd o strip_forall o concl) riscv_pre_def;
159- val riscv_post = (fst o dest_comb o lhs o snd o strip_forall o concl) riscv_post_def;
160- in
161- get_riscv_contract bir_ct prog_bin riscv_pre riscv_post bir_prog_def bir_pre_defs
162- bir_pre1_def riscv_pre_imp_bir_pre_thm bir_post_defs
163- riscv_post_imp_bir_post_thm bir_is_lifted_prog_thm
164- end ;
231+ get_arch_contract_thm ``riscv_cont`` riscv_lift_contract_thm
232+ riscv_wf_varset_def riscv_vars_def bir_post_bir_to_riscv_def
233+ bir_ct init_addr_def end_addr_defs prog_bin_def
234+ riscv_pre_def riscv_post_def bir_prog_def
235+ bir_pre_defs bir_pre1_def riscv_pre_imp_bir_pre_thm bir_post_defs
236+ riscv_post_imp_bir_post_thm bir_is_lifted_prog_thm;
165237
166238 end
167239end
0 commit comments