module DDC.Llvm.Syntax.Module
(
Module (..)
, lookupCallConv
, Global (..)
, typeOfGlobal
, varOfGlobal
, Static (..)
, typeOfStatic)
where
import DDC.Llvm.Syntax.Function
import DDC.Llvm.Syntax.Exp
import DDC.Llvm.Syntax.Metadata
import DDC.Llvm.Syntax.Type
import DDC.Llvm.Syntax.Attr
import Data.List
import Control.Monad
data Module
= Module
{
modComments :: [String]
, modAliases :: [TypeAlias]
, modGlobals :: [Global]
, modFwdDecls :: [FunctionDecl]
, modFuncs :: [Function]
, modMDecls :: [MDecl]
}
lookupCallConv :: String -> Module -> Maybe CallConv
lookupCallConv name mm
= liftM declCallConv
$ find isFunctionDecl $ modFwdDecls mm ++ (map funDecl $ modFuncs mm)
where isFunctionDecl decl
= declName decl == name
data Global
= GlobalStatic Var Static
| GlobalExternal Var
typeOfGlobal :: Global -> Type
typeOfGlobal gg
= case gg of
GlobalStatic v _ -> typeOfVar v
GlobalExternal v -> typeOfVar v
varOfGlobal :: Global -> Var
varOfGlobal gg
= case gg of
GlobalStatic v _ -> v
GlobalExternal v -> v
data Static
= StaticComment String
| StaticLit Lit
| StaticUninitType Type
| StaticStr String Type
| StaticArray [Static] Type
| StaticStruct [Static] Type
| StaticPointer Var
| StaticBitc Static Type
| StaticPtoI Static Type
| StaticAdd Static Static
| StaticSub Static Static
deriving (Show)
typeOfStatic :: Static -> Type
typeOfStatic ss
= case ss of
StaticComment{}
-> error "ddc-core-llvm.typeOfStatic: can't call getStatType on LMComment!"
StaticLit l -> typeOfLit l
StaticUninitType t -> t
StaticStr _ t -> t
StaticArray _ t -> t
StaticStruct _ t -> t
StaticPointer v -> typeOfVar v
StaticBitc _ t -> t
StaticPtoI _ t -> t
StaticAdd t _ -> typeOfStatic t
StaticSub t _ -> typeOfStatic t