From 6fa6a32e4e2fdbb77c82fd7f64a7232cdcac994e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 9 Jul 2008 05:14:23 +0000 Subject: Add a little wrapper header that is put around bc files when emitting bc files for modules with a target triple that indicates they are for darwin. The reader unconditionally handles this, and the writer could turn this on for more targets if we care. This change has two benefits for darwin: 1) it allows us to encode the cpu type of the file in an easy to read place that doesn't require decoding the bc file. 2) it works around a bug (IMO) in darwin's AR where it is incapable of handling files that are not a multiple of 8 bytes long. BC files are only guaranteed to be multiples of 4 bytes long. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53275 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Bitcode/BitstreamWriter.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'include/llvm/Bitcode') diff --git a/include/llvm/Bitcode/BitstreamWriter.h b/include/llvm/Bitcode/BitstreamWriter.h index 3b7e405414..f76bb88dee 100644 --- a/include/llvm/Bitcode/BitstreamWriter.h +++ b/include/llvm/Bitcode/BitstreamWriter.h @@ -157,6 +157,15 @@ public: Emit(Val, CurCodeSize); } + // BackpatchWord - Backpatch a 32-bit word in the output with the specified + // value. + void BackpatchWord(unsigned ByteNo, unsigned NewWord) { + Out[ByteNo++] = (unsigned char)(NewWord >> 0); + Out[ByteNo++] = (unsigned char)(NewWord >> 8); + Out[ByteNo++] = (unsigned char)(NewWord >> 16); + Out[ByteNo ] = (unsigned char)(NewWord >> 24); + } + //===--------------------------------------------------------------------===// // Block Manipulation //===--------------------------------------------------------------------===// @@ -227,10 +236,7 @@ public: unsigned ByteNo = B.StartSizeWord*4; // Update the block size field in the header of this sub-block. - Out[ByteNo++] = (unsigned char)(SizeInWords >> 0); - Out[ByteNo++] = (unsigned char)(SizeInWords >> 8); - Out[ByteNo++] = (unsigned char)(SizeInWords >> 16); - Out[ByteNo++] = (unsigned char)(SizeInWords >> 24); + BackpatchWord(ByteNo, SizeInWords); // Restore the inner block's code size and abbrev table. CurCodeSize = B.PrevCodeSize; -- cgit v1.2.3-70-g09d2