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