diff options
author | David Majnemer <david.majnemer@gmail.com> | 2015-09-01 21:24:07 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2015-09-01 21:24:07 +0000 |
commit | b8ed364d8a64e71520c07a095d1c6a6e8fbce1dd (patch) | |
tree | 09553a27e55015c87d4027549ec95999de75d45f /clang/lib/AST/MicrosoftMangle.cpp | |
parent | 6ddc636862095a3d6f1b02ea034a353c19fff328 (diff) | |
download | bcm5719-llvm-b8ed364d8a64e71520c07a095d1c6a6e8fbce1dd.tar.gz bcm5719-llvm-b8ed364d8a64e71520c07a095d1c6a6e8fbce1dd.zip |
[MS ABI] Switch to the CRC implementation in LLVM
We now have an implementation of the CRC in LLVM's libSupport. Let's
consolidate around that one.
llvm-svn: 246591
Diffstat (limited to 'clang/lib/AST/MicrosoftMangle.cpp')
-rw-r--r-- | clang/lib/AST/MicrosoftMangle.cpp | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index 596f1386570..95ae8f55b4b 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -28,6 +28,7 @@ #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/JamCRC.h" using namespace clang; @@ -2696,28 +2697,6 @@ void MicrosoftMangleContextImpl::mangleStringLiteral(const StringLiteral *SL, // N.B. The length is in terms of bytes, not characters. Mangler.mangleNumber(SL->getByteLength() + SL->getCharByteWidth()); - // We will use the "Rocksoft^tm Model CRC Algorithm" to describe the - // properties of our CRC: - // Width : 32 - // Poly : 04C11DB7 - // Init : FFFFFFFF - // RefIn : True - // RefOut : True - // XorOut : 00000000 - // Check : 340BC6D9 - uint32_t CRC = 0xFFFFFFFFU; - - auto UpdateCRC = [&CRC](char Byte) { - for (unsigned i = 0; i < 8; ++i) { - bool Bit = CRC & 0x80000000U; - if (Byte & (1U << i)) - Bit = !Bit; - CRC <<= 1; - if (Bit) - CRC ^= 0x04C11DB7U; - } - }; - auto GetLittleEndianByte = [&Mangler, &SL](unsigned Index) { unsigned CharByteWidth = SL->getCharByteWidth(); uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth); @@ -2733,22 +2712,19 @@ void MicrosoftMangleContextImpl::mangleStringLiteral(const StringLiteral *SL, }; // CRC all the bytes of the StringLiteral. + llvm::JamCRC JC; for (unsigned I = 0, E = SL->getByteLength(); I != E; ++I) - UpdateCRC(GetLittleEndianByte(I)); + JC.update(GetLittleEndianByte(I)); // The NUL terminator byte(s) were not present earlier, // we need to manually process those bytes into the CRC. for (unsigned NullTerminator = 0; NullTerminator < SL->getCharByteWidth(); ++NullTerminator) - UpdateCRC('\x00'); - - // The literature refers to the process of reversing the bits in the final CRC - // output as "reflection". - CRC = llvm::reverseBits(CRC); + JC.update('\x00'); // <encoded-crc>: The CRC is encoded utilizing the standard number mangling // scheme. - Mangler.mangleNumber(CRC); + Mangler.mangleNumber(JC.getCRC()); // <encoded-string>: The mangled name also contains the first 32 _characters_ // (including null-terminator bytes) of the StringLiteral. |