summaryrefslogtreecommitdiff
path: root/transfer
diff options
context:
space:
mode:
authorbringert <bringert@cs.chalmers.se>2005-11-30 16:32:13 +0000
committerbringert <bringert@cs.chalmers.se>2005-11-30 16:32:13 +0000
commit3139bd2a2ef47a7959122328e75256442b802094 (patch)
tree62fabe3ecfd4170367f5e55f111fa88f2a6da3a1 /transfer
parentcba2fcb9b118cedb603b171ac7d7581c5adb844c (diff)
Transfer compiler now has a search path. Use -ipath to add to the path. Created CompilerAPI.
Diffstat (limited to 'transfer')
-rw-r--r--transfer/compile_to_core.hs51
1 files changed, 12 insertions, 39 deletions
diff --git a/transfer/compile_to_core.hs b/transfer/compile_to_core.hs
index 1f9ea746b..b35d906d0 100644
--- a/transfer/compile_to_core.hs
+++ b/transfer/compile_to_core.hs
@@ -1,52 +1,25 @@
module Main where
-import Transfer.Syntax.Lex
-import Transfer.Syntax.Par
-import Transfer.Syntax.Print
-import Transfer.Syntax.Abs
-import Transfer.Syntax.Layout
-
-import Transfer.ErrM
-import Transfer.SyntaxToCore
-
-import Transfer.PathUtil
+import Transfer.CompilerAPI
+import Data.List (partition, isPrefixOf)
import System.Environment
import System.Exit
import System.IO
-import Debug.Trace
-
-myLLexer = resolveLayout True . myLexer
-
-compile :: Monad m => [Decl] -> m String
-compile m = return (printTree $ declsToCore m)
-
-loadModule :: FilePath -> IO [Decl]
-loadModule f =
- do
- s <- readFile f
- Module is ds <- case pModule (myLLexer s) of
- Bad e -> die $ "Parse error in " ++ f ++ ": " ++ e
- Ok m -> return m
- let dir = directoryOf f
- deps = [ replaceFilename f i ++ ".tr" | Import (Ident i) <- is ]
- dss <- mapM loadModule deps
- return $ concat (ds:dss)
-
die :: String -> IO a
die s = do
hPutStrLn stderr s
exitFailure
-coreFile :: FilePath -> FilePath
-coreFile f = replaceFilenameSuffix f "trc"
-
-compileFile :: FilePath -> IO String
-compileFile f = loadModule f >>= compile
-
main :: IO ()
-main = do args <- getArgs
- case args of
- [f] -> compileFile f >>= writeFile (coreFile f)
- _ -> die "Usage: compile_to_core <file>"
+main = do
+ args <- getArgs
+ let (flags,files) = partition ("-" `isPrefixOf`) args
+ path = [ p | ('-':'i':p) <- flags ]
+ case files of
+ [f] -> do
+ cf <- compileFile path f
+ putStrLn $ "Wrote " ++ cf
+ return ()
+ _ -> die "Usage: compile_to_core [-i<path> [-i<path> ... ]] <file>"