diff --git a/Main.hs b/Main.hs index c0b58a2..5801b8d 100644 --- a/Main.hs +++ b/Main.hs @@ -72,6 +72,7 @@ optionsNoWarnings = , Option ['c'] ["no-main"] (NoArg optNoMain) "file has no main process; do not link either" , Option ['o'] ["output"] (ReqArg optOutput "FILE") "output file (default \"-\")" , Option [] ["sanity-check"] (ReqArg optSanityCheck "SETTING") "internal sanity check (options: on, off)" + , Option ['I'] ["search-path"] (ReqArg optSearchPath "PATHS") "paths to search for #INCLUDE, #USE" , Option [] ["occam2-mobility"] (ReqArg optClassicOccamMobility "SETTING") "occam2 implicit mobility (EXPERIMENTAL) (options: on, off)" , Option [] ["usage-checking"] (ReqArg optUsageChecking "SETTING") "usage checking (options: on, off)" , Option [] ["unknown-stack-size"] (ReqArg optStackSize "BYTES") @@ -118,6 +119,15 @@ optFrontend s ps _ -> dieIO (Nothing, "Unknown frontend: " ++ s) return $ ps { csFrontend = frontend } +optSearchPath :: String -> OptFunc +optSearchPath s ps = return $ ps { csSearchPath = csSearchPath ps ++ splitOnColons s } + where + splitOnColons :: String -> [String] + splitOnColons [] = [] + splitOnColons s = case span (/= ':') s of + (p, _:more) -> p : splitOnColons more + (p, []) -> [p] + optCompilerFlags :: String -> OptFunc optCompilerFlags flags ps = return $ ps { csCompilerFlags = flags ++ " " ++ csCompilerFlags ps} diff --git a/data/CompState.hs b/data/CompState.hs index bbe830d..0402785 100644 --- a/data/CompState.hs +++ b/data/CompState.hs @@ -115,6 +115,7 @@ data CompState = CompState { csRunIndent :: Bool, csClassicOccamMobility :: Bool, csUnknownStackSize :: Int, + csSearchPath :: [String], -- Set by preprocessor csCurrentFile :: String, -- Also used by some later passes! @@ -174,6 +175,7 @@ emptyState = CompState { csRunIndent = False, csClassicOccamMobility = False, csUnknownStackSize = 512, + csSearchPath = ["."], csCurrentFile = "none", csUsedFiles = Set.empty, diff --git a/frontends/PreprocessOccam.hs b/frontends/PreprocessOccam.hs index 54b95e3..041e094 100644 --- a/frontends/PreprocessOccam.hs +++ b/frontends/PreprocessOccam.hs @@ -48,7 +48,8 @@ searchFile :: Meta -> String -> PassM (Handle, String) searchFile m filename = do cs <- get let currentFile = csCurrentFile cs - let possibilities = [joinPath currentFile filename] + let possibilities = joinPath currentFile filename + : [dir ++ "/" ++ filename | dir <- csSearchPath cs] openOneOf possibilities where openOneOf :: [String] -> PassM (Handle, String)