1 //===-- LLVMUserExpression.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_LLVMUserExpression_h
11 #define liblldb_LLVMUserExpression_h
19 // Other libraries and framework includes
20 #include "llvm/IR/LegacyPassManager.h"
23 #include "lldb/Expression/UserExpression.h"
25 namespace lldb_private {
27 //----------------------------------------------------------------------
28 /// @class LLVMUserExpression LLVMUserExpression.h
29 /// "lldb/Expression/LLVMUserExpression.h" Encapsulates a one-time expression
32 /// LLDB uses expressions for various purposes, notably to call functions
33 /// and as a backend for the expr command. LLVMUserExpression is a virtual
34 /// base class that encapsulates the objects needed to parse and JIT an
35 /// expression. The actual parsing part will be provided by the specific
36 /// implementations of LLVMUserExpression - which will be vended through the
37 /// appropriate TypeSystem.
38 //----------------------------------------------------------------------
39 class LLVMUserExpression : public UserExpression {
41 // The IRPasses struct is filled in by a runtime after an expression is
42 // compiled and can be used to to run fixups/analysis passes as required.
43 // EarlyPasses are run on the generated module before lldb runs its own IR
44 // fixups and inserts instrumentation code/pointer checks. LatePasses are run
45 // after the module has been processed by llvm, before the module is
46 // assembled and run in the ThreadPlan.
48 IRPasses() : EarlyPasses(nullptr), LatePasses(nullptr){};
49 std::shared_ptr<llvm::legacy::PassManager> EarlyPasses;
50 std::shared_ptr<llvm::legacy::PassManager> LatePasses;
53 LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
54 llvm::StringRef prefix, lldb::LanguageType language,
55 ResultType desired_type,
56 const EvaluateExpressionOptions &options);
57 ~LLVMUserExpression() override;
59 bool FinalizeJITExecution(
60 DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
61 lldb::ExpressionVariableSP &result,
62 lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS,
63 lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override;
65 bool CanInterpret() override { return m_can_interpret; }
67 //------------------------------------------------------------------
68 /// Return the string that the parser should parse. Must be a full
70 //------------------------------------------------------------------
71 const char *Text() override { return m_transformed_text.c_str(); }
73 lldb::ModuleSP GetJITModule() override;
76 lldb::ExpressionResults
77 DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
78 const EvaluateExpressionOptions &options,
79 lldb::UserExpressionSP &shared_ptr_to_me,
80 lldb::ExpressionVariableSP &result) override;
82 virtual void ScanContext(ExecutionContext &exe_ctx,
83 lldb_private::Status &err) = 0;
85 bool PrepareToExecuteJITExpression(DiagnosticManager &diagnostic_manager,
86 ExecutionContext &exe_ctx,
87 lldb::addr_t &struct_address);
89 virtual bool AddArguments(ExecutionContext &exe_ctx,
90 std::vector<lldb::addr_t> &args,
91 lldb::addr_t struct_address,
92 DiagnosticManager &diagnostic_manager) = 0;
95 m_stack_frame_bottom; ///< The bottom of the allocated stack frame.
96 lldb::addr_t m_stack_frame_top; ///< The top of the allocated stack frame.
98 bool m_allow_cxx; ///< True if the language allows C++.
99 bool m_allow_objc; ///< True if the language allows Objective-C.
101 m_transformed_text; ///< The text of the expression, as send to the parser
103 std::shared_ptr<IRExecutionUnit>
104 m_execution_unit_sp; ///< The execution unit the expression is stored in.
105 std::unique_ptr<Materializer> m_materializer_ap; ///< The materializer to use
108 lldb::ModuleWP m_jit_module_wp;
109 bool m_enforce_valid_object; ///< True if the expression parser should enforce
110 ///the presence of a valid class pointer
111 /// in order to generate the expression as a method.
112 bool m_in_cplusplus_method; ///< True if the expression is compiled as a C++
113 ///member function (true if it was parsed
114 /// when exe_ctx was in a C++ method).
115 bool m_in_objectivec_method; ///< True if the expression is compiled as an
116 ///Objective-C method (true if it was parsed
117 /// when exe_ctx was in an Objective-C method).
118 bool m_in_static_method; ///< True if the expression is compiled as a static
119 ///(or class) method (currently true if it
120 /// was parsed when exe_ctx was in an Objective-C class method).
121 bool m_needs_object_ptr; ///< True if "this" or "self" must be looked up and
122 ///passed in. False if the expression
123 /// doesn't really use them and they can be NULL.
124 bool m_const_object; ///< True if "this" is const.
125 Target *m_target; ///< The target for storing persistent data like types and
128 bool m_can_interpret; ///< True if the expression could be evaluated
129 ///statically; false otherwise.
130 lldb::addr_t m_materialized_address; ///< The address at which the arguments
131 ///to the expression have been
133 Materializer::DematerializerSP m_dematerializer_sp; ///< The dematerializer.
136 } // namespace lldb_private