summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Core/ArchSpec.h10
-rw-r--r--lldb/source/Core/ArchSpec.cpp50
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp18
3 files changed, 74 insertions, 4 deletions
diff --git a/lldb/include/lldb/Core/ArchSpec.h b/lldb/include/lldb/Core/ArchSpec.h
index 96e83dba7bb..70ac9548a7f 100644
--- a/lldb/include/lldb/Core/ArchSpec.h
+++ b/lldb/include/lldb/Core/ArchSpec.h
@@ -288,6 +288,16 @@ public:
GetArchitectureName () const;
//------------------------------------------------------------------
+ /// Returns a string representing current architecture as a target CPU
+ /// for tools like compiler, disassembler etc.
+ ///
+ /// @return A string representing target CPU for the current
+ /// architecture.
+ //------------------------------------------------------------------
+ std::string
+ GetClangTargetCPU ();
+
+ //------------------------------------------------------------------
/// Clears the object state.
///
/// Clears the object state back to a default invalid state.
diff --git a/lldb/source/Core/ArchSpec.cpp b/lldb/source/Core/ArchSpec.cpp
index 6fdc6b666a4..a1fb65f0463 100644
--- a/lldb/source/Core/ArchSpec.cpp
+++ b/lldb/source/Core/ArchSpec.cpp
@@ -511,6 +511,56 @@ ArchSpec::GetArchitectureName () const
return "unknown";
}
+std::string
+ArchSpec::GetClangTargetCPU ()
+{
+ std::string cpu;
+ const llvm::Triple::ArchType machine = GetMachine();
+
+ if (machine == llvm::Triple::mips ||
+ machine == llvm::Triple::mipsel ||
+ machine == llvm::Triple::mips64 ||
+ machine == llvm::Triple::mips64el)
+ {
+ switch (m_core)
+ {
+ case ArchSpec::eCore_mips32:
+ case ArchSpec::eCore_mips32el:
+ cpu = "mips32"; break;
+ case ArchSpec::eCore_mips32r2:
+ case ArchSpec::eCore_mips32r2el:
+ cpu = "mips32r2"; break;
+ case ArchSpec::eCore_mips32r3:
+ case ArchSpec::eCore_mips32r3el:
+ cpu = "mips32r3"; break;
+ case ArchSpec::eCore_mips32r5:
+ case ArchSpec::eCore_mips32r5el:
+ cpu = "mips32r5"; break;
+ case ArchSpec::eCore_mips32r6:
+ case ArchSpec::eCore_mips32r6el:
+ cpu = "mips32r6"; break;
+ case ArchSpec::eCore_mips64:
+ case ArchSpec::eCore_mips64el:
+ cpu = "mips64"; break;
+ case ArchSpec::eCore_mips64r2:
+ case ArchSpec::eCore_mips64r2el:
+ cpu = "mips64r2"; break;
+ case ArchSpec::eCore_mips64r3:
+ case ArchSpec::eCore_mips64r3el:
+ cpu = "mips64r3"; break;
+ case ArchSpec::eCore_mips64r5:
+ case ArchSpec::eCore_mips64r5el:
+ cpu = "mips64r5"; break;
+ case ArchSpec::eCore_mips64r6:
+ case ArchSpec::eCore_mips64r6el:
+ cpu = "mips64r6"; break;
+ default:
+ break;
+ }
+ }
+ return cpu;
+}
+
uint32_t
ArchSpec::GetMachOCPUType () const
{
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index f99ebd26f90..7e583cf0a07 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -179,6 +179,12 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
if (exe_scope)
target_sp = exe_scope->CalculateTarget();
+ ArchSpec target_arch;
+ if (target_sp)
+ target_arch = target_sp->GetArchitecture();
+
+ const auto target_machine = target_arch.GetMachine();
+
// If the expression is being evaluated in the context of an existing
// stack frame, we introspect to see if the language runtime is available.
auto frame = exe_scope->CalculateStackFrame();
@@ -197,9 +203,9 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
// 2. Configure the compiler with a set of default options that are appropriate
// for most situations.
- if (target_sp && target_sp->GetArchitecture().IsValid())
+ if (target_sp && target_arch.IsValid())
{
- std::string triple = target_sp->GetArchitecture().GetTriple().str();
+ std::string triple = target_arch.GetTriple().str();
m_compiler->getTargetOpts().Triple = triple;
if (log)
log->Printf("Using %s as the target triple", m_compiler->getTargetOpts().Triple.c_str());
@@ -224,13 +230,17 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
m_compiler->getTargetOpts().ABI = "apcs-gnu";
}
// Supported subsets of x86
- if (target_sp->GetArchitecture().GetMachine() == llvm::Triple::x86 ||
- target_sp->GetArchitecture().GetMachine() == llvm::Triple::x86_64)
+ if (target_machine == llvm::Triple::x86 ||
+ target_machine == llvm::Triple::x86_64)
{
m_compiler->getTargetOpts().Features.push_back("+sse");
m_compiler->getTargetOpts().Features.push_back("+sse2");
}
+ // Set the target CPU to generate code for.
+ // This will be empty for any CPU that doesn't really need to make a special CPU string.
+ m_compiler->getTargetOpts().CPU = target_arch.GetClangTargetCPU();
+
// 3. Now allow the runtime to provide custom configuration options for the target.
// In this case, a specialized language runtime is available and we can query it for extra options.
// For 99% of use cases, this will not be needed and should be provided when basic platform detection is not enough.
OpenPOWER on IntegriCloud