MS ABI: Simplify endian swapping code
No functionality change. llvm-svn: 205250
This commit is contained in:
parent
39006cd3b8
commit
e49c4b6ff2
|
@ -2388,31 +2388,15 @@ void MicrosoftMangleContextImpl::mangleStringLiteral(const StringLiteral *SL,
|
|||
auto GetLittleEndianByte = [&Mangler, &SL](unsigned Index) {
|
||||
unsigned CharByteWidth = SL->getCharByteWidth();
|
||||
uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth);
|
||||
if (CharByteWidth == 1) {
|
||||
return static_cast<char>(CodeUnit);
|
||||
} else if (CharByteWidth == 2) {
|
||||
if (Index % 2)
|
||||
return static_cast<char>((CodeUnit >> 8) & 0xff);
|
||||
else
|
||||
return static_cast<char>(CodeUnit & 0xff);
|
||||
} else {
|
||||
llvm_unreachable("unsupported CharByteWidth");
|
||||
}
|
||||
unsigned OffsetInCodeUnit = Index % CharByteWidth;
|
||||
return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff);
|
||||
};
|
||||
|
||||
auto GetBigEndianByte = [&Mangler, &SL](unsigned Index) {
|
||||
unsigned CharByteWidth = SL->getCharByteWidth();
|
||||
uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth);
|
||||
if (CharByteWidth == 1) {
|
||||
return static_cast<char>(CodeUnit);
|
||||
} else if (CharByteWidth == 2) {
|
||||
if (Index % 2)
|
||||
return static_cast<char>(CodeUnit & 0xff);
|
||||
else
|
||||
return static_cast<char>((CodeUnit >> 8) & 0xff);
|
||||
} else {
|
||||
llvm_unreachable("unsupported CharByteWidth");
|
||||
}
|
||||
unsigned OffsetInCodeUnit = (CharByteWidth - 1) - (Index % CharByteWidth);
|
||||
return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff);
|
||||
};
|
||||
|
||||
// CRC all the bytes of the StringLiteral.
|
||||
|
|
Loading…
Reference in New Issue