src/HOL/MicroJava/BV/Altern.thy
author haftmann
Sun, 31 Jan 2010 14:51:32 +0100
changeset 34977 27ceb64d41ea
parent 33954 1bc3b688548c
child 35416 d8d7d1b785af
permissions -rwxr-xr-x
dropped some redundancies
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14045
a34d89ce6097 Introduced distinction wf_prog vs. ws_prog
streckem
parents: 13672
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/Altern.thy
a34d89ce6097 Introduced distinction wf_prog vs. ws_prog
streckem
parents: 13672
diff changeset
     2
    Author:     Martin Strecker
a34d89ce6097 Introduced distinction wf_prog vs. ws_prog
streckem
parents: 13672
diff changeset
     3
*)
a34d89ce6097 Introduced distinction wf_prog vs. ws_prog
streckem
parents: 13672
diff changeset
     4
33954
1bc3b688548c backported parts of abstract byte code verifier from AFP/Jinja
haftmann
parents: 26450
diff changeset
     5
header {* Alternative definition of well-typing of bytecode,  used in compiler type correctness proof *}
14045
a34d89ce6097 Introduced distinction wf_prog vs. ws_prog
streckem
parents: 13672
diff changeset
     6
33954
1bc3b688548c backported parts of abstract byte code verifier from AFP/Jinja
haftmann
parents: 26450
diff changeset
     7
theory Altern
1bc3b688548c backported parts of abstract byte code verifier from AFP/Jinja
haftmann
parents: 26450
diff changeset
     8
imports BVSpec
1bc3b688548c backported parts of abstract byte code verifier from AFP/Jinja
haftmann
parents: 26450
diff changeset
     9
begin
13672
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    10
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    11
constdefs
26450
158b924b5153 avoid amiguity of State.state vs. JVMType.state;
wenzelm
parents: 16417
diff changeset
    12
  check_type :: "jvm_prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> JVMType.state \<Rightarrow> bool"
13672
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    13
  "check_type G mxs mxr s \<equiv> s \<in> states G mxs mxr"
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    14
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    15
  wt_instr_altern :: "[instr,jvm_prog,ty,method_type,nat,nat,p_count,
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    16
                exception_table,p_count] \<Rightarrow> bool"
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    17
  "wt_instr_altern i G rT phi mxs mxr max_pc et pc \<equiv>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    18
  app i G mxs rT pc et (phi!pc) \<and>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    19
  check_type G mxs mxr (OK (phi!pc)) \<and>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    20
  (\<forall>(pc',s') \<in> set (eff i G pc et (phi!pc)). pc' < max_pc \<and> G \<turnstile> s' <=' phi!pc')"
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    21
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    22
  wt_method_altern :: "[jvm_prog,cname,ty list,ty,nat,nat,instr list,
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    23
                 exception_table,method_type] \<Rightarrow> bool"
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    24
  "wt_method_altern G C pTs rT mxs mxl ins et phi \<equiv>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    25
  let max_pc = length ins in
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    26
  0 < max_pc \<and> 
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    27
  length phi = length ins \<and>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    28
  check_bounded ins et \<and> 
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    29
  wt_start G C pTs mxl phi \<and>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    30
  (\<forall>pc. pc<max_pc \<longrightarrow> wt_instr_altern (ins!pc) G rT phi mxs (1+length pTs+mxl) max_pc et pc)"
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    31
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    32
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    33
lemma wt_method_wt_method_altern : 
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    34
  "wt_method G C pTs rT mxs mxl ins et phi \<longrightarrow> wt_method_altern G C pTs rT mxs mxl ins et phi"
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    35
apply (simp add: wt_method_def wt_method_altern_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    36
apply (intro strip)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    37
apply clarify
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    38
apply (drule spec, drule mp, assumption)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    39
apply (simp add: check_types_def wt_instr_def wt_instr_altern_def check_type_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    40
apply (auto  intro: imageI)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    41
done
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    42
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    43
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    44
lemma check_type_check_types [rule_format]: 
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    45
  "(\<forall>pc. pc < length phi \<longrightarrow> check_type G mxs mxr (OK (phi ! pc)))
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    46
  \<longrightarrow> check_types G mxs mxr (map OK phi)"
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    47
apply (induct phi)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    48
apply (simp add: check_types_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    49
apply (simp add: check_types_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    50
apply clarify
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    51
apply (frule_tac x=0 in spec)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    52
apply (simp add: check_type_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    53
apply auto
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    54
done
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    55
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    56
lemma wt_method_altern_wt_method [rule_format]: 
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    57
  "wt_method_altern G C pTs rT mxs mxl ins et phi \<longrightarrow> wt_method G C pTs rT mxs mxl ins et phi"
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    58
apply (simp add: wt_method_def wt_method_altern_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    59
apply (intro strip)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    60
apply clarify
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    61
apply (rule conjI)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    62
  (* show check_types *)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    63
apply (rule check_type_check_types)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    64
apply (simp add: wt_instr_altern_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    65
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    66
  (* show wt_instr *)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    67
apply (intro strip)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    68
apply (drule spec, drule mp, assumption)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    69
apply (simp add: wt_instr_def wt_instr_altern_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    70
done
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    71
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    72
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    73
end