{-|
  Description : Aliasing Rules.
  Copyright   : (c) Paul Govereau and Jean-Baptiste Tristan 2010
  License     : All Rights Reserved
  Maintainer  : Paul Govereau <govereau@cs.harvard.edu>

  This module implements the 'mayAlias' relation used by the validator.
-}
module MD.Aliasing
  ( AliasRules, AliasRule(..)
  , allAlias, mayAlias
  )
where
import MD.Syntax.GDSA

type AliasRules = [AliasRule]
data AliasRule = MayAlias Ident Ident

-- | The default aliasing rules -- everything aliases.

allAlias :: AliasRules
allAlias = []

-- | The may alias relation parametrized by aliasing information.

mayAlias :: AliasRules -> Term -> Term -> Bool
mayAlias ars (GetElemPtr t1 a1 l1) (GetElemPtr t2 a2 l2) =
  case (t1 == t2, a1 == a2, l1 /= l2) of
    (True,True,True) -> False
    (_,False,_)      -> mayAlias ars a1 a2
    (_,_,_)          -> True

mayAlias _ (Proj Val (Alloc _ _ _)) (Proj Val (Alloc _ _ _)) = False
mayAlias _ _ _ = True