-
Notifications
You must be signed in to change notification settings - Fork 10
/
Main.fs
134 lines (116 loc) · 4.73 KB
/
Main.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
module Main
open System.Collections.Generic
open GlobalOptions
open Util
open Solver
open ModelVerification
open State
let showHelp () =
printfn "mcBV 1.0 (C) Copyright 2016 Microsoft Corporation"
printfn "Usage: mcbv.exe [options] <filename>"
printfn "Options:"
printfn "Capital letter sets the option ON, lower letter sets the option OFF [default]"
printfn " -I/i Interactive mode (after solving waits for a key to be pressed) [on]"
printfn " -D/d Debug mode [off]"
printfn " -V/v Verbose mode [off]"
printfn " -T/t Print traces [off]"
printfn " -M/m Print model [off]"
printfn " -Q/q Verify model [on]"
printfn " -C/c Run z3 checks [off]"
printfn " -J/j Just answer [off]"
let parseArguments (argv:array<string>) =
for arg in argv do
if arg.Chars 0 = '-' then
for c in arg.ToCharArray() do
match c with
| 'I' -> INTERACTIVE <- true
| 'i' -> INTERACTIVE <- false
| 'V' -> VRB <- true
| 'v' -> VRB <- false
| 'D' -> DBG <- true
| 'd' -> DBG <- false
| 'T' -> TRC <- true
| 't' -> TRC <- false
| 'M' -> SHOWMODEL <- true
| 'm' -> SHOWMODEL <- false
| 'Q' -> VERIFYMODEL <- true
| 'q' -> VERIFYMODEL <- false
| 'C' -> RUNZ3CHECKS <- true
| 'c' -> RUNZ3CHECKS <- false
| 'J' -> POLITE <- true
| 'j' -> POLITE <- false
| 'N' -> PREPROCESS <- true
| 'n' -> PREPROCESS <- false
| 'G' -> GENERALIZE <- true
| 'g' -> GENERALIZE <- false
| 'B' -> USE_BOUNDS <- true
| 'b' -> USE_BOUNDS <- false
| 'K' -> SHOW_CONFLICTS <- true
| _ -> ()
Array.filter (fun (x:string) -> x.Chars 0 <> '-' ) argv
[<EntryPoint>]
let main argv =
if argv.Length <= 0 then
showHelp() ;
30 // `Error'
else
let before = System.DateTime.Now
let mutable exitStatus = 30 // = Error
try
let inputs = parseArguments argv
if inputs.Length <= 0 then
showHelp()
exitStatus <- 30
else
let z3opts = new Dictionary<string,string>()
let s = new Solver()
let p = s.Load(z3opts, inputs.[0])
// printfn "%s" inputs.[0]
// dbg <| (lazy sprintf "%s" (p.ToString()))
let solution = s.Solve p
match solution with
| SAT(m) ->
if not (Verify p m) then
printfn ("Error: Model verification failed.")
exitStatus <- 30
else
printfn("sat")
exitStatus <- 10
| UNSAT ->
printfn ("unsat")
exitStatus <- 20
| UNKNOWN ->
printfn ("unknown")
exitStatus <- 30
with
| :? System.StackOverflowException
| :? System.OutOfMemoryException
| :? Microsoft.Z3.Z3Exception as ex when ex.Message = "out of memory" ->
// Ocassionally OutOfMemory exceptions are thrown from Z3, or from F#
printfn "(error \"out of memory\")"
exitStatus <- 30
| :? System.AccessViolationException as ex ->
// There is a rare case in which Z3 throws an access violation during
// context destruction, could be a cleanup bug in Z3.
// Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
// at Microsoft.Z3.Native.LIB.Z3_del_context(IntPtr a0)
// at Microsoft.Z3.Context.Finalize()
if (ex.Message.Contains("Microsoft.Z3.Native.LIB.Z3_del_context") ||
ex.StackTrace.Contains("Microsoft.Z3.Native.LIB.Z3_del_context")) then
printfn "Z3 cleanup problem ignored."
() // keep previous exit status
else
exitStatus <- 30
| Failure msg ->
printfn "EXCEPTION: %s" msg
printfn "UNKNOWN"
exitStatus <- 30
| ex ->
printfn "EXCEPTION: %s: %s" ((ex.GetType()).ToString()) (ex.StackTrace.ToString())
printfn "UNKNOWN"
exitStatus <- 30
if INTERACTIVE then
System.Console.ReadKey() |> ignore
let time = System.DateTime.Now - before
printfn "%f sec." time.TotalSeconds
exitStatus // All done.