diff --git a/lldb/include/lldb/Expression/IRForTarget.h b/lldb/include/lldb/Expression/IRForTarget.h index d77a8e98346f..e60c5f068bc8 100644 --- a/lldb/include/lldb/Expression/IRForTarget.h +++ b/lldb/include/lldb/Expression/IRForTarget.h @@ -19,7 +19,6 @@ namespace llvm { class Function; class Instruction; class Module; - class TargetData; class Value; } @@ -52,11 +51,6 @@ public: /// for use in looking up globals and allocating the argument /// struct. See the documentation for ClangExpressionDeclMap. /// - /// @param[in] target_data - /// The data layout information for the target. This information is - /// used to determine the sizes of types that have been lowered into - /// IR types. - /// /// @param[in] func_name /// The name of the function to prepare for execution in the target. /// @@ -66,7 +60,6 @@ public: /// are resolved. //------------------------------------------------------------------ IRForTarget(lldb_private::ClangExpressionDeclMap *decl_map, - const llvm::TargetData *target_data, bool resolve_vars, const char* func_name = "___clang_expr"); @@ -305,7 +298,6 @@ private: std::string m_func_name; ///< The name of the function to translate lldb_private::ClangExpressionDeclMap *m_decl_map; ///< The DeclMap containing the Decls - const llvm::TargetData *m_target_data; ///< The TargetData for use in determining type sizes llvm::Constant *m_sel_registerName; ///< The address of the function sel_registerName, cast to the appropriate function pointer type }; diff --git a/lldb/source/Expression/ClangExpressionParser.cpp b/lldb/source/Expression/ClangExpressionParser.cpp index ec385a4cd041..194a90d22bd3 100644 --- a/lldb/source/Expression/ClangExpressionParser.cpp +++ b/lldb/source/Expression/ClangExpressionParser.cpp @@ -436,21 +436,7 @@ ClangExpressionParser::MakeJIT (lldb::addr_t &func_addr, if (decl_map) { - std::string target_error; - - const llvm::Target *target = llvm::TargetRegistry::lookupTarget(m_target_triple, target_error); - - if (!target) - { - err.SetErrorToGenericError(); - err.SetErrorStringWithFormat("Couldn't find a target for %s", m_target_triple.c_str()); - return err; - } - - std::auto_ptr target_machine(target->createTargetMachine(m_target_triple, "")); - IRForTarget ir_for_target(decl_map, - target_machine->getTargetData(), m_expr.NeedsVariableResolution(), function_name.c_str()); diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp index 6ddd6c1d7402..662c086373b4 100644 --- a/lldb/source/Expression/IRForTarget.cpp +++ b/lldb/source/Expression/IRForTarget.cpp @@ -32,22 +32,20 @@ using namespace llvm; static char ID; IRForTarget::IRForTarget(lldb_private::ClangExpressionDeclMap *decl_map, - const TargetData *target_data, bool resolve_vars, const char *func_name) : ModulePass(ID), m_decl_map(decl_map), - m_target_data(target_data), m_sel_registerName(NULL), m_func_name(func_name), m_resolve_vars(resolve_vars) { } -/* A handy utility function used at several places in the code */ +/* Handy utility functions used at several places in the code */ static std::string -PrintValue(Value *V, bool truncate = false) +PrintValue(const Value *V, bool truncate = false) { std::string s; raw_string_ostream rso(s); @@ -58,6 +56,18 @@ PrintValue(Value *V, bool truncate = false) return s; } +static std::string +PrintType(const Type *T, bool truncate = false) +{ + std::string s; + raw_string_ostream rso(s); + T->print(rso); + rso.flush(); + if (truncate) + s.resize(s.length() - 1); + return s; +} + IRForTarget::~IRForTarget() { } @@ -578,23 +588,34 @@ IRForTarget::MaybeHandleVariable(Module &M, std::string name = named_decl->getName().str(); - void *qual_type = NULL; + void *opaque_type = NULL; clang::ASTContext *ast_context = NULL; if (clang::ValueDecl *value_decl = dyn_cast(named_decl)) { - qual_type = value_decl->getType().getAsOpaquePtr(); + opaque_type = value_decl->getType().getAsOpaquePtr(); ast_context = &value_decl->getASTContext(); } else { return false; } + + clang::QualType qual_type(clang::QualType::getFromOpaquePtr(opaque_type)); const Type *value_type = global_variable->getType(); - - size_t value_size = m_target_data->getTypeStoreSize(value_type); - off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type); + + size_t value_size = (ast_context->getTypeSize(qual_type) + 7) / 8; + off_t value_alignment = (ast_context->getTypeAlign(qual_type) + 7) / 8; + + if (log) + log->Printf("Type of %s is [clang %s, lldb %s] [size %d, align %d]", + name.c_str(), + qual_type.getAsString().c_str(), + PrintType(value_type).c_str(), + value_size, + value_alignment); + if (named_decl && !m_decl_map->AddValueToStruct(named_decl, name.c_str(), @@ -1103,6 +1124,13 @@ IRForTarget::runOnModule(Module &M) return false; } + /////////////////////////////// + // Run function-level passes + // + + if (!replaceVariables(M, *function)) + return false; + if (log) { std::string s; @@ -1115,13 +1143,6 @@ IRForTarget::runOnModule(Module &M) log->Printf("Module after preparing for execution: \n%s", s.c_str()); } - /////////////////////////////// - // Run function-level passes - // - - if (!replaceVariables(M, *function)) - return false; - return true; }