| 402 | } |
| 403 | |
| 404 | const Constant* ConstantManager::GetNullCompositeConstant(const Type* type) { |
| 405 | std::vector<uint32_t> literal_words_or_id; |
| 406 | |
| 407 | if (type->AsVector()) { |
| 408 | const Type* element_type = type->AsVector()->element_type(); |
| 409 | const uint32_t null_id = GetNullConstId(element_type); |
| 410 | const uint32_t element_count = type->AsVector()->element_count(); |
| 411 | for (uint32_t i = 0; i < element_count; i++) { |
| 412 | literal_words_or_id.push_back(null_id); |
| 413 | } |
| 414 | } else if (type->AsMatrix()) { |
| 415 | const Type* element_type = type->AsMatrix()->element_type(); |
| 416 | const uint32_t null_id = GetNullConstId(element_type); |
| 417 | const uint32_t element_count = type->AsMatrix()->element_count(); |
| 418 | for (uint32_t i = 0; i < element_count; i++) { |
| 419 | literal_words_or_id.push_back(null_id); |
| 420 | } |
| 421 | } else if (type->AsStruct()) { |
| 422 | // TODO (sfricke-lunarg) add proper struct support |
| 423 | return nullptr; |
| 424 | } else if (type->AsArray()) { |
| 425 | const Type* element_type = type->AsArray()->element_type(); |
| 426 | const uint32_t null_id = GetNullConstId(element_type); |
| 427 | assert(type->AsArray()->length_info().words[0] == |
| 428 | analysis::Array::LengthInfo::kConstant && |
| 429 | "unexpected array length"); |
| 430 | const uint32_t element_count = type->AsArray()->length_info().words[0]; |
| 431 | for (uint32_t i = 0; i < element_count; i++) { |
| 432 | literal_words_or_id.push_back(null_id); |
| 433 | } |
| 434 | } else { |
| 435 | return nullptr; |
| 436 | } |
| 437 | |
| 438 | return GetConstant(type, literal_words_or_id); |
| 439 | } |
| 440 | |
| 441 | const Constant* ConstantManager::GetNumericVectorConstantWithWords( |
| 442 | const Vector* type, const std::vector<uint32_t>& literal_words) { |