-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutogen.hs
More file actions
110 lines (79 loc) · 2.98 KB
/
Autogen.hs
File metadata and controls
110 lines (79 loc) · 2.98 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
{-# LANGUAGE DataKinds
, TypeApplications #-}
module Autogen where
import Autogen.Cabal
import Autogen.Distillery
import Autogen.Mixer
import Autogen.Packager
import Autogen.Parser
import Paths_genvulkan
import Control.Monad
import Data.Foldable
import qualified Data.Set as Set
import System.Directory
import System.Exit
import System.FilePath
import Text.XML.HaXml.Parse (xmlParse')
augments :: Augments
augments =
Augments
{ cauterizedStructs = Set.fromList
[ "VkAccelerationStructureInstanceKHR"
, "VkAccelerationStructureInstanceNV"
, "VkAccelerationStructureSRTMotionInstanceNV"
, "VkAccelerationStructureMatrixMotionInstanceNV"
]
, demotedCommands = Set.fromList
[ "vkCmdSetBlendConstants"
]
}
autogen :: FilePath -> IO ()
autogen xmlPath = do
dir <- getDataDir
let vkdir = dir </> ".." </> "vulkan-raw"
let cabalfile = vkdir </> "vulkan-raw" <.> "cabal"
let gendir = vkdir </> "src-gen"
putStrLn $ "Assuming " <> vkdir <> " is the vulkan directory"
exists <- doesDirectoryExist gendir
when exists $ do
putStrLn "Cleaning the generation directory"
removeDirectoryRecursive gendir
createDirectory gendir
raw <- readFile xmlPath
putStrLn $ "Opened " <> xmlPath
doc <- case xmlParse' "vk" raw of
Left err -> die $ "XML parsing issue:\n" <> err
Right doc -> return doc
putStrLn "Parsed the raw XML"
reg <- case parseDoc doc of
Left err -> die $ "Parser issue:\n" <> err
Right reg -> return reg
putStrLn "Parsed the document"
dist <- case distill reg of
Left errs -> die $ "Distillery issue:\n" <> showErrors errs
Right dist -> return dist
putStrLn "Distilled"
(mixd, plats, bulks) <- case mix dist of
Left err -> die $ "Mixer issue:\n" <> err
Right mixed -> return mixed
putStrLn "Mixed"
pack <- case package mixd augments of
Left err -> die $ "Packager issue:\n" <> err
Right pack -> return pack
classes <- case cabalExtensions =<< purgeModuleLists bulks of
Left err -> die $ "Cabal file forming issue: " <> err
Right cs -> return cs
putStrLn "Packaged"
{-
deps <- case cabalDependencies mixd sdeps of
Left err -> die $ "Cabal dependency resolution issue:\n" <> err
Right deps -> return deps
-}
Right temp <- readTemplate "vulkan-raw.template"
putStrLn "Read the template"
writeModules gendir pack
for_ pack $ \mdl ->
writeFile (modulePath gendir mdl) $ composeModule mdl
putStrLn $ "Writing Cabal file " <> cabalfile
writeFile cabalfile $ fillTemplate temp plats classes
putStrLn "Done"