forked from clash-lang/clash-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClash.hs
76 lines (63 loc) · 2.38 KB
/
Clash.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{-# LANGUAGE CPP #-}
#include "MachDeps.h"
#define HDLSYN Other
import Clash.Driver
import Clash.Driver.Types
import Clash.GHC.Evaluator
import Clash.GHC.GenerateBindings
import Clash.GHC.NetlistTypes
import Clash.GHC.LoadModules (ghcLibDir)
import Clash.Backend
import Clash.Backend.SystemVerilog
import Clash.Backend.VHDL
import Clash.Backend.Verilog
import Clash.Netlist.BlackBox.Types
import Clash.Annotations.BitRepresentation.Internal (buildCustomReprs)
import Control.DeepSeq
import Control.Exception (finally)
import qualified Data.Time.Clock as Clock
import qualified Data.HashMap.Strict as HM
import System.Directory (removeDirectoryRecursive)
import GHC.Stack (HasCallStack)
import Util (OverridingBool(..))
genSystemVerilog
:: String
-> IO ()
genSystemVerilog = doHDL (initBackend WORD_SIZE_IN_BITS HDLSYN True :: SystemVerilogState)
genVHDL
:: String
-> IO ()
genVHDL = doHDL (initBackend WORD_SIZE_IN_BITS HDLSYN True :: VHDLState)
genVerilog
:: String
-> IO ()
genVerilog = doHDL (initBackend WORD_SIZE_IN_BITS HDLSYN True :: VerilogState)
doHDL
:: HasCallStack
=> Backend s
=> s
-> String
-> IO ()
doHDL b src = do
tmpDir <- createTemporaryClashDirectory
finally (do
startTime <- Clock.getCurrentTime
pd <- primDirs b
(bindingsMap,tcm,tupTcm,topEntities,primMap,reprs) <- generateBindings tmpDir Auto pd ["."] (hdlKind b) src Nothing
prepTime <- startTime `deepseq` bindingsMap `deepseq` tcm `deepseq` reprs `deepseq` Clock.getCurrentTime
let prepStartDiff = Clock.diffUTCTime prepTime startTime
putStrLn $ "Loading dependencies took " ++ show prepStartDiff
-- Parse primitives:
startTime' <- Clock.getCurrentTime
topDir <- ghcLibDir
primMap2 <- sequence $ HM.map (sequence . fmap (compilePrimitive ["."] [] topDir)) primMap
prepTime' <- startTime `deepseq` primMap2 `seq` Clock.getCurrentTime
let prepStartDiff' = Clock.diffUTCTime prepTime' startTime'
putStrLn $ "Parsing primitives took " ++ show prepStartDiff'
generateHDL (buildCustomReprs reprs) bindingsMap (Just b) primMap2 tcm tupTcm (ghcTypeToHWType WORD_SIZE_IN_BITS True) reduceConstant topEntities
(ClashOpts 20 20 15 0 DebugNone False True True Auto WORD_SIZE_IN_BITS Nothing tmpDir HDLSYN True True ["."] Nothing True True) (startTime,prepTime)
) (do
removeDirectoryRecursive tmpDir
)
main :: IO ()
main = genVHDL "./examples/FIR.hs"