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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
/*
* Copyright 2009, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PURITAN_KNOBS_H
#define PURITAN_KNOBS_H
#include <string>
#include <list>
#include <vector>
namespace Salem
{
namespace Puritan
{
class OutputInfo
{
public:
typedef enum
{
Float1,
Float2,
Float4
} ArgSize;
unsigned n_samplers;
std::list <std::pair <ArgSize, std::string> > uniforms;
std::list <ArgSize> returns;
};
class Knob
{
class Knob *prev;
const char *name;
const char *help;
virtual bool set_from_argument (const char *val) = 0;
bool parse_argument (const char *val);
virtual void usage (std::ostream &out) const= 0;
friend class Knobs;
friend class IntKnob;
friend class RangeKnob;
friend class BoolKnob;
friend class ProbKnob;
friend std::ostream & operator << (std::ostream &out, const class Knobs& x);
public:
Knob(const char *name, const char *desc);
virtual ~Knob();
virtual void to_stream (std::ostream &) const = 0;
};
class RangeKnob : public Knob
{
int from;
int to;
bool set_from_argument (const char *val);
void usage (std::ostream &) const;
public:
RangeKnob (const char *, const char *,int f, int t);
void set(int, int);
int operator () (class Rand *) const;
unsigned int random_uint (class Rand *) const ;
void to_stream (std::ostream &) const;
};
class IntKnob : public Knob
{
int val;
bool set_from_argument (const char *val);
void usage (std::ostream &) const;
public:
IntKnob (const char *, const char *,int);
int get() const;
unsigned uget() const;
void set(int x) { val = x;}
void to_stream (std::ostream &) const;
};
class BoolKnob : public Knob
{
bool val;
bool set_from_argument (const char *val);
void usage (std::ostream &) const;
public:
BoolKnob (const char *, const char *,bool f);
void to_stream (std::ostream &) const;
bool operator () () const;
void set(bool x);
};
class ProbKnob : public Knob
{
double prob;
bool set_from_argument (const char *val);
void usage (std::ostream &) const;
public:
ProbKnob (const char *, const char *,double d);
void set (double x) { prob = x; }
double get() const;
void to_stream (std::ostream &) const;
bool operator () (Rand *r) const ;
};
class Knobs
{
public:
RangeKnob top_level_statements;
RangeKnob for_count;
RangeKnob while_count;
RangeKnob do_count;
RangeKnob if_count;
RangeKnob block_count;
IntKnob code_limit;
IntKnob exp_limit;
RangeKnob exp_count;
RangeKnob func_count;
ProbKnob func_trim;
ProbKnob arg_in_chance;
ProbKnob arg_out_chance;
RangeKnob for_nesting;
RangeKnob while_nesting;
RangeKnob block_nesting;
RangeKnob do_nesting;
RangeKnob if_nesting;
RangeKnob block_length;
RangeKnob expression_depth;
ProbKnob special_chance;
ProbKnob float4_chance;
ProbKnob float4_struct_member_chance;
ProbKnob float2_chance;
ProbKnob func_chance;
ProbKnob term_chance;
ProbKnob unary_chance;
ProbKnob swizzle_chance;
ProbKnob fcall_chance;
ProbKnob copy_swizzle_chance;
ProbKnob noinline_chance;
ProbKnob lhs_swizzle_chance;
ProbKnob assop_chance;
ProbKnob selfmod_chance;
ProbKnob trifunc_chance;
ProbKnob binfunc_chance;
ProbKnob relop_chance;
ProbKnob relop_cond_chance;
ProbKnob type_change_chance;
ProbKnob type_float4_chance;
ProbKnob type_float2_chance;
RangeKnob sampler_count;
ProbKnob sampler_chance;
RangeKnob uniform_count;
ProbKnob uniform_chance;
RangeKnob arg_count;
RangeKnob static_initializer_depth;
BoolKnob standalone;
IntKnob seed;
ProbKnob variable_reuse;
ProbKnob array_use;
ProbKnob array_reuse;
ProbKnob array_constness;
ProbKnob array_index_const;
ProbKnob array_in_for_use;
ProbKnob if_elses;
ProbKnob loop_breaks;
ProbKnob multiple_stmt;
ProbKnob constant_use;
ProbKnob constant_small;
BoolKnob int_variables;
BoolKnob allow_two_negs;
Knob *first;
Knobs(void);
void to_stream (std::ostream &);
bool parse_argument (const char *arg);
static std::string usage ();
};
class Coverage
{
private:
// Next in chain
std::string title;
std::vector <int> count;
Coverage *prev;
friend class StrCoverage;
friend class IntCoverage;
public:
static Coverage *head;
virtual void output_worker (std::ostream & out) const = 0;
Coverage (std::string _title) ;
virtual ~ Coverage () ;
void increment (size_t idx);
};
class StrCoverage:Coverage
{
private:
std::vector <std::string> selections;
size_t width;
void output_worker (std::ostream & out) const;
public:
StrCoverage (const char *_title, const char **_selections);
std::string choose (class Rand * r);
};
class IntCoverage:public Coverage
{
private:
void output_worker (std::ostream & out) const;
public:
IntCoverage (const char *_title);
};
std::ostream & operator << (std::ostream &out, const class Salem::Puritan::Coverage &x);
std::ostream & operator << (std::ostream &out, const class Salem::Puritan::Knobs &x);
}
}
#endif
|