|
11 | 11 | #include "llvm/Object/Error.h" |
12 | 12 | #include "llvm/Support/Endian.h" |
13 | 13 | #include "llvm/Support/FormatVariadic.h" |
| 14 | +#include "llvm/TargetParser/SubtargetFeature.h" |
14 | 15 |
|
15 | 16 | using namespace llvm; |
16 | 17 | using namespace llvm::object; |
@@ -515,3 +516,183 @@ uint8_t DirectX::PSVRuntimeInfo::getSigPatchOrPrimCount() const { |
515 | 516 | return P->SigPatchOrPrimElements; |
516 | 517 | return 0; |
517 | 518 | } |
| 519 | + |
| 520 | +class DXNotSupportedError : public ErrorInfo<DXNotSupportedError> { |
| 521 | +public: |
| 522 | + static char ID; |
| 523 | + |
| 524 | + DXNotSupportedError(StringRef S) : FeatureString(S) {} |
| 525 | + |
| 526 | + void log(raw_ostream &OS) const override { |
| 527 | + OS << "DXContainer does not support " << FeatureString; |
| 528 | + } |
| 529 | + |
| 530 | + std::error_code convertToErrorCode() const override { |
| 531 | + return inconvertibleErrorCode(); |
| 532 | + } |
| 533 | + |
| 534 | +private: |
| 535 | + StringRef FeatureString; |
| 536 | +}; |
| 537 | + |
| 538 | +char DXNotSupportedError::ID = 0; |
| 539 | + |
| 540 | +Expected<section_iterator> |
| 541 | +DXContainerObjectFile::getSymbolSection(DataRefImpl Symb) const { |
| 542 | + return make_error<DXNotSupportedError>("Symbol sections"); |
| 543 | +} |
| 544 | + |
| 545 | +Expected<StringRef> DXContainerObjectFile::getSymbolName(DataRefImpl) const { |
| 546 | + return make_error<DXNotSupportedError>("Symbol names"); |
| 547 | +} |
| 548 | + |
| 549 | +Expected<uint64_t> |
| 550 | +DXContainerObjectFile::getSymbolAddress(DataRefImpl Symb) const { |
| 551 | + return make_error<DXNotSupportedError>("Symbol addresses"); |
| 552 | +} |
| 553 | + |
| 554 | +uint64_t DXContainerObjectFile::getSymbolValueImpl(DataRefImpl Symb) const { |
| 555 | + llvm_unreachable("DXContainer does not support symbols"); |
| 556 | +} |
| 557 | +uint64_t |
| 558 | +DXContainerObjectFile::getCommonSymbolSizeImpl(DataRefImpl Symb) const { |
| 559 | + llvm_unreachable("DXContainer does not support symbols"); |
| 560 | +} |
| 561 | + |
| 562 | +Expected<SymbolRef::Type> |
| 563 | +DXContainerObjectFile::getSymbolType(DataRefImpl Symb) const { |
| 564 | + return make_error<DXNotSupportedError>("Symbol types"); |
| 565 | +} |
| 566 | + |
| 567 | +void DXContainerObjectFile::moveSectionNext(DataRefImpl &Sec) const { |
| 568 | + PartIterator It = reinterpret_cast<PartIterator>(Sec.p); |
| 569 | + if (It == Parts.end()) |
| 570 | + return; |
| 571 | + |
| 572 | + ++It; |
| 573 | + Sec.p = reinterpret_cast<uintptr_t>(It); |
| 574 | +} |
| 575 | + |
| 576 | +Expected<StringRef> |
| 577 | +DXContainerObjectFile::getSectionName(DataRefImpl Sec) const { |
| 578 | + PartIterator It = reinterpret_cast<PartIterator>(Sec.p); |
| 579 | + return StringRef(It->Part.getName()); |
| 580 | +} |
| 581 | + |
| 582 | +uint64_t DXContainerObjectFile::getSectionAddress(DataRefImpl Sec) const { |
| 583 | + PartIterator It = reinterpret_cast<PartIterator>(Sec.p); |
| 584 | + return It->Offset; |
| 585 | +} |
| 586 | + |
| 587 | +uint64_t DXContainerObjectFile::getSectionIndex(DataRefImpl Sec) const { |
| 588 | + return (Sec.p - reinterpret_cast<uintptr_t>(Parts.begin())) / |
| 589 | + sizeof(PartIterator); |
| 590 | +} |
| 591 | + |
| 592 | +uint64_t DXContainerObjectFile::getSectionSize(DataRefImpl Sec) const { |
| 593 | + PartIterator It = reinterpret_cast<PartIterator>(Sec.p); |
| 594 | + return It->Data.size(); |
| 595 | +} |
| 596 | +Expected<ArrayRef<uint8_t>> |
| 597 | +DXContainerObjectFile::getSectionContents(DataRefImpl Sec) const { |
| 598 | + PartIterator It = reinterpret_cast<PartIterator>(Sec.p); |
| 599 | + return ArrayRef<uint8_t>(It->Data.bytes_begin(), It->Data.size()); |
| 600 | +} |
| 601 | + |
| 602 | +uint64_t DXContainerObjectFile::getSectionAlignment(DataRefImpl Sec) const { |
| 603 | + return 1; |
| 604 | +} |
| 605 | + |
| 606 | +bool DXContainerObjectFile::isSectionCompressed(DataRefImpl Sec) const { |
| 607 | + return false; |
| 608 | +} |
| 609 | + |
| 610 | +bool DXContainerObjectFile::isSectionText(DataRefImpl Sec) const { |
| 611 | + return false; |
| 612 | +} |
| 613 | + |
| 614 | +bool DXContainerObjectFile::isSectionData(DataRefImpl Sec) const { |
| 615 | + return false; |
| 616 | +} |
| 617 | + |
| 618 | +bool DXContainerObjectFile::isSectionBSS(DataRefImpl Sec) const { |
| 619 | + return false; |
| 620 | +} |
| 621 | + |
| 622 | +bool DXContainerObjectFile::isSectionVirtual(DataRefImpl Sec) const { |
| 623 | + return false; |
| 624 | +} |
| 625 | + |
| 626 | +relocation_iterator |
| 627 | +DXContainerObjectFile::section_rel_begin(DataRefImpl Sec) const { |
| 628 | + return relocation_iterator(RelocationRef()); |
| 629 | +} |
| 630 | + |
| 631 | +relocation_iterator |
| 632 | +DXContainerObjectFile::section_rel_end(DataRefImpl Sec) const { |
| 633 | + return relocation_iterator(RelocationRef()); |
| 634 | +} |
| 635 | + |
| 636 | +void DXContainerObjectFile::moveRelocationNext(DataRefImpl &Rel) const { |
| 637 | + llvm_unreachable("DXContainer does not support relocations"); |
| 638 | +} |
| 639 | + |
| 640 | +uint64_t DXContainerObjectFile::getRelocationOffset(DataRefImpl Rel) const { |
| 641 | + llvm_unreachable("DXContainer does not support relocations"); |
| 642 | +} |
| 643 | + |
| 644 | +symbol_iterator |
| 645 | +DXContainerObjectFile::getRelocationSymbol(DataRefImpl Rel) const { |
| 646 | + return symbol_iterator(SymbolRef()); |
| 647 | +} |
| 648 | + |
| 649 | +uint64_t DXContainerObjectFile::getRelocationType(DataRefImpl Rel) const { |
| 650 | + llvm_unreachable("DXContainer does not support relocations"); |
| 651 | +} |
| 652 | + |
| 653 | +void DXContainerObjectFile::getRelocationTypeName( |
| 654 | + DataRefImpl Rel, SmallVectorImpl<char> &Result) const { |
| 655 | + llvm_unreachable("DXContainer does not support relocations"); |
| 656 | +} |
| 657 | + |
| 658 | +section_iterator DXContainerObjectFile::section_begin() const { |
| 659 | + DataRefImpl Sec; |
| 660 | + Sec.p = reinterpret_cast<uintptr_t>(Parts.begin()); |
| 661 | + return section_iterator(SectionRef(Sec, this)); |
| 662 | +} |
| 663 | +section_iterator DXContainerObjectFile::section_end() const { |
| 664 | + DataRefImpl Sec; |
| 665 | + Sec.p = reinterpret_cast<uintptr_t>(Parts.end()); |
| 666 | + return section_iterator(SectionRef(Sec, this)); |
| 667 | +} |
| 668 | + |
| 669 | +uint8_t DXContainerObjectFile::getBytesInAddress() const { return 4; } |
| 670 | + |
| 671 | +StringRef DXContainerObjectFile::getFileFormatName() const { |
| 672 | + return "DirectX Container"; |
| 673 | +} |
| 674 | + |
| 675 | +Triple::ArchType DXContainerObjectFile::getArch() const { return Triple::dxil; } |
| 676 | + |
| 677 | +Expected<SubtargetFeatures> DXContainerObjectFile::getFeatures() const { |
| 678 | + return SubtargetFeatures(); |
| 679 | +} |
| 680 | + |
| 681 | +Error DXContainerObjectFile::printSymbolName(raw_ostream &OS, |
| 682 | + DataRefImpl Symb) const { |
| 683 | + return make_error<DXNotSupportedError>("Symbol names"); |
| 684 | +} |
| 685 | + |
| 686 | +Expected<uint32_t> |
| 687 | +DXContainerObjectFile::getSymbolFlags(DataRefImpl Symb) const { |
| 688 | + return make_error<DXNotSupportedError>("Symbol flags"); |
| 689 | +} |
| 690 | + |
| 691 | +Expected<std::unique_ptr<DXContainerObjectFile>> |
| 692 | +ObjectFile::createDXContainerObjectFile(MemoryBufferRef Object) { |
| 693 | + auto ExC = DXContainer::create(Object); |
| 694 | + if (!ExC) |
| 695 | + return ExC.takeError(); |
| 696 | + std::unique_ptr<DXContainerObjectFile> Obj(new DXContainerObjectFile(*ExC)); |
| 697 | + return std::move(Obj); |
| 698 | +} |
0 commit comments