crucible-llvm-0.10: Support for translating and executing LLVM code in Crucible
Copyright(c) Galois Inc 2015-2016
LicenseBSD3
MaintainerRob Dockins <rdockins@galois.com>
Stabilityprovisional
Safe HaskellNone
LanguageHaskell2010

Lang.Crucible.LLVM.Intrinsics

Description

 
Synopsis

Documentation

data LLVM Source #

The Crucible extension type marker for LLVM.

Instances

Instances details
Data LLVM Source # 
Instance details

Defined in Lang.Crucible.LLVM.Extension

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LLVM -> c LLVM #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LLVM #

toConstr :: LLVM -> Constr #

dataTypeOf :: LLVM -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LLVM) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LLVM) #

gmapT :: (forall b. Data b => b -> b) -> LLVM -> LLVM #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LLVM -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LLVM -> r #

gmapQ :: (forall d. Data d => d -> u) -> LLVM -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> LLVM -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> LLVM -> m LLVM #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LLVM -> m LLVM #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LLVM -> m LLVM #

Generic LLVM Source # 
Instance details

Defined in Lang.Crucible.LLVM.Extension

Associated Types

type Rep LLVM 
Instance details

Defined in Lang.Crucible.LLVM.Extension

type Rep LLVM = D1 ('MetaData "LLVM" "Lang.Crucible.LLVM.Extension" "crucible-llvm-0.10-7vATmqpPuxE7Zx5lX5DUf8" 'False) (V1 :: Type -> Type)

Methods

from :: LLVM -> Rep LLVM x #

to :: Rep LLVM x -> LLVM #

IsSyntaxExtension LLVM Source # 
Instance details

Defined in Lang.Crucible.LLVM.Extension

Eq LLVM Source # 
Instance details

Defined in Lang.Crucible.LLVM.Extension

Methods

(==) :: LLVM -> LLVM -> Bool #

(/=) :: LLVM -> LLVM -> Bool #

Ord LLVM Source # 
Instance details

Defined in Lang.Crucible.LLVM.Extension

Methods

compare :: LLVM -> LLVM -> Ordering #

(<) :: LLVM -> LLVM -> Bool #

(<=) :: LLVM -> LLVM -> Bool #

(>) :: LLVM -> LLVM -> Bool #

(>=) :: LLVM -> LLVM -> Bool #

max :: LLVM -> LLVM -> LLVM #

min :: LLVM -> LLVM -> LLVM #

type Rep LLVM Source # 
Instance details

Defined in Lang.Crucible.LLVM.Extension

type Rep LLVM = D1 ('MetaData "LLVM" "Lang.Crucible.LLVM.Extension" "crucible-llvm-0.10-7vATmqpPuxE7Zx5lX5DUf8" 'False) (V1 :: Type -> Type)
type ExprExtension LLVM Source # 
Instance details

Defined in Lang.Crucible.LLVM.Extension

type StmtExtension LLVM Source # 
Instance details

Defined in Lang.Crucible.LLVM.Extension

data LLVMOverride p sym ext (args :: Ctx CrucibleType) (ret :: CrucibleType) Source #

This type represents an implementation of an LLVM intrinsic function in Crucible.

This is parameterized over ext so that LLVMOverrides can more easily be reused in the context of other language extensions that are also based on the LLVM memory model, such as Macaw.

Constructors

LLVMOverride 

Fields

register_llvm_overrides Source #

Arguments

:: forall sym (wptr :: Natural) (arch :: LLVMArch) p rtp (l :: Ctx CrucibleType) (a :: CrucibleType). (IsSymInterface sym, HasLLVMAnn sym, HasPtrWidth wptr, wptr ~ ArchWidth arch, ?intrinsicsOpts :: IntrinsicsOptions, ?memOpts :: MemOptions) 
=> Module 
-> [OverrideTemplate p sym LLVM arch]

Additional "define" overrides

-> [OverrideTemplate p sym LLVM arch]

Additional "declare" overrides

-> LLVMContext arch 
-> OverrideSim p sym LLVM rtp l a ([SomeLLVMOverride p sym LLVM], [SomeLLVMOverride p sym LLVM])

Applied (define overrides, declare overrides)

Match two sets of OverrideTemplates against the Declares and Defines in a Module, registering all the overrides that apply and returning them as a list. There are internal pre-determined overrides that will be applied, as well as any additional overrides supplied by the user (internal overrides will supercede user overrides).

The "define" overrides are applied to *both* the Defines and Declares elements found within a module.

The "declare" overrides are applied only to the Declares found within a module. The intent is that these overrides should only apply to Declares, whereas the "define" overrides should apply to any matching symbol in the LLVM Module.

If both lists specify an override that matches a declare, the declare override takes precedence over the define override.

register_specific_llvm_overrides Source #

Arguments

:: forall sym (wptr :: Natural) (arch :: LLVMArch) p rtp (l :: Ctx CrucibleType) (a :: CrucibleType). (IsSymInterface sym, HasLLVMAnn sym, HasPtrWidth wptr, wptr ~ ArchWidth arch, ?intrinsicsOpts :: IntrinsicsOptions, ?memOpts :: MemOptions) 
=> [Define] 
-> [Declare] 
-> [OverrideTemplate p sym LLVM arch]

Additional "define" overrides

-> [OverrideTemplate p sym LLVM arch]

Additional "declare" overrides

-> LLVMContext arch 
-> OverrideSim p sym LLVM rtp l a ([SomeLLVMOverride p sym LLVM], [SomeLLVMOverride p sym LLVM]) 

Match a set of OverrideTemplates against a provided set of definitions and declarations, registering all the overrides that apply and returning them as a pair of lists: the registered definition overrides and the registered declaration overrides.

This is an alternative entrypoint for registering overrides. The functionality here is largely the same as register_llvm_overrides except the list of declares and defines are provided manually by the caller instead of being extracted from the LLVM Module.

register_llvm_overrides_ Source #

Arguments

:: forall sym (arch :: LLVMArch) p ext rtp (l :: Ctx CrucibleType) (a :: CrucibleType). (IsSymInterface sym, HasLLVMAnn sym) 
=> LLVMContext arch 
-> [OverrideTemplate p sym ext arch]

Overrides to attempt to match against these declarations

-> [SomeDeclare]

Declarations of the functions that might get overridden

-> OverrideSim p sym ext rtp l a [SomeLLVMOverride p sym ext] 

Match a set of OverrideTemplates against a set of Declares, registering all the overrides that apply and returning them as a list.

llvmDeclToFunHandleRepr :: forall (wptr :: Natural) a. HasPtrWidth wptr => FunDecl -> (forall (args :: Ctx CrucibleType) (ret :: CrucibleType). CtxRepr args -> TypeRepr ret -> a) -> a Source #

Compute the function Crucible function signature that corresponds to the given LLVM function declaration.

declare_overrides :: forall sym (wptr :: Natural) (arch :: LLVMArch) p. (IsSymInterface sym, HasLLVMAnn sym, HasPtrWidth wptr, wptr ~ ArchWidth arch, ?lc :: TypeContext, ?intrinsicsOpts :: IntrinsicsOptions, ?memOpts :: MemOptions) => [OverrideTemplate p sym LLVM arch] Source #

Register overrides for declared-but-not-defined functions

data LLVMOverride p sym ext (args :: Ctx CrucibleType) (ret :: CrucibleType) Source #

This type represents an implementation of an LLVM intrinsic function in Crucible.

This is parameterized over ext so that LLVMOverrides can more easily be reused in the context of other language extensions that are also based on the LLVM memory model, such as Macaw.

Constructors

LLVMOverride 

Fields

llvmOvSymbol :: forall p sym ext (args :: Ctx CrucibleType) (ret :: CrucibleType). LLVMOverride p sym ext args ret -> Symbol Source #

llvmOvName :: forall p sym ext (args :: Ctx CrucibleType) (ret :: CrucibleType). LLVMOverride p sym ext args ret -> FunctionName Source #

llvmOvArgs :: forall p sym ext (args :: Ctx CrucibleType) (ret :: CrucibleType). LLVMOverride p sym ext args ret -> CtxRepr args Source #

llvmOvRet :: forall p sym ext (args :: Ctx CrucibleType) (ret :: CrucibleType). LLVMOverride p sym ext args ret -> TypeRepr ret Source #

data SomeLLVMOverride p sym ext Source #

Constructors

SomeLLVMOverride (LLVMOverride p sym ext args ret) 

someLlvmOverrideDeclare :: SomeLLVMOverride p sym ext -> SomeDeclare Source #

Map llvmOverride_decl inside a SomeLLVMOverride.

newtype MakeOverride p sym ext (arch :: LLVMArch) Source #

A funcion that inspects an LLVM declaration (along with some other data), and constructs an override for the declaration if it can.

llvmSizeT :: forall (wptr :: Natural). HasPtrWidth wptr => Type Source #

Convenient LLVM representation of the size_t type.

llvmSSizeT :: forall (wptr :: Natural). HasPtrWidth wptr => Type Source #

Convenient LLVM representation of the ssize_t type.

data OverrideTemplate p sym ext (arch :: LLVMArch) Source #

Checking if an override applies to a given declaration happens in two "phases", corresponding to the fields of this struct.

Constructors

OverrideTemplate 

Fields

callStackFromMemVar' :: forall p sym ext r (args :: Ctx CrucibleType) (ret :: CrucibleType). GlobalVar Mem -> OverrideSim p sym ext r args ret CallStack Source #

basic_llvm_override :: forall p (args :: Ctx CrucibleType) (ret :: CrucibleType) sym ext (arch :: LLVMArch) (wptr :: Natural). (IsSymInterface sym, HasLLVMAnn sym, HasPtrWidth wptr) => LLVMOverride p sym ext args ret -> OverrideTemplate p sym ext arch Source #

polymorphic1_llvm_override :: forall p sym ext (arch :: LLVMArch) (wptr :: Natural). (IsSymInterface sym, HasLLVMAnn sym, HasPtrWidth wptr) => String -> (forall (w :: Natural). 1 <= w => NatRepr w -> SomeLLVMOverride p sym ext) -> OverrideTemplate p sym ext arch Source #

polymorphic1_vec_llvm_override :: forall p sym ext (arch :: LLVMArch) (wptr :: Natural). (IsSymInterface sym, HasLLVMAnn sym, HasPtrWidth wptr) => String -> (forall (vecSz :: Nat) (intSz :: Natural). 1 <= intSz => NatRepr vecSz -> NatRepr intSz -> SomeLLVMOverride p sym ext) -> OverrideTemplate p sym ext arch Source #

Create an OverrideTemplate for a polymorphic LLVM override involving a vector type. For example, the llvm.vector.reduce.add.* intrinsic can be instantiated at multiple types, including:

  • i32 @llvm.vector.reduce.add.v4i32(x i32)
  • i64 @llvm.vector.reduce.add.v2i64(x i64)
  • etc.

Note that the intrinsic can vary both by the size of the vector type (4, 2, etc.) and the size of the integer type used as the vector element type (i32, i64, etc.) Therefore, the fn argument that this function accepts is parameterized by both the vector size (vecSz) and the integer size (intSz).

polymorphic_cmp_llvm_override :: forall p sym ext (arch :: LLVMArch) (wptr :: Natural). (IsSymInterface sym, HasLLVMAnn sym, HasPtrWidth wptr) => String -> (forall (argSz :: Natural) (resSz :: Natural). (1 <= argSz, 2 <= resSz) => NatRepr argSz -> NatRepr resSz -> SomeLLVMOverride p sym ext) -> OverrideTemplate p sym ext arch Source #

llvmOverrideToTypedOverride :: forall sym p ext (args :: Ctx CrucibleType) (ret :: CrucibleType). (IsSymInterface sym, HasLLVMAnn sym) => GlobalVar Mem -> LLVMOverride p sym ext args ret -> TypedOverride p sym ext args ret Source #

register_llvm_override :: forall p (args :: Ctx CrucibleType) (ret :: CrucibleType) (args' :: Ctx CrucibleType) (ret' :: CrucibleType) sym ext (arch :: LLVMArch) (wptr :: Natural) rtp (l :: Ctx CrucibleType) (a :: CrucibleType). (IsSymInterface sym, HasPtrWidth wptr, HasLLVMAnn sym) => LLVMOverride p sym ext args ret -> Declare args' ret' -> LLVMContext arch -> OverrideSim p sym ext rtp l a () Source #

register_1arg_polymorphic_override :: forall p sym ext (arch :: LLVMArch) (wptr :: Natural). (IsSymInterface sym, HasLLVMAnn sym, HasPtrWidth wptr) => String -> (forall (w :: Natural). 1 <= w => NatRepr w -> SomeLLVMOverride p sym ext) -> MakeOverride p sym ext arch Source #

register_1arg_vec_polymorphic_override :: forall p sym ext (arch :: LLVMArch) (wptr :: Natural). (IsSymInterface sym, HasLLVMAnn sym, HasPtrWidth wptr) => String -> (forall (vecSz :: Nat) (intSz :: Natural). 1 <= intSz => NatRepr vecSz -> NatRepr intSz -> SomeLLVMOverride p sym ext) -> MakeOverride p sym ext arch Source #

Register a polymorphic LLVM override involving a vector type. (See the Haddocks for polymorphic1_vec_llvm_override for details on what this means.) This function is responsible for parsing the suffix in the intrinsic's name, which encodes the sizes of the vector and integer types. As some examples:

  • .v4i32 (vector size 4, integer size 32)
  • .v2i64 (vector size 2, integer size 64)

do_register_llvm_override :: forall p (args :: Ctx CrucibleType) (ret :: CrucibleType) sym ext (arch :: LLVMArch) (wptr :: Natural) (l :: Ctx CrucibleType) (a :: CrucibleType) rtp. (IsSymInterface sym, HasPtrWidth wptr, HasLLVMAnn sym) => LLVMContext arch -> LLVMOverride p sym ext args ret -> OverrideSim p sym ext rtp l a () Source #

Low-level function to register LLVM overrides.

Creates and binds a function handle, and also binds the function to the global function allocation in the LLVM memory.

Useful when you don't have access to a full LLVM AST, e.g., when parsing Crucible CFGs written in crucible-syntax. For more usual cases, use register_llvm_overrides.

alloc_and_register_override Source #

Arguments

:: forall sym bak (wptr :: Natural) (arch :: LLVMArch) p (args :: Ctx CrucibleType) (ret :: CrucibleType) rtp (l :: Ctx CrucibleType) (a :: CrucibleType). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions) 
=> bak 
-> LLVMContext arch 
-> LLVMOverride p sym LLVM args ret 
-> [Symbol]

Aliases

-> OverrideSim p sym LLVM rtp l a () 

Create an allocation for an override and register it.

Useful when registering an override for a function in an LLVM memory that wasn't initialized with the functions in Lang.Crucible.LLVM.Globals, e.g., when parsing Crucible CFGs written in crucible-syntax. For more usual cases, use register_llvm_overrides.

c.f. allocLLVMFunPtr

newtype IntrinsicsOptions Source #

This datatype encodes a variety of tweakable settings that to LLVM overrides.

Constructors

IntrinsicsOptions 

Fields

data AbnormalExitBehavior Source #

Should Crucible fail when simulating a function which triggers an abnormal exit, such as abort()?

Constructors

AlwaysFail

Functions which trigger an abnormal exit will always cause Crucible to fail.

OnlyAssertFail

The __assert_fail() or __assert_rtn() functions will cause Crucible to fail, while other functions which trigger an abnormal exit will not cause failures. This option is primarily useful for SV-COMP.

NeverFail

Functions which trigger an abnormal exit will never cause Crucible to fail. This option is primarily useful for SV-COMP.

defaultIntrinsicsOptions :: IntrinsicsOptions Source #

The default translation options:

  • Functions which trigger an abnormal exit will always cause Crucible to fail.

matches Source #

Arguments

:: String

Function name

-> TemplateMatcher 
-> Bool 

Check whether a TemplateMatcher matches a given function name.

data TemplateMatcher Source #

This type controls whether an override is installed for a given name found in a module. See filterTemplates.

Constructors

ExactMatch String 
PrefixMatch String 
SubstringsMatch [String] 
DarwinAliasMatch String

Match a name up to some number of Darwin aliases. See Note [Darwin aliases].

stripDarwinAliases :: String -> String Source #

Remove all prefixes and suffixes that might occur in a Darwin alias for a function name. See Note [Darwin aliases].