]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Expression/ClangExpressionParser.h
Merge ^/head r275623 through 275634.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Expression / ClangExpressionParser.h
1 //===-- ClangExpressionParser.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_ClangExpressionParser_h_
11 #define liblldb_ClangExpressionParser_h_
12
13 #include "lldb/lldb-public.h"
14 #include "lldb/Core/ArchSpec.h"
15 #include "lldb/Core/ClangForward.h"
16 #include "lldb/Core/Error.h"
17 #include "lldb/Expression/IRForTarget.h"
18
19 #include <string>
20 #include <vector>
21
22 namespace lldb_private
23 {
24
25 class IRExecutionUnit;
26     
27 //----------------------------------------------------------------------
28 /// @class ClangExpressionParser ClangExpressionParser.h "lldb/Expression/ClangExpressionParser.h"
29 /// @brief Encapsulates an instance of Clang that can parse expressions.
30 ///
31 /// ClangExpressionParser is responsible for preparing an instance of
32 /// ClangExpression for execution.  ClangExpressionParser uses ClangExpression
33 /// as a glorified parameter list, performing the required parsing and
34 /// conversion to formats (DWARF bytecode, or JIT compiled machine code)
35 /// that can be executed.
36 //----------------------------------------------------------------------
37 class ClangExpressionParser
38 {
39 public:
40     //------------------------------------------------------------------
41     /// Constructor
42     ///
43     /// Initializes class variables.
44     ///
45     /// @param[in] exe_scope,
46     ///     If non-NULL, an execution context scope that can help to 
47     ///     correctly create an expression with a valid process for 
48     ///     optional tuning Objective-C runtime support. Can be NULL.
49     ///
50     /// @param[in] expr
51     ///     The expression to be parsed.
52     //------------------------------------------------------------------
53     ClangExpressionParser (ExecutionContextScope *exe_scope,
54                            ClangExpression &expr,
55                            bool generate_debug_info);
56     
57     //------------------------------------------------------------------
58     /// Destructor
59     //------------------------------------------------------------------
60     ~ClangExpressionParser ();
61     
62     //------------------------------------------------------------------
63     /// Parse a single expression and convert it to IR using Clang.  Don't
64     /// wrap the expression in anything at all.
65     ///
66     /// @param[in] stream
67     ///     The stream to print errors to.
68     ///
69     /// @return
70     ///     The number of errors encountered during parsing.  0 means
71     ///     success.
72     //------------------------------------------------------------------
73     unsigned
74     Parse (Stream &stream);
75     
76     //------------------------------------------------------------------
77     /// Ready an already-parsed expression for execution, possibly
78     /// evaluating it statically.
79     ///
80     /// @param[out] func_addr
81     ///     The address to which the function has been written.
82     ///
83     /// @param[out] func_end
84     ///     The end of the function's allocated memory region.  (func_addr
85     ///     and func_end do not delimit an allocated region; the allocated
86     ///     region may begin before func_addr.)
87     ///
88     /// @param[in] execution_unit_sp
89     ///     After parsing, ownership of the execution unit for
90     ///     for the expression is handed to this shared pointer.
91     ///
92     /// @param[in] exe_ctx
93     ///     The execution context to write the function into.
94     ///
95     /// @param[out] evaluated_statically
96     ///     Set to true if the expression could be interpreted statically;
97     ///     untouched otherwise.
98     ///
99     /// @param[out] const_result
100     ///     If the result of the expression is constant, and the
101     ///     expression has no side effects, this is set to the result of the 
102     ///     expression.
103     ///
104     /// @param[in] execution_policy
105     ///     Determines whether the expression must be JIT-compiled, must be
106     ///     evaluated statically, or whether this decision may be made
107     ///     opportunistically.
108     ///
109     /// @return
110     ///     An error code indicating the success or failure of the operation.
111     ///     Test with Success().
112     //------------------------------------------------------------------
113     Error
114     PrepareForExecution (lldb::addr_t &func_addr,
115                          lldb::addr_t &func_end,
116                          std::shared_ptr<IRExecutionUnit> &execution_unit_sp,
117                          ExecutionContext &exe_ctx,
118                          bool &can_interpret,
119                          lldb_private::ExecutionPolicy execution_policy);
120         
121     //------------------------------------------------------------------
122     /// Disassemble the machine code for a JITted function from the target 
123     /// process's memory and print the result to a stream.
124     ///
125     /// @param[in] stream
126     ///     The stream to print disassembly to.
127     ///
128     /// @param[in] exc_context
129     ///     The execution context to get the machine code from.
130     ///
131     /// @return
132     ///     The error generated.  If .Success() is true, disassembly succeeded.
133     //------------------------------------------------------------------
134     Error
135     DisassembleFunction (Stream &stream, 
136                          ExecutionContext &exe_ctx);
137     
138     bool
139     GetGenerateDebugInfo () const;
140     
141 private:
142     ClangExpression &                       m_expr;                 ///< The expression to be parsed
143     std::unique_ptr<llvm::LLVMContext>       m_llvm_context;         ///< The LLVM context to generate IR into
144     std::unique_ptr<clang::FileManager>      m_file_manager;         ///< The Clang file manager object used by the compiler
145     std::unique_ptr<clang::CompilerInstance> m_compiler;             ///< The Clang compiler used to parse expressions into IR
146     std::unique_ptr<clang::Builtin::Context> m_builtin_context;      ///< Context for Clang built-ins
147     std::unique_ptr<clang::SelectorTable>    m_selector_table;       ///< Selector table for Objective-C methods
148     std::unique_ptr<clang::ASTContext>       m_ast_context;          ///< The AST context used to hold types and names for the parser
149     std::unique_ptr<clang::CodeGenerator>    m_code_generator;       ///< The Clang object that generates IR
150 };
151     
152 }
153
154 #endif  // liblldb_ClangExpressionParser_h_