diff options
| author | hallgren <hallgren@chalmers.se> | 2014-01-09 17:30:24 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2014-01-09 17:30:24 +0000 |
| commit | ed3d30e3d1134dfd06ae2a88b51767041eda6c0b (patch) | |
| tree | 99931497cd2c5316ae42e0acca22d31ce4293ad8 /src/compiler/GFC.hs | |
| parent | 768d9de6681b5ac69b42128fbde18c8421cb5f1e (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/GFC.hs')
| -rw-r--r-- | src/compiler/GFC.hs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/compiler/GFC.hs b/src/compiler/GFC.hs index 65650d922..6e4c50258 100644 --- a/src/compiler/GFC.hs +++ b/src/compiler/GFC.hs @@ -10,7 +10,7 @@ import GF.Compile import GF.Compile.Export import GF.Grammar.CF ---- should this be on a deeper level? AR 15/10/2008 -import GF.Infra.Ident(identS) +import GF.Infra.Ident(identS,showIdent) import GF.Infra.UseIO import GF.Infra.Option @@ -45,13 +45,19 @@ mainGFC opts fs = do compileSourceFiles :: Options -> [FilePath] -> IOE () compileSourceFiles opts fs = - do gr <- batchCompile opts fs - let cnc = justModuleName (last fs) + do cnc_gr@(cnc,t_src,gr) <- batchCompile opts fs unless (flag optStopAfterPhase opts == Compile) $ - do pgf <- link opts (identS cnc) gr - writePGF opts pgf - writeByteCode opts pgf - writeOutputs opts pgf + do let abs = showIdent (srcAbsName gr cnc) + pgfFile = grammarName' opts abs<.>"pgf" + t_pgf <- if outputJustPGF opts + then maybeIO $ getModificationTime pgfFile + else return Nothing + if t_pgf >= Just t_src + then putIfVerb opts $ pgfFile ++ " is up-to-date." + else do pgf <- link opts cnc_gr + writePGF opts pgf + writeByteCode opts pgf + writeOutputs opts pgf compileCFFiles :: Options -> [FilePath] -> IOE () compileCFFiles opts fs = @@ -59,13 +65,13 @@ compileCFFiles opts fs = let cnc = justModuleName (last fs) gr <- compileSourceGrammar opts =<< getCF cnc s unless (flag optStopAfterPhase opts == Compile) $ - do pgf <- link opts (identS cnc) gr + do pgf <- link opts (identS cnc, (), gr) writePGF opts pgf writeOutputs opts pgf unionPGFFiles :: Options -> [FilePath] -> IOE () unionPGFFiles opts fs = - if null (outputFormats opts) + if outputJustPGF opts then maybe doIt checkFirst (flag optName opts) else doIt where @@ -97,6 +103,7 @@ writeOutputs opts pgf = do (name,str) <- exportPGF opts fmt pgf] outputFormats opts = [fmt | fmt <- flag optOutputFormats opts, fmt/=FmtByteCode] +outputJustPGF opts = null (flag optOutputFormats opts) && not (flag optSplitPGF opts) writeByteCode :: Options -> PGF -> IOE () writeByteCode opts pgf @@ -132,7 +139,9 @@ writePGF opts pgf putPointE Normal opts ("Writing " ++ outfile ++ "...") $ liftIO $ encodeFile outfile pgf grammarName :: Options -> PGF -> String -grammarName opts pgf = fromMaybe (showCId (absname pgf)) (flag optName opts) +grammarName opts pgf = --fromMaybe (showCId (absname pgf)) (flag optName opts) + grammarName' opts (showCId (absname pgf)) +grammarName' opts abs = fromMaybe abs (flag optName opts) writeOutput :: Options -> FilePath-> String -> IOE () writeOutput opts file str = |
