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