DxilDiaTableInjectedSources.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilDiaTableInjectedSources.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 "DxilDiaTableInjectedSources.h"
  12. #include "DxilDia.h"
  13. #include "DxilDiaSession.h"
  14. #include "DxilDiaTable.h"
  15. llvm::MDTuple *dxil_dia::InjectedSource::NameContent() {
  16. return llvm::cast<llvm::MDTuple>(m_pSession->Contents()->getOperand(m_index));
  17. }
  18. llvm::StringRef dxil_dia::InjectedSource::Name() {
  19. return llvm::dyn_cast<llvm::MDString>(NameContent()->getOperand(0))->getString();
  20. }
  21. llvm::StringRef dxil_dia::InjectedSource::Content() {
  22. return llvm::dyn_cast<llvm::MDString>(NameContent()->getOperand(1))->getString();
  23. }
  24. STDMETHODIMP dxil_dia::InjectedSource::get_length(_Out_ ULONGLONG *pRetVal) {
  25. *pRetVal = Content().size();
  26. return S_OK;
  27. }
  28. STDMETHODIMP dxil_dia::InjectedSource::get_filename(BSTR *pRetVal) {
  29. DxcThreadMalloc TM(m_pMalloc);
  30. return StringRefToBSTR(Name(), pRetVal);
  31. }
  32. STDMETHODIMP dxil_dia::InjectedSource::get_objectFilename(BSTR *pRetVal) {
  33. *pRetVal = nullptr;
  34. return S_OK;
  35. }
  36. STDMETHODIMP dxil_dia::InjectedSource::get_virtualFilename(BSTR *pRetVal) {
  37. return get_filename(pRetVal);
  38. }
  39. STDMETHODIMP dxil_dia::InjectedSource::get_source(
  40. /* [in] */ DWORD cbData,
  41. /* [out] */ DWORD *pcbData,
  42. /* [size_is][out] */ BYTE *pbData) {
  43. if (pbData == nullptr) {
  44. if (pcbData != nullptr) {
  45. *pcbData = Content().size();
  46. }
  47. return S_OK;
  48. }
  49. cbData = std::min((DWORD)Content().size(), cbData);
  50. memcpy(pbData, Content().begin(), cbData);
  51. if (pcbData) {
  52. *pcbData = cbData;
  53. }
  54. return S_OK;
  55. }
  56. dxil_dia::InjectedSourcesTable::InjectedSourcesTable(
  57. IMalloc *pMalloc,
  58. Session *pSession)
  59. : impl::TableBase<IDiaEnumInjectedSources,
  60. IDiaInjectedSource>(pMalloc, pSession, Table::Kind::InjectedSource) {
  61. // Count the number of source files available.
  62. // m_count = m_pSession->InfoRef().compile_unit_count();
  63. m_count =
  64. (m_pSession->Contents() == nullptr) ? 0 : m_pSession->Contents()->getNumOperands();
  65. }
  66. HRESULT dxil_dia::InjectedSourcesTable::GetItem(DWORD index, IDiaInjectedSource **ppItem) {
  67. if (index >= m_count)
  68. return E_INVALIDARG;
  69. unsigned itemIndex = index;
  70. if (m_count == m_indexList.size())
  71. itemIndex = m_indexList[index];
  72. *ppItem = CreateOnMalloc<InjectedSource>(m_pMalloc, m_pSession, itemIndex);
  73. if (*ppItem == nullptr)
  74. return E_OUTOFMEMORY;
  75. (*ppItem)->AddRef();
  76. return S_OK;
  77. }
  78. void dxil_dia::InjectedSourcesTable::Init(llvm::StringRef filename) {
  79. for (unsigned i = 0; i < m_pSession->Contents()->getNumOperands(); ++i) {
  80. llvm::StringRef fn =
  81. llvm::dyn_cast<llvm::MDString>(m_pSession->Contents()->getOperand(i)->getOperand(0))
  82. ->getString();
  83. if (fn.equals(filename)) {
  84. m_indexList.emplace_back(i);
  85. }
  86. }
  87. m_count = m_indexList.size();
  88. }