summaryrefslogtreecommitdiff
path: root/testsuite/tests/annotations/should_run/annrun01.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/annotations/should_run/annrun01.hs')
-rw-r--r--testsuite/tests/annotations/should_run/annrun01.hs49
1 files changed, 49 insertions, 0 deletions
diff --git a/testsuite/tests/annotations/should_run/annrun01.hs b/testsuite/tests/annotations/should_run/annrun01.hs
new file mode 100644
index 0000000000..e626dadebc
--- /dev/null
+++ b/testsuite/tests/annotations/should_run/annrun01.hs
@@ -0,0 +1,49 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module Main where
+
+import GHC
+import MonadUtils ( liftIO )
+import DynFlags ( defaultLogAction )
+import Annotations ( AnnTarget(..), CoreAnnTarget )
+import Serialized ( deserializeWithData )
+import Panic
+
+import Config
+import Annrun01_Help
+
+import qualified Language.Haskell.TH as TH
+import Data.List
+import Data.Function
+
+main = defaultErrorHandler defaultLogAction
+ $ runGhc (Just cTop) $ do
+ liftIO $ putStrLn "Initializing Package Database"
+ dflags <- getSessionDynFlags
+ let dflags' = dflags
+ setSessionDynFlags dflags'
+
+ let mod_nm = mkModuleName "Annrun01_Help"
+
+ liftIO $ putStrLn "Setting Target"
+ setTargets [Target (TargetModule mod_nm) True Nothing]
+ liftIO $ putStrLn "Loading Targets"
+ load LoadAllTargets
+
+ liftIO $ putStrLn "Finding Module"
+ mod <- findModule mod_nm Nothing
+ liftIO $ putStrLn "Getting Module Info"
+ Just mod_info <- getModuleInfo mod
+
+ liftIO $ putStrLn "Showing Details For Module"
+ showTargetAnns (ModuleTarget mod)
+ liftIO $ putStrLn "Showing Details For Exports"
+ mapM (showTargetAnns . NamedTarget) $ sortBy (compare `on` getOccName) $ modInfoExports mod_info
+
+showTargetAnns :: CoreAnnTarget -> Ghc ()
+showTargetAnns target = do
+ (int_anns :: [Int]) <- findGlobalAnns deserializeWithData target
+ (mb_bool_anns :: [Maybe Bool]) <- findGlobalAnns deserializeWithData target
+ (string_anns :: [String]) <- findGlobalAnns deserializeWithData target
+ (name_anns :: [TH.Name]) <- findGlobalAnns deserializeWithData target
+ liftIO $ print (int_anns, mb_bool_anns, string_anns, name_anns)