Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/wasm/asm-types.h" | 7 #include "src/wasm/asm-types.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| 11 namespace wasm { | 11 namespace wasm { |
| 12 | 12 |
| 13 AsmCallableType* AsmType::AsCallableType() { | 13 AsmCallableType* AsmType::AsCallableType() { |
| 14 if (AsValueType() != nullptr) { | |
| 15 return nullptr; | |
| 16 } | |
| 17 | |
| 14 DCHECK(this->AsFunctionType() != nullptr || | 18 DCHECK(this->AsFunctionType() != nullptr || |
| 15 this->AsOverloadedFunctionType() != nullptr); | 19 this->AsOverloadedFunctionType() != nullptr || |
| 20 this->AsFFIType() != nullptr || | |
| 21 this->AsFunctionTableType() != nullptr); | |
| 16 return reinterpret_cast<AsmCallableType*>(this); | 22 return reinterpret_cast<AsmCallableType*>(this); |
| 17 } | 23 } |
| 18 | 24 |
| 19 std::string AsmType::Name() { | 25 std::string AsmType::Name() { |
| 20 AsmValueType* avt = this->AsValueType(); | 26 AsmValueType* avt = this->AsValueType(); |
| 21 if (avt != nullptr) { | 27 if (avt != nullptr) { |
| 22 switch (avt->Bitset()) { | 28 switch (avt->Bitset()) { |
| 23 #define RETURN_TYPE_NAME(CamelName, string_name, number, parent_types) \ | 29 #define RETURN_TYPE_NAME(CamelName, string_name, number, parent_types) \ |
| 24 case AsmValueType::kAsm##CamelName: \ | 30 case AsmValueType::kAsm##CamelName: \ |
| 25 return string_name; | 31 return string_name; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 class AsmFroundType final : public AsmFunctionType { | 164 class AsmFroundType final : public AsmFunctionType { |
| 159 public: | 165 public: |
| 160 bool IsFroundType() const override { return true; } | 166 bool IsFroundType() const override { return true; } |
| 161 | 167 |
| 162 private: | 168 private: |
| 163 friend AsmType; | 169 friend AsmType; |
| 164 | 170 |
| 165 explicit AsmFroundType(Zone* zone) | 171 explicit AsmFroundType(Zone* zone) |
| 166 : AsmFunctionType(zone, AsmType::Float()) {} | 172 : AsmFunctionType(zone, AsmType::Float()) {} |
| 167 | 173 |
| 168 AsmType* ValidateCall(AsmType* function_type) override; | 174 AsmType* ValidateCall(AsmType* return_type, |
| 175 const ZoneVector<AsmType*>& args) override; | |
| 169 }; | 176 }; |
| 170 } // namespace | 177 } // namespace |
| 171 | 178 |
| 172 AsmType* AsmType::FroundType(Zone* zone) { | 179 AsmType* AsmType::FroundType(Zone* zone) { |
| 173 auto* Fround = new (zone) AsmFroundType(zone); | 180 auto* Fround = new (zone) AsmFroundType(zone); |
| 174 return reinterpret_cast<AsmType*>(Fround); | 181 return reinterpret_cast<AsmType*>(Fround); |
| 175 } | 182 } |
| 176 | 183 |
| 177 AsmType* AsmFroundType::ValidateCall(AsmType* function_type) { | 184 AsmType* AsmFroundType::ValidateCall(AsmType* return_type, |
| 178 auto* callable = function_type->AsFunctionType(); | 185 const ZoneVector<AsmType*>& args) { |
| 179 if (callable->Arguments().size() != 1) { | 186 if (args.size() != 1) { |
| 180 return AsmType::None(); | 187 return AsmType::None(); |
| 181 } | 188 } |
| 182 | 189 |
| 183 auto* arg = callable->Arguments()[0]; | 190 auto* arg = args[0]; |
| 184 if (!arg->IsA(AsmType::Floatish()) && !arg->IsA(AsmType::DoubleQ()) && | 191 if (!arg->IsA(AsmType::Floatish()) && !arg->IsA(AsmType::DoubleQ()) && |
| 185 !arg->IsA(AsmType::Signed()) && !arg->IsA(AsmType::Unsigned())) { | 192 !arg->IsA(AsmType::Signed()) && !arg->IsA(AsmType::Unsigned())) { |
| 186 return AsmType::None(); | 193 return AsmType::None(); |
| 187 } | 194 } |
| 188 | 195 |
| 189 return AsmType::Float(); | 196 return AsmType::Float(); |
| 190 } | 197 } |
| 191 | 198 |
| 192 namespace { | 199 namespace { |
| 193 class AsmMinMaxType final : public AsmFunctionType { | 200 class AsmMinMaxType final : public AsmFunctionType { |
| 194 public: | 201 public: |
| 195 bool IsMinMaxType() const override { return true; } | 202 bool IsMinMaxType() const override { return true; } |
| 196 | 203 |
| 197 private: | 204 private: |
| 198 friend AsmType; | 205 friend AsmType; |
| 199 | 206 |
| 200 AsmMinMaxType(Zone* zone, AsmType* dest, AsmType* src) | 207 AsmMinMaxType(Zone* zone, AsmType* dest, AsmType* src) |
| 201 : AsmFunctionType(zone, dest) { | 208 : AsmFunctionType(zone, dest) { |
| 202 AddArgument(src); | 209 AddArgument(src); |
| 203 AddArgument(src); | 210 AddArgument(src); |
| 204 } | 211 } |
| 205 | 212 |
| 206 AsmType* ValidateCall(AsmType* function_type) override { | 213 AsmType* ValidateCall(AsmType* return_type, |
| 207 auto* callable = function_type->AsFunctionType(); | 214 const ZoneVector<AsmType*>& args) override { |
| 208 if (callable == nullptr) { | 215 if (!ReturnType()->IsExactly(return_type)) { |
| 209 return nullptr; | |
| 210 } | |
| 211 | |
| 212 if (!ReturnType()->IsExactly(callable->ReturnType())) { | |
| 213 return AsmType::None(); | 216 return AsmType::None(); |
| 214 } | 217 } |
| 215 | 218 |
| 216 if (callable->Arguments().size() < 2) { | 219 if (args.size() < 2) { |
| 217 return AsmType::None(); | 220 return AsmType::None(); |
| 218 } | 221 } |
| 219 | 222 |
| 220 for (size_t ii = 0; ii < Arguments().size(); ++ii) { | 223 for (size_t ii = 0; ii < Arguments().size(); ++ii) { |
| 221 if (!Arguments()[0]->IsExactly(callable->Arguments()[ii])) { | 224 if (!Arguments()[0]->IsExactly(args[ii])) { |
| 222 return AsmType::None(); | 225 return AsmType::None(); |
| 223 } | 226 } |
| 224 } | 227 } |
| 225 | 228 |
| 226 return ReturnType(); | 229 return ReturnType(); |
| 227 } | 230 } |
| 228 }; | 231 }; |
| 229 } // namespace | 232 } // namespace |
| 230 | 233 |
| 231 AsmType* AsmType::MinMaxType(Zone* zone, AsmType* dest, AsmType* src) { | 234 AsmType* AsmType::MinMaxType(Zone* zone, AsmType* dest, AsmType* src) { |
| 232 DCHECK(dest->AsValueType() != nullptr); | 235 DCHECK(dest->AsValueType() != nullptr); |
| 233 DCHECK(src->AsValueType() != nullptr); | 236 DCHECK(src->AsValueType() != nullptr); |
| 234 auto* MinMax = new (zone) AsmMinMaxType(zone, dest, src); | 237 auto* MinMax = new (zone) AsmMinMaxType(zone, dest, src); |
| 235 return reinterpret_cast<AsmType*>(MinMax); | 238 return reinterpret_cast<AsmType*>(MinMax); |
| 236 } | 239 } |
| 237 | 240 |
| 238 AsmType* AsmFunctionType::ValidateCall(AsmType* function_type) { | 241 AsmType* AsmFFIType::ValidateCall(AsmType* return_type, |
| 239 auto* callable = function_type->AsFunctionType(); | 242 const ZoneVector<AsmType*>& args) { |
| 240 if (callable == nullptr) { | 243 for (size_t ii = 0; ii < args.size(); ++ii) { |
| 241 return nullptr; | 244 if (!args[ii]->IsA(AsmType::Extern())) { |
| 245 return AsmType::None(); | |
| 246 } | |
| 242 } | 247 } |
| 243 | 248 |
| 244 if (!return_type_->IsExactly(callable->return_type_)) { | 249 return return_type; |
| 250 } | |
| 251 | |
| 252 AsmType* AsmFunctionType::ValidateCall(AsmType* return_type, | |
| 253 const ZoneVector<AsmType*>& args) { | |
| 254 if (!return_type_->IsExactly(return_type)) { | |
| 245 return AsmType::None(); | 255 return AsmType::None(); |
| 246 } | 256 } |
| 247 | 257 |
| 248 if (args_.size() != callable->args_.size()) { | 258 if (args_.size() != args.size()) { |
| 249 return AsmType::None(); | 259 return AsmType::None(); |
| 250 } | 260 } |
| 251 | 261 |
| 252 for (size_t ii = 0; ii < args_.size(); ++ii) { | 262 for (size_t ii = 0; ii < args_.size(); ++ii) { |
| 253 if (!args_[ii]->IsExactly(callable->args_[ii])) { | 263 if (!args_[ii]->IsExactly(args[ii])) { |
| 254 return AsmType::None(); | 264 return AsmType::None(); |
| 255 } | 265 } |
| 256 } | 266 } |
| 257 | 267 |
| 258 return return_type_; | 268 return return_type_; |
| 259 } | 269 } |
| 260 | 270 |
| 261 std::string AsmOverloadedFunctionType::Name() { | 271 std::string AsmOverloadedFunctionType::Name() { |
| 262 std::string ret; | 272 std::string ret; |
| 263 | 273 |
| 264 for (size_t ii = 0; ii < overloads_.size(); ++ii) { | 274 for (size_t ii = 0; ii < overloads_.size(); ++ii) { |
| 265 if (ii != 0) { | 275 if (ii != 0) { |
| 266 ret += " /\\ "; | 276 ret += " /\\ "; |
| 267 } | 277 } |
| 268 ret += overloads_[ii]->Name(); | 278 ret += overloads_[ii]->Name(); |
| 269 } | 279 } |
| 270 | 280 |
| 271 return ret; | 281 return ret; |
| 272 } | 282 } |
| 273 | 283 |
| 274 AsmType* AsmOverloadedFunctionType::ValidateCall(AsmType* function_type) { | 284 AsmType* AsmOverloadedFunctionType::ValidateCall( |
| 275 auto* callable = function_type->AsFunctionType(); | 285 AsmType* return_type, const ZoneVector<AsmType*>& args) { |
| 276 if (callable == nullptr) { | |
| 277 return AsmType::None(); | |
| 278 } | |
| 279 | |
| 280 for (size_t ii = 0; ii < overloads_.size(); ++ii) { | 286 for (size_t ii = 0; ii < overloads_.size(); ++ii) { |
| 281 auto* validated_type = | 287 auto* validated_type = |
| 282 overloads_[ii]->AsCallableType()->ValidateCall(function_type); | 288 overloads_[ii]->AsCallableType()->ValidateCall(return_type, args); |
| 283 if (validated_type != AsmType::None()) { | 289 if (validated_type != AsmType::None()) { |
| 284 return validated_type; | 290 return validated_type; |
| 285 } | 291 } |
| 286 } | 292 } |
| 287 | 293 |
| 288 return AsmType::None(); | 294 return AsmType::None(); |
| 289 } | 295 } |
| 290 | 296 |
| 291 void AsmOverloadedFunctionType::AddOverload(AsmType* overload) { | 297 void AsmOverloadedFunctionType::AddOverload(AsmType* overload) { |
| 292 DCHECK(overload->AsFunctionType() != nullptr); | 298 DCHECK(overload->AsFunctionType() != nullptr); |
| 293 overloads_.push_back(overload); | 299 overloads_.push_back(overload); |
| 294 } | 300 } |
| 295 | 301 |
| 302 AsmFunctionTableType::AsmFunctionTableType(size_t length, AsmType* signature) | |
| 303 : length_(length), signature_(signature) { | |
| 304 DCHECK(signature_ != nullptr); | |
| 305 DCHECK(signature_->AsFunctionType() != nullptr); | |
| 306 } | |
| 307 | |
| 308 std::string AsmFunctionTableType::Name() { | |
| 309 return signature_->Name() + "[" + std::to_string(length_) + "]"; | |
|
Mostyn Bramley-Moore
2016/07/04 20:23:36
std::to_string is in the "C++11 Standard Library F
| |
| 310 } | |
| 311 | |
| 312 AsmType* AsmFunctionTableType::ValidateCall(AsmType* return_type, | |
| 313 const ZoneVector<AsmType*>& args) { | |
| 314 return signature_->AsCallableType()->ValidateCall(return_type, args); | |
| 315 } | |
| 316 | |
| 296 } // namespace wasm | 317 } // namespace wasm |
| 297 } // namespace internal | 318 } // namespace internal |
| 298 } // namespace v8 | 319 } // namespace v8 |
| OLD | NEW |