ClangExpression.h revision 5cf4a1ca412654c3f912e2b3cea931fb814f322f
1//===-- ClangExpression.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_ClangExpression_h_ 11#define liblldb_ClangExpression_h_ 12 13// C Includes 14// C++ Includes 15#include <string> 16#include <map> 17#include <memory> 18 19// Other libraries and framework includes 20// Project includes 21 22#include "lldb/lldb-forward.h" 23#include "lldb/lldb-private.h" 24#include "lldb/Core/ClangForward.h" 25#include "llvm/ExecutionEngine/JITMemoryManager.h" 26 27namespace llvm 28{ 29 class ExecutionEngine; 30 class StringRef; 31} 32 33namespace lldb_private { 34 35class RecordingMemoryManager; 36 37class ClangExpression 38{ 39public: 40 41 //------------------------------------------------------------------ 42 // Constructors and Destructors 43 //------------------------------------------------------------------ 44 ClangExpression(const char *target_triple, 45 ClangExpressionDeclMap *expr_decl_map); 46 47 ~ClangExpression(); 48 49 unsigned Compile(); 50 51 unsigned 52 ParseExpression (const char *expr_text, 53 Stream &stream, 54 bool add_result_var = false); 55 56 unsigned 57 ParseBareExpression (llvm::StringRef expr_text, 58 Stream &stream, 59 bool add_result_var = false); 60 61 unsigned 62 ConvertExpressionToDWARF (ClangExpressionVariableList &expr_local_variable_list, 63 StreamString &dwarf_opcode_strm); 64 65 bool 66 ConvertIRToDWARF (ClangExpressionVariableList &excpr_local_variable_list, 67 StreamString &dwarf_opcode_strm); 68 69 bool 70 PrepareIRForTarget (ClangExpressionVariableList &excpr_local_variable_list); 71 72 bool 73 JITFunction (const ExecutionContext &exc_context, const char *func_name); 74 75 bool 76 WriteJITCode (const ExecutionContext &exc_context); 77 78 lldb::addr_t 79 GetFunctionAddress (const char *name); 80 81 clang::CompilerInstance * 82 GetCompilerInstance () 83 { 84 return m_clang_ap.get(); 85 } 86 87 clang::ASTContext * 88 GetASTContext (); 89 90 static Mutex & 91 GetClangMutex (); 92protected: 93 94 // This class is a pass-through for the default JIT memory manager, 95 // which just records the memory regions that were handed out so we 96 // can copy them into the target later on. 97 98 99 //------------------------------------------------------------------ 100 // Classes that inherit from ClangExpression can see and modify these 101 //------------------------------------------------------------------ 102 103 struct JittedFunction { 104 std::string m_name; 105 lldb::addr_t m_local_addr; 106 lldb::addr_t m_remote_addr; 107 108 JittedFunction (const char *name, 109 lldb::addr_t local_addr = LLDB_INVALID_ADDRESS, 110 lldb::addr_t remote_addr = LLDB_INVALID_ADDRESS) : 111 m_name (name), 112 m_local_addr (local_addr), 113 m_remote_addr (remote_addr) {} 114 }; 115 116 std::string m_target_triple; 117 ClangExpressionDeclMap *m_decl_map; 118 std::auto_ptr<clang::CompilerInstance> m_clang_ap; 119 clang::CodeGenerator *m_code_generator_ptr; // This will be deleted by the Execution Engine. 120 RecordingMemoryManager *m_jit_mm_ptr; // This will be deleted by the Execution Engine. 121 std::auto_ptr<llvm::ExecutionEngine> m_execution_engine; 122 std::vector<JittedFunction> m_jitted_functions; 123private: 124 125 bool CreateCompilerInstance(bool &IsAST); 126 127 //------------------------------------------------------------------ 128 // For ClangExpression only 129 //------------------------------------------------------------------ 130 ClangExpression(const ClangExpression&); 131 const ClangExpression& operator=(const ClangExpression&); 132}; 133 134} // namespace lldb_private 135 136#endif // liblldb_ClangExpression_h_ 137