Skip to content

Commit

Permalink
Make test binary load, translate, and typecheck Cryptol.cry.
Browse files Browse the repository at this point in the history
(This addresses part of #25.)
  • Loading branch information
Brian Huffman committed Jul 30, 2020
1 parent f72b9cf commit 497effb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cryptol-verifier.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@ test-suite cryptol-verifier-tc-test

build-depends:
base,
bytestring,
containers,
cryptol,
cryptol-verifier,
saw-core
27 changes: 26 additions & 1 deletion test/CryptolVerifierTC.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
{-# LANGUAGE ImplicitParams #-}

module Main where

import qualified Data.ByteString as BS
import qualified Data.Map as Map

import qualified Cryptol.ModuleSystem.Name as N
import qualified Cryptol.Utils.Ident as N

import qualified Verifier.SAW.Cryptol as C
import Verifier.SAW.SharedTerm
import qualified Verifier.SAW.SCTypeCheck as TC
import qualified Verifier.SAW.Cryptol.Prelude as C
import qualified Verifier.SAW.CryptolEnv as CEnv

main :: IO ()
main =
do sc <- mkSharedContext
C.scLoadPreludeModule sc
C.scLoadCryptolModule sc
putStrLn "Loaded!"
putStrLn "Loaded Cryptol.sawcore!"
let ?fileReader = BS.readFile
cenv <- CEnv.initCryptolEnv sc
putStrLn "Translated Cryptol.cry!"
mapM_ (checkTranslation sc) $ Map.assocs (CEnv.eTermEnv cenv)
putStrLn "Checked all terms!"

checkTranslation :: SharedContext -> (N.Name, Term) -> IO ()
checkTranslation sc (name, term) =
do result <- TC.scTypeCheck sc Nothing term
case result of
Right _ -> pure ()
Left err ->
do putStrLn $ "Type error when checking " ++ show (N.unpackIdent (N.nameIdent name))
putStrLn $ unlines $ TC.prettyTCError err
fail "internal type error"

0 comments on commit 497effb

Please sign in to comment.