IRInterpreter.h revision 0f0551e67d8ea8d63ace5456f7d42d951827b017
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/ADT/ArrayRef.h"
18#include "llvm/Pass.h"
19
20namespace llvm {
21    class Function;
22    class Module;
23}
24
25namespace lldb_private {
26
27class ClangExpressionDeclMap;
28class IRMemoryMap;
29
30}
31
32//----------------------------------------------------------------------
33/// @class IRInterpreter IRInterpreter.h "lldb/Expression/IRInterpreter.h"
34/// @brief Attempt to interpret the function's code if it does not require
35///        running the target.
36///
37/// In some cases, the IR for an expression can be evaluated entirely
38/// in the debugger, manipulating variables but not executing any code
39/// in the target.  The IRInterpreter attempts to do this.
40//----------------------------------------------------------------------
41class IRInterpreter
42{
43public:
44    //------------------------------------------------------------------
45    /// Run the IR interpreter on a single function
46    ///
47    /// @param[in] result
48    ///     This variable is populated with the return value of the
49    ///     function, if it could be interpreted completely.
50    ///
51    /// @param[in] result_name
52    ///     The name of the result in the IR.  If this name got a
53    ///     value written to it as part of execution, then that value
54    ///     will be used to create the result variable.
55    ///
56    /// @param[in] result_type
57    ///     The type of the result.
58    ///
59    /// @param[in] llvm_function
60    ///     The function to interpret.
61    ///
62    /// @param[in] llvm_module
63    ///     The module containing the function.
64    ///
65    /// @param[in] error
66    ///     If the expression fails to interpret, a reason why.
67    ///
68    /// @return
69    ///     True on success; false otherwise
70    //------------------------------------------------------------------
71    static bool
72    maybeRunOnFunction (lldb_private::ClangExpressionDeclMap *decl_map,
73                        lldb_private::IRMemoryMap &memory_map,
74                        lldb_private::Stream *error_stream,
75                        lldb::ClangExpressionVariableSP &result,
76                        const lldb_private::ConstString &result_name,
77                        lldb_private::TypeFromParser result_type,
78                        llvm::Function &llvm_function,
79                        llvm::Module &llvm_module,
80                        lldb_private::Error &err);
81
82    // new api
83
84    static bool
85    CanInterpret (llvm::Module &module,
86                  llvm::Function &function,
87                  lldb_private::Error &error);
88
89    static bool
90    Interpret (llvm::Module &module,
91               llvm::Function &function,
92               llvm::ArrayRef<lldb::addr_t> args,
93               lldb_private::IRMemoryMap &memory_map,
94               lldb_private::Error &error);
95
96private:
97    static bool
98    supportsFunction (llvm::Function &llvm_function,
99                      lldb_private::Error &err);
100
101    static bool
102    runOnFunction (lldb_private::ClangExpressionDeclMap *decl_map,
103                   lldb_private::IRMemoryMap &memory_map,
104                   lldb_private::Stream *error_stream,
105                   lldb::ClangExpressionVariableSP &result,
106                   const lldb_private::ConstString &result_name,
107                   lldb_private::TypeFromParser result_type,
108                   llvm::Function &llvm_function,
109                   llvm::Module &llvm_module,
110                   lldb_private::Error &err);
111};
112
113#endif
114