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
17 #include "llvm/IR/LegacyPassManager.h"
19 #include "lldb/Expression/UserExpression.h"
21 namespace lldb_private {
23 //----------------------------------------------------------------------
24 /// @class LLVMUserExpression LLVMUserExpression.h
25 /// "lldb/Expression/LLVMUserExpression.h" Encapsulates a one-time expression
28 /// LLDB uses expressions for various purposes, notably to call functions
29 /// and as a backend for the expr command. LLVMUserExpression is a virtual
30 /// base class that encapsulates the objects needed to parse and JIT an
31 /// expression. The actual parsing part will be provided by the specific
32 /// implementations of LLVMUserExpression - which will be vended through the
33 /// appropriate TypeSystem.
34 //----------------------------------------------------------------------
35 class LLVMUserExpression : public UserExpression {
37 // The IRPasses struct is filled in by a runtime after an expression is
38 // compiled and can be used to to run fixups/analysis passes as required.
39 // EarlyPasses are run on the generated module before lldb runs its own IR
40 // fixups and inserts instrumentation code/pointer checks. LatePasses are run
41 // after the module has been processed by llvm, before the module is
42 // assembled and run in the ThreadPlan.
44 IRPasses() : EarlyPasses(nullptr), LatePasses(nullptr){};
45 std::shared_ptr<llvm::legacy::PassManager> EarlyPasses;
46 std::shared_ptr<llvm::legacy::PassManager> LatePasses;
49 LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
50 llvm::StringRef prefix, lldb::LanguageType language,
51 ResultType desired_type,
52 const EvaluateExpressionOptions &options);
53 ~LLVMUserExpression() override;
55 bool FinalizeJITExecution(
56 DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
57 lldb::ExpressionVariableSP &result,
58 lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS,
59 lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override;
61 bool CanInterpret() override { return m_can_interpret; }
63 //------------------------------------------------------------------
64 /// Return the string that the parser should parse. Must be a full
66 //------------------------------------------------------------------
67 const char *Text() override { return m_transformed_text.c_str(); }
69 lldb::ModuleSP GetJITModule() override;
72 lldb::ExpressionResults
73 DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
74 const EvaluateExpressionOptions &options,
75 lldb::UserExpressionSP &shared_ptr_to_me,
76 lldb::ExpressionVariableSP &result) override;
78 virtual void ScanContext(ExecutionContext &exe_ctx,
79 lldb_private::Status &err) = 0;
81 bool PrepareToExecuteJITExpression(DiagnosticManager &diagnostic_manager,
82 ExecutionContext &exe_ctx,
83 lldb::addr_t &struct_address);
85 virtual bool AddArguments(ExecutionContext &exe_ctx,
86 std::vector<lldb::addr_t> &args,
87 lldb::addr_t struct_address,
88 DiagnosticManager &diagnostic_manager) = 0;
91 m_stack_frame_bottom; ///< The bottom of the allocated stack frame.
92 lldb::addr_t m_stack_frame_top; ///< The top of the allocated stack frame.
94 bool m_allow_cxx; ///< True if the language allows C++.
95 bool m_allow_objc; ///< True if the language allows Objective-C.
97 m_transformed_text; ///< The text of the expression, as send to the parser
99 std::shared_ptr<IRExecutionUnit>
100 m_execution_unit_sp; ///< The execution unit the expression is stored in.
101 std::unique_ptr<Materializer> m_materializer_ap; ///< The materializer to use
104 lldb::ModuleWP m_jit_module_wp;
105 bool m_enforce_valid_object; ///< True if the expression parser should enforce
106 ///the presence of a valid class pointer
107 /// in order to generate the expression as a method.
108 bool m_in_cplusplus_method; ///< True if the expression is compiled as a C++
109 ///member function (true if it was parsed
110 /// when exe_ctx was in a C++ method).
111 bool m_in_objectivec_method; ///< True if the expression is compiled as an
112 ///Objective-C method (true if it was parsed
113 /// when exe_ctx was in an Objective-C method).
114 bool m_in_static_method; ///< True if the expression is compiled as a static
115 ///(or class) method (currently true if it
116 /// was parsed when exe_ctx was in an Objective-C class method).
117 bool m_needs_object_ptr; ///< True if "this" or "self" must be looked up and
118 ///passed in. False if the expression
119 /// doesn't really use them and they can be NULL.
120 bool m_const_object; ///< True if "this" is const.
121 Target *m_target; ///< The target for storing persistent data like types and
124 bool m_can_interpret; ///< True if the expression could be evaluated
125 ///statically; false otherwise.
126 lldb::addr_t m_materialized_address; ///< The address at which the arguments
127 ///to the expression have been
129 Materializer::DematerializerSP m_dematerializer_sp; ///< The dematerializer.
132 } // namespace lldb_private