Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===-- llvm/Support/JamCRC.h - Cyclic Redundancy Check ---------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file contains an implementation of JamCRC. |
| 10 | // |
| 11 | // We will use the "Rocksoft^tm Model CRC Algorithm" to describe the properties |
| 12 | // of this CRC: |
| 13 | // Width : 32 |
| 14 | // Poly : 04C11DB7 |
| 15 | // Init : FFFFFFFF |
| 16 | // RefIn : True |
| 17 | // RefOut : True |
| 18 | // XorOut : 00000000 |
| 19 | // Check : 340BC6D9 (result of CRC for "123456789") |
| 20 | // |
| 21 | // N.B. We permit flexibility of the "Init" value. Some consumers of this need |
| 22 | // it to be zero. |
| 23 | // |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | #ifndef LLVM_SUPPORT_JAMCRC_H |
| 27 | #define LLVM_SUPPORT_JAMCRC_H |
| 28 | |
| 29 | #include "llvm/Support/DataTypes.h" |
| 30 | |
| 31 | namespace llvm { |
| 32 | template <typename T> class ArrayRef; |
| 33 | |
| 34 | class JamCRC { |
| 35 | public: |
| 36 | JamCRC(uint32_t Init = 0xFFFFFFFFU) : CRC(Init) {} |
| 37 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 38 | // Update the CRC calculation with Data. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 39 | void update(ArrayRef<char> Data); |
| 40 | |
| 41 | uint32_t getCRC() const { return CRC; } |
| 42 | |
| 43 | private: |
| 44 | uint32_t CRC; |
| 45 | }; |
| 46 | } // End of namespace llvm |
| 47 | |
| 48 | #endif |