summaryrefslogtreecommitdiff
path: root/Source/GPUVerify/CommandLineOptions.cs
blob: 5f6f0066951e6d9f9098a8ed96d7c3abb0cb5410 (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace GPUVerify
{

    class CommandLineOptions
    {

        public static List<string> inputFiles = new List<string>();

        public static string outputFile = null;

        public static bool OnlyDivergence = false;
        public static bool AdversarialAbstraction = false;
        public static bool EqualityAbstraction = false;
        public static bool Inference = false;
        public static bool ArrayEqualities = false;
        public static string invariantsFile = null;

        public static bool ShowStages = false;

        public static bool ShowUniformityAnalysis = false;
        public static bool DoUniformityAnalysis = false;

        public static bool ShowMayBePowerOfTwoAnalysis = false;
        public static bool ShowArrayControlFlowAnalysis = false;

        public static bool NoLoopPredicateInvariants = false;

        public static bool Unstructured = true;
        public static bool SmartPredication = true;

        public static bool OnlyIntraGroupRaceChecking = false;

        public static int Parse(string[] args)
        {
            for (int i = 0; i < args.Length; i++)
            {
                bool hasColonArgument = false;
                string beforeColon;
                string afterColon = null;
                int colonIndex = args[i].IndexOf(':');
                if (colonIndex >= 0 && (args[i].StartsWith("-") || args[i].StartsWith("/"))) {
                    hasColonArgument = true;
                    beforeColon = args[i].Substring(0, colonIndex);
                    afterColon = args[i].Substring(colonIndex + 1);
                } else {
                    beforeColon = args[i];
                }

                switch (beforeColon)
                {
                    case "-help":
                    case "/help":
                    case "-?":
                    case "/?":
                    return -1;
                    
                    case "-print":
                    case "/print":
                        if (!hasColonArgument)
                        {
                            Console.WriteLine("Error: filename expected after " + beforeColon + " argument");
                            Environment.Exit(1);
                        }
                        Debug.Assert(afterColon != null);
                        outputFile = afterColon;
                    break;

                    case "-onlyDivergence":
                    case "/onlyDivergence":
                    OnlyDivergence = true;

                    break;

                    case "-adversarialAbstraction":
                    case "/adversarialAbstraction":
                    AdversarialAbstraction = true;

                    break;

                    case "-equalityAbstraction":
                    case "/equalityAbstraction":
                    EqualityAbstraction = true;

                    break;

                    case "-showStages":
                    case "/showStages":
                    ShowStages = true;
                    break;

                    case "-inference":
                    case "/inference":
                    Inference = true;
                    if (hasColonArgument)
                    {
                        Debug.Assert(afterColon != null);
                        invariantsFile = afterColon;
                    }

                    break;

                    case "-arrayEqualities":
                    case "/arrayEqualities":
                    ArrayEqualities = true;
                    break;

                    case "-showUniformityAnalysis":
                    case "/showUniformityAnalysis":
                    ShowUniformityAnalysis = true;
                    break;

                    case "-uniformityAnalysis":
                    case "/uniformityAnalysis":
                    DoUniformityAnalysis = true;
                    break;

                    case "-showMayBePowerOfTwoAnalysis":
                    case "/showMayBePowerOfTwoAnalysis":
                    ShowMayBePowerOfTwoAnalysis = true;
                    break;

                    case "-showArrayControlFlowAnalysis":
                    case "/showArrayControlFlowAnalysis":
                    ShowArrayControlFlowAnalysis = true;
                    break;

                    case "-noLoopPredicateInvariants":
                    case "/noLoopPredicateInvariants":
                    NoLoopPredicateInvariants = true;
                    break;

                    case "-structured":
                    case "/structured":
                    Unstructured = false;
                    break;

                    case "-noSmartPredication":
                    case "/noSmartPredication":
                    SmartPredication = false;
                    break;

                    case "-onlyIntraGroupRaceChecking":
                    case "/onlyIntraGroupRaceChecking":
                    OnlyIntraGroupRaceChecking = true;
                    break;

                    default:
                        inputFiles.Add(args[i]);
                        break;
                }

            }
            return 0;
        }

        private static bool printedHelp = false;

        public static void Usage()
        {
            // Ensure that we only print the help message once
            if (printedHelp)
            {
                return;
            }
            printedHelp = true;

            Console.WriteLine(@"GPUVerify: usage:  GPUVerify [ option ... ] [ filename ... ]
  where <option> is one of

  /help            : this message
  /adversarialAbstraction : apply full state abstraction
  /onlyDivergence  : only check for divergence-freedom, not race-freedom
  /symmetry        : apply symmetry breaking
  /eager           : check races eagerly, rather than waiting for barrier
  /inference:file  : use automatic invariant inference.  Optional file can include manually supplied candidates
  /raceCheckingContract : try to infer race-freedom contracts for procedures
  /setEncoding     : check races using set encoding
  /divided         : check individual pairs of possibly racing statements separately
  /dividedArray    : check races on arrays one at a time
  /dividedElement  : ???
  /unstructured    : operate on the unstructured form of the program

");
        }


    }
}