packages feed

language-cil 0.2.1 → 0.2.2

raw patch · 4 files changed

+337/−17 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Language.Cil.Build: cge :: MethodDecl
- Language.Cil.Build: cle :: MethodDecl
- Language.Cil.Syntax: Cge :: OpCode
- Language.Cil.Syntax: Cle :: OpCode
+ Language.Cil.Build: add_ovf :: MethodDecl
+ Language.Cil.Build: add_ovf_un :: MethodDecl
+ Language.Cil.Build: and :: MethodDecl
+ Language.Cil.Build: break :: MethodDecl
+ Language.Cil.Build: ckfinite :: MethodDecl
+ Language.Cil.Build: div :: MethodDecl
+ Language.Cil.Build: div_un :: MethodDecl
+ Language.Cil.Build: ldelem_i :: MethodDecl
+ Language.Cil.Build: ldelem_i1 :: MethodDecl
+ Language.Cil.Build: ldelem_i2 :: MethodDecl
+ Language.Cil.Build: ldelem_i4 :: MethodDecl
+ Language.Cil.Build: ldelem_i8 :: MethodDecl
+ Language.Cil.Build: ldelem_r4 :: MethodDecl
+ Language.Cil.Build: ldelem_r8 :: MethodDecl
+ Language.Cil.Build: ldelem_ref :: MethodDecl
+ Language.Cil.Build: ldelem_u1 :: MethodDecl
+ Language.Cil.Build: ldelem_u2 :: MethodDecl
+ Language.Cil.Build: ldelem_u4 :: MethodDecl
+ Language.Cil.Build: ldelem_u8 :: MethodDecl
+ Language.Cil.Build: ldelema :: MethodDecl
+ Language.Cil.Build: ldlen :: MethodDecl
+ Language.Cil.Build: ldnull :: MethodDecl
+ Language.Cil.Build: mul_ovf :: MethodDecl
+ Language.Cil.Build: mul_ovf_un :: MethodDecl
+ Language.Cil.Build: newarr :: PrimitiveType -> MethodDecl
+ Language.Cil.Build: not :: MethodDecl
+ Language.Cil.Build: or :: MethodDecl
+ Language.Cil.Build: rem_un :: MethodDecl
+ Language.Cil.Build: shl :: MethodDecl
+ Language.Cil.Build: shr :: MethodDecl
+ Language.Cil.Build: shr_un :: MethodDecl
+ Language.Cil.Build: stelem_i :: MethodDecl
+ Language.Cil.Build: stelem_i1 :: MethodDecl
+ Language.Cil.Build: stelem_i2 :: MethodDecl
+ Language.Cil.Build: stelem_i4 :: MethodDecl
+ Language.Cil.Build: stelem_i8 :: MethodDecl
+ Language.Cil.Build: stelem_r4 :: MethodDecl
+ Language.Cil.Build: stelem_r8 :: MethodDecl
+ Language.Cil.Build: stelem_ref :: MethodDecl
+ Language.Cil.Build: sub_ovf :: MethodDecl
+ Language.Cil.Build: sub_ovf_un :: MethodDecl
+ Language.Cil.Build: throw :: MethodDecl
+ Language.Cil.Build: unaligned :: Alignment -> MethodDecl
+ Language.Cil.Build: unalignedPtr :: Alignment -> MethodDecl -> MethodDecl
+ Language.Cil.Build: volatile :: MethodDecl
+ Language.Cil.Build: volatilePtr :: MethodDecl -> MethodDecl
+ Language.Cil.Build: xor :: MethodDecl
+ Language.Cil.Pretty: instance Pretty Alignment
+ Language.Cil.Syntax: Add_ovf :: OpCode
+ Language.Cil.Syntax: Add_ovf_un :: OpCode
+ Language.Cil.Syntax: Break :: OpCode
+ Language.Cil.Syntax: ByteAligned :: Alignment
+ Language.Cil.Syntax: Ckfinite :: OpCode
+ Language.Cil.Syntax: Div :: OpCode
+ Language.Cil.Syntax: Div_un :: OpCode
+ Language.Cil.Syntax: DoubleByteAligned :: Alignment
+ Language.Cil.Syntax: Ldelem_i :: OpCode
+ Language.Cil.Syntax: Ldelem_i1 :: OpCode
+ Language.Cil.Syntax: Ldelem_i2 :: OpCode
+ Language.Cil.Syntax: Ldelem_i4 :: OpCode
+ Language.Cil.Syntax: Ldelem_i8 :: OpCode
+ Language.Cil.Syntax: Ldelem_r4 :: OpCode
+ Language.Cil.Syntax: Ldelem_r8 :: OpCode
+ Language.Cil.Syntax: Ldelem_ref :: OpCode
+ Language.Cil.Syntax: Ldelem_u1 :: OpCode
+ Language.Cil.Syntax: Ldelem_u2 :: OpCode
+ Language.Cil.Syntax: Ldelem_u4 :: OpCode
+ Language.Cil.Syntax: Ldelem_u8 :: OpCode
+ Language.Cil.Syntax: Ldelema :: OpCode
+ Language.Cil.Syntax: Ldlen :: OpCode
+ Language.Cil.Syntax: Ldnull :: OpCode
+ Language.Cil.Syntax: Mul_ovf :: OpCode
+ Language.Cil.Syntax: Mul_ovf_un :: OpCode
+ Language.Cil.Syntax: Newarr :: PrimitiveType -> OpCode
+ Language.Cil.Syntax: Not :: OpCode
+ Language.Cil.Syntax: Or :: OpCode
+ Language.Cil.Syntax: QuadByteAligned :: Alignment
+ Language.Cil.Syntax: Rem_un :: OpCode
+ Language.Cil.Syntax: Shl :: OpCode
+ Language.Cil.Syntax: Shr :: OpCode
+ Language.Cil.Syntax: Shr_un :: OpCode
+ Language.Cil.Syntax: Stelem_i :: OpCode
+ Language.Cil.Syntax: Stelem_i1 :: OpCode
+ Language.Cil.Syntax: Stelem_i2 :: OpCode
+ Language.Cil.Syntax: Stelem_i4 :: OpCode
+ Language.Cil.Syntax: Stelem_i8 :: OpCode
+ Language.Cil.Syntax: Stelem_r4 :: OpCode
+ Language.Cil.Syntax: Stelem_r8 :: OpCode
+ Language.Cil.Syntax: Stelem_ref :: OpCode
+ Language.Cil.Syntax: Sub_ovf :: OpCode
+ Language.Cil.Syntax: Sub_ovf_un :: OpCode
+ Language.Cil.Syntax: Throw :: OpCode
+ Language.Cil.Syntax: Unaligned :: Alignment -> OpCode
+ Language.Cil.Syntax: UnalignedPtr :: Alignment -> OpCode -> OpCode
+ Language.Cil.Syntax: Volatile :: OpCode
+ Language.Cil.Syntax: VolatilePtr :: OpCode -> OpCode
+ Language.Cil.Syntax: Xor :: OpCode
+ Language.Cil.Syntax: data Alignment
+ Language.Cil.Syntax: instance Show Alignment

Files

language-cil.cabal view
@@ -1,5 +1,5 @@ name:                language-cil-version:             0.2.1+version:             0.2.2 homepage:            https://github.com/tomlokhorst/language-cil synopsis:            Manipulating Common Intermediate Language AST description:         Language-Cil is a Haskell library for manipulating CIL
src/Language/Cil/Build.hs view
@@ -14,6 +14,9 @@    -- * mdecl functions   , add+  , add_ovf+  , add_ovf_un+  , and   , beq   , bge   , bgt@@ -21,16 +24,18 @@   , blt   , box   , br+  , break   , brfalse   , brtrue   , call   , callvirt   , ceq-  , cge   , cgt-  , cle+  , ckfinite   , clt    , dup+  , div+  , div_un   , isinst   , ldarg   , ldargN@@ -39,6 +44,19 @@   , ldc_r4   , ldc_r8   , ldchar+  , ldelem_i+  , ldelem_i1+  , ldelem_i2+  , ldelem_i4+  , ldelem_i8+  , ldelem_u1+  , ldelem_u2+  , ldelem_u4+  , ldelem_u8+  , ldelem_r4+  , ldelem_r8+  , ldelem_ref+  , ldelema   , ldfld   , ldflda   , ldftn@@ -53,20 +71,39 @@   , ldind_u1   , ldind_u2   , ldind_u4+  , ldlen   , ldloc   , ldlocN   , ldloca   , ldlocaN+  , ldnull   , ldsfld   , ldsflda   , ldstr   , mul+  , mul_ovf+  , mul_ovf_un   , neg+  , newarr   , newobj   , nop+  , not+  , or   , pop   , rem+  , rem_un   , ret+  , shl+  , shr+  , shr_un+  , stelem_i+  , stelem_i1+  , stelem_i2+  , stelem_i4+  , stelem_i8+  , stelem_r4+  , stelem_r8+  , stelem_ref   , stfld   , stind_i   , stind_i1@@ -80,9 +117,17 @@   , stlocN   , stsfld   , sub+  , sub_ovf+  , sub_ovf_un   , tail   , tailcall+  , throw+  , unaligned+  , unalignedPtr   , unbox+  , volatile+  , volatilePtr+  , xor    -- * Convenient AST functions   , label@@ -97,9 +142,9 @@   , mscorlibRef   ) where --- If someone uses the `rem' or `tail' opcode, they can deal with the ambiguous--- occurence themselves!-import Prelude hiding (rem, tail)+-- Ambiguous occurences of functions can be resolved when by importing this+-- module qualified, or by hiding Prelude functions.+import Prelude hiding (rem, tail, and, or, not, break, div) import Data.Char (ord)  import Language.Cil.Syntax@@ -126,6 +171,15 @@ add :: MethodDecl add = mdecl $ Add +add_ovf :: MethodDecl+add_ovf = mdecl $ Add_ovf++add_ovf_un :: MethodDecl+add_ovf_un = mdecl $ Add_ovf_un++and :: MethodDecl+and = mdecl $ And+ beq :: Label -> MethodDecl beq = mdecl . Beq @@ -150,6 +204,9 @@ br :: Label -> MethodDecl br = mdecl . Br +break :: MethodDecl+break = mdecl $ Break+ brfalse :: Label -> MethodDecl brfalse = mdecl . Brfalse @@ -162,16 +219,23 @@ callvirt :: PrimitiveType -> AssemblyName -> TypeName -> MethodName -> [PrimitiveType] -> MethodDecl callvirt p l t m ps = mdecl $ CallVirt p l t m ps -ceq, cge, cgt, cle, clt :: MethodDecl+ceq, cgt, clt :: MethodDecl ceq = mdecl $ Ceq-cge = mdecl $ Cge cgt = mdecl $ Cgt-cle = mdecl $ Cle clt = mdecl $ Clt +ckfinite :: MethodDecl+ckfinite = mdecl $ Ckfinite+ dup :: MethodDecl dup = mdecl $ Dup +div :: MethodDecl+div = mdecl $ Div++div_un :: MethodDecl+div_un = mdecl $ Div_un+ isinst :: TypeName -> MethodDecl isinst = mdecl . Isinst @@ -212,6 +276,45 @@ ldchar :: Char -> MethodDecl ldchar c = ldc_i4 (toInteger $ ord c) +ldelem_i :: MethodDecl+ldelem_i = mdecl $ Ldelem_i++ldelem_i1 :: MethodDecl+ldelem_i1 = mdecl $ Ldelem_i1++ldelem_i2 :: MethodDecl+ldelem_i2 = mdecl $ Ldelem_i2++ldelem_i4 :: MethodDecl+ldelem_i4 = mdecl $ Ldelem_i4++ldelem_i8 :: MethodDecl+ldelem_i8 = mdecl $ Ldelem_i8++ldelem_u1 :: MethodDecl+ldelem_u1 = mdecl $ Ldelem_u1++ldelem_u2 :: MethodDecl+ldelem_u2 = mdecl $ Ldelem_u2++ldelem_u4 :: MethodDecl+ldelem_u4 = mdecl $ Ldelem_u4++ldelem_u8 :: MethodDecl+ldelem_u8 = mdecl $ Ldelem_u8++ldelem_r4 :: MethodDecl+ldelem_r4 = mdecl $ Ldelem_r4++ldelem_r8 :: MethodDecl+ldelem_r8 = mdecl $ Ldelem_r8++ldelem_ref :: MethodDecl+ldelem_ref = mdecl $ Ldelem_ref++ldelema :: MethodDecl+ldelema = mdecl $ Ldelema+ ldfld :: PrimitiveType -> AssemblyName -> TypeName -> FieldName -> MethodDecl ldfld p a t f = mdecl $ Ldfld p a t f @@ -254,6 +357,9 @@ ldind_u4 :: MethodDecl ldind_u4 = mdecl $ Ldind_u4 +ldlen :: MethodDecl+ldlen = mdecl $ Ldlen+ ldloc :: Offset -> MethodDecl ldloc 0 = mdecl $ Ldloc_0 ldloc 1 = mdecl $ Ldloc_1@@ -270,6 +376,9 @@ ldlocaN :: LocalName -> MethodDecl ldlocaN nm = mdecl $ LdlocaN nm +ldnull :: MethodDecl+ldnull = mdecl $ Ldnull+ ldsfld :: PrimitiveType -> AssemblyName -> TypeName -> FieldName -> MethodDecl ldsfld p a t f = mdecl $ Ldsfld p a t f @@ -282,9 +391,18 @@ mul :: MethodDecl mul = mdecl $ Mul +mul_ovf :: MethodDecl+mul_ovf = mdecl $ Mul_ovf++mul_ovf_un :: MethodDecl+mul_ovf_un = mdecl $ Mul_ovf_un+ neg :: MethodDecl neg = mdecl $ Neg +newarr :: PrimitiveType -> MethodDecl+newarr t = mdecl $ Newarr t+ -- | Creates a new object. -- Note that this function assumes the constructor returns Void. -- If this is not the case, call the Newobj constructor manually.@@ -294,15 +412,57 @@ nop :: MethodDecl nop = mdecl $ Nop +not :: MethodDecl+not = mdecl $ Not++or :: MethodDecl+or = mdecl $ Or+ pop :: MethodDecl pop = mdecl $ Pop  rem :: MethodDecl rem = mdecl $ Rem +rem_un :: MethodDecl+rem_un = mdecl $ Rem_un+ ret :: MethodDecl ret = mdecl $ Ret +shl :: MethodDecl+shl = mdecl $ Shl++shr :: MethodDecl+shr = mdecl $ Shr++shr_un :: MethodDecl+shr_un = mdecl $ Shr_un++stelem_i :: MethodDecl+stelem_i = mdecl $ Stelem_i++stelem_i1 :: MethodDecl+stelem_i1 = mdecl $ Stelem_i1++stelem_i2 :: MethodDecl+stelem_i2 = mdecl $ Stelem_i2++stelem_i4 :: MethodDecl+stelem_i4 = mdecl $ Stelem_i4++stelem_i8 :: MethodDecl+stelem_i8 = mdecl $ Stelem_i8++stelem_r4 :: MethodDecl+stelem_r4 = mdecl $ Stelem_r4++stelem_r8 :: MethodDecl+stelem_r8 = mdecl $ Stelem_r8++stelem_ref :: MethodDecl+stelem_ref = mdecl $ Stelem_ref+ stfld :: PrimitiveType -> AssemblyName -> TypeName -> FieldName -> MethodDecl stfld p a t f = mdecl $ Stfld p a t f @@ -346,6 +506,12 @@ sub :: MethodDecl sub = mdecl $ Sub +sub_ovf :: MethodDecl+sub_ovf = mdecl $ Sub_ovf++sub_ovf_un :: MethodDecl+sub_ovf_un = mdecl $ Sub_ovf_un+ tail :: MethodDecl tail = mdecl $ Tail @@ -353,11 +519,69 @@ tailcall (Instr (OpCode oc)) = Instr (OpCode (Tailcall oc)) tailcall _                   = error $ "Language.Cil.Build.tailcall: Can't tailcall supplied argument" +throw :: MethodDecl+throw = mdecl $ Throw +unaligned :: Alignment -> MethodDecl+unaligned a = mdecl $ Unaligned a++unalignedPtr :: Alignment -> MethodDecl -> MethodDecl+unalignedPtr a (Instr (OpCode oc)) | supportsUnaligned oc = mdecl $ UnalignedPtr a oc+unalignedPtr _ _                                          = error $ "Language.Cil.Build.unalignedPtr: Supplied argument doesn't require alignment"++volatile :: MethodDecl+volatile = mdecl $ Volatile++volatilePtr :: MethodDecl -> MethodDecl+volatilePtr (Instr (OpCode oc)) | supportsVolatile oc = mdecl $ VolatilePtr oc+volatilePtr _                                         = error $ "Language.Cil.Build.volatilePtr: Supplied argument cannot be marked volatile"++xor :: MethodDecl+xor = mdecl $ Xor+ -- Helper functions  mdecl :: OpCode -> MethodDecl mdecl i = Instr $ OpCode i++supportsUnaligned :: OpCode -> Bool+supportsUnaligned (VolatilePtr oc) = supportsPrefix oc+supportsUnaligned oc               = supportsPrefix oc++supportsVolatile :: OpCode -> Bool+supportsVolatile (UnalignedPtr _ oc) = supportsPrefix oc+supportsVolatile oc                  = supportsPrefix oc++supportsPrefix :: OpCode -> Bool+supportsPrefix Ldind_i   = True+supportsPrefix Ldind_i1  = True+supportsPrefix Ldind_i2  = True+supportsPrefix Ldind_i4  = True+supportsPrefix Ldind_i8  = True+supportsPrefix Ldind_r4  = True+supportsPrefix Ldind_r8  = True+supportsPrefix Ldind_ref = True+supportsPrefix Ldind_u1  = True+supportsPrefix Ldind_u2  = True+supportsPrefix Ldind_u4  = True+supportsPrefix Stind_i   = True+supportsPrefix Stind_i1  = True+supportsPrefix Stind_i2  = True+supportsPrefix Stind_i4  = True+supportsPrefix Stind_i8  = True+supportsPrefix Stind_r4  = True+supportsPrefix Stind_r8  = True+supportsPrefix Stind_ref = True+supportsPrefix (Ldfld _ _ _ _) = True+supportsPrefix (Stfld _ _ _ _) = True+-- there are several cases for not-yet-supported opcodes+-- supportsPrefix (Ldobj ...)+-- supportsPrefix (Stobj ...)+-- supportsPrefix (Initblk ...)+-- supportsPrefix (Cpblk ...)+supportsPrefix _         = False++  -- Convenient AST functions 
src/Language/Cil/Pretty.hs view
@@ -162,6 +162,8 @@  instance Pretty OpCode where   pr (Add)                 = ("add" ++)+  pr (Add_ovf)             = ("add.ovf" ++)+  pr (Add_ovf_un)          = ("add.ovf.un" ++)   pr (And)                 = ("and" ++)   pr (Beq l)               = ("beq " ++) . (l ++)   pr (Bge l)               = ("bge " ++) . (l ++)@@ -170,6 +172,7 @@   pr (Blt l)               = ("blt " ++) . (l ++)   pr (Box t)               = ("box " ++) . pr t   pr (Br l)                = ("br " ++) . (l ++)+  pr (Break)               = ("break" ++)   pr (Brfalse l)           = ("brfalse " ++) . (l ++)   pr (Brtrue l)            = ("brtrue " ++) . (l ++)   pr (Call ccs t a c m ps) = ("call " ++) . prList ccs . pr t . sp@@ -177,10 +180,11 @@   pr (CallVirt t a c m ps) = ("callvirt instance " ++) . prsp t . sp                                . prCall a c m ps   pr (Ceq)                 = ("ceq" ++)-  pr (Cge)                 = ("cge" ++)   pr (Cgt)                 = ("cgt" ++)-  pr (Cle)                 = ("cle" ++)+  pr (Ckfinite)            = ("ckfinite" ++)   pr (Clt)                 = ("clt" ++)+  pr (Div)                 = ("div" ++)+  pr (Div_un)              = ("div.un" ++)   pr (Dup)                 = ("dup" ++)   pr (Isinst nm)           = ("isinst " ++) . prName nm   pr (Ldarg x)             = ("ldarg " ++) . shows x@@ -204,6 +208,16 @@   pr (Ldc_i8 x)            = ("ldc.i8 " ++) . shows x   pr (Ldc_r4 x)            = ("ldc.r4 " ++) . shows x   pr (Ldc_r8 x)            = ("ldc.r8 " ++) . shows x+  pr (Ldelem_i)            = ("ldelem.i " ++)+  pr (Ldelem_i1)           = ("ldelem.i1 " ++)+  pr (Ldelem_i2)           = ("ldelem.i2 " ++)+  pr (Ldelem_i4)           = ("ldelem.i4 " ++)+  pr (Ldelem_i8)           = ("ldelem.i8 " ++)+  pr (Ldelem_u1)           = ("ldelem.u1 " ++)+  pr (Ldelem_u2)           = ("ldelem.u2 " ++)+  pr (Ldelem_u4)           = ("ldelem.u4 " ++)+  pr (Ldelem_u8)           = ("ldelem.u8 " ++)+  pr (Ldelem_ref)          = ("ldelem.ref " ++)   pr (Ldfld t a c f)       = ("ldfld " ++) . pr t . sp . prFld a c f   pr (Ldflda t a c f)      = ("ldflda " ++) . pr t . sp . prFld a c f   pr (Ldftn t a c m ps)    = ("ldftn " ++) . pr t . sp . prCall a c m ps@@ -218,6 +232,7 @@   pr (Ldind_u1)            = ("ldind.u1 " ++)   pr (Ldind_u2)            = ("ldind.u2 " ++)   pr (Ldind_u4)            = ("ldind.u4 " ++)+  pr (Ldlen)               = ("ldlen " ++)   pr (Ldloc x)             = ("ldloc " ++) . shows x   pr (Ldloc_0)             = ("ldloc.0 " ++)   pr (Ldloc_1)             = ("ldloc.1 " ++)@@ -226,17 +241,33 @@   pr (LdlocN nm)           = ("ldloc " ++) . prName nm   pr (Ldloca x)            = ("ldloca " ++) . shows x   pr (LdlocaN nm)          = ("ldloca " ++) . prName nm+  pr (Ldnull)              = ("ldnull " ++)   pr (Ldsfld t a c f)      = ("ldsfld " ++) . pr t . sp . prFld a c f   pr (Ldsflda t a c f)     = ("ldsflda " ++) . pr t . sp . prFld a c f   pr (Ldstr s)             = ("ldstr " ++) . shows s   pr (Mul)                 = ("mul" ++)+  pr (Mul_ovf)             = ("mul.ovf" ++)+  pr (Mul_ovf_un)          = ("mul.ovf.un" ++)   pr (Neg)                 = ("neg" ++)+  pr (Newarr t)            = ("newarr " ++) . pr t   pr (Newobj t a c ps)     = ("newobj instance " ++) . pr t . sp                                . prNewobj a c ps   pr (Nop)                 = ("nop" ++)+  pr (Not)                 = ("not" ++)+  pr (Or)                  = ("or" ++)   pr (Pop)                 = ("pop" ++)   pr (Rem)                 = ("rem" ++)+  pr (Rem_un)              = ("rem.un" ++)   pr (Ret)                 = ("ret" ++)+  pr (Shl)                 = ("shl" ++)+  pr (Shr)                 = ("shr" ++)+  pr (Shr_un)              = ("shr.un" ++)+  pr (Stelem_i)            = ("stelem.i " ++)+  pr (Stelem_i1)           = ("stelem.i1 " ++)+  pr (Stelem_i2)           = ("stelem.i2 " ++)+  pr (Stelem_i4)           = ("stelem.i4 " ++)+  pr (Stelem_i8)           = ("stelem.i8 " ++)+  pr (Stelem_ref)          = ("stelem.ref " ++)   pr (Stfld t a c f)       = ("stfld " ++) . pr t . sp . prFld a c f   pr (Stind_i)             = ("stind.i " ++)   pr (Stind_i1)            = ("stind.i1 " ++)@@ -254,9 +285,17 @@   pr (StlocN nm)           = ("stloc " ++) . prName nm   pr (Stsfld t a c f)      = ("stsfld " ++) . pr t . sp . prFld a c f   pr (Sub)                 = ("sub" ++)+  pr (Sub_ovf)             = ("sub.ovf" ++)+  pr (Sub_ovf_un)          = ("sub.ovf.un" ++)   pr (Tail)                = ("tail." ++)   pr (Tailcall opcode)     = ("tail. " ++) . pr opcode+  pr (Throw)               = ("throw" ++)+  pr (Unaligned a)         = ("unaligned. " ++) . pr a+  pr (UnalignedPtr a opcode)  = ("unaligned. " ++) . pr a . sp . pr opcode   pr (Unbox t)             = ("unbox " ++) . pr t+  pr (Volatile)            = ("volatile." ++)+  pr (VolatilePtr opcode)  = ("volatile. " ++) . pr opcode+  pr (Xor)                 = ("xor" ++)  instance Pretty CallConv where   pr (CcInstance) = ("instance" ++)@@ -312,6 +351,11 @@                                        . ("<" ++) . foldr (.) id (intersperse ("," ++) (map ((("!" ++) .) . prName) gs)) . (">" ++)   pr (GenericType x)     = ("!" ++) . shows x   pr (ByRef pt)          = pr pt . ("&" ++)++instance Pretty Alignment where+  pr ByteAligned         = ("1" ++)+  pr DoubleByteAligned   = ("2" ++)+  pr QuadByteAligned     = ("4" ++)  -- Helper functions, to pretty print prsp :: (Pretty a) => a -> ShowS
src/Language/Cil/Syntax.hs view
@@ -36,6 +36,7 @@   , Label   , OpCode        (..)   , PrimitiveType (..)+  , Alignment     (..)   , CallConv      (..)   ) where @@ -145,6 +146,13 @@   | GenericType Offset   deriving Show +-- | A specification of pointer alignment.+data Alignment+  = ByteAligned+  | DoubleByteAligned+  | QuadByteAligned+  deriving Show+ -- | A Method definition in CIL. data MethodDef   = Constructor [MethAttr] PrimitiveType [Parameter] [MethodDecl]@@ -204,14 +212,17 @@ -- for a more complete list with documentation. data OpCode   = Add                -- ^ Pops 2 values, adds the values, pushes result.+  | Add_ovf            -- ^ Pops 2 values, adds the values with a signed overflow check, pushes result.+  | Add_ovf_un         -- ^ Pops 2 values, adds the values with an unsigned overflow check, pushes result.   | And                -- ^ Pops 2 values, do bitwise AND between the values, pushes result.   | Beq Label          -- ^ Pops 2 values, if first value is equal to second value, jump to specified label.   | Bge Label          -- ^ Pops 2 values, if first value is greater or equal to second value, jump to specified label.   | Bgt Label          -- ^ Pops 2 values, if first value is greater than second value, jump to specified label.-  | Ble Label          -- ^ Pops 2 values, if first value is lesser or equal to second value, jump to specified label.-  | Blt Label          -- ^ Pops 2 values, if first value is lesser or equal to second value, jump to specified label.+  | Ble Label          -- ^ Pops 2 values, if first value is less or equal to second value, jump to specified label.+  | Blt Label          -- ^ Pops 2 values, if first value is less than second value, jump to specified label.   | Box PrimitiveType  -- ^ Pops 1 value, boxes value type, pushes object reference.   | Br Label           -- ^ Unconditionally jump to specified label.+  | Break              -- ^ Inform a debugger that a breakpoint has been reached.   | Brfalse Label      -- ^ Pops 1 value, if value is false, null reference or zero, jump to specified label.   | Brtrue Label       -- ^ Pops 1 value, if value is true, not null or non-zero, jump to specified label.   | Call@@ -230,11 +241,12 @@       , paramTypes   :: [PrimitiveType] -- ^ Types of the formal parameters of the method.       } -- ^ Pops /n/ values, calls specified virtual method, pushes return value. (where /n/ is the number of formal parameters of the method).   | Ceq                -- ^ Pops 2 values, if they are equal, pushes 1 to stack; otherwise, pushes 0.-  | Cge                -- ^ Pops 2 values and compares them.   | Cgt                -- ^ Pops 2 values and compares them.-  | Cle                -- ^ Pops 2 values and compares them.+  | Ckfinite           -- ^ Pops a float or double. Throws an ArithmeticException if the popped value is NaN or +/- infinity. Pushes the popped value.   | Clt                -- ^ Pops 2 values and compares them.   | Dup                -- ^ Pops 1 value, copies it, pushes the same value twise.+  | Div                -- ^ Pops 2 values, divides the first by the second, pushes the result.+  | Div_un             -- ^ Pops 2 integers, divides the first by the second when consider as unsigned integers, pushes the result.   | Isinst TypeName    -- ^ Tests if an object reference is an instance of class, returning either a null reference or an instance of that class or interface.   | Ldarg Offset       -- ^ Loads /n/-th argument to current method onto stack.   | Ldarg_0            -- ^ Loads 0th argument to current method onto stack.@@ -257,6 +269,19 @@   | Ldc_i8 Integer     -- ^ Loads the supplied 64-bit integer onto the stack.   | Ldc_r4 Float       -- ^ Loads the supplied 32-bit float onto the stack.   | Ldc_r8 Double      -- ^ Loads the supplied 64-bit double onto the stack.+  | Ldelem_i           -- ^ Pops an array reference and an index. Pushes the native integer in the specified slot of the array.+  | Ldelem_i1          -- ^ Pops an array reference and an index. Pushes the 8-bit integer in the specified slot of the array.+  | Ldelem_i2          -- ^ Pops an array reference and an index. Pushes the 16-bit integer in the specified slot of the array.+  | Ldelem_i4          -- ^ Pops an array reference and an index. Pushes the 32-bit integer in the specified slot of the array.+  | Ldelem_i8          -- ^ Pops an array reference and an index. Pushes the 64-bit integer in the specified slot of the array.+  | Ldelem_u1          -- ^ Pops an array reference and an index. Pushes the unsigned 8-bit integer in the specified slot of the array.+  | Ldelem_u2          -- ^ Pops an array reference and an index. Pushes the unsigned 16-bit integer in the specified slot of the array.+  | Ldelem_u4          -- ^ Pops an array reference and an index. Pushes the unsigned 32-bit integer in the specified slot of the array.+  | Ldelem_u8          -- ^ Pops an array reference and an index. Pushes the unsigned 64-bit integer in the specified slot of the array.+  | Ldelem_r4          -- ^ Pops an array reference and an index. Pushes the float in the specified slot of the array.+  | Ldelem_r8          -- ^ Pops an array reference and an index. Pushes the double in the specified slot of the array.+  | Ldelem_ref         -- ^ Pops an array reference and an index. Pushes the object reference in the specified slot of the array.+  | Ldelema            -- ^ Pops an array reference and an index. Pushes the address of the specified slot of the array.   | Ldfld       { fieldType    :: PrimitiveType  -- ^ Type of the field.       , assemblyName :: AssemblyName   -- ^ Name of the assembly where the field resides.@@ -287,6 +312,7 @@   | Ldind_u1           -- ^ Pops an address, pushes the 8-bit unsigned integer stored at the address as a 32-bit integer.   | Ldind_u2           -- ^ Pops an address, pushes the 16-bit unsigned integer stored at the address as a 32-bit integer.   | Ldind_u4           -- ^ Pops an address, pushes the 32-bit unsigned integer stored at the address as a 32-bit integer.+  | Ldlen              -- ^ Pops an array reference, pushes the native unsigned integer length of the array.   | Ldloc Offset       -- ^ Pushes value of local variable, specified by index, to the stack.   | Ldloc_0            -- ^ Pushes 0th local variable to the stack.   | Ldloc_1            -- ^ Pushes 1th local variable to the stack.@@ -295,6 +321,7 @@   | LdlocN DottedName  -- ^ Pushes value of local variable, specified by name, to the stack.   | Ldloca Offset      -- ^ Pushes address of local variable, specified by index, to the stack.   | LdlocaN DottedName -- ^ Pushes address of local variable, specified by name, to the stack.+  | Ldnull             -- ^ Pushes a size-agnostic null reference on the stack.   | Ldsfld       { fieldType    :: PrimitiveType  -- ^ Type of the field.       , assemblyName :: AssemblyName   -- ^ Name of the assembly where the field resides.@@ -309,6 +336,8 @@       } -- ^ Pops type reference, find address of specified field on the type, pushes address to the stack.   | Ldstr String       -- ^ Pushes an object reference to the specified string constant.   | Mul                -- ^ Pops 2 values, multiplies the values, pushes result.+  | Mul_ovf            -- ^ Pops 2 values, multiplies the values with a signed overflow check, pushes result.+  | Mul_ovf_un         -- ^ Pops 2 values, multiplies the values with an unsigned overflow check, pushes result.   | Neg                -- ^ Pops 1 value, negates the value, pushes the value.   | Newobj       { returnType   :: PrimitiveType    -- ^ Return type of the constructor (almost alway Void).@@ -316,10 +345,25 @@       , typeName     :: TypeName         -- ^ Name of the type of which the constructor is a member.       , paramTypes   :: [PrimitiveType]  -- ^ Types of the formal paramters of the constructor.       } -- ^ Creates a new object or instance of a value type. Pops /n/ values, calls the specified constructor, pushes a new object reference onto the stack (where /n/ is the number of formal parameters of the constructor).+  | Newarr PrimitiveType -- ^ Creates a new one-dimensional array. Pops a native int or int32, pushes a new array with that length.   | Nop                -- ^ No operation is performed.+  | Not                -- ^ Pops 1 value, does a bitwise complement, pushes result.+  | Or                 -- ^ Pops 2 values, do bitwise OR between the values, pushes result.   | Pop                -- ^ Pops the top of the stack.-  | Rem                -- ^ Pops 2 values, devides the first value by the second value, pushes the remainder.+  | Rem                -- ^ Pops 2 values, divides the first value by the second value, pushes the remainder.+  | Rem_un             -- ^ Pops 2 integers, divides the first by the second when considered as unsigned integers, pushes the remainder.   | Ret                -- ^ Returns from the current method. Pushes top of the stack to the top of the callers stack (if stack is not empty).+  | Shl                -- ^ Pops 2 values, shifts the first to the left by the number of bits specified by the second, pushes the result.+  | Shr                -- ^ Pops 2 values, shifts the first to the right by the number of bits specified by the second (with sign extension), pushes the result.+  | Shr_un             -- ^ Pops 2 values, shifts the first to the right by the number of bits specified by the second (without sign extension), pushes the result.+  | Stelem_i           -- ^ Pops an array reference, an index, and a native integer. Stores the integer in the array.+  | Stelem_i1          -- ^ Pops an array reference, an index, and an 8-bit integer. Stores the integer in the array.+  | Stelem_i2          -- ^ Pops an array reference, an index, and a 16-bit integer. Stores the integer in the array.+  | Stelem_i4          -- ^ Pops an array reference, an index, and a 32-bit integer. Stores the integer in the array.+  | Stelem_i8          -- ^ Pops an array reference, an index, and a 64-bit integer. Stores the integer in the array.+  | Stelem_r4          -- ^ Pops an array reference, an index, and a float. Stores the float in the array.+  | Stelem_r8          -- ^ Pops an array reference, an index, and a double integer. Stores the double in the array.+  | Stelem_ref          -- ^ Pops an array reference, an index, and an object reference. Stores the object reference in the array.   | Stfld       { fieldType    :: PrimitiveType  -- ^ Type of the field.       , assemblyName :: AssemblyName   -- ^ Name of the assembly where the field resides.@@ -346,10 +390,18 @@       , typeName     :: TypeName       -- ^ Name of the type of which the field is a member.       , fieldName    :: FieldName      -- ^ Name of the field.       } -- ^ Replaces the value stored in the static field of a type with a new value.-  | Sub                -- ^ Pops 2 values, substracts second value from the first value, pushes result.+  | Sub                -- ^ Pops 2 values, subtracts second value from the first value, pushes result.+  | Sub_ovf            -- ^ Pops 2 values, subtracts second value from the first value with a signed overflow check, pushes result.+  | Sub_ovf_un         -- ^ Pops 2 values, subtracts second value from the first value with an unsigned overflow check, pushes result.   | Tail               -- ^ Performs subsequent call as a tail call, by replacing current stack frame with callee stack frame.   | Tailcall OpCode    -- ^ Performs provided call as a tail call, by replacing current stack frame with callee stack frame.+  | Throw              -- ^ Pops an object reference from the stack and throws it as an exception.+  | Unaligned Alignment -- ^ Performs subsequent load or store operation under a weaker-than-usual alignment precondition.+  | UnalignedPtr  Alignment OpCode -- ^ Performs provided load or store operation under a weaker-than-usual alignment precondition.   | Unbox PrimitiveType  -- ^ Pops 1 value, unboxes object reference, pushes value type.+  | Volatile           -- ^ Marks subsequent pointer reference as volatile, i.e. the value it points at can be modified from another thread.+  | VolatilePtr OpCode -- ^ Marks provided pointer reference as volatile, i.e. the value it points at can be modified from another thread.+  | Xor                -- ^ Pops 2 values, do bitwise XOR between the values, pushes result.   deriving Show  -- | Calling convention for method calls.