[MLIR][NVVM] Add Op for TMA Store with reduction (#118853)
[llvm-project.git] / lldb / source / API / SBCompileUnit.cpp
blob65fdb11032b9c032011efe3bb0dd760027868747
1 //===-- SBCompileUnit.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBCompileUnit.h"
10 #include "lldb/API/SBLineEntry.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Module.h"
13 #include "lldb/Symbol/CompileUnit.h"
14 #include "lldb/Symbol/LineEntry.h"
15 #include "lldb/Symbol/LineTable.h"
16 #include "lldb/Symbol/SymbolFile.h"
17 #include "lldb/Symbol/Type.h"
18 #include "lldb/Symbol/TypeList.h"
19 #include "lldb/Utility/Instrumentation.h"
21 using namespace lldb;
22 using namespace lldb_private;
24 SBCompileUnit::SBCompileUnit() { LLDB_INSTRUMENT_VA(this); }
26 SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr)
27 : m_opaque_ptr(lldb_object_ptr) {}
29 SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs)
30 : m_opaque_ptr(rhs.m_opaque_ptr) {
31 LLDB_INSTRUMENT_VA(this, rhs);
34 const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) {
35 LLDB_INSTRUMENT_VA(this, rhs);
37 m_opaque_ptr = rhs.m_opaque_ptr;
38 return *this;
41 SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = nullptr; }
43 SBFileSpec SBCompileUnit::GetFileSpec() const {
44 LLDB_INSTRUMENT_VA(this);
46 SBFileSpec file_spec;
47 if (m_opaque_ptr)
48 file_spec.SetFileSpec(m_opaque_ptr->GetPrimaryFile());
49 return file_spec;
52 uint32_t SBCompileUnit::GetNumLineEntries() const {
53 LLDB_INSTRUMENT_VA(this);
55 if (m_opaque_ptr) {
56 LineTable *line_table = m_opaque_ptr->GetLineTable();
57 if (line_table) {
58 return line_table->GetSize();
61 return 0;
64 SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const {
65 LLDB_INSTRUMENT_VA(this, idx);
67 SBLineEntry sb_line_entry;
68 if (m_opaque_ptr) {
69 LineTable *line_table = m_opaque_ptr->GetLineTable();
70 if (line_table) {
71 LineEntry line_entry;
72 if (line_table->GetLineEntryAtIndex(idx, line_entry))
73 sb_line_entry.SetLineEntry(line_entry);
77 return sb_line_entry;
80 uint32_t SBCompileUnit::FindLineEntryIndex(lldb::SBLineEntry &line_entry,
81 bool exact) const {
82 LLDB_INSTRUMENT_VA(this, line_entry, exact);
84 if (!m_opaque_ptr || !line_entry.IsValid())
85 return UINT32_MAX;
87 LineEntry found_line_entry;
89 return m_opaque_ptr->FindLineEntry(0, line_entry.GetLine(),
90 line_entry.GetFileSpec().get(), exact,
91 &line_entry.ref());
94 uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
95 SBFileSpec *inline_file_spec) const {
96 LLDB_INSTRUMENT_VA(this, start_idx, line, inline_file_spec);
98 const bool exact = true;
99 return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);
102 uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
103 SBFileSpec *inline_file_spec,
104 bool exact) const {
105 LLDB_INSTRUMENT_VA(this, start_idx, line, inline_file_spec, exact);
107 uint32_t index = UINT32_MAX;
108 if (m_opaque_ptr) {
109 FileSpec file_spec;
110 if (inline_file_spec && inline_file_spec->IsValid())
111 file_spec = inline_file_spec->ref();
112 else
113 file_spec = m_opaque_ptr->GetPrimaryFile();
115 LineEntry line_entry;
116 index = m_opaque_ptr->FindLineEntry(
117 start_idx, line, inline_file_spec ? inline_file_spec->get() : nullptr,
118 exact, &line_entry);
121 return index;
124 uint32_t SBCompileUnit::GetNumSupportFiles() const {
125 LLDB_INSTRUMENT_VA(this);
127 if (m_opaque_ptr)
128 return m_opaque_ptr->GetSupportFiles().GetSize();
130 return 0;
133 lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {
134 LLDB_INSTRUMENT_VA(this, type_mask);
136 SBTypeList sb_type_list;
138 if (!m_opaque_ptr)
139 return sb_type_list;
141 ModuleSP module_sp(m_opaque_ptr->GetModule());
142 if (!module_sp)
143 return sb_type_list;
145 SymbolFile *symfile = module_sp->GetSymbolFile();
146 if (!symfile)
147 return sb_type_list;
149 TypeClass type_class = static_cast<TypeClass>(type_mask);
150 TypeList type_list;
151 symfile->GetTypes(m_opaque_ptr, type_class, type_list);
152 sb_type_list.m_opaque_up->Append(type_list);
153 return sb_type_list;
156 SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const {
157 LLDB_INSTRUMENT_VA(this, idx);
159 SBFileSpec sb_file_spec;
160 if (m_opaque_ptr) {
161 FileSpec spec = m_opaque_ptr->GetSupportFiles().GetFileSpecAtIndex(idx);
162 sb_file_spec.SetFileSpec(spec);
165 return sb_file_spec;
168 uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx,
169 const SBFileSpec &sb_file,
170 bool full) {
171 LLDB_INSTRUMENT_VA(this, start_idx, sb_file, full);
173 if (m_opaque_ptr) {
174 const SupportFileList &support_files = m_opaque_ptr->GetSupportFiles();
175 return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
177 return 0;
180 lldb::LanguageType SBCompileUnit::GetLanguage() {
181 LLDB_INSTRUMENT_VA(this);
183 if (m_opaque_ptr)
184 return m_opaque_ptr->GetLanguage();
185 return lldb::eLanguageTypeUnknown;
188 bool SBCompileUnit::IsValid() const {
189 LLDB_INSTRUMENT_VA(this);
190 return this->operator bool();
192 SBCompileUnit::operator bool() const {
193 LLDB_INSTRUMENT_VA(this);
195 return m_opaque_ptr != nullptr;
198 bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
199 LLDB_INSTRUMENT_VA(this, rhs);
201 return m_opaque_ptr == rhs.m_opaque_ptr;
204 bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
205 LLDB_INSTRUMENT_VA(this, rhs);
207 return m_opaque_ptr != rhs.m_opaque_ptr;
210 const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
211 return m_opaque_ptr;
214 const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
215 return *m_opaque_ptr;
218 lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
220 void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
221 m_opaque_ptr = lldb_object_ptr;
224 bool SBCompileUnit::GetDescription(SBStream &description) {
225 LLDB_INSTRUMENT_VA(this, description);
227 Stream &strm = description.ref();
229 if (m_opaque_ptr) {
230 m_opaque_ptr->Dump(&strm, false);
231 } else
232 strm.PutCString("No value");
234 return true;