summaryrefslogtreecommitdiffstats
path: root/lldb/source/Symbol
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2015-10-08 21:04:34 +0000
committerGreg Clayton <gclayton@apple.com>2015-10-08 21:04:34 +0000
commit5beec213e24139e99ebbf1b35ca9731849f8843a (patch)
tree0350e660a6bd95ad384cc8d8e74a5569591a4cc2 /lldb/source/Symbol
parent1890799f0ca4b83bda70b2ad8e9b79d24ccc4d14 (diff)
downloadbcm5719-llvm-5beec213e24139e99ebbf1b35ca9731849f8843a.tar.gz
bcm5719-llvm-5beec213e24139e99ebbf1b35ca9731849f8843a.zip
Moved the target specific ClangASTContext initialization over into ClangASTContext::CreateInstance.
This involved changing the TypeSystem::CreateInstance to take a module or a target. This allows type systems to create an AST for modules (no expression support needed) or targets (expression support is needed) and return the correct class instance for both cases. llvm-svn: 249747
Diffstat (limited to 'lldb/source/Symbol')
-rw-r--r--lldb/source/Symbol/ClangASTContext.cpp65
-rw-r--r--lldb/source/Symbol/GoASTContext.cpp9
-rw-r--r--lldb/source/Symbol/TypeSystem.cpp116
3 files changed, 166 insertions, 24 deletions
diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index 485e8ff7781..a420c65d3b1 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -367,36 +367,59 @@ ClangASTContext::GetPluginVersion()
}
lldb::TypeSystemSP
-ClangASTContext::CreateInstance (lldb::LanguageType language, const lldb_private::ArchSpec &arch)
+ClangASTContext::CreateInstance (lldb::LanguageType language, Module *module, Target *target)
{
if (ClangASTContextSupportsLanguage(language))
{
- std::shared_ptr<ClangASTContext> ast_sp(new ClangASTContext);
- if (ast_sp)
+ ArchSpec arch;
+ if (module)
+ arch = module->GetArchitecture();
+ else if (target)
+ arch = target->GetArchitecture();
+
+ if (arch.IsValid())
{
- if (arch.IsValid())
+ ArchSpec fixed_arch = arch;
+ // LLVM wants this to be set to iOS or MacOSX; if we're working on
+ // a bare-boards type image, change the triple for llvm's benefit.
+ if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple &&
+ fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
{
- ArchSpec fixed_arch = arch;
- // LLVM wants this to be set to iOS or MacOSX; if we're working on
- // a bare-boards type image, change the triple for llvm's benefit.
- if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple &&
- fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
+ if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm ||
+ fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
+ fixed_arch.GetTriple().getArch() == llvm::Triple::thumb)
{
- if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm ||
- fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
- fixed_arch.GetTriple().getArch() == llvm::Triple::thumb)
- {
- fixed_arch.GetTriple().setOS(llvm::Triple::IOS);
- }
- else
- {
- fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX);
- }
+ fixed_arch.GetTriple().setOS(llvm::Triple::IOS);
+ }
+ else
+ {
+ fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX);
+ }
+ }
+
+ if (module)
+ {
+ std::shared_ptr<ClangASTContext> ast_sp(new ClangASTContext);
+ if (ast_sp)
+ {
+ ast_sp->SetArchitecture (fixed_arch);
+ }
+ return ast_sp;
+ }
+ else if (target)
+ {
+ std::shared_ptr<ClangASTContextForExpressions> ast_sp(new ClangASTContextForExpressions(*target));
+ if (ast_sp)
+ {
+ ast_sp->SetArchitecture(fixed_arch);
+ ast_sp->m_scratch_ast_source_ap.reset (new ClangASTSource(target->shared_from_this()));
+ ast_sp->m_scratch_ast_source_ap->InstallASTContext(ast_sp->getASTContext());
+ llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(ast_sp->m_scratch_ast_source_ap->CreateProxy());
+ ast_sp->SetExternalSource(proxy_ast_source);
+ return ast_sp;
}
- ast_sp->SetArchitecture (fixed_arch);
}
}
- return ast_sp;
}
return lldb::TypeSystemSP();
}
diff --git a/lldb/source/Symbol/GoASTContext.cpp b/lldb/source/Symbol/GoASTContext.cpp
index 6568b1253e6..8946aaae0b2 100644
--- a/lldb/source/Symbol/GoASTContext.cpp
+++ b/lldb/source/Symbol/GoASTContext.cpp
@@ -22,6 +22,7 @@
#include "lldb/Symbol/GoASTContext.h"
#include "lldb/Symbol/Type.h"
#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Target.h"
#include "Plugins/SymbolFile/DWARF/DWARFASTParserGo.h"
@@ -321,10 +322,16 @@ GoASTContext::GetPluginVersion()
}
lldb::TypeSystemSP
-GoASTContext::CreateInstance (lldb::LanguageType language, const lldb_private::ArchSpec &arch)
+GoASTContext::CreateInstance (lldb::LanguageType language, Module *module, Target *target)
{
if (language == eLanguageTypeGo)
{
+ ArchSpec arch;
+ if (module)
+ arch = module->GetArchitecture();
+ else if (target)
+ arch = target->GetArchitecture();
+
if (arch.IsValid())
{
std::shared_ptr<GoASTContext> go_ast_sp(new GoASTContext);
diff --git a/lldb/source/Symbol/TypeSystem.cpp b/lldb/source/Symbol/TypeSystem.cpp
index 84c243cd066..cd0ceb76aae 100644
--- a/lldb/source/Symbol/TypeSystem.cpp
+++ b/lldb/source/Symbol/TypeSystem.cpp
@@ -8,6 +8,8 @@
#include "lldb/Symbol/TypeSystem.h"
+#include <set>
+
#include "lldb/Core/PluginManager.h"
#include "lldb/Symbol/CompilerType.h"
@@ -24,13 +26,28 @@ TypeSystem::~TypeSystem()
}
lldb::TypeSystemSP
-TypeSystem::CreateInstance (lldb::LanguageType language, const lldb_private::ArchSpec &arch)
+TypeSystem::CreateInstance (lldb::LanguageType language, Module *module)
{
uint32_t i = 0;
TypeSystemCreateInstance create_callback;
while ((create_callback = PluginManager::GetTypeSystemCreateCallbackAtIndex (i++)) != nullptr)
{
- lldb::TypeSystemSP type_system_sp = create_callback(language, arch);
+ lldb::TypeSystemSP type_system_sp = create_callback(language, module, nullptr);
+ if (type_system_sp)
+ return type_system_sp;
+ }
+
+ return lldb::TypeSystemSP();
+}
+
+lldb::TypeSystemSP
+TypeSystem::CreateInstance (lldb::LanguageType language, Target *target)
+{
+ uint32_t i = 0;
+ TypeSystemCreateInstance create_callback;
+ while ((create_callback = PluginManager::GetTypeSystemCreateCallbackAtIndex (i++)) != nullptr)
+ {
+ lldb::TypeSystemSP type_system_sp = create_callback(language, nullptr, target);
if (type_system_sp)
return type_system_sp;
}
@@ -91,3 +108,98 @@ TypeSystem::ShouldPrintAsOneLiner (void* type)
{
return eLazyBoolCalculate;
}
+
+#pragma mark TypeSystemMap
+
+TypeSystemMap::TypeSystemMap() :
+ m_mutex (),
+ m_map ()
+{
+}
+
+TypeSystemMap::~TypeSystemMap()
+{
+}
+
+void
+TypeSystemMap::Clear ()
+{
+ Mutex::Locker locker (m_mutex);
+ m_map.clear();
+}
+
+
+void
+TypeSystemMap::ForEach (std::function <bool(TypeSystem *)> const &callback)
+{
+ Mutex::Locker locker (m_mutex);
+ // Use a std::set so we only call the callback once for each unique
+ // TypeSystem instance
+ std::set<TypeSystem *> visited;
+ for (auto pair : m_map)
+ {
+ TypeSystem *type_system = pair.second.get();
+ if (type_system && !visited.count(type_system))
+ {
+ visited.insert(type_system);
+ if (callback (type_system) == false)
+ break;
+ }
+ }
+}
+
+TypeSystem *
+TypeSystemMap::GetTypeSystemForLanguage (lldb::LanguageType language, Module *module, bool can_create)
+{
+ Mutex::Locker locker (m_mutex);
+ collection::iterator pos = m_map.find(language);
+ if (pos != m_map.end())
+ return pos->second.get();
+
+ for (const auto &pair : m_map)
+ {
+ if (pair.second && pair.second->SupportsLanguage(language))
+ {
+ // Add a new mapping for "language" to point to an already existing
+ // TypeSystem that supports this language
+ m_map[language] = pair.second;
+ return pair.second.get();
+ }
+ }
+
+ if (!can_create)
+ return nullptr;
+
+ // Cache even if we get a shared pointer that contains null type system back
+ lldb::TypeSystemSP type_system_sp = TypeSystem::CreateInstance (language, module);
+ m_map[language] = type_system_sp;
+ return type_system_sp.get();
+}
+
+TypeSystem *
+TypeSystemMap::GetTypeSystemForLanguage (lldb::LanguageType language, Target *target, bool can_create)
+{
+ Mutex::Locker locker (m_mutex);
+ collection::iterator pos = m_map.find(language);
+ if (pos != m_map.end())
+ return pos->second.get();
+
+ for (const auto &pair : m_map)
+ {
+ if (pair.second && pair.second->SupportsLanguage(language))
+ {
+ // Add a new mapping for "language" to point to an already existing
+ // TypeSystem that supports this language
+ m_map[language] = pair.second;
+ return pair.second.get();
+ }
+ }
+
+ if (!can_create)
+ return nullptr;
+
+ // Cache even if we get a shared pointer that contains null type system back
+ lldb::TypeSystemSP type_system_sp = TypeSystem::CreateInstance (language, target);
+ m_map[language] = type_system_sp;
+ return type_system_sp.get();
+}
OpenPOWER on IntegriCloud