@@ -22,7 +22,9 @@ main = do
2222 Left msg -> SI. hPutStrLn SI. stderr msg
2323 Right registry -> do
2424 printTokens api registry
25- printFunctions api registry
25+ let sigMap = signatureMap registry
26+ printForeign sigMap
27+ printFunctions api registry sigMap
2628 printExtensions api registry
2729 CM. forM_ [" 1.0" , " 1.1" , " 1.2" , " 1.3" , " 1.4" , " 1.5" , " 2.0" , " 2.1" ] $ \ v ->
2830 printFeature api (read v) (ProfileName " version" ) registry
@@ -62,24 +64,34 @@ signatureMap registry = fst $ M.foldl' step (M.empty, 0) (commands registry)
6264 (newMap, maybe notFound (const found) maybeValue)
6365 where (maybeValue, newMap) = M. insertLookupWithKey (\ _ _ s -> s) key value map
6466
65- printFunctions :: API -> Registry -> IO ()
66- printFunctions api registry = do
67+ printForeign :: M. Map String String -> IO ()
68+ printForeign sigMap = do
69+ let comment = [" All foreign imports." ]
70+ startModule Nothing [" Foreign" ] (Just " {-# LANGUAGE CPP #-}" ) comment $ \ moduleName h -> do
71+ SI. hPutStrLn h $ " module " ++ moduleName ++ " where"
72+ SI. hPutStrLn h " "
73+ SI. hPutStrLn h " import Foreign.C.Types"
74+ SI. hPutStrLn h " import Foreign.Ptr"
75+ SI. hPutStrLn h " import Graphics.Rendering.OpenGL.Raw.Types"
76+ SI. hPutStrLn h " "
77+ mapM_ (SI. hPutStrLn h . uncurry makeImportDynamic) (M. assocs sigMap)
78+
79+ printFunctions :: API -> Registry -> M. Map String String -> IO ()
80+ printFunctions api registry sigMap = do
6781 let comment =
6882 [" All raw functions from the" ,
6983 " <http://www.opengl.org/registry/ OpenGL registry>." ]
70- startModule Nothing [" Functions" ] ( Just " {-# LANGUAGE CPP #-} " ) comment $ \ moduleName h -> do
84+ startModule Nothing [" Functions" ] Nothing comment $ \ moduleName h -> do
7185 SI. hPutStrLn h $ " module " ++ moduleName ++ " ("
72- SI. hPutStrLn h . separate unCommandName . M. keys . commands $ registry
86+ SI. hPutStrLn h . separate unCommandName . M. keys . commands $ registry
7387 SI. hPutStrLn h " ) where"
7488 SI. hPutStrLn h " "
75- SI. hPutStrLn h " -- Make the foreign imports happy."
76- SI. hPutStrLn h " import Foreign.C.Types"
77- SI. hPutStrLn h " "
7889 SI. hPutStrLn h " import Control.Monad.IO.Class ( MonadIO(..) )"
7990 SI. hPutStrLn h " import Foreign.Marshal.Error ( throwIf )"
8091 SI. hPutStrLn h " import Foreign.Ptr ( Ptr, FunPtr, nullFunPtr )"
8192 SI. hPutStrLn h " import System.IO.Unsafe ( unsafePerformIO )"
8293 SI. hPutStrLn h " "
94+ SI. hPutStrLn h " import Graphics.Rendering.OpenGL.Raw.Foreign"
8395 SI. hPutStrLn h " import Graphics.Rendering.OpenGL.Raw.GetProcAddress ( getProcAddress )"
8496 SI. hPutStrLn h " import Graphics.Rendering.OpenGL.Raw.Types"
8597 SI. hPutStrLn h " "
@@ -90,9 +102,6 @@ printFunctions api registry = do
90102 SI. hPutStrLn h " throwIfNullFunPtr :: String -> IO (FunPtr a) -> IO (FunPtr a)"
91103 SI. hPutStrLn h " throwIfNullFunPtr = throwIf (== nullFunPtr) . const"
92104 SI. hPutStrLn h " "
93- let sigMap = signatureMap registry
94- mapM_ (SI. hPutStrLn h . uncurry makeImportDynamic) (M. assocs sigMap)
95- SI. hPutStrLn h " "
96105 mapM_ (SI. hPutStrLn h . showCommand api sigMap) (M. elems (commands registry))
97106
98107printExtensions :: API -> Registry -> IO ()
0 commit comments