{-# LANGUAGE Safe #-}
-- | A thin shim over rewire-base's "ReWire.Config" adding the embedder's
--   output-file helpers. The embedder ignores the hardware-oriented config
--   fields (clock, reset, signal names, etc.).
module Embedder.Config
      ( module ReWire.Config
      , getEmbedFile, getAtmoFile
      ) where

import ReWire.Config

import Control.Lens ((^.))
import Data.Maybe (fromMaybe)
import System.FilePath ((-<.>))

-- | Output path for the generated Isabelle theory (.thy) file.
getEmbedFile :: Config -> FilePath -> FilePath
getEmbedFile :: Config -> FilePath -> FilePath
getEmbedFile Config
c FilePath
filename = (FilePath -> Maybe FilePath -> FilePath)
-> Maybe FilePath -> FilePath -> FilePath
forall a b c. (a -> b -> c) -> b -> a -> c
flip FilePath -> Maybe FilePath -> FilePath
forall a. a -> Maybe a -> a
fromMaybe (Config
cConfig
-> Getting (Maybe FilePath) Config (Maybe FilePath)
-> Maybe FilePath
forall s a. s -> Getting a s a -> a
^.Getting (Maybe FilePath) Config (Maybe FilePath)
Lens' Config (Maybe FilePath)
outFile) (FilePath -> FilePath) -> FilePath -> FilePath
forall a b. (a -> b) -> a -> b
$ FilePath
filename FilePath -> FilePath -> FilePath
-<.> FilePath
"thy"

-- | Output path for the generated Atmo IR (.atmo) file.
getAtmoFile :: Config -> FilePath -> FilePath
getAtmoFile :: Config -> FilePath -> FilePath
getAtmoFile Config
c FilePath
filename = (FilePath -> Maybe FilePath -> FilePath)
-> Maybe FilePath -> FilePath -> FilePath
forall a b c. (a -> b -> c) -> b -> a -> c
flip FilePath -> Maybe FilePath -> FilePath
forall a. a -> Maybe a -> a
fromMaybe (Config
cConfig
-> Getting (Maybe FilePath) Config (Maybe FilePath)
-> Maybe FilePath
forall s a. s -> Getting a s a -> a
^.Getting (Maybe FilePath) Config (Maybe FilePath)
Lens' Config (Maybe FilePath)
outFile) (FilePath -> FilePath) -> FilePath -> FilePath
forall a b. (a -> b) -> a -> b
$ FilePath
filename FilePath -> FilePath -> FilePath
-<.> FilePath
"atmo"