| 1721 | } |
| 1722 | |
| 1723 | BfIRValue BfModule::CreateStringObjectValue(const StringImpl& str, int stringId, bool define) |
| 1724 | { |
| 1725 | auto stringTypeInst = ResolveTypeDef(mCompiler->mStringTypeDef, define ? BfPopulateType_Data : BfPopulateType_Declaration)->ToTypeInstance(); |
| 1726 | mBfIRBuilder->PopulateType(stringTypeInst); |
| 1727 | |
| 1728 | auto classVDataGlobal = CreateClassVDataGlobal(stringTypeInst); |
| 1729 | |
| 1730 | String stringObjName = StrFormat("__bfStrObj%d", stringId); |
| 1731 | |
| 1732 | BfIRValue stringValData; |
| 1733 | |
| 1734 | if (define) |
| 1735 | { |
| 1736 | BfIRValue stringCharsVal = CreateStringCharPtr(str, stringId, define); |
| 1737 | mStringCharPtrPool[stringId] = stringCharsVal; |
| 1738 | |
| 1739 | SizedArray<BfIRValue, 8> typeValueParams; |
| 1740 | GetConstClassValueParam(classVDataGlobal, typeValueParams); |
| 1741 | FixConstValueParams(stringTypeInst->mBaseType, typeValueParams); |
| 1742 | auto objData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(stringTypeInst->mBaseType, BfIRPopulateType_Full), typeValueParams); |
| 1743 | |
| 1744 | auto lenByteCount = stringTypeInst->mFieldInstances[0].mResolvedType->mSize; |
| 1745 | |
| 1746 | typeValueParams.clear(); |
| 1747 | typeValueParams.push_back(objData); |
| 1748 | |
| 1749 | if (lenByteCount == 4) |
| 1750 | { |
| 1751 | typeValueParams.push_back(GetConstValue32((int)str.length())); // mLength |
| 1752 | typeValueParams.push_back(GetConstValue32((int32)(0x40000000 + str.length() + 1))); // mAllocSizeAndFlags |
| 1753 | } |
| 1754 | else |
| 1755 | { |
| 1756 | typeValueParams.push_back(GetConstValue64(str.length())); // mLength |
| 1757 | typeValueParams.push_back(GetConstValue64(0x4000000000000000LL + str.length() + 1)); // mAllocSizeAndFlags |
| 1758 | } |
| 1759 | typeValueParams.push_back(stringCharsVal); // mPtr |
| 1760 | FixConstValueParams(stringTypeInst, typeValueParams); |
| 1761 | |
| 1762 | stringValData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(stringTypeInst, BfIRPopulateType_Full), typeValueParams); |
| 1763 | } |
| 1764 | |
| 1765 | mBfIRBuilder->PopulateType(stringTypeInst); |
| 1766 | auto stringValLiteral = mBfIRBuilder->CreateGlobalVariable( |
| 1767 | mBfIRBuilder->MapTypeInst(stringTypeInst, BfIRPopulateType_Full), |
| 1768 | true, |
| 1769 | BfIRLinkageType_External, |
| 1770 | define ? stringValData : BfIRValue(), |
| 1771 | stringObjName); |
| 1772 | |
| 1773 | return stringValLiteral; |
| 1774 | } |
| 1775 | |
| 1776 | bool BfModule::HasStringId(BfIRValue constantStr, BfIRConstHolder* constHolder) |
| 1777 | { |
no test coverage detected