From 87fffffbdf41eaf0f269bd65d8380b80d899bec8 Mon Sep 17 00:00:00 2001 From: "kr.angelov" Date: Tue, 10 Dec 2013 10:43:13 +0000 Subject: 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. --- src/compiler/GFC.hs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/compiler/GFC.hs') 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) -- cgit v1.2.3