llvm.org GIT mirror llvm / c2ac2d5
Add const qualifiers for isBitcodeWrapper, and add new functions isRawBitcode and isBitcode to allow clients to test whether a given memory buffer holds a bitcode image. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80804 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
1 changed file(s) with 36 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
5252 ModulePass *createBitcodeWriterPass(raw_ostream &Str);
5353
5454
55 /// isBitcodeWrapper - Return true fi this is a wrapper for LLVM IR bitcode
56 /// files.
57 static bool inline isBitcodeWrapper(unsigned char *BufPtr,
58 unsigned char *BufEnd) {
59 return (BufPtr != BufEnd && BufPtr[0] == 0xDE && BufPtr[1] == 0xC0 &&
60 BufPtr[2] == 0x17 && BufPtr[3] == 0x0B);
55 /// isBitcodeWrapper - Return true if the given bytes are the magic bytes
56 /// for an LLVM IR bitcode wrapper.
57 ///
58 static inline bool isBitcodeWrapper(const unsigned char *BufPtr,
59 const unsigned char *BufEnd) {
60 // See if you can find the hidden message in the magic bytes :-).
61 // (Hint: it's a little-endian encoding.)
62 return BufPtr != BufEnd &&
63 BufPtr[0] == 0xDE &&
64 BufPtr[1] == 0xC0 &&
65 BufPtr[2] == 0x17 &&
66 BufPtr[3] == 0x0B;
6167 }
62
68
69 /// isRawBitcode - Return true if the given bytes are the magic bytes for
70 /// raw LLVM IR bitcode (without a wrapper).
71 ///
72 static inline bool isRawBitcode(const unsigned char *BufPtr,
73 const unsigned char *BufEnd) {
74 // These bytes sort of have a hidden message, but it's not in
75 // little-endian this time, and it's a little redundant.
76 return BufPtr != BufEnd &&
77 BufPtr[0] == 'B' &&
78 BufPtr[1] == 'C' &&
79 BufPtr[2] == 0xc0 &&
80 BufPtr[3] == 0xde;
81 }
82
83 /// isBitcode - Return true if the given bytes are the magic bytes for
84 /// LLVM IR bitcode, either with or without a wrapper.
85 ///
86 static bool inline isBitcode(const unsigned char *BufPtr,
87 const unsigned char *BufEnd) {
88 return isBitcodeWrapper(BufPtr, BufEnd) ||
89 isRawBitcode(BufPtr, BufEnd);
90 }
91
6392 /// SkipBitcodeWrapperHeader - Some systems wrap bc files with a special
6493 /// header for padding or other reasons. The format of this header is:
6594 ///