Professional Documents
Culture Documents
PUSH n : c, e, s c, n : e, s
ADD : c, z 1 : z 2 : e, s c, (z 1 + z 2 ) : e, s
if z 1 , z 2
if z 1 , z 2
FALSE : c, e, s c, ff : e, s
EQ : c, z 1 : z 2 : e, s c, (z 1 = z 2 ) : e, s
LE : c, z 1 : z 2 : e, s c, (z 1 z 2 ) : e, s
AND : c, t 1 : t 2 : e, s
c, tt : e, s { c, ff : e, s NEG : c, t : e, s
c, ff : e, s { c, tt : e, s FETCH x : c, e, s c, (sx) : e, s
if t = tt; if t = ff.
c, e, s
Abstract Properties
We have two datatypes in the AM code that we need to be aware of and make abstract properties for; namely numbers and booleans. The Abstract Properties creates a lattice as shown by the graphs.
More about the properties of properties can be read in Semantics with Applications.
Abstract Interpretation
We adapt the above semantics to work on abstract properties. The operation PUSH-n pushes a constant value n onto the stack. We redefine it for our abstract interpretation to push not the value itself but instead its property.
ADD : c, v 1 : v 2 : c, ps c, (v 1 + S v 2 ) : e, ps
MULT : c, v 1 : v 2 : c, ps c, (v 1 S v 2 ) : e, ps SUB : c, v 1 : v 2 : c, ps c, (v 1 S v 2 ) : e, ps
if z 1 , z 2 if z 1 , z 2 if z 1 , z 2
TRUE : c, e, ps c, TT : e, ps
FALSE : c, e, ps c, FF : e, ps
EQ and LE is redefined similarly to ADD.
EQ : c, z 1 : z 2 : c, ps c, (z 1 = S z 2 ) : e, ps
LE : c, z 1 : z 2 : c, ps c, (z 1 S z 2 ) : e, ps
AND is where our first optimisation kicks in. If it is given that both t1 and t2 has the property TT, or to put it differently TT TE t1,t2 then the AND operation will always be true.
NEG is similar
FETCH-x pushes the value bound to x onto the stack. We redefine this to work on the property instead.
Results
We now run a couple of example programs (while-lang.) through our tool and explain our findings. It should be noted that we present the heap values as those after the statement has run. RHS is, of course, the right hand side of the assignement.
Dangerous Example
code heap rhs x := 7; {x=(POS)} (POS) x := (x - 7); {x=(Z)} (Z) x := (7 / x); {x=(ANY_A)} (ANY_A)! x := (x + 7) {x=(ANY_A)} (ANY_A)! Result: Possible uncaught exception We note that ANY_A_ is in the heap. This means that there is a potential for an error to be thrown. This creeps up after a division with a number with the property Z, which means that it can be any number.
Fibonacci Example
code heap rhs k := 20; {k=(POS)} (POS) i := 0; {k=(POS), i=(ZERO)} (ZERO) j := 1; {j=(POS), k=(POS), i=(ZERO)} (POS) while 2 <= k do (T) k := (k - 1); {tmp=(POS), j=(POS), k=(Z), i=(NON_NEG)} (Z) tmp := j; {tmp=(POS), j=(POS), k=(Z), i=(NON_NEG)} (POS) j := (i + j); {tmp=(POS), j=(POS), k=(Z), i=(NON_NEG)} (POS) i := tmp {tmp=(POS), j=(POS), k=(Z), i=(NON_NEG)} (POS) Normal Termination This Fibonacci example shows that it works on loops; notice that on the seventh line (j := i + j) that i is NON_NEG and started as ZERO. We can also see that the while loop has T as the rhs which means that it might run. Had it been FF it would never have run and if it had been TT it would have been an infinite loop.