-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
llvm: Remove the LLVM declaration from LLVMOverride
#1138
Comments
Here's a first cut of functions to create an LLVM declaration from a Crucible-LLVM type signature: llvmType :: HasPtrWidth wptr => TypeRepr t -> Maybe L.Type
llvmType =
\case
AnyRepr {} -> Nothing
BoolRepr -> Just (L.PrimType (L.Integer 1))
CharRepr {} -> Nothing
BVRepr w -> intType w
ComplexRealRepr {} -> Nothing
FloatRepr {} -> Nothing -- TODO?
FunctionHandleRepr {} -> Nothing
IEEEFloatRepr {} -> Nothing -- TODO?
IntegerRepr {} -> Nothing
MaybeRepr {} -> Nothing
NatRepr {} -> Nothing
RealValRepr {} -> Nothing
RecursiveRepr {} -> Nothing
ReferenceRepr {} -> Nothing
SequenceRepr {} -> Nothing
StringRepr {} -> Nothing
StringMapRepr {} -> Nothing
StructRepr {} -> Nothing
SymbolicArrayRepr {} -> Nothing
SymbolicStructRepr {} -> Nothing
UnitRepr -> Just (L.PrimType L.Void)
VariantRepr {} -> Nothing
VectorRepr {} -> Nothing
WordMapRepr {} -> Nothing
LLVMPointerRepr w ->
case testEquality w ?ptrWidth of
Just Refl -> Just L.PtrOpaque
Nothing -> intType w
IntrinsicRepr {} -> Nothing
where
intType :: NatRepr n -> Maybe L.Type
intType w =
let natVal = natValue w
in if natVal > fromIntegral (maxBound :: Word32)
then Nothing
else Just (L.PrimType (L.Integer (fromIntegral natVal)))
llvmOverrideDeclare ::
HasPtrWidth w =>
LLVMOverride p sym args ret ->
Either (Some TypeRepr) L.Declare
llvmOverrideDeclare ov = do
let getType :: forall t. TypeRepr t -> Either (Some TypeRepr) L.Type
getType t =
case llvmType t of
Nothing -> Left (Some t)
Just llTy -> Right llTy
(Some args, isVarArgs) <-
case Ctx.viewAssign (llvmOverride_args ov) of
Ctx.AssignEmpty ->
pure (Some (llvmOverride_args ov), False)
Ctx.AssignExtend rest lastTy | Just Refl <- testEquality varArgsRepr lastTy ->
pure (Some rest, True)
_ ->
pure (Some (llvmOverride_args ov), False)
llvmArgs <- sequence (toListFC getType args)
llvmRet <- getType (llvmOverride_ret ov)
pure $
L.Declare
{ L.decArgs = llvmArgs
, L.decAttrs = []
, L.decComdat = Nothing
, L.decLinkage = Nothing
, L.decName = llvmOverride_name ov
, L.decRetType = llvmRet
, L.decVarArgs = isVarArgs
, L.decVisibility = Nothing
}
llvmOverride_declare :: HasPtrWidth wptr => LLVMOverride p sym args ret -> L.Declare
llvmOverride_declare ov =
case llvmOverrideDeclare ov of
Right decl -> decl
Left (Some tpr) ->
panic "Intrinsics.llvmOverride_declare"
[ "Couldn't convert Crucible-LLVM type to LLVM type"
, show tpr
]
{-# DEPRECATED llvmOverride_declare "Use llvmOverrideDeclare instead" #-} |
Is |
Looks like it, though that search doesn't capture pattern matches that don't use the record selector names.
👍 |
The
LLVMOverride
type has aL.Declare
:crucible/crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics/Common.hs
Lines 78 to 82 in 0834003
This is used to check that an override's "provided" declaration matches the declaration found in the LLVM module under the same name:
crucible/crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics/Common.hs
Lines 255 to 276 in 0834003
Note, however that the equality check happens modulo opaque pointers, meaning that
T*
andptr
are treated as equal for allT
. As LLVM has completed the migration to pointer types, none of the more-specific (non-opaque) in our overrides'L.Declare
s add any additional type-safety beyond just usingptr
. We can remove theL.Declare
fromLLVMOverride
and instead create a functionTypeRepr t -> L.Type
that mapsLLVMPointerType sym w
to LLVM'sptr
. This would obviate our LLVM quasiquoters, and allow us to specify the types of each override just once (as Crucbile-LLVM types).The text was updated successfully, but these errors were encountered: