src/HOL/BCV/Machine.thy
author wenzelm
Mon, 29 Nov 1999 15:52:49 +0100
changeset 8039 a901bafe4578
parent 7626 5997f35954d7
permissions -rw-r--r--
Goal: tuned pris;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7626
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/BCV/Machine.thy
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
     2
    ID:         $Id$
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
     3
    Author:     Tobias Nipkow
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
     4
    Copyright   1999 TUM
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
     5
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
     6
A register machine.
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
     7
*)
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
     8
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
     9
Machine = Types + DFAimpl +
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    10
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    11
datatype ('a,'b,'c)instr =
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    12
    Move nat nat
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    13
  | Aload 'a nat | Bload 'b nat | Cload 'c nat
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    14
  | Aop nat nat nat | Bop nat nat nat | Cop nat nat nat
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    15
  | Comp nat nat nat
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    16
  | Halt
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    17
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    18
consts maxreg :: ('a,'b,'c)instr => nat
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    19
       maxregs :: ('a,'b,'c)instr list => nat
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    20
primrec
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    21
"maxreg(Move m n) = max m n"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    22
"maxreg(Aload x n) = n"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    23
"maxreg(Bload x n) = n"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    24
"maxreg(Cload x n) = n"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    25
"maxreg(Aop i j k) = max i (max j k)"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    26
"maxreg(Bop i j k) = max i (max j k)"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    27
"maxreg(Cop i j k) = max i (max j k)"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    28
"maxreg(Comp i j l) = max i j"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    29
"maxreg Halt = 0"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    30
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    31
primrec
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    32
"maxregs [] = 0"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    33
"maxregs (x#xs) = max (maxreg x+1) (maxregs xs)"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    34
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    35
constdefs
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    36
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    37
 wt_instr :: ('a,'b,'c)instr => nat => typ list option list => bool
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    38
"wt_instr b p T ==
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    39
 case T!p of
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    40
   None => True
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    41
 | Some ts =>
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    42
 case b of
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    43
   Move i j  => Some(ts[j:=ts!i]) <= T!(p+1)
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    44
 | Aload x i => Some(ts[i:=Atyp]) <= T!(p+1)
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    45
 | Bload x i => Some(ts[i:=Btyp]) <= T!(p+1)
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    46
 | Cload x i => Some(ts[i:=Ctyp]) <= T!(p+1)
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    47
 | Aop i j k => ts!i <= Atyp & ts!j <= Atyp & Some(ts[k:=Atyp]) <= T!(p+1)
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    48
 | Bop i j k => ts!i <= Btyp & ts!j <= Btyp & Some(ts[k:=Btyp]) <= T!(p+1)
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    49
 | Cop i j k => ts!i <= Ctyp & ts!j <= Ctyp & Some(ts[k:=Ctyp]) <= T!(p+1)
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    50
 | Comp i j q => (ts!i <= ts!j & ts!j ~= Top | ts!j <= ts!i & ts!i ~= Top) &
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    51
                 T!p <= T!(p+1) & T!p <= T!q
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    52
 | Halt =>      True"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    53
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    54
 stype :: ('a,'b,'c)instr list => typ list set
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    55
"stype bs == listsn (maxregs bs) UNIV"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    56
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    57
constdefs
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    58
 succs :: "('a,'b,'c)instr => nat => nat list"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    59
"succs instr p ==
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    60
  case instr of
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    61
    Move i j  => [p+1]
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    62
  | Aload x i => [p+1]
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    63
  | Bload x i => [p+1]
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    64
  | Cload x i => [p+1]
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    65
  | Aop i j k => [p+1]
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    66
  | Bop i j k => [p+1]
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    67
  | Cop i j k => [p+1]
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    68
  | Comp i j q => [p+1,q]
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    69
  | Halt       => []"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    70
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    71
 exec :: "('a,'b,'c)instr => typ list => typ list option"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    72
"exec instr ts ==
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    73
  case instr of
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    74
    Move i j  => Some(ts[j := ts!i])
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    75
  | Aload x i => Some(ts[i := Atyp])
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    76
  | Bload x i => Some(ts[i := Btyp])
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    77
  | Cload x i => Some(ts[i := Ctyp])
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    78
  | Aop i j k => if ts!i <= Atyp & ts!j <= Atyp
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    79
                 then Some(ts[k := Atyp])
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    80
                 else None
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    81
  | Bop i j k => if ts!i <= Btyp & ts!j <= Btyp
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    82
                 then Some(ts[k := Btyp])
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    83
                 else None
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    84
  | Cop i j k => if ts!i <= Ctyp & ts!j <= Ctyp
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    85
                 then Some(ts[k := Ctyp])
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    86
                 else None
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    87
  | Comp i j q => if ts!i <= ts!j & ts!j ~= Top | ts!j <= ts!i & ts!i ~= Top
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    88
                  then Some ts
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    89
                  else None
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    90
  | Halt       => Some ts"
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    91
(*
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    92
  | Bop i j k => if ts!i <= Btyp & ts!j <= Btyp
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    93
                 then Some(ts[k := ts!i+ts!j])
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    94
                 else None
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    95
*)
5997f35954d7 A new theory: a model of bytecode verification.
nipkow
parents:
diff changeset
    96
end