IRInterpreter.h revision e804caf35c6cca4b42ff609ded7e4dc6f22c6eba
1//===-- IRInterpreter.h -----------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef liblldb_IRInterpreter_h_ 11#define liblldb_IRInterpreter_h_ 12 13#include "lldb/lldb-public.h" 14#include "lldb/Core/ConstString.h" 15#include "lldb/Core/Stream.h" 16#include "lldb/Symbol/TaggedASTType.h" 17#include "llvm/Pass.h" 18 19namespace llvm { 20 class Function; 21 class Module; 22} 23 24namespace lldb_private { 25 26class ClangExpressionDeclMap; 27class IRMemoryMap; 28 29} 30 31//---------------------------------------------------------------------- 32/// @class IRInterpreter IRInterpreter.h "lldb/Expression/IRInterpreter.h" 33/// @brief Attempt to interpret the function's code if it does not require 34/// running the target. 35/// 36/// In some cases, the IR for an expression can be evaluated entirely 37/// in the debugger, manipulating variables but not executing any code 38/// in the target. The IRInterpreter attempts to do this. 39//---------------------------------------------------------------------- 40class IRInterpreter 41{ 42public: 43 //------------------------------------------------------------------ 44 /// Constructor 45 /// 46 /// @param[in] decl_map 47 /// The list of externally-referenced variables for the expression, 48 /// for use in looking up globals and allocating the argument 49 /// struct. See the documentation for ClangExpressionDeclMap. 50 /// 51 /// @param[in] error_stream 52 /// If non-NULL, a stream on which errors can be printed. 53 //------------------------------------------------------------------ 54 IRInterpreter(lldb_private::ClangExpressionDeclMap *decl_map, 55 lldb_private::IRMemoryMap &memory_map, 56 lldb_private::Stream *error_stream); 57 58 //------------------------------------------------------------------ 59 /// Destructor 60 //------------------------------------------------------------------ 61 ~IRInterpreter(); 62 63 //------------------------------------------------------------------ 64 /// Run the IR interpreter on a single function 65 /// 66 /// @param[in] result 67 /// This variable is populated with the return value of the 68 /// function, if it could be interpreted completely. 69 /// 70 /// @param[in] result_name 71 /// The name of the result in the IR. If this name got a 72 /// value written to it as part of execution, then that value 73 /// will be used to create the result variable. 74 /// 75 /// @param[in] result_type 76 /// The type of the result. 77 /// 78 /// @param[in] llvm_function 79 /// The function to interpret. 80 /// 81 /// @param[in] llvm_module 82 /// The module containing the function. 83 /// 84 /// @param[in] error 85 /// If the expression fails to interpret, a reason why. 86 /// 87 /// @return 88 /// True on success; false otherwise 89 //------------------------------------------------------------------ 90 bool 91 maybeRunOnFunction (lldb::ClangExpressionVariableSP &result, 92 const lldb_private::ConstString &result_name, 93 lldb_private::TypeFromParser result_type, 94 llvm::Function &llvm_function, 95 llvm::Module &llvm_module, 96 lldb_private::Error &err); 97private: 98 lldb_private::ClangExpressionDeclMap *m_decl_map; ///< The DeclMap containing the Decls 99 lldb_private::IRMemoryMap &m_memory_map; ///< The IRMemoryMap to use when accessing memory 100 101 bool 102 supportsFunction (llvm::Function &llvm_function, 103 lldb_private::Error &err); 104 105 bool 106 runOnFunction (lldb::ClangExpressionVariableSP &result, 107 const lldb_private::ConstString &result_name, 108 lldb_private::TypeFromParser result_type, 109 llvm::Function &llvm_function, 110 llvm::Module &llvm_module, 111 lldb_private::Error &err); 112}; 113 114#endif 115