DxilDiaTableSourceFiles.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilDiaTableSourceFiles.cpp //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // DIA API implementation for DXIL modules. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "DxilDiaTableSourceFiles.h"
  12. #include "DxilDiaSession.h"
  13. dxil_dia::SourceFile::SourceFile(IMalloc *pMalloc, Session *pSession, DWORD index)
  14. : m_pMalloc(pMalloc), m_pSession(pSession), m_index(index) {}
  15. llvm::MDTuple *dxil_dia::SourceFile::NameContent() const {
  16. return llvm::cast<llvm::MDTuple>(m_pSession->Contents()->getOperand(m_index));
  17. }
  18. llvm::StringRef dxil_dia::SourceFile::Name() const {
  19. return llvm::dyn_cast<llvm::MDString>(NameContent()->getOperand(0))->getString();
  20. }
  21. STDMETHODIMP dxil_dia::SourceFile::get_uniqueId(
  22. /* [retval][out] */ DWORD *pRetVal) {
  23. *pRetVal = m_index;
  24. return S_OK;
  25. }
  26. STDMETHODIMP dxil_dia::SourceFile::get_fileName(
  27. /* [retval][out] */ BSTR *pRetVal) {
  28. DxcThreadMalloc TM(m_pMalloc);
  29. return StringRefToBSTR(Name(), pRetVal);
  30. }
  31. dxil_dia::SourceFilesTable::SourceFilesTable(
  32. IMalloc *pMalloc,
  33. Session *pSession)
  34. : impl::TableBase<IDiaEnumSourceFiles, IDiaSourceFile>(pMalloc, pSession, Table::Kind::SourceFiles) {
  35. m_count =
  36. (m_pSession->Contents() == nullptr) ? 0 : m_pSession->Contents()->getNumOperands();
  37. m_items.assign(m_count, nullptr);
  38. }
  39. dxil_dia::SourceFilesTable::SourceFilesTable(
  40. IMalloc *pMalloc,
  41. Session *pSession,
  42. std::vector<CComPtr<IDiaSourceFile>> &&items)
  43. : impl::TableBase<IDiaEnumSourceFiles, IDiaSourceFile>(pMalloc, pSession, Table::Kind::SourceFiles),
  44. m_items(std::move(items)) {
  45. m_count = m_items.size();
  46. }
  47. HRESULT dxil_dia::SourceFilesTable::GetItem(DWORD index, IDiaSourceFile **ppItem) {
  48. if (!m_items[index]) {
  49. m_items[index] = CreateOnMalloc<SourceFile>(m_pMalloc, m_pSession, index);
  50. if (m_items[index] == nullptr)
  51. return E_OUTOFMEMORY;
  52. }
  53. m_items[index].p->AddRef();
  54. *ppItem = m_items[index];
  55. (*ppItem)->AddRef();
  56. return S_OK;
  57. }