Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp

Issue 1122423005: Add (unsupported experimental) feature allowing byte aligned bitcode. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix nits. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===--- Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp - Bitcode Writer -------===// 1 //===--- Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp - Bitcode Writer -------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // Bitcode writer implementation. 10 // Bitcode writer implementation.
(...skipping 22 matching lines...) Expand all
33 #include "llvm/Support/raw_ostream.h" 33 #include "llvm/Support/raw_ostream.h"
34 #include <cctype> 34 #include <cctype>
35 #include <map> 35 #include <map>
36 using namespace llvm; 36 using namespace llvm;
37 37
38 static cl::opt<unsigned> 38 static cl::opt<unsigned>
39 PNaClVersion("pnacl-version", 39 PNaClVersion("pnacl-version",
40 cl::desc("Specify PNaCl bitcode version to write"), 40 cl::desc("Specify PNaCl bitcode version to write"),
41 cl::init(2)); 41 cl::init(2));
42 42
43 static cl::opt<bool>
44 AlignBitcodeRecords("align-bitcode-records",
45 cl::desc("Align bitcode records in PNaCl bitcode files (experimental)"),
46 cl::init(false));
47
43 /// These are manifest constants used by the bitcode writer. They do 48 /// These are manifest constants used by the bitcode writer. They do
44 /// not need to be kept in sync with the reader, but need to be 49 /// not need to be kept in sync with the reader, but need to be
45 /// consistent within this file. 50 /// consistent within this file.
46 /// 51 ///
47 /// Note that for each block type GROUP, the last entry should be of 52 /// Note that for each block type GROUP, the last entry should be of
48 /// the form: 53 /// the form:
49 /// 54 ///
50 /// GROUP_MAX_ABBREV = GROUP_LAST_ABBREV, 55 /// GROUP_MAX_ABBREV = GROUP_LAST_ABBREV,
51 /// 56 ///
52 /// where GROUP_LAST_ABBREV is the last defined abbreviation. See 57 /// where GROUP_LAST_ABBREV is the last defined abbreviation. See
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 // Max size for variable fields. Currently only used for writing them 1172 // Max size for variable fields. Currently only used for writing them
1168 // out to files (the parsing works for arbitrary sizes). 1173 // out to files (the parsing works for arbitrary sizes).
1169 static const size_t kMaxVariableFieldSize = 256; 1174 static const size_t kMaxVariableFieldSize = 256;
1170 1175
1171 void llvm::NaClWriteHeader(NaClBitstreamWriter &Stream, 1176 void llvm::NaClWriteHeader(NaClBitstreamWriter &Stream,
1172 bool AcceptSupportedOnly) { 1177 bool AcceptSupportedOnly) {
1173 NaClBitcodeHeader Header; 1178 NaClBitcodeHeader Header;
1174 Header.push_back( 1179 Header.push_back(
1175 new NaClBitcodeHeaderField(NaClBitcodeHeaderField::kPNaClVersion, 1180 new NaClBitcodeHeaderField(NaClBitcodeHeaderField::kPNaClVersion,
1176 PNaClVersion)); 1181 PNaClVersion));
1182 if (AlignBitcodeRecords)
1183 Header.push_back(new NaClBitcodeHeaderField(
1184 NaClBitcodeHeaderField::kAlignBitcodeRecords));
1185
1177 Header.InstallFields(); 1186 Header.InstallFields();
1178 if (!(Header.IsSupported() || 1187 if (!(Header.IsSupported() ||
1179 (!AcceptSupportedOnly && Header.IsReadable()))) { 1188 (!AcceptSupportedOnly && Header.IsReadable()))) {
1180 report_fatal_error(Header.Unsupported()); 1189 report_fatal_error(Header.Unsupported());
1181 } 1190 }
1182 NaClWriteHeader(Header, Stream); 1191 NaClWriteHeader(Header, Stream);
1183 } 1192 }
1184 1193
1185 // Write out the given Header to the bitstream. 1194 // Write out the given Header to the bitstream.
1186 void llvm::NaClWriteHeader(const NaClBitcodeHeader &Header, 1195 void llvm::NaClWriteHeader(const NaClBitcodeHeader &Header,
1187 NaClBitstreamWriter &Stream) { 1196 NaClBitstreamWriter &Stream) {
1197 Stream.initFromHeader(Header);
1198
1188 // Emit the file magic number; 1199 // Emit the file magic number;
1189 Stream.Emit((unsigned)'P', 8); 1200 Stream.Emit((unsigned)'P', 8);
1190 Stream.Emit((unsigned)'E', 8); 1201 Stream.Emit((unsigned)'E', 8);
1191 Stream.Emit((unsigned)'X', 8); 1202 Stream.Emit((unsigned)'X', 8);
1192 Stream.Emit((unsigned)'E', 8); 1203 Stream.Emit((unsigned)'E', 8);
1193 1204
1194 // Emit placeholder for number of bytes used to hold header fields. 1205 // Emit placeholder for number of bytes used to hold header fields.
1195 // This value is necessary so that the streamable reader can preallocate 1206 // This value is necessary so that the streamable reader can preallocate
1196 // a buffer to read the fields. 1207 // a buffer to read the fields.
1197 Stream.Emit(0, naclbitc::BlockSizeWidth); 1208 Stream.Emit(0, naclbitc::BlockSizeWidth);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 // Emit the module into the buffer. 1243 // Emit the module into the buffer.
1233 { 1244 {
1234 NaClBitstreamWriter Stream(Buffer); 1245 NaClBitstreamWriter Stream(Buffer);
1235 NaClWriteHeader(Stream, AcceptSupportedOnly); 1246 NaClWriteHeader(Stream, AcceptSupportedOnly);
1236 WriteModule(M, Stream); 1247 WriteModule(M, Stream);
1237 } 1248 }
1238 1249
1239 // Write the generated bitstream to "Out". 1250 // Write the generated bitstream to "Out".
1240 Out.write((char*)&Buffer.front(), Buffer.size()); 1251 Out.write((char*)&Buffer.front(), Buffer.size());
1241 } 1252 }
OLDNEW
« no previous file with comments | « lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeReader.cpp ('k') | test/NaCl/Bitcode/pnacl-bcdis/no-abbreviations.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698