| 505 | } |
| 506 | |
| 507 | const Constant* ConstantManager::GetIntConst(uint64_t val, int32_t bitWidth, |
| 508 | bool isSigned) { |
| 509 | Type* int_type = context()->get_type_mgr()->GetIntType(bitWidth, isSigned); |
| 510 | |
| 511 | if (isSigned) { |
| 512 | // Sign extend the value. |
| 513 | int32_t num_of_bit_to_ignore = 64 - bitWidth; |
| 514 | val = static_cast<int64_t>(val << num_of_bit_to_ignore) >> |
| 515 | num_of_bit_to_ignore; |
| 516 | } else if (bitWidth < 64) { |
| 517 | // Clear the upper bit that are not used. |
| 518 | uint64_t mask = ((1ull << bitWidth) - 1); |
| 519 | val &= mask; |
| 520 | } |
| 521 | |
| 522 | if (bitWidth <= 32) { |
| 523 | return GetConstant(int_type, {static_cast<uint32_t>(val)}); |
| 524 | } |
| 525 | |
| 526 | // If the value is more than 32-bit, we need to split the operands into two |
| 527 | // 32-bit integers. |
| 528 | return GetConstant( |
| 529 | int_type, {static_cast<uint32_t>(val), static_cast<uint32_t>(val >> 32)}); |
| 530 | } |
| 531 | |
| 532 | uint32_t ConstantManager::GetUIntConstId(uint32_t val) { |
| 533 | Type* uint_type = context()->get_type_mgr()->GetUIntType(); |
no test coverage detected