OLD | NEW |
1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// | 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
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 file implements the PNaCl bitcode file to Ice, to machine code | 10 // This file implements the PNaCl bitcode file to Ice, to machine code |
11 // translator. | 11 // translator. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "PNaClTranslator.h" | |
16 #include "IceCfg.h" | 15 #include "IceCfg.h" |
17 #include "IceCfgNode.h" | 16 #include "IceCfgNode.h" |
18 #include "IceClFlags.h" | 17 #include "IceClFlags.h" |
19 #include "IceDefs.h" | 18 #include "IceDefs.h" |
20 #include "IceInst.h" | 19 #include "IceInst.h" |
21 #include "IceOperand.h" | 20 #include "IceOperand.h" |
22 #include "IceTypeConverter.h" | 21 #include "IceTypeConverter.h" |
23 #include "llvm/Analysis/NaCl/PNaClABIProps.h" | 22 #include "llvm/Analysis/NaCl/PNaClABIProps.h" |
24 #include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h" | 23 #include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h" |
25 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" | 24 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" |
26 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" | 25 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" |
27 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" | 26 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" |
28 #include "llvm/IR/Constants.h" | 27 #include "llvm/IR/Constants.h" |
29 #include "llvm/IR/DataLayout.h" | 28 #include "llvm/IR/DataLayout.h" |
30 #include "llvm/IR/LLVMContext.h" | 29 #include "llvm/IR/LLVMContext.h" |
31 #include "llvm/IR/Module.h" | 30 #include "llvm/IR/Module.h" |
| 31 #include "llvm/IR/ValueHandle.h" |
32 #include "llvm/Support/Format.h" | 32 #include "llvm/Support/Format.h" |
33 #include "llvm/Support/MemoryBuffer.h" | 33 #include "llvm/Support/MemoryBuffer.h" |
34 #include "llvm/Support/raw_ostream.h" | 34 #include "llvm/Support/raw_ostream.h" |
35 #include "llvm/Support/ValueHandle.h" | |
36 | 35 |
| 36 #include <cassert> |
37 #include <vector> | 37 #include <vector> |
38 #include <cassert> | |
39 | 38 |
40 using namespace llvm; | 39 using namespace llvm; |
41 | 40 |
42 namespace { | 41 namespace { |
43 | 42 |
44 // TODO(kschimpf) Remove error recovery once implementation complete. | 43 // TODO(kschimpf) Remove error recovery once implementation complete. |
45 static cl::opt<bool> AllowErrorRecovery( | 44 static cl::opt<bool> AllowErrorRecovery( |
46 "allow-pnacl-reader-error-recovery", | 45 "allow-pnacl-reader-error-recovery", |
47 cl::desc("Allow error recovery when reading PNaCl bitcode."), | 46 cl::desc("Allow error recovery when reading PNaCl bitcode."), |
48 cl::init(false)); | 47 cl::init(false)); |
(...skipping 10 matching lines...) Expand all Loading... |
59 : NaClBitcodeParser(Cursor), Translator(Translator), | 58 : NaClBitcodeParser(Cursor), Translator(Translator), |
60 Mod(new Module(InputName, getGlobalContext())), DL(PNaClDataLayout), | 59 Mod(new Module(InputName, getGlobalContext())), DL(PNaClDataLayout), |
61 Header(Header), TypeConverter(getLLVMContext()), | 60 Header(Header), TypeConverter(getLLVMContext()), |
62 ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0), | 61 ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0), |
63 NumFunctionBlocks(0), | 62 NumFunctionBlocks(0), |
64 GlobalVarPlaceHolderType(convertToLLVMType(Ice::IceType_i8)) { | 63 GlobalVarPlaceHolderType(convertToLLVMType(Ice::IceType_i8)) { |
65 Mod->setDataLayout(PNaClDataLayout); | 64 Mod->setDataLayout(PNaClDataLayout); |
66 setErrStream(Translator.getContext()->getStrDump()); | 65 setErrStream(Translator.getContext()->getStrDump()); |
67 } | 66 } |
68 | 67 |
69 virtual ~TopLevelParser() {} | 68 ~TopLevelParser() override {} |
70 LLVM_OVERRIDE; | |
71 | 69 |
72 Ice::Translator &getTranslator() { return Translator; } | 70 Ice::Translator &getTranslator() { return Translator; } |
73 | 71 |
74 // Generates error with given Message. Always returns true. | 72 // Generates error with given Message. Always returns true. |
75 virtual bool Error(const std::string &Message) LLVM_OVERRIDE { | 73 bool Error(const std::string &Message) override { |
76 ErrorStatus = true; | 74 ErrorStatus = true; |
77 ++NumErrors; | 75 ++NumErrors; |
78 NaClBitcodeParser::Error(Message); | 76 NaClBitcodeParser::Error(Message); |
79 if (!AllowErrorRecovery) | 77 if (!AllowErrorRecovery) |
80 report_fatal_error("Unable to continue"); | 78 report_fatal_error("Unable to continue"); |
81 return true; | 79 return true; |
82 } | 80 } |
83 | 81 |
84 /// Returns the number of errors found while parsing the bitcode | 82 /// Returns the number of errors found while parsing the bitcode |
85 /// file. | 83 /// file. |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 244 |
247 /// Returns the model for pointer types in ICE. | 245 /// Returns the model for pointer types in ICE. |
248 Ice::Type getIcePointerType() const { | 246 Ice::Type getIcePointerType() const { |
249 return TypeConverter.getIcePointerType(); | 247 return TypeConverter.getIcePointerType(); |
250 } | 248 } |
251 | 249 |
252 private: | 250 private: |
253 // The translator associated with the parser. | 251 // The translator associated with the parser. |
254 Ice::Translator &Translator; | 252 Ice::Translator &Translator; |
255 // The parsed module. | 253 // The parsed module. |
256 OwningPtr<Module> Mod; | 254 std::unique_ptr<Module> Mod; |
257 // The data layout to use. | 255 // The data layout to use. |
258 DataLayout DL; | 256 DataLayout DL; |
259 // The bitcode header. | 257 // The bitcode header. |
260 NaClBitcodeHeader &Header; | 258 NaClBitcodeHeader &Header; |
261 // Converter between LLVM and ICE types. | 259 // Converter between LLVM and ICE types. |
262 Ice::TypeConverter TypeConverter; | 260 Ice::TypeConverter TypeConverter; |
263 // The exit status that should be set to true if an error occurs. | 261 // The exit status that should be set to true if an error occurs. |
264 bool &ErrorStatus; | 262 bool &ErrorStatus; |
265 // The number of errors reported. | 263 // The number of errors reported. |
266 unsigned NumErrors; | 264 unsigned NumErrors; |
267 // The types associated with each type ID. | 265 // The types associated with each type ID. |
268 std::vector<Type *> TypeIDValues; | 266 std::vector<Type *> TypeIDValues; |
269 // The (global) value IDs. | 267 // The (global) value IDs. |
270 std::vector<WeakVH> ValueIDValues; | 268 std::vector<WeakVH> ValueIDValues; |
271 // Relocatable constants associated with ValueIDValues. | 269 // Relocatable constants associated with ValueIDValues. |
272 std::vector<Ice::Constant *> ValueIDConstants; | 270 std::vector<Ice::Constant *> ValueIDConstants; |
273 // The number of function IDs. | 271 // The number of function IDs. |
274 unsigned NumFunctionIds; | 272 unsigned NumFunctionIds; |
275 // The number of function blocks (processed so far). | 273 // The number of function blocks (processed so far). |
276 unsigned NumFunctionBlocks; | 274 unsigned NumFunctionBlocks; |
277 // The list of value IDs (in the order found) of defining function | 275 // The list of value IDs (in the order found) of defining function |
278 // addresses. | 276 // addresses. |
279 std::vector<unsigned> DefiningFunctionsList; | 277 std::vector<unsigned> DefiningFunctionsList; |
280 // Cached global variable placeholder type. Used for all forward | 278 // Cached global variable placeholder type. Used for all forward |
281 // references to global variable addresses. | 279 // references to global variable addresses. |
282 Type *GlobalVarPlaceHolderType; | 280 Type *GlobalVarPlaceHolderType; |
283 | 281 |
284 virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE; | 282 bool ParseBlock(unsigned BlockID) override; |
285 | 283 |
286 /// Reports that type ID is undefined, and then returns | 284 /// Reports that type ID is undefined, and then returns |
287 /// the void type. | 285 /// the void type. |
288 Type *reportTypeIDAsUndefined(unsigned ID); | 286 Type *reportTypeIDAsUndefined(unsigned ID); |
289 | 287 |
290 /// Reports error about bad call to setTypeID. | 288 /// Reports error about bad call to setTypeID. |
291 void reportBadSetTypeID(unsigned ID, Type *Ty); | 289 void reportBadSetTypeID(unsigned ID, Type *Ty); |
292 | 290 |
293 // Reports that there is no corresponding ICE type for LLVMTy, and | 291 // Reports that there is no corresponding ICE type for LLVMTy, and |
294 // returns ICE::IceType_void. | 292 // returns ICE::IceType_void. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 // Base class for parsing blocks within the bitcode file. Note: | 330 // Base class for parsing blocks within the bitcode file. Note: |
333 // Because this is the base class of block parsers, we generate error | 331 // Because this is the base class of block parsers, we generate error |
334 // messages if ParseBlock or ParseRecord is not overridden in derived | 332 // messages if ParseBlock or ParseRecord is not overridden in derived |
335 // classes. | 333 // classes. |
336 class BlockParserBaseClass : public NaClBitcodeParser { | 334 class BlockParserBaseClass : public NaClBitcodeParser { |
337 public: | 335 public: |
338 // Constructor for the top-level module block parser. | 336 // Constructor for the top-level module block parser. |
339 BlockParserBaseClass(unsigned BlockID, TopLevelParser *Context) | 337 BlockParserBaseClass(unsigned BlockID, TopLevelParser *Context) |
340 : NaClBitcodeParser(BlockID, Context), Context(Context) {} | 338 : NaClBitcodeParser(BlockID, Context), Context(Context) {} |
341 | 339 |
342 virtual ~BlockParserBaseClass() LLVM_OVERRIDE {} | 340 ~BlockParserBaseClass() override {} |
343 | 341 |
344 protected: | 342 protected: |
345 // The context parser that contains the decoded state. | 343 // The context parser that contains the decoded state. |
346 TopLevelParser *Context; | 344 TopLevelParser *Context; |
347 | 345 |
348 // Constructor for nested block parsers. | 346 // Constructor for nested block parsers. |
349 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 347 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
350 : NaClBitcodeParser(BlockID, EnclosingParser), | 348 : NaClBitcodeParser(BlockID, EnclosingParser), |
351 Context(EnclosingParser->Context) {} | 349 Context(EnclosingParser->Context) {} |
352 | 350 |
353 // Gets the translator associated with the bitcode parser. | 351 // Gets the translator associated with the bitcode parser. |
354 Ice::Translator &getTranslator() const { return Context->getTranslator(); } | 352 Ice::Translator &getTranslator() const { return Context->getTranslator(); } |
355 | 353 |
356 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } | 354 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } |
357 | 355 |
358 // Generates an error Message with the bit address prefixed to it. | 356 // Generates an error Message with the bit address prefixed to it. |
359 virtual bool Error(const std::string &Message) LLVM_OVERRIDE { | 357 bool Error(const std::string &Message) override { |
360 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; | 358 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; |
361 std::string Buffer; | 359 std::string Buffer; |
362 raw_string_ostream StrBuf(Buffer); | 360 raw_string_ostream StrBuf(Buffer); |
363 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), | 361 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), |
364 static_cast<unsigned>(Bit % 8)) << ") " << Message; | 362 static_cast<unsigned>(Bit % 8)) << ") " << Message; |
365 return Context->Error(StrBuf.str()); | 363 return Context->Error(StrBuf.str()); |
366 } | 364 } |
367 | 365 |
368 // Default implementation. Reports that block is unknown and skips | 366 // Default implementation. Reports that block is unknown and skips |
369 // its contents. | 367 // its contents. |
370 virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE; | 368 bool ParseBlock(unsigned BlockID) override; |
371 | 369 |
372 // Default implementation. Reports that the record is not | 370 // Default implementation. Reports that the record is not |
373 // understood. | 371 // understood. |
374 virtual void ProcessRecord() LLVM_OVERRIDE; | 372 void ProcessRecord() override; |
375 | 373 |
376 // Checks if the size of the record is Size. Return true if valid. | 374 // Checks if the size of the record is Size. Return true if valid. |
377 // Otherwise generates an error and returns false. | 375 // Otherwise generates an error and returns false. |
378 bool isValidRecordSize(unsigned Size, const char *RecordName) { | 376 bool isValidRecordSize(unsigned Size, const char *RecordName) { |
379 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 377 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
380 if (Values.size() == Size) | 378 if (Values.size() == Size) |
381 return true; | 379 return true; |
382 ReportRecordSizeError(Size, RecordName, NULL); | 380 ReportRecordSizeError(Size, RecordName, NULL); |
383 return false; | 381 return false; |
384 } | 382 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 StrBuf << "Don't know how to process record: " << Record; | 456 StrBuf << "Don't know how to process record: " << Record; |
459 Error(StrBuf.str()); | 457 Error(StrBuf.str()); |
460 } | 458 } |
461 | 459 |
462 // Class to parse a types block. | 460 // Class to parse a types block. |
463 class TypesParser : public BlockParserBaseClass { | 461 class TypesParser : public BlockParserBaseClass { |
464 public: | 462 public: |
465 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 463 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
466 : BlockParserBaseClass(BlockID, EnclosingParser), NextTypeId(0) {} | 464 : BlockParserBaseClass(BlockID, EnclosingParser), NextTypeId(0) {} |
467 | 465 |
468 ~TypesParser() LLVM_OVERRIDE {} | 466 ~TypesParser() override {} |
469 | 467 |
470 private: | 468 private: |
471 // The type ID that will be associated with the next type defining | 469 // The type ID that will be associated with the next type defining |
472 // record in the types block. | 470 // record in the types block. |
473 unsigned NextTypeId; | 471 unsigned NextTypeId; |
474 | 472 |
475 virtual void ProcessRecord() LLVM_OVERRIDE; | 473 void ProcessRecord() override; |
476 }; | 474 }; |
477 | 475 |
478 void TypesParser::ProcessRecord() { | 476 void TypesParser::ProcessRecord() { |
479 Type *Ty = NULL; | 477 Type *Ty = NULL; |
480 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 478 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
481 switch (Record.GetCode()) { | 479 switch (Record.GetCode()) { |
482 case naclbitc::TYPE_CODE_NUMENTRY: | 480 case naclbitc::TYPE_CODE_NUMENTRY: |
483 // NUMENTRY: [numentries] | 481 // NUMENTRY: [numentries] |
484 if (!isValidRecordSize(1, "Type count")) | 482 if (!isValidRecordSize(1, "Type count")) |
485 return; | 483 return; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 | 556 |
559 /// Parses the globals block (i.e. global variables). | 557 /// Parses the globals block (i.e. global variables). |
560 class GlobalsParser : public BlockParserBaseClass { | 558 class GlobalsParser : public BlockParserBaseClass { |
561 public: | 559 public: |
562 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 560 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
563 : BlockParserBaseClass(BlockID, EnclosingParser), InitializersNeeded(0), | 561 : BlockParserBaseClass(BlockID, EnclosingParser), InitializersNeeded(0), |
564 Alignment(1), IsConstant(false) { | 562 Alignment(1), IsConstant(false) { |
565 NextGlobalID = Context->getNumFunctionIDs(); | 563 NextGlobalID = Context->getNumFunctionIDs(); |
566 } | 564 } |
567 | 565 |
568 virtual ~GlobalsParser() LLVM_OVERRIDE {} | 566 ~GlobalsParser() override {} |
569 | 567 |
570 private: | 568 private: |
571 // Holds the sequence of initializers for the global. | 569 // Holds the sequence of initializers for the global. |
572 SmallVector<Constant *, 10> Initializers; | 570 SmallVector<Constant *, 10> Initializers; |
573 | 571 |
574 // Keeps track of how many initializers are expected for | 572 // Keeps track of how many initializers are expected for |
575 // the global variable being built. | 573 // the global variable being built. |
576 unsigned InitializersNeeded; | 574 unsigned InitializersNeeded; |
577 | 575 |
578 // The alignment assumed for the global variable being built. | 576 // The alignment assumed for the global variable being built. |
579 unsigned Alignment; | 577 unsigned Alignment; |
580 | 578 |
581 // True if the global variable being built is a constant. | 579 // True if the global variable being built is a constant. |
582 bool IsConstant; | 580 bool IsConstant; |
583 | 581 |
584 // The index of the next global variable. | 582 // The index of the next global variable. |
585 unsigned NextGlobalID; | 583 unsigned NextGlobalID; |
586 | 584 |
587 virtual void ExitBlock() LLVM_OVERRIDE { | 585 void ExitBlock() override { |
588 verifyNoMissingInitializers(); | 586 verifyNoMissingInitializers(); |
589 unsigned NumIDs = Context->getNumGlobalValueIDs(); | 587 unsigned NumIDs = Context->getNumGlobalValueIDs(); |
590 if (NextGlobalID < NumIDs) { | 588 if (NextGlobalID < NumIDs) { |
591 unsigned NumFcnIDs = Context->getNumFunctionIDs(); | 589 unsigned NumFcnIDs = Context->getNumFunctionIDs(); |
592 std::string Buffer; | 590 std::string Buffer; |
593 raw_string_ostream StrBuf(Buffer); | 591 raw_string_ostream StrBuf(Buffer); |
594 StrBuf << "Globals block expects " << (NumIDs - NumFcnIDs) | 592 StrBuf << "Globals block expects " << (NumIDs - NumFcnIDs) |
595 << " global definitions. Found: " << (NextGlobalID - NumFcnIDs); | 593 << " global definitions. Found: " << (NextGlobalID - NumFcnIDs); |
596 Error(StrBuf.str()); | 594 Error(StrBuf.str()); |
597 } | 595 } |
598 BlockParserBaseClass::ExitBlock(); | 596 BlockParserBaseClass::ExitBlock(); |
599 } | 597 } |
600 | 598 |
601 virtual void ProcessRecord() LLVM_OVERRIDE; | 599 void ProcessRecord() override; |
602 | 600 |
603 // Checks if the number of initializers needed is the same as the | 601 // Checks if the number of initializers needed is the same as the |
604 // number found in the bitcode file. If different, and error message | 602 // number found in the bitcode file. If different, and error message |
605 // is generated, and the internal state of the parser is fixed so | 603 // is generated, and the internal state of the parser is fixed so |
606 // this condition is no longer violated. | 604 // this condition is no longer violated. |
607 void verifyNoMissingInitializers() { | 605 void verifyNoMissingInitializers() { |
608 if (InitializersNeeded != Initializers.size()) { | 606 if (InitializersNeeded != Initializers.size()) { |
609 std::string Buffer; | 607 std::string Buffer; |
610 raw_string_ostream StrBuf(Buffer); | 608 raw_string_ostream StrBuf(Buffer); |
611 StrBuf << "Global variable @g" | 609 StrBuf << "Global variable @g" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 | 764 |
767 /// Base class for parsing a valuesymtab block in the bitcode file. | 765 /// Base class for parsing a valuesymtab block in the bitcode file. |
768 class ValuesymtabParser : public BlockParserBaseClass { | 766 class ValuesymtabParser : public BlockParserBaseClass { |
769 ValuesymtabParser(const ValuesymtabParser &) LLVM_DELETED_FUNCTION; | 767 ValuesymtabParser(const ValuesymtabParser &) LLVM_DELETED_FUNCTION; |
770 void operator=(const ValuesymtabParser &) LLVM_DELETED_FUNCTION; | 768 void operator=(const ValuesymtabParser &) LLVM_DELETED_FUNCTION; |
771 | 769 |
772 public: | 770 public: |
773 ValuesymtabParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 771 ValuesymtabParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
774 : BlockParserBaseClass(BlockID, EnclosingParser) {} | 772 : BlockParserBaseClass(BlockID, EnclosingParser) {} |
775 | 773 |
776 virtual ~ValuesymtabParser() LLVM_OVERRIDE {} | 774 ~ValuesymtabParser() override {} |
777 | 775 |
778 protected: | 776 protected: |
779 typedef SmallString<128> StringType; | 777 typedef SmallString<128> StringType; |
780 | 778 |
781 // Associates Name with the value defined by the given Index. | 779 // Associates Name with the value defined by the given Index. |
782 virtual void setValueName(uint64_t Index, StringType &Name) = 0; | 780 virtual void setValueName(uint64_t Index, StringType &Name) = 0; |
783 | 781 |
784 // Associates Name with the value defined by the given Index; | 782 // Associates Name with the value defined by the given Index; |
785 virtual void setBbName(uint64_t Index, StringType &Name) = 0; | 783 virtual void setBbName(uint64_t Index, StringType &Name) = 0; |
786 | 784 |
787 private: | 785 private: |
788 | 786 |
789 virtual void ProcessRecord() LLVM_OVERRIDE; | 787 void ProcessRecord() override; |
790 | 788 |
791 void ConvertToString(StringType &ConvertedName) { | 789 void ConvertToString(StringType &ConvertedName) { |
792 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 790 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
793 for (size_t i = 1, e = Values.size(); i != e; ++i) { | 791 for (size_t i = 1, e = Values.size(); i != e; ++i) { |
794 ConvertedName += static_cast<char>(Values[i]); | 792 ConvertedName += static_cast<char>(Values[i]); |
795 } | 793 } |
796 } | 794 } |
797 }; | 795 }; |
798 | 796 |
799 void ValuesymtabParser::ProcessRecord() { | 797 void ValuesymtabParser::ProcessRecord() { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 Func->setInternal(LLVMFunc->hasInternalLinkage()); | 844 Func->setInternal(LLVMFunc->hasInternalLinkage()); |
847 CurrentNode = InstallNextBasicBlock(); | 845 CurrentNode = InstallNextBasicBlock(); |
848 Func->setEntryNode(CurrentNode); | 846 Func->setEntryNode(CurrentNode); |
849 for (Function::const_arg_iterator ArgI = LLVMFunc->arg_begin(), | 847 for (Function::const_arg_iterator ArgI = LLVMFunc->arg_begin(), |
850 ArgE = LLVMFunc->arg_end(); | 848 ArgE = LLVMFunc->arg_end(); |
851 ArgI != ArgE; ++ArgI) { | 849 ArgI != ArgE; ++ArgI) { |
852 Func->addArg(getNextInstVar(Context->convertToIceType(ArgI->getType()))); | 850 Func->addArg(getNextInstVar(Context->convertToIceType(ArgI->getType()))); |
853 } | 851 } |
854 } | 852 } |
855 | 853 |
856 ~FunctionParser() LLVM_OVERRIDE; | 854 ~FunctionParser() override; |
857 | 855 |
858 // Set the next constant ID to the given constant C. | 856 // Set the next constant ID to the given constant C. |
859 void setNextConstantID(Ice::Constant *C) { | 857 void setNextConstantID(Ice::Constant *C) { |
860 setOperand(NextLocalInstIndex++, C); | 858 setOperand(NextLocalInstIndex++, C); |
861 } | 859 } |
862 | 860 |
863 private: | 861 private: |
864 // Timer for reading function bitcode and converting to ICE. | 862 // Timer for reading function bitcode and converting to ICE. |
865 Ice::Timer TConvert; | 863 Ice::Timer TConvert; |
866 // The corresponding ICE function defined by the function block. | 864 // The corresponding ICE function defined by the function block. |
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2381 // Generate error message by using default block implementation. | 2379 // Generate error message by using default block implementation. |
2382 BlockParserBaseClass Parser(BlockID, this); | 2380 BlockParserBaseClass Parser(BlockID, this); |
2383 return Parser.ParseThisBlock(); | 2381 return Parser.ParseThisBlock(); |
2384 } | 2382 } |
2385 | 2383 |
2386 } // end of anonymous namespace | 2384 } // end of anonymous namespace |
2387 | 2385 |
2388 namespace Ice { | 2386 namespace Ice { |
2389 | 2387 |
2390 void PNaClTranslator::translate(const std::string &IRFilename) { | 2388 void PNaClTranslator::translate(const std::string &IRFilename) { |
2391 OwningPtr<MemoryBuffer> MemBuf; | 2389 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = |
2392 if (error_code ec = | 2390 MemoryBuffer::getFileOrSTDIN(IRFilename); |
2393 MemoryBuffer::getFileOrSTDIN(IRFilename.c_str(), MemBuf)) { | 2391 if (std::error_code EC = ErrOrFile.getError()) { |
2394 errs() << "Error reading '" << IRFilename << "': " << ec.message() << "\n"; | 2392 errs() << "Error reading '" << IRFilename << "': " << EC.message() << "\n"; |
2395 ErrorStatus = true; | 2393 ErrorStatus = true; |
2396 return; | 2394 return; |
2397 } | 2395 } |
| 2396 std::unique_ptr<MemoryBuffer> MemBuf(ErrOrFile.get().release()); |
2398 | 2397 |
2399 if (MemBuf->getBufferSize() % 4 != 0) { | 2398 if (MemBuf->getBufferSize() % 4 != 0) { |
2400 errs() << IRFilename | 2399 errs() << IRFilename |
2401 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; | 2400 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; |
2402 ErrorStatus = true; | 2401 ErrorStatus = true; |
2403 return; | 2402 return; |
2404 } | 2403 } |
2405 | 2404 |
2406 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); | 2405 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); |
2407 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); | 2406 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); |
(...skipping 23 matching lines...) Expand all Loading... |
2431 | 2430 |
2432 if (TopLevelBlocks != 1) { | 2431 if (TopLevelBlocks != 1) { |
2433 errs() << IRFilename | 2432 errs() << IRFilename |
2434 << ": Contains more than one module. Found: " << TopLevelBlocks | 2433 << ": Contains more than one module. Found: " << TopLevelBlocks |
2435 << "\n"; | 2434 << "\n"; |
2436 ErrorStatus = true; | 2435 ErrorStatus = true; |
2437 } | 2436 } |
2438 } | 2437 } |
2439 | 2438 |
2440 } // end of namespace Ice | 2439 } // end of namespace Ice |
OLD | NEW |