Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
changed defineModuleFromFileWithFns to also emit a function for loadi…
Browse files Browse the repository at this point in the history
…ng the given module into the current SharedContext
  • Loading branch information
Eddy Westbrook committed May 10, 2018
1 parent 276ddb2 commit 580836b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Verifier/SAW.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Verifier.SAW
, module Verifier.SAW.ExternalFormat
, Module
, preludeModule
, scLoadPreludeModule
) where

import Verifier.SAW.SharedTerm
Expand Down
28 changes: 20 additions & 8 deletions src/Verifier/SAW/ParserUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,24 @@ declareSharedModuleFns m =
declareCtorFun (Un.moduleName m) c tp


-- | @defineModuleFromFileWithFns str file@ reads an untyped module from @file@,
-- adds a TH declaration of the name @str@ that is bound to that module at
-- runtime, and then calls 'declareSharedModuleFns' to add declarations of
-- | @defineModuleFromFileWithFns str str2 file@ reads an untyped module from
-- @file@, adds a TH declaration of the name @str@ that is bound to that module
-- at runtime, and then calls 'declareSharedModuleFns' to add declarations of
-- Haskell term-building functions for each definition, constructor, and
-- datatype declared in the module that is loaded.
defineModuleFromFileWithFns :: String -> FilePath -> Q [Dec]
defineModuleFromFileWithFns decNameStr path =
runDecWriter (defineModuleFromFile decNameStr path >>=
declareSharedModuleFns)
-- datatype declared in the module that is loaded. It also defines the function
--
-- > str2 :: SharedContext -> IO ()
--
-- that will load the module @str@ into the current 'SharedContext'.
defineModuleFromFileWithFns :: String -> String -> FilePath -> Q [Dec]
defineModuleFromFileWithFns mod_name mod_loader path =
runDecWriter $
do m <- defineModuleFromFile mod_name path
declareSharedModuleFns m
let sc = mkName "sc"
load_tp <- lift $ [t| SharedContext -> IO () |]
load_body <-
lift $ [e| tcInsertModule $(varE sc) $(varE $ mkName mod_name) |]
addDecs [ SigD (mkName mod_loader) load_tp
, FunD (mkName mod_loader) [ Clause [VarP sc] (NormalB load_body) [] ]
]
4 changes: 3 additions & 1 deletion src/Verifier/SAW/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ module Verifier.SAW.Prelude
import Verifier.SAW.ParserUtils
import Verifier.SAW.Prelude.Constants
import Verifier.SAW.SharedTerm
import Verifier.SAW.Typechecker

$(defineModuleFromFileWithFns "preludeModule" "prelude/Prelude.sawcore")
$(defineModuleFromFileWithFns
"preludeModule" "scLoadPreludeModule" "prelude/Prelude.sawcore")

scEq :: SharedContext -> Term -> Term -> IO Term
scEq sc x y = do
Expand Down
3 changes: 2 additions & 1 deletion tools/extcore-info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import Verifier.SAW

processFile :: FilePath -> IO ()
processFile file = do
sc <- mkSharedContext preludeModule
sc <- mkSharedContext
scLoadPreludeModule sc
tm <- scReadExternal sc =<< readFile file
putStrLn $ "Shared size: " ++ show (scSharedSize tm)
putStrLn $ "Tree size: " ++ show (scTreeSize tm)
Expand Down

0 comments on commit 580836b

Please sign in to comment.