OLD | NEW |
1 //===-- pnacl-bccompress.cpp - Bitcode (abbrev) compression ---------------===// | 1 //===-- pnacl-bccompress.cpp - Bitcode (abbrev) compression ---------------===// |
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 // This tool may be invoked in the following manner: | 10 // This tool may be invoked in the following manner: |
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr); | 1246 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr); |
1247 NaClBitstreamCursor Stream(StreamFile); | 1247 NaClBitstreamCursor Stream(StreamFile); |
1248 | 1248 |
1249 // Parse the the bitcode file. | 1249 // Parse the the bitcode file. |
1250 NaClAnalyzeParser Parser(Stream, BlockAbbrevsMap); | 1250 NaClAnalyzeParser Parser(Stream, BlockAbbrevsMap); |
1251 while (!Stream.AtEndOfStream()) { | 1251 while (!Stream.AtEndOfStream()) { |
1252 if (Parser.Parse()) return true; | 1252 if (Parser.Parse()) return true; |
1253 } | 1253 } |
1254 | 1254 |
1255 if (ShowAbbreviationFrequencies || ShowValueDistributions) { | 1255 if (ShowAbbreviationFrequencies || ShowValueDistributions) { |
1256 std::string ErrorInfo; | 1256 std::error_code EC; |
1257 raw_fd_ostream Output(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None); | 1257 raw_fd_ostream Output(OutputFilename, EC, sys::fs::F_None); |
1258 if (!ErrorInfo.empty()) { | 1258 if (EC) { |
1259 errs() << ErrorInfo << "\n"; | 1259 errs() << EC.message() << "\n"; |
1260 exit(1); | 1260 exit(1); |
1261 } | 1261 } |
1262 if (ShowAbbreviationFrequencies) | 1262 if (ShowAbbreviationFrequencies) |
1263 DisplayAbbreviationFrequencies(Output, Parser.BlockDist, BlockAbbrevsMap); | 1263 DisplayAbbreviationFrequencies(Output, Parser.BlockDist, BlockAbbrevsMap); |
1264 if (ShowValueDistributions) | 1264 if (ShowValueDistributions) |
1265 Parser.BlockDist.Print(Output); | 1265 Parser.BlockDist.Print(Output); |
1266 } | 1266 } |
1267 | 1267 |
1268 AddNewAbbreviations(Parser.BlockDist, BlockAbbrevsMap); | 1268 AddNewAbbreviations(Parser.BlockDist, BlockAbbrevsMap); |
1269 return false; | 1269 return false; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 | 1463 |
1464 // Set up the parser. | 1464 // Set up the parser. |
1465 NaClBitcodeCopyParser Parser(Stream, BlockAbbrevsMap, StreamWriter); | 1465 NaClBitcodeCopyParser Parser(Stream, BlockAbbrevsMap, StreamWriter); |
1466 | 1466 |
1467 // Parse the bitcode and copy. | 1467 // Parse the bitcode and copy. |
1468 while (!Stream.AtEndOfStream()) { | 1468 while (!Stream.AtEndOfStream()) { |
1469 if (Parser.Parse()) return true; | 1469 if (Parser.Parse()) return true; |
1470 } | 1470 } |
1471 | 1471 |
1472 // Write out the copied results. | 1472 // Write out the copied results. |
1473 std::string ErrorInfo; | 1473 std::error_code EC; |
1474 std::unique_ptr<tool_output_file> OutFile( | 1474 std::unique_ptr<tool_output_file> OutFile( |
1475 new tool_output_file(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None)); | 1475 new tool_output_file(OutputFilename.c_str(), EC, sys::fs::F_None)); |
1476 if (!ErrorInfo.empty()) | 1476 if (EC) |
1477 return Error(ErrorInfo); | 1477 return Error(EC.message()); |
1478 | 1478 |
1479 // Write the generated bitstream to "Out". | 1479 // Write the generated bitstream to "Out". |
1480 OutFile->os().write((char*)&OutputBuffer.front(), | 1480 OutFile->os().write((char*)&OutputBuffer.front(), |
1481 OutputBuffer.size()); | 1481 OutputBuffer.size()); |
1482 OutFile->keep(); | 1482 OutFile->keep(); |
1483 | 1483 |
1484 return false; | 1484 return false; |
1485 } | 1485 } |
1486 | 1486 |
1487 // Build fast lookup abbreviation maps for each of the abbreviation blocks | 1487 // Build fast lookup abbreviation maps for each of the abbreviation blocks |
(...skipping 20 matching lines...) Expand all Loading... |
1508 if (ReadAndBuffer(MemBuf)) return 1; | 1508 if (ReadAndBuffer(MemBuf)) return 1; |
1509 BlockAbbrevsMapType BlockAbbrevsMap; | 1509 BlockAbbrevsMapType BlockAbbrevsMap; |
1510 if (AnalyzeBitcode(MemBuf, BlockAbbrevsMap)) return 1; | 1510 if (AnalyzeBitcode(MemBuf, BlockAbbrevsMap)) return 1; |
1511 if (ShowAbbreviationFrequencies || ShowValueDistributions) { | 1511 if (ShowAbbreviationFrequencies || ShowValueDistributions) { |
1512 return 0; | 1512 return 0; |
1513 } | 1513 } |
1514 BuildAbbrevLookupMaps(BlockAbbrevsMap); | 1514 BuildAbbrevLookupMaps(BlockAbbrevsMap); |
1515 if (CopyBitcode(MemBuf, BlockAbbrevsMap)) return 1; | 1515 if (CopyBitcode(MemBuf, BlockAbbrevsMap)) return 1; |
1516 return 0; | 1516 return 0; |
1517 } | 1517 } |
OLD | NEW |