text
stringlengths 0
1.05M
|
---|
addFunDef $
|
I.FunDef
|
(Just entry')
|
(internaliseAttrs attrs)
|
(baseName ofname)
|
(concat entry_rettype)
|
(shapeparams ++ concat params')
|
entry_body
|
entryPoint ::
|
[(E.EntryType, [I.FParam])] ->
|
( E.EntryType,
|
[[I.TypeBase ExtShape Uniqueness]]
|
) ->
|
I.EntryPoint
|
entryPoint params (eret, crets) =
|
( concatMap (entryPointType . preParam) params,
|
case ( isTupleRecord $ entryType eret,
|
entryAscribed eret
|
) of
|
(Just ts, Just (E.TETuple e_ts _)) ->
|
concatMap entryPointType $
|
zip (zipWith E.EntryType ts (map Just e_ts)) crets
|
(Just ts, Nothing) ->
|
concatMap entryPointType $
|
zip (map (`E.EntryType` Nothing) ts) crets
|
_ ->
|
entryPointType (eret, concat crets)
|
)
|
where
|
preParam (e_t, ps) = (e_t, staticShapes $ map I.paramDeclType ps)
|
entryPointType (t, ts)
|
| E.Scalar (E.Prim E.Unsigned {}) <- E.entryType t =
|
[I.TypeUnsigned]
|
| E.Array _ _ (E.Prim E.Unsigned {}) _ <- E.entryType t =
|
[I.TypeUnsigned]
|
| E.Scalar E.Prim {} <- E.entryType t =
|
[I.TypeDirect]
|
| E.Array _ _ E.Prim {} _ <- E.entryType t =
|
[I.TypeDirect]
|
| otherwise =
|
[I.TypeOpaque desc $ length ts]
|
where
|
desc = maybe (pretty t') typeExpOpaqueName $ E.entryAscribed t
|
t' = noSizes (E.entryType t) `E.setUniqueness` Nonunique
|
typeExpOpaqueName (TEApply te TypeArgExpDim {} _) =
|
typeExpOpaqueName te
|
typeExpOpaqueName (TEArray te _ _) =
|
let (d, te') = withoutDims te
|
in "arr_" ++ typeExpOpaqueName te'
|
++ "_"
|
++ show (1 + d)
|
++ "d"
|
typeExpOpaqueName te = pretty te
|
withoutDims (TEArray te _ _) =
|
let (d, te') = withoutDims te
|
in (d + 1, te')
|
withoutDims te = (0 :: Int, te)
|
internaliseIdent :: E.Ident -> InternaliseM I.VName
|
internaliseIdent (E.Ident name (Info tp) loc) =
|
case tp of
|
E.Scalar E.Prim {} -> return name
|
_ ->
|
error $
|
"Futhark.Internalise.internaliseIdent: asked to internalise non-prim-typed ident '"
|
++ pretty name
|
++ " of type "
|
++ pretty tp
|
++ " at "
|
++ locStr loc
|
++ "."
|
internaliseBody :: E.Exp -> InternaliseM Body
|
internaliseBody e = insertStmsM $ resultBody <$> internaliseExp "res" e
|
bodyFromStms ::
|
InternaliseM (Result, a) ->
|
InternaliseM (Body, a)
|
bodyFromStms m = do
|
((res, a), stms) <- collectStms m
|
(,a) <$> mkBodyM stms res
|
internaliseExp :: String -> E.Exp -> InternaliseM [I.SubExp]
|
internaliseExp desc (E.Parens e _) =
|
internaliseExp desc e
|
internaliseExp desc (E.QualParens _ e _) =
|
internaliseExp desc e
|
internaliseExp desc (E.StringLit vs _) =
|
fmap pure $
|
letSubExp desc $
|
I.BasicOp $ I.ArrayLit (map constant vs) $ I.Prim int8
|
internaliseExp _ (E.Var (E.QualName _ name) (Info t) loc) = do
|
subst <- lookupSubst name
|
case subst of
|
Just substs -> return substs
|
Nothing -> do
|