summaryrefslogtreecommitdiff
path: root/src/compiler/GF
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2014-01-09 17:30:24 +0000
committerhallgren <hallgren@chalmers.se>2014-01-09 17:30:24 +0000
commited3d30e3d1134dfd06ae2a88b51767041eda6c0b (patch)
tree99931497cd2c5316ae42e0acca22d31ce4293ad8 /src/compiler/GF
parent768d9de6681b5ac69b42128fbde18c8421cb5f1e (diff)
Check file datestamp before creating PGF file when compiling grammars
When running a command like gf -make L_1.gf ... L_n.gf gf now avoids recreating the target PGF file if it already exists and is up-to-date. gf still reads all required .gfo files, so significant additional speed improvements are still possible. This could be done by reading .gfo files more lazily...
Diffstat (limited to 'src/compiler/GF')
-rw-r--r--src/compiler/GF/Command/Importing.hs4
-rw-r--r--src/compiler/GF/Compile.hs35
2 files changed, 20 insertions, 19 deletions
diff --git a/src/compiler/GF/Command/Importing.hs b/src/compiler/GF/Command/Importing.hs
index 4697e8b64..2bdc091f8 100644
--- a/src/compiler/GF/Command/Importing.hs
+++ b/src/compiler/GF/Command/Importing.hs
@@ -46,7 +46,7 @@ importSource :: SourceGrammar -> Options -> [FilePath] -> IO SourceGrammar
importSource src0 opts files = do
src <- appIOE $ batchCompile opts files
case src of
- Ok gr -> return gr
+ Ok (_,_,gr) -> return gr
Bad msg -> do
putStrLn msg
return src0
@@ -58,7 +58,7 @@ importCF opts files get = do
Ok gf -> return gf
Bad s -> error s ----
Ok gr <- appIOE $ compileSourceGrammar opts gf
- epgf <- appIOE $ link opts (identS (justModuleName (last files) ++ "Abs")) gr
+ epgf <- appIOE $ link opts (identS (justModuleName (last files) ++ "Abs"), (), gr)
case epgf of
Ok pgf -> return pgf
Bad s -> error s ----
diff --git a/src/compiler/GF/Compile.hs b/src/compiler/GF/Compile.hs
index b74fd340c..962a63815 100644
--- a/src/compiler/GF/Compile.hs
+++ b/src/compiler/GF/Compile.hs
@@ -1,4 +1,4 @@
-module GF.Compile (batchCompile, link, compileToPGF, compileSourceGrammar) where
+module GF.Compile (batchCompile, link, srcAbsName, compileToPGF, compileSourceGrammar) where
import Prelude hiding (catch)
import GF.System.Catch
@@ -31,6 +31,7 @@ import System.FilePath
import qualified Data.Map as Map
--import qualified Data.Set as Set
import Data.List(nub)
+import Data.Time(UTCTime)
import Text.PrettyPrint
import PGF.Optimize
@@ -38,33 +39,33 @@ import PGF
-- | Compiles a number of source files and builds a 'PGF' structure for them.
compileToPGF :: Options -> [FilePath] -> IOE PGF
-compileToPGF opts fs =
- do gr <- batchCompile opts fs
- let name = justModuleName (last fs)
- link opts (identS name) gr
-
-link :: Options -> Ident -> SourceGrammar -> IOE PGF
-link opts cnc gr = do
- let isv = (verbAtLeast opts Normal)
+compileToPGF opts fs = link opts =<< batchCompile opts fs
+
+link :: Options -> (Ident,t,SourceGrammar) -> IOE PGF
+link opts (cnc,_,gr) =
putPointE Normal opts "linking ... " $ do
- let abs = err (const cnc) id $ abstractOfConcrete gr cnc
+ let abs = srcAbsName gr cnc
pgf <- mkCanon2pgf opts gr abs
probs <- liftIO (maybe (return . defaultProbabilities) readProbabilitiesFromFile (flag optProbsFile opts) pgf)
when (verbAtLeast opts Normal) $ putStrE "OK"
return $ setProbabilities probs
$ if flag optOptimizePGF opts then optimizePGF pgf else pgf
-batchCompile :: Options -> [FilePath] -> IOE SourceGrammar
+srcAbsName gr cnc = err (const cnc) id $ abstractOfConcrete gr cnc
+
+batchCompile :: Options -> [FilePath] -> IOE (Ident,UTCTime,SourceGrammar)
batchCompile opts files = do
- (_,gr,_) <- foldM (compileModule opts) emptyCompileEnv files
- return gr
+ (_,gr,menv) <- foldM (compileModule opts) emptyCompileEnv files
+ let cnc = identS (justModuleName (last files))
+ t = maximum . map fst $ Map.elems menv
+ return (cnc,t,gr)
-- to compile a set of modules, e.g. an old GF or a .cf file
compileSourceGrammar :: Options -> SourceGrammar -> IOE SourceGrammar
compileSourceGrammar opts gr = do
cwd <- liftIO getCurrentDirectory
(_,gr',_) <- foldM (\env -> compileSourceModule opts cwd env Nothing)
- (0,emptySourceGrammar,Map.empty)
+ emptyCompileEnv
(modules gr)
return gr'
@@ -84,9 +85,6 @@ warnOut opts warnings
then '\n':warnings
else warnings
--- | the environment
-type CompileEnv = (Int,SourceGrammar,ModEnv)
-
-- | compile with one module as starting point
-- command-line options override options (marked by --#) in the file
-- As for path: if it is read from file, the file path is prepended to each name.
@@ -238,6 +236,9 @@ writeGFO opts file mo = do
--reverseModules (MGrammar ms) = MGrammar $ reverse ms
+-- | The environment
+type CompileEnv = (Int,SourceGrammar,ModEnv)
+
emptyCompileEnv :: CompileEnv
emptyCompileEnv = (0,emptySourceGrammar,Map.empty)