| 1 | {-# OPTIONS_GHC -package ghc -w #-} |
|---|
| 2 | module API where |
|---|
| 3 | |
|---|
| 4 | import DynFlags |
|---|
| 5 | import GHC |
|---|
| 6 | import PprTyThing |
|---|
| 7 | import System.Process |
|---|
| 8 | import System.IO |
|---|
| 9 | import Outputable |
|---|
| 10 | import Data.Maybe |
|---|
| 11 | |
|---|
| 12 | -- 0. '-package' is ignored in source pragmas, without even a warning |
|---|
| 13 | -- 1. comments, including pragmas, will be lost in output |
|---|
| 14 | -- 2. there'll be a syntax error here due to extra lists in output |
|---|
| 15 | instance Num () where fromInteger = undefined |
|---|
| 16 | |
|---|
| 17 | mode = CompManager |
|---|
| 18 | compileToCoreFlag = False |
|---|
| 19 | |
|---|
| 20 | -- shouldn't something like this be in System.Process? |
|---|
| 21 | writer >| cmd = runInteractiveCommand cmd >>= \(i,o,e,p)->writer i |
|---|
| 22 | cmd |> reader = runInteractiveCommand cmd >>= \(i,o,e,p)->reader o |
|---|
| 23 | |
|---|
| 24 | -- shouldn't GHC export a hostSession, |
|---|
| 25 | -- so that we could ask for things like topDir there? |
|---|
| 26 | ghcDir = "c:/fptools/ghc/compiler/stage2/ghc-inplace --print-libdir" |
|---|
| 27 | |> (fmap dropLineEnds . hGetContents) |
|---|
| 28 | where dropLineEnds = filter (not . (`elem` "\r\n")) |
|---|
| 29 | |
|---|
| 30 | main = defaultErrorHandler defaultDynFlags $ do |
|---|
| 31 | s <- newSession . Just =<< ghcDir |
|---|
| 32 | flags <- getSessionDynFlags s |
|---|
| 33 | (flags, _) <- parseDynamicFlags flags ["-package ghc"] |
|---|
| 34 | GHC.defaultCleanupHandler flags $ do |
|---|
| 35 | setSessionDynFlags s flags{ hscTarget=HscInterpreted } |
|---|
| 36 | addTarget s =<< guessTarget "API_Layout.hs" Nothing |
|---|
| 37 | load s LoadAllTargets |
|---|
| 38 | prelude <- findModule s (mkModuleName "Prelude") Nothing |
|---|
| 39 | usermod <- findModule s (mkModuleName "API") Nothing |
|---|
| 40 | setContext s [usermod] [prelude] |
|---|
| 41 | Just cm <- checkModule s (mkModuleName "API") compileToCoreFlag |
|---|
| 42 | unqual <- getPrintUnqual s |
|---|
| 43 | printForUser stdout unqual $ ppr $ parsedSource cm |
|---|