src/HOL/MicroJava/BV/JVM.thy
changeset 13006 51c5f3f11d16
parent 12951 a9fdcb71d252
child 13066 b57d926d1de2
equal deleted inserted replaced
13005:42a54d6cec15 13006:51c5f3f11d16
    12 constdefs
    12 constdefs
    13   exec :: "jvm_prog \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> exception_table \<Rightarrow> instr list \<Rightarrow> state step_type"
    13   exec :: "jvm_prog \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> exception_table \<Rightarrow> instr list \<Rightarrow> state step_type"
    14   "exec G maxs rT et bs == 
    14   "exec G maxs rT et bs == 
    15   err_step (\<lambda>pc. app (bs!pc) G maxs rT pc et) (\<lambda>pc. eff (bs!pc) G pc et)"
    15   err_step (\<lambda>pc. app (bs!pc) G maxs rT pc et) (\<lambda>pc. eff (bs!pc) G pc et)"
    16 
    16 
    17   kiljvm :: "jvm_prog => nat => nat => ty => exception_table => 
    17   kiljvm :: "jvm_prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> exception_table \<Rightarrow> 
    18              instr list => state list => state list"
    18              instr list \<Rightarrow> state list \<Rightarrow> state list"
    19   "kiljvm G maxs maxr rT et bs ==
    19   "kiljvm G maxs maxr rT et bs ==
    20   kildall (JVMType.le G maxs maxr) (JVMType.sup G maxs maxr) (exec G maxs rT et bs)"
    20   kildall (JVMType.le G maxs maxr) (JVMType.sup G maxs maxr) (exec G maxs rT et bs)"
    21 
    21 
    22   wt_kil :: "jvm_prog \<Rightarrow> cname \<Rightarrow> ty list \<Rightarrow> ty \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 
    22   wt_kil :: "jvm_prog \<Rightarrow> cname \<Rightarrow> ty list \<Rightarrow> ty \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 
    23              exception_table \<Rightarrow> instr list \<Rightarrow> bool"
    23              exception_table \<Rightarrow> instr list \<Rightarrow> bool"
    26    (let first  = Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err));
    26    (let first  = Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err));
    27         start  = OK first#(replicate (size ins - 1) (OK None));
    27         start  = OK first#(replicate (size ins - 1) (OK None));
    28         result = kiljvm G mxs (1+size pTs+mxl) rT et ins start
    28         result = kiljvm G mxs (1+size pTs+mxl) rT et ins start
    29     in \<forall>n < size ins. result!n \<noteq> Err)"
    29     in \<forall>n < size ins. result!n \<noteq> Err)"
    30 
    30 
    31   wt_jvm_prog_kildall :: "jvm_prog => bool"
    31   wt_jvm_prog_kildall :: "jvm_prog \<Rightarrow> bool"
    32   "wt_jvm_prog_kildall G ==
    32   "wt_jvm_prog_kildall G ==
    33   wf_prog (\<lambda>G C (sig,rT,(maxs,maxl,b,et)). wt_kil G C (snd sig) rT maxs maxl et b) G"
    33   wf_prog (\<lambda>G C (sig,rT,(maxs,maxl,b,et)). wt_kil G C (snd sig) rT maxs maxl et b) G"
    34 
    34 
    35 
    35 
    36 lemma special_ex_swap_lemma [iff]: 
    36 lemma special_ex_swap_lemma [iff]: 
    75   show ?thesis by blast
    75   show ?thesis by blast
    76 qed
    76 qed
    77 
    77 
    78 
    78 
    79 theorem exec_pres_type:
    79 theorem exec_pres_type:
    80   "wf_prog wf_mb S ==> 
    80   "wf_prog wf_mb S \<Longrightarrow> 
    81   pres_type (exec S maxs rT et bs) (size bs) (states S maxs maxr)"
    81   pres_type (exec S maxs rT et bs) (size bs) (states S maxs maxr)"
    82   apply (unfold exec_def JVM_states_unfold)
    82   apply (unfold exec_def JVM_states_unfold)
    83   apply (rule pres_type_lift)
    83   apply (rule pres_type_lift)
    84   apply clarify
    84   apply clarify
    85   apply (case_tac s)
    85   apply (case_tac s)
   241 lemma order_sup_state_opt:
   241 lemma order_sup_state_opt:
   242   "wf_prog wf_mb G \<Longrightarrow> order (sup_state_opt G)"
   242   "wf_prog wf_mb G \<Longrightarrow> order (sup_state_opt G)"
   243   by (unfold sup_state_opt_unfold) (blast dest: acyclic_subcls1 order_widen)
   243   by (unfold sup_state_opt_unfold) (blast dest: acyclic_subcls1 order_widen)
   244 
   244 
   245 theorem exec_mono:
   245 theorem exec_mono:
   246   "wf_prog wf_mb G ==>
   246   "wf_prog wf_mb G \<Longrightarrow>
   247   mono (JVMType.le G maxs maxr) (exec G maxs rT et bs) (size bs) (states G maxs maxr)"  
   247   mono (JVMType.le G maxs maxr) (exec G maxs rT et bs) (size bs) (states G maxs maxr)"  
   248   apply (unfold exec_def JVM_le_unfold JVM_states_unfold)  
   248   apply (unfold exec_def JVM_le_unfold JVM_states_unfold)  
   249   apply (rule mono_lift)
   249   apply (rule mono_lift)
   250      apply (fold sup_state_opt_unfold opt_states_def)
   250      apply (fold sup_state_opt_unfold opt_states_def)
   251      apply (erule order_sup_state_opt)
   251      apply (erule order_sup_state_opt)
   255   apply (rule eff_mono)
   255   apply (rule eff_mono)
   256   apply assumption+
   256   apply assumption+
   257   done
   257   done
   258 
   258 
   259 theorem semilat_JVM_slI:
   259 theorem semilat_JVM_slI:
   260   "wf_prog wf_mb G ==> semilat (JVMType.sl G maxs maxr)"
   260   "wf_prog wf_mb G \<Longrightarrow> semilat (JVMType.sl G maxs maxr)"
   261   apply (unfold JVMType.sl_def stk_esl_def reg_sl_def)
   261   apply (unfold JVMType.sl_def stk_esl_def reg_sl_def)
   262   apply (rule semilat_opt)
   262   apply (rule semilat_opt)
   263   apply (rule err_semilat_Product_esl)
   263   apply (rule err_semilat_Product_esl)
   264   apply (rule err_semilat_upto_esl)
   264   apply (rule err_semilat_upto_esl)
   265   apply (rule err_semilat_JType_esl, assumption+)
   265   apply (rule err_semilat_JType_esl, assumption+)
   273   (states G maxs maxr, JVMType.le G maxs maxr, JVMType.sup G maxs maxr)"
   273   (states G maxs maxr, JVMType.le G maxs maxr, JVMType.sup G maxs maxr)"
   274   by (simp (no_asm) add: states_def JVMType.le_def JVMType.sup_def)
   274   by (simp (no_asm) add: states_def JVMType.le_def JVMType.sup_def)
   275 
   275 
   276 
   276 
   277 theorem is_bcv_kiljvm:
   277 theorem is_bcv_kiljvm:
   278   "[| wf_prog wf_mb G; bounded (exec G maxs rT et bs) (size bs) |] ==> 
   278   "\<lbrakk> wf_prog wf_mb G; bounded (exec G maxs rT et bs) (size bs) \<rbrakk> \<Longrightarrow> 
   279       is_bcv (JVMType.le G maxs maxr) Err (exec G maxs rT et bs)
   279       is_bcv (JVMType.le G maxs maxr) Err (exec G maxs rT et bs)
   280              (size bs) (states G maxs maxr) (kiljvm G maxs maxr rT et bs)"
   280              (size bs) (states G maxs maxr) (kiljvm G maxs maxr rT et bs)"
   281   apply (unfold kiljvm_def sl_triple_conv)
   281   apply (unfold kiljvm_def sl_triple_conv)
   282   apply (rule is_bcv_kildall)
   282   apply (rule is_bcv_kildall)
   283        apply (simp (no_asm) add: sl_triple_conv [symmetric]) 
   283        apply (simp (no_asm) add: sl_triple_conv [symmetric]) 
   291   apply (erule exec_mono)
   291   apply (erule exec_mono)
   292   done
   292   done
   293 
   293 
   294 
   294 
   295 theorem wt_kil_correct:
   295 theorem wt_kil_correct:
   296   "[| wt_kil G C pTs rT maxs mxl et bs; wf_prog wf_mb G; 
   296   "\<lbrakk> wt_kil G C pTs rT maxs mxl et bs; wf_prog wf_mb G; 
   297       is_class G C; \<forall>x \<in> set pTs. is_type G x |]
   297       is_class G C; \<forall>x \<in> set pTs. is_type G x \<rbrakk>
   298   ==> \<exists>phi. wt_method G C pTs rT maxs mxl bs et phi"
   298   \<Longrightarrow> \<exists>phi. wt_method G C pTs rT maxs mxl bs et phi"
   299 proof -
   299 proof -
   300   let ?start = "OK (Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err)))
   300   let ?start = "OK (Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err)))
   301                 #(replicate (size bs - 1) (OK None))"
   301                 #(replicate (size bs - 1) (OK None))"
   302 
   302 
   303   assume wf:      "wf_prog wf_mb G"
   303   assume wf:      "wf_prog wf_mb G"
   384   thus ?thesis by blast
   384   thus ?thesis by blast
   385 qed
   385 qed
   386 
   386 
   387 
   387 
   388 theorem wt_kil_complete:
   388 theorem wt_kil_complete:
   389   "[| wt_method G C pTs rT maxs mxl bs et phi; wf_prog wf_mb G; 
   389   "\<lbrakk> wt_method G C pTs rT maxs mxl bs et phi; wf_prog wf_mb G; 
   390       length phi = length bs; is_class G C; \<forall>x \<in> set pTs. is_type G x;
   390       length phi = length bs; is_class G C; \<forall>x \<in> set pTs. is_type G x;
   391       map OK phi \<in> list (length bs) (states G maxs (1+size pTs+mxl)) |]
   391       map OK phi \<in> list (length bs) (states G maxs (1+size pTs+mxl)) \<rbrakk>
   392   ==> wt_kil G C pTs rT maxs mxl et bs"
   392   \<Longrightarrow> wt_kil G C pTs rT maxs mxl et bs"
   393 proof -
   393 proof -
   394   assume wf: "wf_prog wf_mb G"  
   394   assume wf: "wf_prog wf_mb G"  
   395   assume isclass: "is_class G C"
   395   assume isclass: "is_class G C"
   396   assume istype: "\<forall>x \<in> set pTs. is_type G x"
   396   assume istype: "\<forall>x \<in> set pTs. is_type G x"
   397   assume length: "length phi = length bs"
   397   assume length: "length phi = length bs"
   488       moreover
   488       moreover
   489       { fix n'
   489       { fix n'
   490         have "JVMType.le G maxs ?maxr (OK None) (?phi!n)"
   490         have "JVMType.le G maxs ?maxr (OK None) (?phi!n)"
   491           by (auto simp add: JVM_le_Err_conv Err.le_def lesub_def 
   491           by (auto simp add: JVM_le_Err_conv Err.le_def lesub_def 
   492             split: err.splits)        
   492             split: err.splits)        
   493         hence "[| n = Suc n'; n < length ?start |] 
   493         hence "\<lbrakk> n = Suc n'; n < length ?start \<rbrakk> 
   494           ==> JVMType.le G maxs ?maxr (?start!n) (?phi!n)"
   494           \<Longrightarrow> JVMType.le G maxs ?maxr (?start!n) (?phi!n)"
   495           by simp
   495           by simp
   496       }
   496       }
   497       ultimately
   497       ultimately
   498       have "n < length ?start ==> (?start!n) <=_(JVMType.le G maxs ?maxr) (?phi!n)"
   498       have "n < length ?start \<Longrightarrow> (?start!n) <=_(JVMType.le G maxs ?maxr) (?phi!n)"
   499         by (unfold lesub_def) (cases n, blast+)
   499         by (unfold lesub_def) (cases n, blast+)
   500     } 
   500     } 
   501     ultimately show ?thesis by (rule le_listI)
   501     ultimately show ?thesis by (rule le_listI)
   502   qed         
   502   qed         
   503 
   503 
   538 
   538 
   539   The other direction (@{text wt_kil_correct}) can be lifted to
   539   The other direction (@{text wt_kil_correct}) can be lifted to
   540   programs without problems:
   540   programs without problems:
   541 *}
   541 *}
   542 lemma is_type_pTs:
   542 lemma is_type_pTs:
   543   "[| wf_prog wf_mb G; (C,S,fs,mdecls) \<in> set G; (sig,rT,code) \<in> set mdecls; 
   543   "\<lbrakk> wf_prog wf_mb G; (C,S,fs,mdecls) \<in> set G; (sig,rT,code) \<in> set mdecls; 
   544       t \<in> set (snd sig) |]
   544       t \<in> set (snd sig) \<rbrakk>
   545   ==> is_type G t"
   545   \<Longrightarrow> is_type G t"
   546 proof -
   546 proof -
   547   assume "wf_prog wf_mb G" 
   547   assume "wf_prog wf_mb G" 
   548          "(C,S,fs,mdecls) \<in> set G"
   548          "(C,S,fs,mdecls) \<in> set G"
   549          "(sig,rT,code) \<in> set mdecls"
   549          "(sig,rT,code) \<in> set mdecls"
   550   hence "wf_mdecl wf_mb G C (sig,rT,code)"
   550   hence "wf_mdecl wf_mb G C (sig,rT,code)"
   557   show ?thesis by blast
   557   show ?thesis by blast
   558 qed
   558 qed
   559 
   559 
   560 
   560 
   561 theorem jvm_kildall_correct:
   561 theorem jvm_kildall_correct:
   562   "wt_jvm_prog_kildall G ==> \<exists>Phi. wt_jvm_prog G Phi"
   562   "wt_jvm_prog_kildall G \<Longrightarrow> \<exists>Phi. wt_jvm_prog G Phi"
   563 proof -  
   563 proof -  
   564   assume wtk: "wt_jvm_prog_kildall G"
   564   assume wtk: "wt_jvm_prog_kildall G"
   565 
   565 
   566   then obtain wf_mb where
   566   then obtain wf_mb where
   567     wf: "wf_prog wf_mb G"
   567     wf: "wf_prog wf_mb G"