| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 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 |  | 
| Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 13 | #include "lldb/lldb-public.h" | 
| Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 14 | #include "lldb/Core/ArchSpec.h" | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 15 | #include "lldb/Core/ClangForward.h" | 
|  | 16 | #include "lldb/Core/Error.h" | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 17 | #include "lldb/Expression/ExpressionParser.h" | 
| Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 18 |  | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 19 | #include <string> | 
|  | 20 | #include <vector> | 
|  | 21 |  | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 22 | namespace lldb_private | 
|  | 23 | { | 
|  | 24 |  | 
| Sean Callanan | 8dfb68e | 2013-03-19 00:10:07 +0000 | [diff] [blame] | 25 | class IRExecutionUnit; | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 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 | //---------------------------------------------------------------------- | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 37 | class ClangExpressionParser : public ExpressionParser | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 38 | { | 
|  | 39 | public: | 
|  | 40 | //------------------------------------------------------------------ | 
|  | 41 | /// Constructor | 
|  | 42 | /// | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 43 | /// Initializes class variables. | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 44 | /// | 
| Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 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. | 
| Sean Callanan | c3a1600 | 2011-01-17 23:42:46 +0000 | [diff] [blame] | 49 | /// | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 50 | /// @param[in] expr | 
|  | 51 | ///     The expression to be parsed. | 
|  | 52 | //------------------------------------------------------------------ | 
| Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 53 | ClangExpressionParser (ExecutionContextScope *exe_scope, | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 54 | Expression &expr, | 
| Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 55 | bool generate_debug_info); | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 56 |  | 
|  | 57 | //------------------------------------------------------------------ | 
|  | 58 | /// Destructor | 
|  | 59 | //------------------------------------------------------------------ | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 60 | ~ClangExpressionParser () override; | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 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 | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 74 | Parse (Stream &stream) override; | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 75 |  | 
|  | 76 | //------------------------------------------------------------------ | 
| Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 77 | /// Ready an already-parsed expression for execution, possibly | 
|  | 78 | /// evaluating it statically. | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 79 | /// | 
|  | 80 | /// @param[out] func_addr | 
|  | 81 | ///     The address to which the function has been written. | 
|  | 82 | /// | 
| Sean Callanan | e71d553 | 2010-08-27 23:31:21 +0000 | [diff] [blame] | 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 | /// | 
| Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 88 | /// @param[in] execution_unit_sp | 
| Sean Callanan | 5a1af4e | 2013-04-05 02:22:57 +0000 | [diff] [blame] | 89 | ///     After parsing, ownership of the execution unit for | 
| Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 90 | ///     for the expression is handed to this shared pointer. | 
| Sean Callanan | 5a1af4e | 2013-04-05 02:22:57 +0000 | [diff] [blame] | 91 | /// | 
| Sean Callanan | e71d553 | 2010-08-27 23:31:21 +0000 | [diff] [blame] | 92 | /// @param[in] exe_ctx | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 93 | ///     The execution context to write the function into. | 
|  | 94 | /// | 
| Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 95 | /// @param[out] evaluated_statically | 
|  | 96 | ///     Set to true if the expression could be interpreted statically; | 
|  | 97 | ///     untouched otherwise. | 
| Sean Callanan | 79763a4 | 2011-05-23 21:40:23 +0000 | [diff] [blame] | 98 | /// | 
| Sean Callanan | e4ec90e | 2010-12-16 03:17:46 +0000 | [diff] [blame] | 99 | /// @param[out] const_result | 
| Sean Callanan | 63697e5 | 2011-05-07 01:06:41 +0000 | [diff] [blame] | 100 | ///     If the result of the expression is constant, and the | 
| Sean Callanan | e4ec90e | 2010-12-16 03:17:46 +0000 | [diff] [blame] | 101 | ///     expression has no side effects, this is set to the result of the | 
| Sean Callanan | 63697e5 | 2011-05-07 01:06:41 +0000 | [diff] [blame] | 102 | ///     expression. | 
|  | 103 | /// | 
| Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 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. | 
| Sean Callanan | e4ec90e | 2010-12-16 03:17:46 +0000 | [diff] [blame] | 108 | /// | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 109 | /// @return | 
|  | 110 | ///     An error code indicating the success or failure of the operation. | 
|  | 111 | ///     Test with Success(). | 
|  | 112 | //------------------------------------------------------------------ | 
|  | 113 | Error | 
| Sean Callanan | 8dfb68e | 2013-03-19 00:10:07 +0000 | [diff] [blame] | 114 | PrepareForExecution (lldb::addr_t &func_addr, | 
| Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 115 | lldb::addr_t &func_end, | 
| Jim Ingham | c29e698 | 2015-11-05 01:50:42 +0000 | [diff] [blame^] | 116 | lldb::IRExecutionUnitSP &execution_unit_sp, | 
| Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 117 | ExecutionContext &exe_ctx, | 
| Sean Callanan | 1582ee6 | 2013-04-18 22:06:33 +0000 | [diff] [blame] | 118 | bool &can_interpret, | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 119 | lldb_private::ExecutionPolicy execution_policy) override; | 
| Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 120 |  | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 121 | private: | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 122 | std::unique_ptr<llvm::LLVMContext>       m_llvm_context;         ///< The LLVM context to generate IR into | 
|  | 123 | std::unique_ptr<clang::FileManager>      m_file_manager;         ///< The Clang file manager object used by the compiler | 
|  | 124 | std::unique_ptr<clang::CompilerInstance> m_compiler;             ///< The Clang compiler used to parse expressions into IR | 
|  | 125 | std::unique_ptr<clang::Builtin::Context> m_builtin_context;      ///< Context for Clang built-ins | 
|  | 126 | std::unique_ptr<clang::SelectorTable>    m_selector_table;       ///< Selector table for Objective-C methods | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 127 | std::unique_ptr<clang::CodeGenerator>    m_code_generator;       ///< The Clang object that generates IR | 
| Sean Callanan | c8278af | 2014-12-05 01:27:35 +0000 | [diff] [blame] | 128 |  | 
|  | 129 | class LLDBPreprocessorCallbacks; | 
|  | 130 | LLDBPreprocessorCallbacks               *m_pp_callbacks;         ///< Called when the preprocessor encounters module imports | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 131 | std::unique_ptr<ClangASTContext>         m_ast_context; | 
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 132 | }; | 
|  | 133 |  | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | #endif  // liblldb_ClangExpressionParser_h_ |