{-# LANGUAGE CPP #-}
#ifdef SOLIDITY_COMPILER
{-# LANGUAGE RecordWildCards #-}
#endif
module Language.Solidity.Compiler where
#ifdef SOLIDITY_COMPILER
import Data.ByteString (ByteString)
import Data.Map (Map)
import Data.Semigroup (Semigroup (..))
import qualified Language.Solidity.Compiler.Foreign as FFI
import System.IO.Unsafe (unsafePerformIO)
data Sources = Sources
{ sourceMap :: Map ByteString ByteString
, libraries :: Map ByteString ByteString
, optimization :: Bool
} deriving (Eq, Show)
instance Semigroup Sources where
a <> b = Sources (sourceMap a `mappend` sourceMap b)
(libraries a `mappend` libraries b)
(optimization a || optimization b)
instance Monoid Sources where
mappend = (<>)
mempty = Sources mempty mempty False
type Compiled = Map ByteString (ByteString, ByteString)
compile :: Sources
-> Either ByteString Compiled
{-# NOINLINE compile #-}
compile Sources{..} = unsafePerformIO $
FFI.compile sourceMap libraries optimization
#endif