diff options
| author | kr.angelov <kr.angelov@gmail.com> | 2013-12-10 10:43:13 +0000 |
|---|---|---|
| committer | kr.angelov <kr.angelov@gmail.com> | 2013-12-10 10:43:13 +0000 |
| commit | 87fffffbdf41eaf0f269bd65d8380b80d899bec8 (patch) | |
| tree | 4f7978256da871aff44790bd6cd6309d5fe138f2 /src/compiler/GFC.hs | |
| parent | 2dda42e4d9ccba0223d4f3c78ab64af2213810b9 (diff) | |
option --split-pgf replaces option --mk-index. This splits the PGF into one file for the abstract and one more for each concrete syntax. This is a preparation for being able to load only specific languages from the whole grammar.
Diffstat (limited to 'src/compiler/GFC.hs')
| -rw-r--r-- | src/compiler/GFC.hs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/compiler/GFC.hs b/src/compiler/GFC.hs index 99156e16d..cb3fa7afd 100644 --- a/src/compiler/GFC.hs +++ b/src/compiler/GFC.hs @@ -5,7 +5,7 @@ import PGF --import PGF.CId import PGF.Data import PGF.Optimize -import GF.Index +import PGF.Binary(putSplitAbs) import GF.Compile import GF.Compile.Export @@ -24,7 +24,7 @@ import qualified Data.ByteString.Lazy as BSL import System.FilePath import System.IO import Control.Exception -import Control.Monad(unless) +import Control.Monad(unless,forM_) mainGFC :: Options -> [FilePath] -> IO () mainGFC opts fs = do @@ -66,10 +66,9 @@ unionPGFFiles :: Options -> [FilePath] -> IOE () unionPGFFiles opts fs = do pgfs <- mapM readPGFVerbose fs let pgf0 = foldl1 unionPGF pgfs - pgf1 = if flag optOptimizePGF opts then optimizePGF pgf0 else pgf0 - pgf = if flag optMkIndexPGF opts then addIndex pgf1 else pgf1 + pgf = if flag optOptimizePGF opts then optimizePGF pgf0 else pgf0 pgfFile = grammarName opts pgf <.> "pgf" - if pgfFile `elem` fs + if pgfFile `elem` fs then putStrLnE $ "Refusing to overwrite " ++ pgfFile else writePGF opts pgf writeOutputs opts pgf @@ -104,9 +103,16 @@ writeByteCode opts pgf [(id,addr) | (id,(_,_,_,addr)) <- Map.toList (cats (abstract pgf))] writePGF :: Options -> PGF -> IOE () -writePGF opts pgf = do - let outfile = grammarName opts pgf <.> "pgf" - putPointE Normal opts ("Writing " ++ outfile ++ "...") $ liftIO $ encodeFile outfile pgf +writePGF opts pgf + | flag optSplitPGF opts = do let outfile = grammarName opts pgf <.> "pgf" + putPointE Normal opts ("Writing " ++ outfile ++ "...") $ liftIO $ do + encodeFile_ outfile (putSplitAbs pgf) + forM_ (Map.toList (concretes pgf)) $ \cnc -> do + let outfile = showCId (fst cnc) <.> "pgf_c" + putPointE Normal opts ("Writing " ++ outfile ++ "...") $ liftIO $ encodeFile outfile cnc + return () + | otherwise = do let outfile = grammarName opts pgf <.> "pgf" + putPointE Normal opts ("Writing " ++ outfile ++ "...") $ liftIO $ encodeFile outfile pgf grammarName :: Options -> PGF -> String grammarName opts pgf = fromMaybe (showCId (absname pgf)) (flag optName opts) |
