Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coq section #1468

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions saw-core-coq/src/Language/Coq/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ data Decl
| Parameter Ident Type
| Variable Ident Type
| InductiveDecl Inductive
| Section Ident [Decl]
| Snippet String
deriving (Show)
6 changes: 6 additions & 0 deletions saw-core-coq/src/Language/Coq/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ ppDecl decl = case decl of
, ppTerm PrecNone body <> period
]) <> hardline
InductiveDecl ind -> ppInductive ind
Section nm ds ->
vsep $ concat
[ [ hsep [text "Section", text nm, period] ]
, map (indent 2 . ppDecl) ds
, [ hsep [text "End", text nm, period] ]
]
Snippet s -> text s

ppConstructor :: Constructor -> Doc ann
Expand Down
5 changes: 3 additions & 2 deletions saw-core-coq/src/Verifier/SAW/Translation/Coq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,19 @@ translateSAWModule configuration m =
]

translateCryptolModule ::
Coq.Ident {- ^ Section name -} ->
TranslationConfiguration ->
-- | List of already translated global declarations
[String] ->
CryptolModule ->
Either (TranslationError Term) (Doc ann)
translateCryptolModule configuration globalDecls m =
translateCryptolModule nm configuration globalDecls m =
let decls = CryptolModuleTranslation.translateCryptolModule
configuration
globalDecls
m
in
vcat . map Coq.ppDecl <$> decls
Coq.ppDecl . Coq.Section nm <$> decls

moduleDeclName :: ModuleDecl -> String
moduleDeclName (TypeDecl (DataType { dtName })) = identName dtName
Expand Down
3 changes: 2 additions & 1 deletion saw-core-coq/src/Verifier/SAW/Translation/Coq/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ namedDecls = concatMap filterNamed
filterNamed (Coq.Definition n _ _ _) = [n]
filterNamed (Coq.InductiveDecl (Coq.Inductive n _ _ _ _)) = [n]
filterNamed (Coq.Snippet _) = []
filterNamed (Coq.Section _ ds) = namedDecls ds

-- | Retrieve the names of all local and global declarations from the
-- translation state.
Expand Down Expand Up @@ -616,7 +617,7 @@ translateTermUnshared t = withLocalTranslationState $ do
modify $ set sharedNames IntMap.empty
modify $ set nextSharedName "var__0"
translateTermLet (ecType n)
modify $ over topLevelDeclarations $ (Coq.Parameter renamed tp :)
modify $ over topLevelDeclarations $ (Coq.Variable renamed tp :)
Coq.Var <$> pure renamed

-- Constants with a body
Expand Down
16 changes: 11 additions & 5 deletions saw-core/src/Verifier/SAW/Term/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,17 @@ scTermCount doBinders t0 = execState (go [t0]) IntMap.empty
argsAndSubterms (unwrapTermF -> App f arg) = arg : argsAndSubterms f
argsAndSubterms h =
case unwrapTermF h of
Lambda _ t1 _ | not doBinders -> [t1]
Pi _ t1 _ | not doBinders -> [t1]
Constant{} -> []
FTermF (Primitive _) -> []
tf -> Fold.toList tf
Lambda _ t1 _ | not doBinders -> [t1]
Pi _ t1 _ | not doBinders -> [t1]
Constant{} -> []
FTermF (Primitive _) -> []
FTermF (DataTypeApp _ ps xs) -> ps ++ xs
FTermF (CtorApp _ ps xs) -> ps ++ xs
FTermF (RecursorType _ ps m _) -> ps ++ [m]
FTermF (Recursor crec) -> recursorParams crec ++
[recursorMotive crec] ++
map fst (Map.elems (recursorElims crec))
tf -> Fold.toList tf

-- | Return true if the printing of the given term should be memoized; we do not
-- want to memoize the printing of terms that are "too small"
Expand Down
3 changes: 2 additions & 1 deletion src/SAWScript/Prover/Exporter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ writeCoqCryptolModule inputFile outputFile notations skips = io $ do
withImportCryptolPrimitivesForSAWCore $
withImportSAWCorePrelude $
coqTranslationConfiguration notations skips
case Coq.translateCryptolModule configuration cryptolPreludeDecls cm of
let nm = takeBaseName inputFile
case Coq.translateCryptolModule nm configuration cryptolPreludeDecls cm of
Left e -> putStrLn $ show e
Right cmDoc ->
writeFile outputFile
Expand Down