diff options
author | Edward Z. Yang <ezyang@cs.stanford.edu> | 2015-12-29 13:43:02 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-12-29 14:13:34 +0100 |
commit | 5bb7fecb09f828ea41e5b5a295ea159fa405dcc5 (patch) | |
tree | 1f5e89ec50555aabbbbacf60d3675b1fd445f683 /compiler/main/DriverPhases.hs | |
parent | 4f69203dd7892d3640e871c5914b7ee2be5f5dff (diff) | |
download | haskell-5bb7fecb09f828ea41e5b5a295ea159fa405dcc5.tar.gz |
Export some useful GHC API functions.
Working on some code using the GHC API, I found these
functions were useful and wished they were exported. This
commit exports them.
Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Test Plan: validate
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: hvr, thomie
Differential Revision: https://phabricator.haskell.org/D1710
Diffstat (limited to 'compiler/main/DriverPhases.hs')
-rw-r--r-- | compiler/main/DriverPhases.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/compiler/main/DriverPhases.hs b/compiler/main/DriverPhases.hs index ff6f8b8ab1..84eee1bfb6 100644 --- a/compiler/main/DriverPhases.hs +++ b/compiler/main/DriverPhases.hs @@ -25,6 +25,8 @@ module DriverPhases ( isHaskellSigSuffix, isSourceSuffix, + isHaskellishTarget, + isHaskellishFilename, isHaskellSrcFilename, isHaskellSigFilename, @@ -42,6 +44,7 @@ import Outputable import Platform import System.FilePath import Binary +import Util ----------------------------------------------------------------------------- -- Phases @@ -333,6 +336,23 @@ isDynLibSuffix platform s = s `elem` dynlib_suffixes platform isSourceSuffix :: String -> Bool isSourceSuffix suff = isHaskellishSuffix suff || isCishSuffix suff +-- | When we are given files (modified by -x arguments) we need +-- to determine if they are Haskellish or not to figure out +-- how we should try to compile it. The rules are: +-- +-- 1. If no -x flag was specified, we check to see if +-- the file looks like a module name, has no extension, +-- or has a Haskell source extension. +-- +-- 2. If an -x flag was specified, we just make sure the +-- specified suffix is a Haskell one. +isHaskellishTarget :: (String, Maybe Phase) -> Bool +isHaskellishTarget (f,Nothing) = + looksLikeModuleName f || isHaskellSrcFilename f || '.' `notElem` f +isHaskellishTarget (_,Just phase) = + phase `notElem` [ As True, As False, Cc, Cobjc, Cobjcxx, CmmCpp, Cmm + , StopLn] + isHaskellishFilename, isHaskellSrcFilename, isCishFilename, isHaskellUserSrcFilename, isSourceFilename, isHaskellSigFilename :: FilePath -> Bool |