OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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(NaClBitcodeHeaderField::kAlignBi tcodeRecords)); | |
jvoung (off chromium)
2015/05/07 18:11:17
80 col
Karl
2015/05/07 22:18:55
Done.
| |
1184 | |
1177 Header.InstallFields(); | 1185 Header.InstallFields(); |
1178 if (!(Header.IsSupported() || | 1186 if (!(Header.IsSupported() || |
1179 (!AcceptSupportedOnly && Header.IsReadable()))) { | 1187 (!AcceptSupportedOnly && Header.IsReadable()))) { |
1180 report_fatal_error(Header.Unsupported()); | 1188 report_fatal_error(Header.Unsupported()); |
1181 } | 1189 } |
1182 NaClWriteHeader(Header, Stream); | 1190 NaClWriteHeader(Header, Stream); |
1183 } | 1191 } |
1184 | 1192 |
1185 // Write out the given Header to the bitstream. | 1193 // Write out the given Header to the bitstream. |
1186 void llvm::NaClWriteHeader(const NaClBitcodeHeader &Header, | 1194 void llvm::NaClWriteHeader(const NaClBitcodeHeader &Header, |
1187 NaClBitstreamWriter &Stream) { | 1195 NaClBitstreamWriter &Stream) { |
1196 Stream.initFromHeader(Header); | |
1197 | |
1188 // Emit the file magic number; | 1198 // Emit the file magic number; |
1189 Stream.Emit((unsigned)'P', 8); | 1199 Stream.Emit((unsigned)'P', 8); |
1190 Stream.Emit((unsigned)'E', 8); | 1200 Stream.Emit((unsigned)'E', 8); |
1191 Stream.Emit((unsigned)'X', 8); | 1201 Stream.Emit((unsigned)'X', 8); |
1192 Stream.Emit((unsigned)'E', 8); | 1202 Stream.Emit((unsigned)'E', 8); |
1193 | 1203 |
1194 // Emit placeholder for number of bytes used to hold header fields. | 1204 // Emit placeholder for number of bytes used to hold header fields. |
1195 // This value is necessary so that the streamable reader can preallocate | 1205 // This value is necessary so that the streamable reader can preallocate |
1196 // a buffer to read the fields. | 1206 // a buffer to read the fields. |
1197 Stream.Emit(0, naclbitc::BlockSizeWidth); | 1207 Stream.Emit(0, naclbitc::BlockSizeWidth); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1232 // Emit the module into the buffer. | 1242 // Emit the module into the buffer. |
1233 { | 1243 { |
1234 NaClBitstreamWriter Stream(Buffer); | 1244 NaClBitstreamWriter Stream(Buffer); |
1235 NaClWriteHeader(Stream, AcceptSupportedOnly); | 1245 NaClWriteHeader(Stream, AcceptSupportedOnly); |
1236 WriteModule(M, Stream); | 1246 WriteModule(M, Stream); |
1237 } | 1247 } |
1238 | 1248 |
1239 // Write the generated bitstream to "Out". | 1249 // Write the generated bitstream to "Out". |
1240 Out.write((char*)&Buffer.front(), Buffer.size()); | 1250 Out.write((char*)&Buffer.front(), Buffer.size()); |
1241 } | 1251 } |
OLD | NEW |