{-# LANGUAGE DeriveGeneric #-}
{-|
Module      : IRTS.CodegenCommon
Description : Common data structures required for all code generators.

License     : BSD3
Maintainer  : The Idris Community.
-}
module IRTS.CodegenCommon where

import Idris.Core.Evaluate
import Idris.Core.TT
import IRTS.Defunctionalise
import IRTS.Simplified

import GHC.Generics (Generic)

data DbgLevel = NONE | DEBUG | TRACE deriving DbgLevel -> DbgLevel -> Bool
(DbgLevel -> DbgLevel -> Bool)
-> (DbgLevel -> DbgLevel -> Bool) -> Eq DbgLevel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DbgLevel -> DbgLevel -> Bool
== :: DbgLevel -> DbgLevel -> Bool
$c/= :: DbgLevel -> DbgLevel -> Bool
/= :: DbgLevel -> DbgLevel -> Bool
Eq
data OutputType = Raw | Object | Executable deriving (OutputType -> OutputType -> Bool
(OutputType -> OutputType -> Bool)
-> (OutputType -> OutputType -> Bool) -> Eq OutputType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OutputType -> OutputType -> Bool
== :: OutputType -> OutputType -> Bool
$c/= :: OutputType -> OutputType -> Bool
/= :: OutputType -> OutputType -> Bool
Eq, Int -> OutputType -> ShowS
[OutputType] -> ShowS
OutputType -> String
(Int -> OutputType -> ShowS)
-> (OutputType -> String)
-> ([OutputType] -> ShowS)
-> Show OutputType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OutputType -> ShowS
showsPrec :: Int -> OutputType -> ShowS
$cshow :: OutputType -> String
show :: OutputType -> String
$cshowList :: [OutputType] -> ShowS
showList :: [OutputType] -> ShowS
Show, (forall x. OutputType -> Rep OutputType x)
-> (forall x. Rep OutputType x -> OutputType) -> Generic OutputType
forall x. Rep OutputType x -> OutputType
forall x. OutputType -> Rep OutputType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OutputType -> Rep OutputType x
from :: forall x. OutputType -> Rep OutputType x
$cto :: forall x. Rep OutputType x -> OutputType
to :: forall x. Rep OutputType x -> OutputType
Generic)

-- | Everything which might be needed in a code generator.
--
-- A CG can choose which level of Decls to generate code from
-- (simplified, defunctionalised or merely lambda lifted) and has
-- access to the list of object files, libraries, etc.

data CodegenInfo = CodegenInfo {
    CodegenInfo -> String
outputFile    :: String
  , CodegenInfo -> OutputType
outputType    :: OutputType
  , CodegenInfo -> String
targetTriple  :: String
  , CodegenInfo -> String
targetCPU     :: String
  , CodegenInfo -> [String]
includes      :: [FilePath]
  , CodegenInfo -> [String]
importDirs    :: [FilePath]
  , CodegenInfo -> [String]
compileObjs   :: [String]
  , CodegenInfo -> [String]
compileLibs   :: [String]
  , CodegenInfo -> [String]
compilerFlags :: [String]
  , CodegenInfo -> DbgLevel
debugLevel    :: DbgLevel
  , CodegenInfo -> [(Name, SDecl)]
simpleDecls   :: [(Name, SDecl)]
  , CodegenInfo -> [(Name, DDecl)]
defunDecls    :: [(Name, DDecl)]
  , CodegenInfo -> [(Name, LDecl)]
liftDecls     :: [(Name, LDecl)]
  , CodegenInfo -> Bool
interfaces    :: Bool
  , CodegenInfo -> [ExportIFace]
exportDecls   :: [ExportIFace]
  , CodegenInfo -> [(Name, TTDecl)]
ttDecls       :: [(Name, TTDecl)]
  }

type CodeGenerator = CodegenInfo -> IO ()