| author | kleing |
| Sun, 16 Dec 2001 00:17:44 +0100 | |
| changeset 12516 | d09d0f160888 |
| parent 11085 | b830bf10bf71 |
| child 12911 | 704713ca07ea |
| permissions | -rw-r--r-- |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
1 |
(* Title: HOL/MicroJava/BV/LBVSpec.thy |
| 8245 | 2 |
ID: $Id$ |
3 |
Author: Gerwin Klein |
|
4 |
Copyright 1999 Technische Universitaet Muenchen |
|
| 9054 | 5 |
*) |
| 8245 | 6 |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
7 |
header {* The Lightweight Bytecode Verifier *}
|
| 9054 | 8 |
|
| 12516 | 9 |
theory LBVSpec = Effect + Kildall: |
| 8245 | 10 |
|
| 12516 | 11 |
text {*
|
12 |
The Lightweight Bytecode Verifier with exceptions has not |
|
13 |
made it completely into the Isabelle 2001 release. Currently |
|
14 |
there is only the specification itself available. The proofs of |
|
15 |
soundness and completeness are broken (they still need to be |
|
16 |
ported to the exception version). Both theories are included |
|
17 |
for documentation (but they don't work for this specification), |
|
18 |
please see the Isabelle 99-2 release for a working copy. |
|
19 |
*} |
|
| 8245 | 20 |
|
21 |
types |
|
22 |
certificate = "state_type option list" |
|
| 10042 | 23 |
class_certificate = "sig => certificate" |
24 |
prog_certificate = "cname => class_certificate" |
|
| 8245 | 25 |
|
| 12516 | 26 |
consts |
27 |
merge :: "[jvm_prog, p_count, nat, nat, p_count, certificate, (nat \<times> (state_type option)) list, state] \<Rightarrow> state" |
|
28 |
primrec |
|
29 |
"merge G pc mxs mxr max_pc cert [] x = x" |
|
30 |
"merge G pc mxs mxr max_pc cert (s#ss) x = (let (pc',s') = s in |
|
31 |
if pc' < max_pc \<and> pc' = pc+1 then |
|
32 |
merge G pc mxs mxr max_pc cert ss (OK s' +_(sup G mxs mxr) x) |
|
33 |
else if pc' < max_pc \<and> G \<turnstile> s' <=' cert!pc' then |
|
34 |
merge G pc mxs mxr max_pc cert ss x |
|
35 |
else Err)" |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
36 |
|
| 12516 | 37 |
constdefs |
38 |
wtl_inst :: "[instr,jvm_prog,ty,state_type option,certificate,nat,nat,p_count,exception_table,p_count] |
|
| 10042 | 39 |
=> state_type option err" |
| 12516 | 40 |
"wtl_inst i G rT s cert maxs maxr max_pc et pc == |
41 |
if app i G maxs rT pc et s then |
|
42 |
merge G pc maxs maxr max_pc cert (eff i G pc et s) (OK (cert!(pc+1))) |
|
| 10628 | 43 |
else Err" |
| 8245 | 44 |
|
| 12516 | 45 |
wtl_cert :: "[instr,jvm_prog,ty,state_type option,certificate,nat,nat,p_count,exception_table,p_count] |
| 10042 | 46 |
=> state_type option err" |
| 12516 | 47 |
"wtl_cert i G rT s cert maxs maxr max_pc et pc == |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
48 |
case cert!pc of |
| 12516 | 49 |
None => wtl_inst i G rT s cert maxs maxr max_pc et pc |
| 10042 | 50 |
| Some s' => if G \<turnstile> s <=' (Some s') then |
| 12516 | 51 |
wtl_inst i G rT (Some s') cert maxs maxr max_pc et pc |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
52 |
else Err" |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
53 |
|
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
54 |
consts |
| 12516 | 55 |
wtl_inst_list :: "[instr list,jvm_prog,ty,certificate,nat,nat,p_count,exception_table,p_count, |
| 10042 | 56 |
state_type option] => state_type option err" |
| 8245 | 57 |
primrec |
| 12516 | 58 |
"wtl_inst_list [] G rT cert maxs maxr max_pc et pc s = OK s" |
59 |
"wtl_inst_list (i#is) G rT cert maxs maxr max_pc et pc s = |
|
60 |
(let s' = wtl_cert i G rT s cert maxs maxr max_pc et pc in |
|
61 |
strict (wtl_inst_list is G rT cert maxs maxr max_pc et (pc+1)) s')" |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
62 |
|
| 8245 | 63 |
|
64 |
constdefs |
|
| 12516 | 65 |
wtl_method :: "[jvm_prog,cname,ty list,ty,nat,nat,exception_table,instr list,certificate] => bool" |
66 |
"wtl_method G C pTs rT mxs mxl et ins cert == |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
67 |
let max_pc = length ins |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
68 |
in |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
69 |
0 < max_pc \<and> |
| 12516 | 70 |
wtl_inst_list ins G rT cert mxs mxl max_pc et 0 |
| 10496 | 71 |
(Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err))) \<noteq> Err" |
| 8245 | 72 |
|
| 10042 | 73 |
wtl_jvm_prog :: "[jvm_prog,prog_certificate] => bool" |
74 |
"wtl_jvm_prog G cert == |
|
| 12516 | 75 |
wf_prog (\<lambda>G C (sig,rT,maxs,maxl,b,et). wtl_method G C (snd sig) rT maxs maxl et b (cert C sig)) G" |
| 9012 | 76 |
|
| 10042 | 77 |
|
|
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10638
diff
changeset
|
78 |
lemmas [iff] = not_Err_eq |
|
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10638
diff
changeset
|
79 |
|
| 12516 | 80 |
lemma if_eq_cases: |
81 |
"(P \<Longrightarrow> x = z) \<Longrightarrow> (\<not>P \<Longrightarrow> y = z) \<Longrightarrow> (if P then x else y) = z" |
|
82 |
by simp |
|
83 |
||
84 |
lemma merge_def: |
|
85 |
"!!x. merge G pc mxs mxr max_pc cert ss x = |
|
86 |
(if \<forall>(pc',s') \<in> set ss. pc' < max_pc \<and> (pc' \<noteq> pc+1 \<longrightarrow> G \<turnstile> s' <=' cert!pc') then |
|
87 |
map (OK \<circ> snd) [(p',t') \<in> ss. p'=pc+1] ++_(sup G mxs mxr) x |
|
88 |
else Err)" (is "!!x. ?merge ss x = ?if ss x" is "!!x. ?P ss x") |
|
89 |
proof (induct ss) |
|
90 |
show "!!x. ?P [] x" by simp |
|
91 |
next |
|
92 |
have OK_snd: "(\<lambda>u. OK (snd u)) = OK \<circ> snd" by (rule ext) auto |
|
93 |
fix x ss and s::"nat \<times> (state_type option)" |
|
94 |
assume IH: "\<And>x. ?P ss x" |
|
95 |
obtain pc' s' where s: "s = (pc',s')" by (cases s) |
|
96 |
hence "?merge (s#ss) x = ?merge ((pc',s')#ss) x" by hypsubst (rule refl) |
|
97 |
also |
|
98 |
have "\<dots> = (if pc' < max_pc \<and> pc' = pc+1 then |
|
99 |
?merge ss (OK s' +_(sup G mxs mxr) x) |
|
100 |
else if pc' < max_pc \<and> G \<turnstile> s' <=' cert!pc' then |
|
101 |
?merge ss x |
|
102 |
else Err)" |
|
103 |
(is "_ = (if ?pc' then ?merge ss (_ +_?f _) else if ?G then _ else _)") |
|
104 |
by simp |
|
105 |
also |
|
106 |
let "if ?all ss then _ else _" = "?if ss x" |
|
107 |
have "\<dots> = ?if ((pc',s')#ss) x" |
|
108 |
proof (cases "?pc'") |
|
109 |
case True |
|
110 |
hence "?all (((pc',s')#ss)) = (pc+1 < max_pc \<and> ?all ss)" by simp |
|
111 |
with True |
|
112 |
have "?if ss (OK s' +_?f x) = ?if ((pc',s')#ss) x" by (auto simp add: OK_snd) |
|
113 |
hence "?merge ss (OK s' +_?f x) = ?if ((pc',s')#ss) x" by (simp only: IH) |
|
114 |
with True show ?thesis by (fast intro: if_eq_cases) |
|
115 |
next |
|
116 |
case False |
|
117 |
have "(if ?G then ?merge ss x else Err) = ?if ((pc',s')#ss) x" |
|
118 |
proof (cases ?G) |
|
119 |
assume G: ?G with False |
|
120 |
have "?if ss x = ?if ((pc',s')#ss) x" by (auto simp add: OK_snd) |
|
121 |
hence "?merge ss x = ?if ((pc',s')#ss) x" by (simp only: IH) |
|
122 |
with G show ?thesis by (fast intro: if_eq_cases) |
|
123 |
next |
|
124 |
assume G: "\<not>?G" |
|
125 |
with False have "Err = ?if ((pc',s')#ss) x" by auto |
|
126 |
with G show ?thesis by (fast intro: if_eq_cases) |
|
127 |
qed |
|
128 |
with False show ?thesis by (fast intro: if_eq_cases) |
|
129 |
qed |
|
130 |
also from s have "\<dots> = ?if (s#ss) x" by hypsubst (rule refl) |
|
131 |
finally show "?P (s#ss) x" . |
|
132 |
qed |
|
133 |
||
| 10042 | 134 |
|
| 10496 | 135 |
lemma wtl_inst_OK: |
| 12516 | 136 |
"(wtl_inst i G rT s cert mxs mxr max_pc et pc = OK s') = ( |
137 |
app i G mxs rT pc et s \<and> |
|
138 |
(\<forall>(pc',r) \<in> set (eff i G pc et s). |
|
139 |
pc' < max_pc \<and> (pc' \<noteq> pc+1 \<longrightarrow> G \<turnstile> r <=' cert!pc')) \<and> |
|
140 |
map (OK \<circ> snd) [(p',t') \<in> (eff i G pc et s). p'=pc+1] |
|
141 |
++_(sup G mxs mxr) (OK (cert!(pc+1))) = OK s')" |
|
142 |
by (auto simp add: wtl_inst_def merge_def split: split_if_asm) |
|
| 9012 | 143 |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
144 |
lemma wtl_Cons: |
| 12516 | 145 |
"wtl_inst_list (i#is) G rT cert maxs maxr max_pc et pc s \<noteq> Err = |
146 |
(\<exists>s'. wtl_cert i G rT s cert maxs maxr max_pc et pc = OK s' \<and> |
|
147 |
wtl_inst_list is G rT cert maxs maxr max_pc et (pc+1) s' \<noteq> Err)" |
|
|
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10638
diff
changeset
|
148 |
by (auto simp del: split_paired_Ex) |
|
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
149 |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
150 |
lemma wtl_append: |
| 12516 | 151 |
"\<forall> s pc. (wtl_inst_list (a@b) G rT cert mxs mxr mpc et pc s = OK s') = |
152 |
(\<exists>s''. wtl_inst_list a G rT cert mxs mxr mpc et pc s = OK s'' \<and> |
|
153 |
wtl_inst_list b G rT cert mxs mxr mpc et (pc+length a) s'' = OK s')" |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
154 |
(is "\<forall> s pc. ?C s pc a" is "?P a") |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
155 |
proof (induct ?P a) |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
156 |
show "?P []" by simp |
| 12516 | 157 |
next |
158 |
fix x xs assume IH: "?P xs" |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
159 |
show "?P (x#xs)" |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
160 |
proof (intro allI) |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
161 |
fix s pc |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
162 |
show "?C s pc (x#xs)" |
| 12516 | 163 |
proof (cases "wtl_cert x G rT s cert mxs mxr mpc et pc") |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
164 |
case Err thus ?thesis by simp |
| 9183 | 165 |
next |
| 12516 | 166 |
fix s0 assume "wtl_cert x G rT s cert mxs mxr mpc et pc = OK s0" |
167 |
with IH have "?C s0 (Suc pc) xs" by blast |
|
168 |
thus ?thesis by (simp!) |
|
| 9183 | 169 |
qed |
170 |
qed |
|
171 |
qed |
|
| 9012 | 172 |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
173 |
lemma wtl_take: |
| 12516 | 174 |
"wtl_inst_list is G rT cert mxs mxr mpc et pc s = OK s'' ==> |
175 |
\<exists>s'. wtl_inst_list (take pc' is) G rT cert mxs mxr mpc et pc s = OK s'" |
|
| 9183 | 176 |
proof - |
| 12516 | 177 |
assume "wtl_inst_list is G rT cert mxs mxr mpc et pc s = OK s''" |
178 |
hence "wtl_inst_list (take pc' is @ drop pc' is) G rT cert mxs mxr mpc et pc s = OK s''" |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
179 |
by simp |
| 12516 | 180 |
thus ?thesis by (auto simp add: wtl_append simp del: append_take_drop_id) |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
181 |
qed |
| 9012 | 182 |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
183 |
lemma take_Suc: |
| 10042 | 184 |
"\<forall>n. n < length l --> take (Suc n) l = (take n l)@[l!n]" (is "?P l") |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
185 |
proof (induct l) |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
186 |
show "?P []" by simp |
| 12516 | 187 |
next |
188 |
fix x xs assume IH: "?P xs" |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
189 |
show "?P (x#xs)" |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
190 |
proof (intro strip) |
| 12516 | 191 |
fix n assume "n < length (x#xs)" |
192 |
with IH show "take (Suc n) (x # xs) = take n (x # xs) @ [(x # xs) ! n]" |
|
193 |
by (cases n, auto) |
|
| 9183 | 194 |
qed |
195 |
qed |
|
| 9012 | 196 |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
197 |
lemma wtl_Suc: |
| 12516 | 198 |
"[| wtl_inst_list (take pc is) G rT cert maxs maxr (length is) et 0 s = OK s'; |
199 |
wtl_cert (is!pc) G rT s' cert maxs maxr (length is) et pc = OK s''; |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
200 |
Suc pc < length is |] ==> |
| 12516 | 201 |
wtl_inst_list (take (Suc pc) is) G rT cert maxs maxr (length is) et 0 s = OK s''" |
| 9183 | 202 |
proof - |
| 12516 | 203 |
assume "wtl_inst_list (take pc is) G rT cert maxs maxr (length is) et 0 s = OK s'" |
204 |
"wtl_cert (is!pc) G rT s' cert maxs maxr (length is) et pc = OK s''" |
|
205 |
"Suc pc < length is" |
|
206 |
hence "take (Suc pc) is = (take pc is)@[is!pc]" by (simp add: take_Suc) |
|
207 |
thus ?thesis by (simp! add: wtl_append min_def) |
|
| 9183 | 208 |
qed |
| 9012 | 209 |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
210 |
lemma wtl_all: |
| 12516 | 211 |
"[| wtl_inst_list is G rT cert maxs maxr (length is) et 0 s \<noteq> Err; |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
212 |
pc < length is |] ==> |
| 12516 | 213 |
\<exists>s' s''. wtl_inst_list (take pc is) G rT cert maxs maxr (length is) et 0 s = OK s' \<and> |
214 |
wtl_cert (is!pc) G rT s' cert maxs maxr (length is) et pc = OK s''" |
|
| 9183 | 215 |
proof - |
| 12516 | 216 |
assume all: "wtl_inst_list is G rT cert maxs maxr (length is) et 0 s \<noteq> Err" |
| 9012 | 217 |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
218 |
assume pc: "pc < length is" |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
219 |
hence "0 < length (drop pc is)" by simp |
| 12516 | 220 |
then obtain i r where Cons: "drop pc is = i#r" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
221 |
by (auto simp add: neq_Nil_conv simp del: length_drop) |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
222 |
hence "i#r = drop pc is" .. |
| 12516 | 223 |
with all have take: |
224 |
"wtl_inst_list (take pc is@i#r) G rT cert maxs maxr (length is) et 0 s \<noteq> Err" |
|
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
225 |
by simp |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
226 |
|
| 12516 | 227 |
from pc have "is!pc = drop pc is ! 0" by simp |
228 |
with Cons have "is!pc = i" by simp |
|
229 |
with take pc show ?thesis by (auto simp add: wtl_append min_def) |
|
| 9183 | 230 |
qed |
| 9012 | 231 |
|
| 10042 | 232 |
|
| 9183 | 233 |
end |