8388
|
1 |
(* Title: HOL/MicroJava/BV/LBVComplete.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Gerwin Klein
|
|
4 |
Copyright 2000 Technische Universitaet Muenchen
|
|
5 |
|
|
6 |
Proof of completeness for the lightweight bytecode verifier
|
|
7 |
*)
|
|
8 |
|
|
9 |
LBVComplete= LBVSpec +
|
|
10 |
|
|
11 |
constdefs
|
|
12 |
is_approx :: "['a option list, 'a list] \\<Rightarrow> bool"
|
|
13 |
"is_approx a b \\<equiv> length a = length b \\<and> (\\<forall> n. n < length a \\<longrightarrow>
|
|
14 |
(a!n = None \\<or> a!n = Some (b!n)))"
|
|
15 |
|
|
16 |
fits :: "[instr list, certificate, method_type] \\<Rightarrow> bool"
|
|
17 |
"fits ins cert phi \\<equiv> is_approx cert phi \\<and> length ins < length phi \\<and>
|
|
18 |
(\\<forall> pc. pc < length ins \\<longrightarrow>
|
|
19 |
contains_dead ins cert phi pc \\<and>
|
|
20 |
contains_targets ins cert phi pc)"
|
|
21 |
|
|
22 |
contains_dead :: "[instr list, certificate, method_type, p_count] \\<Rightarrow> bool"
|
|
23 |
"contains_dead ins cert phi pc \\<equiv>
|
|
24 |
(((\\<exists> branch. ins!pc = BR (Goto branch)) \\<or> ins!pc = MR Return) \\<or>
|
|
25 |
(\\<exists>mi. ins!pc = MI mi)) \\<longrightarrow> Suc pc < length phi \\<longrightarrow>
|
|
26 |
cert ! (Suc pc) = Some (phi ! Suc pc)"
|
|
27 |
|
|
28 |
contains_targets :: "[instr list, certificate, method_type, p_count] \\<Rightarrow> bool"
|
|
29 |
"contains_targets ins cert phi pc \\<equiv>
|
|
30 |
\\<forall> branch. (ins!pc = BR (Goto branch) \\<or> ins!pc = BR (Ifcmpeq branch)) \\<longrightarrow>
|
|
31 |
(let pc' = nat (int pc+branch) in pc' < length phi \\<longrightarrow> cert!pc' = Some (phi!pc'))"
|
|
32 |
|
|
33 |
is_target :: "[instr list, p_count] \\<Rightarrow> bool"
|
|
34 |
"is_target ins pc \\<equiv>
|
|
35 |
\\<exists> pc' branch. pc' < length ins \\<and>
|
|
36 |
(ins ! pc' = (BR (Ifcmpeq branch)) \\<or> ins ! pc' = (BR (Goto branch))) \\<and>
|
|
37 |
pc = (nat(int pc'+branch))"
|
|
38 |
|
|
39 |
maybe_dead :: "[instr list, p_count] \\<Rightarrow> bool"
|
|
40 |
"maybe_dead ins pc \\<equiv>
|
|
41 |
\\<exists> pc'. pc = pc'+1 \\<and> ((\\<exists> branch. ins!pc' = BR (Goto branch)) \\<or>
|
|
42 |
ins!pc' = MR Return \\<or>
|
|
43 |
(\\<exists>mi. ins!pc' = MI mi))"
|
|
44 |
|
|
45 |
|
|
46 |
mdot :: "[instr list, p_count] \\<Rightarrow> bool"
|
|
47 |
"mdot ins pc \\<equiv> maybe_dead ins pc \\<or> is_target ins pc"
|
|
48 |
|
|
49 |
|
|
50 |
consts
|
|
51 |
option_filter_n :: "['a list, nat \\<Rightarrow> bool, nat] \\<Rightarrow> 'a option list"
|
|
52 |
primrec
|
|
53 |
"option_filter_n [] P n = []"
|
|
54 |
"option_filter_n (h#t) P n = (if (P n) then Some h # option_filter_n t P (n+1)
|
|
55 |
else None # option_filter_n t P (n+1))"
|
|
56 |
|
|
57 |
constdefs
|
|
58 |
option_filter :: "['a list, nat \\<Rightarrow> bool] \\<Rightarrow> 'a option list"
|
|
59 |
"option_filter l P \\<equiv> option_filter_n l P 0"
|
|
60 |
|
|
61 |
make_cert :: "[instr list, method_type] \\<Rightarrow> certificate"
|
|
62 |
"make_cert ins phi \\<equiv> option_filter phi (mdot ins)"
|
|
63 |
|
|
64 |
make_Cert :: "[jvm_prog, prog_type] \\<Rightarrow> prog_certificate"
|
|
65 |
"make_Cert G Phi \\<equiv> \\<lambda> C sig.
|
|
66 |
let (C,x,y,mdecls) = \\<epsilon> (Cl,x,y,mdecls). (Cl,x,y,mdecls) \\<in> set G \\<and> Cl = C in
|
|
67 |
let (sig,rT,maxl,b) = \\<epsilon> (sg,rT,maxl,b). (sg,rT,maxl,b) \\<in> set mdecls \\<and> sg = sig in
|
|
68 |
make_cert b (Phi C sig)"
|
|
69 |
|
|
70 |
constdefs
|
|
71 |
wfprg :: "jvm_prog \\<Rightarrow> bool"
|
|
72 |
"wfprg G \\<equiv> \\<exists>wf_mb. wf_prog wf_mb G"
|
|
73 |
|
|
74 |
end
|