| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 integers.push_back(isolate->factory()->NewNumber(+rng_->NextInt(10))); | 82 integers.push_back(isolate->factory()->NewNumber(+rng_->NextInt(10))); |
| 83 for (int i = 0; i < 10; ++i) { | 83 for (int i = 0; i < 10; ++i) { |
| 84 double x = rng_->NextInt(); | 84 double x = rng_->NextInt(); |
| 85 integers.push_back(isolate->factory()->NewNumber(x)); | 85 integers.push_back(isolate->factory()->NewNumber(x)); |
| 86 x *= rng_->NextInt(); | 86 x *= rng_->NextInt(); |
| 87 if (!IsMinusZero(x)) integers.push_back(isolate->factory()->NewNumber(x)); | 87 if (!IsMinusZero(x)) integers.push_back(isolate->factory()->NewNumber(x)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 Integer = Type::Range(-V8_INFINITY, +V8_INFINITY, zone); | 90 Integer = Type::Range(-V8_INFINITY, +V8_INFINITY, zone); |
| 91 | 91 |
| 92 NumberArray = Type::Array(Number, zone); | |
| 93 StringArray = Type::Array(String, zone); | |
| 94 AnyArray = Type::Array(Any, zone); | |
| 95 | |
| 96 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, zone); | |
| 97 NumberFunction1 = Type::Function(Number, Number, zone); | |
| 98 NumberFunction2 = Type::Function(Number, Number, Number, zone); | |
| 99 MethodFunction = Type::Function(String, Object, 0, zone); | |
| 100 | |
| 101 for (int i = 0; i < 30; ++i) { | 92 for (int i = 0; i < 30; ++i) { |
| 102 types.push_back(Fuzz()); | 93 types.push_back(Fuzz()); |
| 103 } | 94 } |
| 104 } | 95 } |
| 105 | 96 |
| 106 Handle<i::Map> object_map; | 97 Handle<i::Map> object_map; |
| 107 | 98 |
| 108 Handle<i::Smi> smi; | 99 Handle<i::Smi> smi; |
| 109 Handle<i::HeapNumber> signed32; | 100 Handle<i::HeapNumber> signed32; |
| 110 Handle<i::JSObject> object1; | 101 Handle<i::JSObject> object1; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 | 115 |
| 125 Type* SmiConstant; | 116 Type* SmiConstant; |
| 126 Type* Signed32Constant; | 117 Type* Signed32Constant; |
| 127 Type* ObjectConstant1; | 118 Type* ObjectConstant1; |
| 128 Type* ObjectConstant2; | 119 Type* ObjectConstant2; |
| 129 Type* ArrayConstant; | 120 Type* ArrayConstant; |
| 130 Type* UninitializedConstant; | 121 Type* UninitializedConstant; |
| 131 | 122 |
| 132 Type* Integer; | 123 Type* Integer; |
| 133 | 124 |
| 134 Type* NumberArray; | |
| 135 Type* StringArray; | |
| 136 Type* AnyArray; | |
| 137 | |
| 138 Type* SignedFunction1; | |
| 139 Type* NumberFunction1; | |
| 140 Type* NumberFunction2; | |
| 141 Type* MethodFunction; | |
| 142 | |
| 143 typedef std::vector<Type*> TypeVector; | 125 typedef std::vector<Type*> TypeVector; |
| 144 typedef std::vector<Handle<i::Object> > ValueVector; | 126 typedef std::vector<Handle<i::Object> > ValueVector; |
| 145 | 127 |
| 146 TypeVector types; | 128 TypeVector types; |
| 147 ValueVector values; | 129 ValueVector values; |
| 148 ValueVector integers; // "Integer" values used for range limits. | 130 ValueVector integers; // "Integer" values used for range limits. |
| 149 | 131 |
| 150 Type* Of(Handle<i::Object> value) { return Type::Of(value, zone_); } | 132 Type* Of(Handle<i::Object> value) { return Type::Of(value, zone_); } |
| 151 | 133 |
| 152 Type* Constant(Handle<i::Object> value) { | 134 Type* Constant(Handle<i::Object> value) { |
| 153 return Type::Constant(value, zone_); | 135 return Type::Constant(value, zone_); |
| 154 } | 136 } |
| 155 | 137 |
| 156 Type* Range(double min, double max) { return Type::Range(min, max, zone_); } | 138 Type* Range(double min, double max) { return Type::Range(min, max, zone_); } |
| 157 | 139 |
| 158 Type* Array1(Type* element) { return Type::Array(element, zone_); } | |
| 159 | |
| 160 Type* Function0(Type* result, Type* receiver) { | |
| 161 return Type::Function(result, receiver, 0, zone_); | |
| 162 } | |
| 163 | |
| 164 Type* Function1(Type* result, Type* receiver, Type* arg) { | |
| 165 Type* type = Type::Function(result, receiver, 1, zone_); | |
| 166 type->AsFunction()->InitParameter(0, arg); | |
| 167 return type; | |
| 168 } | |
| 169 | |
| 170 Type* Function2(Type* result, Type* arg1, Type* arg2) { | |
| 171 return Type::Function(result, arg1, arg2, zone_); | |
| 172 } | |
| 173 | |
| 174 Type* Union(Type* t1, Type* t2) { return Type::Union(t1, t2, zone_); } | 140 Type* Union(Type* t1, Type* t2) { return Type::Union(t1, t2, zone_); } |
| 175 | 141 |
| 176 Type* Intersect(Type* t1, Type* t2) { return Type::Intersect(t1, t2, zone_); } | 142 Type* Intersect(Type* t1, Type* t2) { return Type::Intersect(t1, t2, zone_); } |
| 177 | 143 |
| 178 Type* Representation(Type* t) { return Type::Representation(t, zone_); } | 144 Type* Representation(Type* t) { return Type::Representation(t, zone_); } |
| 179 | 145 |
| 180 Type* Semantic(Type* t) { return Type::Semantic(t, zone_); } | 146 Type* Semantic(Type* t) { return Type::Semantic(t, zone_); } |
| 181 | 147 |
| 182 Type* Random() { | 148 Type* Random() { |
| 183 return types[rng_->NextInt(static_cast<int>(types.size()))]; | 149 return types[rng_->NextInt(static_cast<int>(types.size()))]; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 213 return Type::Constant(values[i], zone_); | 179 return Type::Constant(values[i], zone_); |
| 214 } | 180 } |
| 215 case 2: { // range | 181 case 2: { // range |
| 216 int i = rng_->NextInt(static_cast<int>(integers.size())); | 182 int i = rng_->NextInt(static_cast<int>(integers.size())); |
| 217 int j = rng_->NextInt(static_cast<int>(integers.size())); | 183 int j = rng_->NextInt(static_cast<int>(integers.size())); |
| 218 double min = integers[i]->Number(); | 184 double min = integers[i]->Number(); |
| 219 double max = integers[j]->Number(); | 185 double max = integers[j]->Number(); |
| 220 if (min > max) std::swap(min, max); | 186 if (min > max) std::swap(min, max); |
| 221 return Type::Range(min, max, zone_); | 187 return Type::Range(min, max, zone_); |
| 222 } | 188 } |
| 223 case 3: { // array | |
| 224 Type* element = Fuzz(depth / 2); | |
| 225 return Type::Array(element, zone_); | |
| 226 } | |
| 227 case 4: | |
| 228 case 5: { // function | |
| 229 Type* result = Fuzz(depth / 2); | |
| 230 Type* receiver = Fuzz(depth / 2); | |
| 231 int arity = rng_->NextInt(3); | |
| 232 Type* type = Type::Function(result, receiver, arity, zone_); | |
| 233 for (int i = 0; i < type->AsFunction()->Arity(); ++i) { | |
| 234 Type* parameter = Fuzz(depth / 2); | |
| 235 type->AsFunction()->InitParameter(i, parameter); | |
| 236 } | |
| 237 return type; | |
| 238 } | |
| 239 default: { // union | 189 default: { // union |
| 240 int n = rng_->NextInt(10); | 190 int n = rng_->NextInt(10); |
| 241 Type* type = None; | 191 Type* type = None; |
| 242 for (int i = 0; i < n; ++i) { | 192 for (int i = 0; i < n; ++i) { |
| 243 Type* operand = Fuzz(depth - 1); | 193 Type* operand = Fuzz(depth - 1); |
| 244 type = Type::Union(type, operand, zone_); | 194 type = Type::Union(type, operand, zone_); |
| 245 } | 195 } |
| 246 return type; | 196 return type; |
| 247 } | 197 } |
| 248 } | 198 } |
| 249 UNREACHABLE(); | 199 UNREACHABLE(); |
| 250 } | 200 } |
| 251 | 201 |
| 252 Zone* zone() { return zone_; } | 202 Zone* zone() { return zone_; } |
| 253 | 203 |
| 254 private: | 204 private: |
| 255 Zone* zone_; | 205 Zone* zone_; |
| 256 v8::base::RandomNumberGenerator* rng_; | 206 v8::base::RandomNumberGenerator* rng_; |
| 257 }; | 207 }; |
| 258 | 208 |
| 259 | 209 |
| 260 } // namespace internal | 210 } // namespace internal |
| 261 } // namespace v8 | 211 } // namespace v8 |
| 262 | 212 |
| 263 #endif | 213 #endif |
| OLD | NEW |