Implemented a search path for Tock (for #INCLUDE and #USE directives)
This commit is contained in:
parent
8220630426
commit
427938039c
10
Main.hs
10
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}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user