Skip to content

Commit 6d6b6a2

Browse files
author
Andrew Kent
authored
saw-remote-api/feat: add docs, argo submodule bump (#1017)
* saw-remote-api/feat: add docs, argo submodule bump * PR comment fixes, colocate docs with their methods * PR requested tweak * chore: add missing doc for saveTerm * build fixes
1 parent a52e408 commit 6d6b6a2

File tree

11 files changed

+274
-21
lines changed

11 files changed

+274
-21
lines changed

saw-remote-api/saw-remote-api/Main.hs

+63-18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
module Main (main) where
33

4-
import qualified Data.Aeson as JSON
5-
import Data.Text (Text)
6-
74
import Argo
85
import Argo.DefaultMain
6+
import qualified Argo.Doc as Doc
97

108
import SAWServer
119
import SAWServer.CryptolSetup
@@ -20,32 +18,79 @@ import SAWServer.SetOption
2018

2119
main :: IO ()
2220
main =
23-
do theApp <- mkApp initialState sawMethods
21+
do theApp <- mkApp "SAW RPC Server" serverDocs initialState sawMethods
2422
defaultMain description theApp
2523

24+
serverDocs :: [Doc.Block]
25+
serverDocs =
26+
[ Doc.Section "Summary" $ [ Doc.Paragraph
27+
[Doc.Text "A remote server for ",
28+
Doc.Link (Doc.URL "https://saw.galois.com/") "SAW",
29+
Doc.Text " for verifying programs with a featureset similar to SAWScript."]]]
30+
2631
description :: String
2732
description =
2833
"An RPC server for SAW."
2934

30-
sawMethods :: [(Text, MethodType, JSON.Value -> Method SAWState JSON.Value)]
35+
sawMethods :: [AppMethod SAWState]
3136
sawMethods =
3237
-- Cryptol
33-
[ ("SAW/Cryptol/load module", Command, method cryptolLoadModule)
34-
, ("SAW/Cryptol/load file", Command, method cryptolLoadFile)
35-
, ("SAW/Cryptol/save term", Command, method saveTerm)
38+
[ method
39+
"SAW/Cryptol/load module"
40+
Command
41+
cryptolLoadModuleDescr
42+
cryptolLoadModule
43+
, method
44+
"SAW/Cryptol/load file"
45+
Command
46+
cryptolLoadFileDescr
47+
cryptolLoadFile
48+
, method
49+
"SAW/Cryptol/save term"
50+
Command
51+
saveTermDescr
52+
saveTerm
3653
-- JVM
3754
{-
38-
, ("SAW/JVM/load class", Command, method jvmLoadClass)
39-
, ("SAW/JVM/verify", Command, method jvmVerify)
40-
, ("SAW/JVM/assume", Command, method jvmAssume)
55+
, method "SAW/JVM/load class" Command (Doc.Paragraph [Doc.Text "TODO"]) jvmLoadClass
56+
, method "SAW/JVM/verify" Command (Doc.Paragraph [Doc.Text "TODO"]) jvmVerify
57+
, method "SAW/JVM/assume" Command (Doc.Paragraph [Doc.Text "TODO"]) jvmAssume
4158
-}
4259
-- LLVM
43-
, ("SAW/LLVM/load module", Command, method llvmLoadModule)
44-
, ("SAW/LLVM/verify", Command, method llvmVerify)
45-
, ("SAW/LLVM/verify x86", Command, method llvmVerifyX86)
46-
, ("SAW/LLVM/assume", Command, method llvmAssume)
60+
, method
61+
"SAW/LLVM/load module"
62+
Command
63+
llvmLoadModuleDescr
64+
llvmLoadModule
65+
, method
66+
"SAW/LLVM/verify"
67+
Command
68+
llvmVerifyDescr
69+
llvmVerify
70+
, method
71+
"SAW/LLVM/verify x86"
72+
Command
73+
llvmVerifyX86Descr
74+
llvmVerifyX86
75+
, method
76+
"SAW/LLVM/assume"
77+
Command
78+
llvmAssumeDescr
79+
llvmAssume
4780
-- General
48-
, ("SAW/make simpset", Command, method makeSimpset)
49-
, ("SAW/prove", Command, method prove)
50-
, ("SAW/set option", Command, method setOption)
81+
, method
82+
"SAW/make simpset"
83+
Command
84+
makeSimpsetDescr
85+
makeSimpset
86+
, method
87+
"SAW/prove"
88+
Command
89+
proveDescr
90+
prove
91+
, method
92+
"SAW/set option"
93+
Command
94+
setOptionDescr
95+
setOption
5196
]

saw-remote-api/src/SAWServer/CryptolSetup.hs

+25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
{-# LANGUAGE ScopedTypeVariables #-}
55
module SAWServer.CryptolSetup
66
( cryptolLoadFile
7+
, cryptolLoadFileDescr
78
, cryptolLoadModule
9+
, cryptolLoadModuleDescr
810
) where
911

1012
import Control.Exception (SomeException, try)
@@ -19,10 +21,15 @@ import SAWScript.Value (biSharedContext, rwCryptol)
1921
import qualified Verifier.SAW.CryptolEnv as CEnv
2022

2123
import Argo
24+
import qualified Argo.Doc as Doc
2225
import SAWServer
2326
import SAWServer.Exceptions
2427
import SAWServer.OK
2528

29+
cryptolLoadModuleDescr :: Doc.Block
30+
cryptolLoadModuleDescr =
31+
Doc.Paragraph [Doc.Text "Load the specified Cryptol module."]
32+
2633
cryptolLoadModule :: CryptolLoadModuleParams -> Method SAWState OK
2734
cryptolLoadModule (CryptolLoadModuleParams modName) =
2835
do sc <- biSharedContext . view sawBIC <$> getState
@@ -46,6 +53,18 @@ instance FromJSON CryptolLoadModuleParams where
4653
withObject "params for \"SAW/Cryptol setup/load module\"" $ \o ->
4754
CryptolLoadModuleParams . textToModName <$> o .: "module name"
4855

56+
instance Doc.DescribedParams CryptolLoadModuleParams where
57+
parameterFieldDescription =
58+
[ ("module name",
59+
Doc.Paragraph [Doc.Text "Name of module to load."])
60+
]
61+
62+
63+
cryptolLoadFileDescr :: Doc.Block
64+
cryptolLoadFileDescr =
65+
Doc.Paragraph [Doc.Text "Load the given file as a Cryptol module."]
66+
67+
4968
cryptolLoadFile :: CryptolLoadFileParams -> Method SAWState OK
5069
cryptolLoadFile (CryptolLoadFileParams fileName) =
5170
do sc <- biSharedContext . view sawBIC <$> getState
@@ -68,3 +87,9 @@ instance FromJSON CryptolLoadFileParams where
6887
parseJSON =
6988
withObject "params for \"SAW/Cryptol setup/load file\"" $ \o ->
7089
CryptolLoadFileParams . T.unpack <$> o .: "file"
90+
91+
instance Doc.DescribedParams CryptolLoadFileParams where
92+
parameterFieldDescription =
93+
[ ("file",
94+
Doc.Paragraph [Doc.Text "File to load as a Cryptol module."])
95+
]

saw-remote-api/src/SAWServer/JVMCrucibleSetup.hs

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import Verifier.SAW.CryptolEnv (CryptolEnv)
3737
import Verifier.SAW.TypedTerm (TypedTerm)
3838

3939
import Argo
40+
import qualified Argo.Doc as Doc
4041
import SAWServer
4142
import SAWServer.Data.Contract
4243
import SAWServer.Data.SetupValue ()
@@ -58,6 +59,12 @@ instance FromJSON StartJVMSetupParams where
5859
withObject "params for \"SAW/Crucible setup\"" $ \o ->
5960
StartJVMSetupParams <$> o .: "name"
6061

62+
instance Doc.DescribedParams StartJVMSetupParams where
63+
parameterFieldDescription =
64+
[ ("name",
65+
Doc.Paragraph [Doc.Text "The name of the item to setup on the server."])
66+
]
67+
6168
data ServerSetupVal = Val (SetupValue CJ.JVM)
6269

6370
-- TODO: this is an extra layer of indirection that could be collapsed, but is easy to implement for now.
@@ -187,3 +194,11 @@ jvmLoadClass (JVMLoadClassParams serverName cname) =
187194
do c <- tl $ loadJavaClass cname
188195
setServerVal serverName c
189196
ok
197+
198+
instance Doc.DescribedParams JVMLoadClassParams where
199+
parameterFieldDescription =
200+
[ ("name",
201+
Doc.Paragraph [Doc.Text "The name of the class on the server."])
202+
, ("class",
203+
Doc.Paragraph [Doc.Text "The java class to load."])
204+
]

saw-remote-api/src/SAWServer/LLVMCrucibleSetup.hs

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
module SAWServer.LLVMCrucibleSetup
1111
( startLLVMCrucibleSetup
1212
, llvmLoadModule
13+
, llvmLoadModuleDescr
1314
, Contract(..)
1415
, ContractVar(..)
1516
, Allocated(..)
@@ -51,6 +52,7 @@ import Verifier.SAW.CryptolEnv (CryptolEnv)
5152
import Verifier.SAW.TypedTerm (TypedTerm)
5253

5354
import Argo
55+
import qualified Argo.Doc as Doc
5456
import SAWServer
5557
import SAWServer.Data.Contract
5658
import SAWServer.Data.LLVMType (JSONLLVMType, llvmType)
@@ -192,6 +194,19 @@ instance FromJSON LLVMLoadModuleParams where
192194
withObject "params for \"SAW/LLVM/load module\"" $ \o ->
193195
LLVMLoadModuleParams <$> o .: "name" <*> o .: "bitcode file"
194196

197+
198+
instance Doc.DescribedParams LLVMLoadModuleParams where
199+
parameterFieldDescription =
200+
[ ("name",
201+
Doc.Paragraph [Doc.Text "The name to refer to the loaded module by later."])
202+
, ("bitcode file",
203+
Doc.Paragraph [Doc.Text "The file containing the bitcode LLVM module to load."])
204+
]
205+
206+
llvmLoadModuleDescr :: Doc.Block
207+
llvmLoadModuleDescr =
208+
Doc.Paragraph [Doc.Text "Load the specified LLVM module."]
209+
195210
llvmLoadModule :: LLVMLoadModuleParams -> Method SAWState OK
196211
llvmLoadModule (LLVMLoadModuleParams serverName fileName) =
197212
do tasks <- view sawTask <$> getState

saw-remote-api/src/SAWServer/LLVMVerify.hs

+27
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
module SAWServer.LLVMVerify
44
( llvmVerify
5+
, llvmVerifyDescr
56
, llvmVerifyX86
7+
, llvmVerifyX86Descr
68
, llvmAssume
9+
, llvmAssumeDescr
710
) where
811

912
import Prelude hiding (mod)
@@ -14,6 +17,7 @@ import SAWScript.Crucible.LLVM.X86
1417
import SAWScript.Value (rwCryptol)
1518

1619
import Argo
20+
import qualified Argo.Doc as Doc
1721
import CryptolServer.Data.Expression
1822
import SAWServer
1923
import SAWServer.Data.Contract
@@ -49,13 +53,36 @@ llvmVerifyAssume mode (VerifyParams modName fun lemmaNames checkSat contract scr
4953
setServerVal lemmaName res
5054
ok
5155

56+
57+
58+
llvmVerifyDescr :: Doc.Block
59+
llvmVerifyDescr =
60+
Doc.Paragraph [Doc.Text "Verify the named LLVM function meets its specification."]
61+
5262
llvmVerify :: VerifyParams JSONLLVMType -> Method SAWState OK
5363
llvmVerify = llvmVerifyAssume VerifyContract
5464

65+
66+
67+
68+
69+
llvmAssumeDescr :: Doc.Block
70+
llvmAssumeDescr =
71+
Doc.Paragraph [Doc.Text $ "Assume the function meets its specification."]
72+
5573
llvmAssume :: AssumeParams JSONLLVMType -> Method SAWState OK
5674
llvmAssume (AssumeParams modName fun contract lemmaName) =
5775
llvmVerifyAssume AssumeContract (VerifyParams modName fun [] False contract (ProofScript []) lemmaName)
5876

77+
78+
79+
80+
81+
llvmVerifyX86Descr :: Doc.Block
82+
llvmVerifyX86Descr =
83+
Doc.Paragraph [ Doc.Text "Verify an x86 function from an ELF file for use as"
84+
, Doc.Text " an override in an LLVM verification meets its specification."]
85+
5986
llvmVerifyX86 :: X86VerifyParams JSONLLVMType -> Method SAWState OK
6087
llvmVerifyX86 (X86VerifyParams modName objName fun globals _lemmaNames checkSat contract script lemmaName) =
6188
do tasks <- view sawTask <$> getState

saw-remote-api/src/SAWServer/NoParams.hs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module SAWServer.NoParams (NoParams(..)) where
22

33
import Data.Aeson
4+
import qualified Argo.Doc as Doc
45

56
data NoParams = NoParams
67

@@ -9,3 +10,6 @@ instance ToJSON NoParams where
910

1011
instance FromJSON NoParams where
1112
parseJSON = withObject "no parameters" (const (pure NoParams))
13+
14+
instance Doc.DescribedParams NoParams where
15+
parameterFieldDescription = []

saw-remote-api/src/SAWServer/ProofScript.hs

+30
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module SAWServer.ProofScript
44
( ProofScript(..)
55
, interpretProofScript
66
, makeSimpset
7+
, makeSimpsetDescr
78
, prove
9+
, proveDescr
810
) where
911

1012
import Control.Applicative
@@ -13,6 +15,7 @@ import Data.Aeson
1315
import Data.Text (Text)
1416

1517
import Argo
18+
import qualified Argo.Doc as Doc
1619
import qualified SAWScript.Builtins as SB
1720
import qualified SAWScript.Value as SV
1821
import SAWServer
@@ -83,6 +86,19 @@ instance FromJSON MakeSimpsetParams where
8386
MakeSimpsetParams <$> o .: "elements"
8487
<*> o .: "result"
8588

89+
instance Doc.DescribedParams MakeSimpsetParams where
90+
parameterFieldDescription =
91+
[ ("elements",
92+
Doc.Paragraph [Doc.Text "The items to include in the simpset."])
93+
, ("result",
94+
Doc.Paragraph [Doc.Text "The name to assign to this simpset."])
95+
]
96+
97+
98+
makeSimpsetDescr :: Doc.Block
99+
makeSimpsetDescr =
100+
Doc.Paragraph [Doc.Text "Create a simplification rule set from the given rules."]
101+
86102
makeSimpset :: MakeSimpsetParams -> Method SAWState OK
87103
makeSimpset params = do
88104
let add ss n = do
@@ -107,6 +123,14 @@ instance FromJSON ProveParams where
107123
ProveParams <$> o .: "script"
108124
<*> o .: "term"
109125

126+
instance Doc.DescribedParams ProveParams where
127+
parameterFieldDescription =
128+
[ ("script",
129+
Doc.Paragraph [Doc.Text "Script to use to prove the term."])
130+
, ("term",
131+
Doc.Paragraph [Doc.Text "The term to interpret as a theorm and prove."])
132+
]
133+
110134
--data CexValue = CexValue String TypedTerm
111135

112136
data ProveResult
@@ -121,6 +145,12 @@ instance ToJSON ProveResult where
121145
toJSON ProofInvalid {-cex-} =
122146
object [ "status" .= ("invalid" :: Text) ] -- , "counterexample" .= cex]
123147

148+
149+
proveDescr :: Doc.Block
150+
proveDescr =
151+
Doc.Paragraph [ Doc.Text "Attempt to prove the given term representing a"
152+
, Doc.Text " theorem, given a proof script context."]
153+
124154
prove :: ProveParams -> Method SAWState ProveResult
125155
prove params = do
126156
t <- getTerm (ppTermName params)

0 commit comments

Comments
 (0)