src/HOL/MicroJava/BV/Altern.thy
author wenzelm
Sun, 02 Nov 2014 17:58:35 +0100
changeset 58886 8a6cac7c7247
parent 35416 d8d7d1b785af
child 61361 8b5f00202e1a
permissions -rw-r--r--
modernized header;
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
58886
8a6cac7c7247 modernized header;
wenzelm
parents: 35416
diff changeset
     5
section {* 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
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33954
diff changeset
    11
definition check_type :: "jvm_prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> JVMType.state \<Rightarrow> bool" where
13672
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    12
  "check_type G mxs mxr s \<equiv> s \<in> states G mxs mxr"
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    13
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33954
diff changeset
    14
definition wt_instr_altern :: "[instr,jvm_prog,ty,method_type,nat,nat,p_count,
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33954
diff changeset
    15
                exception_table,p_count] \<Rightarrow> bool" where
13672
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    16
  "wt_instr_altern i G rT phi mxs mxr max_pc et pc \<equiv>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    17
  app i G mxs rT pc et (phi!pc) \<and>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    18
  check_type G mxs mxr (OK (phi!pc)) \<and>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    19
  (\<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
    20
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33954
diff changeset
    21
definition wt_method_altern :: "[jvm_prog,cname,ty list,ty,nat,nat,instr list,
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33954
diff changeset
    22
                 exception_table,method_type] \<Rightarrow> bool" where
13672
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    23
  "wt_method_altern G C pTs rT mxs mxl ins et phi \<equiv>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    24
  let max_pc = length ins in
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    25
  0 < max_pc \<and> 
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    26
  length phi = length ins \<and>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    27
  check_bounded ins et \<and> 
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    28
  wt_start G C pTs mxl phi \<and>
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    29
  (\<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
    30
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    31
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    32
lemma wt_method_wt_method_altern : 
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    33
  "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
    34
apply (simp add: wt_method_def wt_method_altern_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    35
apply (intro strip)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    36
apply clarify
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    37
apply (drule spec, drule mp, assumption)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    38
apply (simp add: check_types_def wt_instr_def wt_instr_altern_def check_type_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    39
apply (auto  intro: imageI)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    40
done
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    41
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    42
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    43
lemma check_type_check_types [rule_format]: 
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    44
  "(\<forall>pc. pc < length phi \<longrightarrow> check_type G mxs mxr (OK (phi ! pc)))
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    45
  \<longrightarrow> check_types G mxs mxr (map OK phi)"
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    46
apply (induct phi)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    47
apply (simp add: check_types_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    48
apply (simp add: check_types_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    49
apply clarify
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    50
apply (frule_tac x=0 in spec)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    51
apply (simp add: check_type_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    52
apply auto
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    53
done
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    54
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    55
lemma wt_method_altern_wt_method [rule_format]: 
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    56
  "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
    57
apply (simp add: wt_method_def wt_method_altern_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    58
apply (intro strip)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    59
apply clarify
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    60
apply (rule conjI)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    61
  (* show check_types *)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    62
apply (rule check_type_check_types)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    63
apply (simp add: wt_instr_altern_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    64
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    65
  (* show wt_instr *)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    66
apply (intro strip)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    67
apply (drule spec, drule mp, assumption)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    68
apply (simp add: wt_instr_def wt_instr_altern_def)
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    69
done
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    70
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    71
b95d12325b51 Added compiler
streckem
parents:
diff changeset
    72
end