Added support for locating a function that is
referenced in the IR.  We don't yet support updating
the call to that function.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@109483 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/IRForTarget.cpp b/source/Expression/IRForTarget.cpp
index ce28a8f..4f5d44c 100644
--- a/source/Expression/IRForTarget.cpp
+++ b/source/Expression/IRForTarget.cpp
@@ -82,7 +82,6 @@
 
 bool 
 IRForTarget::MaybeHandleVariable(Module &M, 
-                                 lldb_private::ClangExpressionDeclMap *DM,
                                  llvm::Value *V,
                                  bool Store)
 {
@@ -110,13 +109,13 @@
         size_t value_size = m_target_data->getTypeStoreSize(value_type);
         off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type);
         
-        if (named_decl && !DM->AddValueToStruct(V, 
-                                                named_decl,
-                                                name,
-                                                qual_type,
-                                                ast_context,
-                                                value_size, 
-                                                value_alignment))
+        if (named_decl && !m_decl_map->AddValueToStruct(V, 
+                                                        named_decl,
+                                                        name,
+                                                        qual_type,
+                                                        ast_context,
+                                                        value_size, 
+                                                        value_alignment))
             return false;
     }
     
@@ -124,6 +123,41 @@
 }
 
 bool
+IRForTarget::MaybeHandleCall(Module &M,
+                             CallInst *C)
+{
+    lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+
+    llvm::Function *fun = C->getCalledFunction();
+    
+    if (fun == NULL)
+        return true;
+    
+    clang::NamedDecl *fun_decl = DeclForGlobalValue(M, fun);
+    
+    if (!fun_decl)
+    {
+        if (log)
+            log->Printf("Function %s wasn't in the metadata", fun->getName().str().c_str());
+        return false;
+    }
+    
+    uint64_t fun_addr = m_decl_map->GetFunctionAddress(fun_decl);
+    
+    if (fun_addr == 0)
+    {
+        if (log)
+            log->Printf("Function %s had no address", fun_decl->getNameAsCString());
+        return false;
+    }
+        
+    if (log)
+        log->Printf("Found %s at %llx", fun_decl->getNameAsCString(), fun_addr);
+    
+    return true;
+}
+
+bool
 IRForTarget::runOnBasicBlock(Module &M, BasicBlock &BB)
 {        
     /////////////////////////////////////////////////////////////////////////
@@ -139,11 +173,15 @@
         Instruction &inst = *ii;
         
         if (LoadInst *load = dyn_cast<LoadInst>(&inst))
-            if (!MaybeHandleVariable(M, m_decl_map, load->getPointerOperand(), false))
+            if (!MaybeHandleVariable(M, load->getPointerOperand(), false))
                 return false;
         
         if (StoreInst *store = dyn_cast<StoreInst>(&inst))
-            if (!MaybeHandleVariable(M, m_decl_map, store->getPointerOperand(), false))
+            if (!MaybeHandleVariable(M, store->getPointerOperand(), true))
+                return false;
+        
+        if (CallInst *call = dyn_cast<CallInst>(&inst))
+            if (!MaybeHandleCall(M, call))
                 return false;
     }