Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:47

0001 //===-- LLVMUserExpression.h ------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_EXPRESSION_LLVMUSEREXPRESSION_H
0010 #define LLDB_EXPRESSION_LLVMUSEREXPRESSION_H
0011 
0012 #include <map>
0013 #include <string>
0014 #include <vector>
0015 
0016 #include "llvm/IR/LegacyPassManager.h"
0017 
0018 #include "lldb/Expression/UserExpression.h"
0019 
0020 namespace lldb_private {
0021 
0022 /// \class LLVMUserExpression LLVMUserExpression.h
0023 /// "lldb/Expression/LLVMUserExpression.h" Encapsulates a one-time expression
0024 /// for use in lldb.
0025 ///
0026 /// LLDB uses expressions for various purposes, notably to call functions
0027 /// and as a backend for the expr command.  LLVMUserExpression is a virtual
0028 /// base class that encapsulates the objects needed to parse and JIT an
0029 /// expression. The actual parsing part will be provided by the specific
0030 /// implementations of LLVMUserExpression - which will be vended through the
0031 /// appropriate TypeSystem.
0032 class LLVMUserExpression : public UserExpression {
0033   // LLVM RTTI support
0034   static char ID;
0035 
0036 public:
0037   bool isA(const void *ClassID) const override {
0038     return ClassID == &ID || UserExpression::isA(ClassID);
0039   }
0040   static bool classof(const Expression *obj) { return obj->isA(&ID); }
0041 
0042   // The IRPasses struct is filled in by a runtime after an expression is
0043   // compiled and can be used to run fixups/analysis passes as required.
0044   // EarlyPasses are run on the generated module before lldb runs its own IR
0045   // fixups and inserts instrumentation code/pointer checks. LatePasses are run
0046   // after the module has been processed by llvm, before the module is
0047   // assembled and run in the ThreadPlan.
0048   struct IRPasses {
0049     IRPasses() : EarlyPasses(nullptr), LatePasses(nullptr){};
0050     std::shared_ptr<llvm::legacy::PassManager> EarlyPasses;
0051     std::shared_ptr<llvm::legacy::PassManager> LatePasses;
0052   };
0053 
0054   LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
0055                      llvm::StringRef prefix, SourceLanguage language,
0056                      ResultType desired_type,
0057                      const EvaluateExpressionOptions &options);
0058   ~LLVMUserExpression() override;
0059 
0060   bool FinalizeJITExecution(
0061       DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
0062       lldb::ExpressionVariableSP &result,
0063       lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS,
0064       lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override;
0065 
0066   bool CanInterpret() override { return m_can_interpret; }
0067 
0068   Materializer *GetMaterializer() override { return m_materializer_up.get(); }
0069 
0070   /// Return the string that the parser should parse.  Must be a full
0071   /// translation unit.
0072   const char *Text() override { return m_transformed_text.c_str(); }
0073 
0074 protected:
0075   lldb::ExpressionResults
0076   DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
0077             const EvaluateExpressionOptions &options,
0078             lldb::UserExpressionSP &shared_ptr_to_me,
0079             lldb::ExpressionVariableSP &result) override;
0080 
0081   virtual void ScanContext(ExecutionContext &exe_ctx,
0082                            lldb_private::Status &err) = 0;
0083 
0084   bool PrepareToExecuteJITExpression(DiagnosticManager &diagnostic_manager,
0085                                      ExecutionContext &exe_ctx,
0086                                      lldb::addr_t &struct_address);
0087 
0088   virtual bool AddArguments(ExecutionContext &exe_ctx,
0089                             std::vector<lldb::addr_t> &args,
0090                             lldb::addr_t struct_address,
0091                             DiagnosticManager &diagnostic_manager) = 0;
0092 
0093   lldb::addr_t
0094       m_stack_frame_bottom;       ///< The bottom of the allocated stack frame.
0095   lldb::addr_t m_stack_frame_top; ///< The top of the allocated stack frame.
0096 
0097   bool m_allow_cxx;  ///< True if the language allows C++.
0098   bool m_allow_objc; ///< True if the language allows Objective-C.
0099   std::string
0100       m_transformed_text; ///< The text of the expression, as send to the parser
0101 
0102   std::shared_ptr<IRExecutionUnit>
0103       m_execution_unit_sp; ///< The execution unit the expression is stored in.
0104   std::unique_ptr<Materializer> m_materializer_up; ///< The materializer to use
0105                                                    /// when running the
0106                                                    /// expression.
0107   lldb::ModuleWP m_jit_module_wp;
0108   Target *m_target; ///< The target for storing persistent data like types and
0109                     ///variables.
0110 
0111   bool m_can_interpret; ///< True if the expression could be evaluated
0112                         ///statically; false otherwise.
0113   lldb::addr_t m_materialized_address; ///< The address at which the arguments
0114                                        ///to the expression have been
0115                                        ///materialized.
0116   Materializer::DematerializerSP m_dematerializer_sp; ///< The dematerializer.
0117 };
0118 
0119 } // namespace lldb_private
0120 #endif