[Lldb-commits] [lldb] r269407 - [LLDB][MIPS] Provide ABI string to compiler for appropriate code generation for MIPS

Sagar Thakur via lldb-commits lldb-commits at lists.llvm.org
Fri May 13 04:04:48 PDT 2016


Author: slthakur
Date: Fri May 13 06:04:47 2016
New Revision: 269407

URL: http://llvm.org/viewvc/llvm-project?rev=269407&view=rev
Log:
[LLDB][MIPS] Provide ABI string to compiler for appropriate code generation for MIPS

Patch by Nitesh Jain.

Summary: These patch will set clang::TargetOptions::ABI and accordingly code will be generated for MIPS target.

Reviewers: ovyalov, clayborg
Subscribers: lldb-commits, mohit.bhakkad, sagar, jaydeep, bhushan
Differential: D18638

Modified:
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=269407&r1=269406&r2=269407&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Fri May 13 06:04:47 2016
@@ -286,7 +286,8 @@ ClangExpressionParser::ClangExpressionPa
     lldb::LanguageType frame_lang = expr.Language(); // defaults to lldb::eLanguageTypeUnknown
     bool overridden_target_opts = false;
     lldb_private::LanguageRuntime *lang_rt = nullptr;
-    
+
+    std::string abi;
     ArchSpec target_arch;
     target_arch = target_sp->GetArchitecture();
 
@@ -350,6 +351,11 @@ ClangExpressionParser::ClangExpressionPa
     // 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();
 
+    // Set the target ABI
+    abi = GetClangTargetABI(target_arch);
+    if (!abi.empty())
+        m_compiler->getTargetOpts().ABI = abi;
+
     // 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.
@@ -658,6 +664,29 @@ ClangExpressionParser::Parse(DiagnosticM
     return num_errors;
 }
 
+std::string
+ClangExpressionParser::GetClangTargetABI (const ArchSpec &target_arch)
+{
+    std::string abi;
+    const llvm::Triple::ArchType machine = target_arch.GetMachine();
+    
+    if(target_arch.IsMIPS())
+    {
+       switch (target_arch.GetFlags () & ArchSpec::eMIPSABI_mask)
+       {
+       case ArchSpec::eMIPSABI_N64:
+            abi = "n64"; break;
+       case ArchSpec::eMIPSABI_N32:
+            abi = "n32"; break;
+       case ArchSpec::eMIPSABI_O32:
+            abi = "o32"; break;
+       default:
+              break;
+       }
+    }
+    return abi;
+}
+
 bool
 ClangExpressionParser::RewriteExpression(DiagnosticManager &diagnostic_manager)
 {

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h?rev=269407&r1=269406&r2=269407&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h Fri May 13 06:04:47 2016
@@ -137,7 +137,19 @@ public:
     Error
     RunStaticInitializers (lldb::IRExecutionUnitSP &execution_unit_sp,
                            ExecutionContext &exe_ctx);
-        
+
+    //------------------------------------------------------------------
+    /// Returns a string representing current ABI.
+    ///
+    /// @param[in] target_arch
+    ///     The target architecture.
+    ///
+    /// @return
+    ///     A string representing target ABI for the current architecture.
+    //-------------------------------------------------------------------
+    std::string
+    GetClangTargetABI (const ArchSpec &target_arch);
+ 
 private:
     std::unique_ptr<llvm::LLVMContext>       m_llvm_context;         ///< The LLVM context to generate IR into
     std::unique_ptr<clang::FileManager>      m_file_manager;         ///< The Clang file manager object used by the compiler




More information about the lldb-commits mailing list