ClangExpression.h revision 8c6934d1ada526541e85aa381f07089764408a3b
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 unsigned 66 ConvertIRToDWARF (ClangExpressionVariableList &excpr_local_variable_list, 67 StreamString &dwarf_opcode_strm); 68 69 bool 70 JITFunction (const ExecutionContext &exc_context, const char *func_name); 71 72 bool 73 WriteJITCode (const ExecutionContext &exc_context); 74 75 lldb::addr_t 76 GetFunctionAddress (const char *name); 77 78 clang::CompilerInstance * 79 GetCompilerInstance () 80 { 81 return m_clang_ap.get(); 82 } 83 84 clang::ASTContext * 85 GetASTContext (); 86 87 static Mutex & 88 GetClangMutex (); 89protected: 90 91 // This class is a pass-through for the default JIT memory manager, 92 // which just records the memory regions that were handed out so we 93 // can copy them into the target later on. 94 95 96 //------------------------------------------------------------------ 97 // Classes that inherit from ClangExpression can see and modify these 98 //------------------------------------------------------------------ 99 100 struct JittedFunction { 101 std::string m_name; 102 lldb::addr_t m_local_addr; 103 lldb::addr_t m_remote_addr; 104 105 JittedFunction (const char *name, 106 lldb::addr_t local_addr = LLDB_INVALID_ADDRESS, 107 lldb::addr_t remote_addr = LLDB_INVALID_ADDRESS) : 108 m_name (name), 109 m_local_addr (local_addr), 110 m_remote_addr (remote_addr) {} 111 }; 112 113 std::string m_target_triple; 114 ClangExpressionDeclMap *m_decl_map; 115 std::auto_ptr<clang::CompilerInstance> m_clang_ap; 116 clang::CodeGenerator *m_code_generator_ptr; // This will be deleted by the Execution Engine. 117 RecordingMemoryManager *m_jit_mm_ptr; // This will be deleted by the Execution Engine. 118 std::auto_ptr<llvm::ExecutionEngine> m_execution_engine; 119 std::vector<JittedFunction> m_jitted_functions; 120private: 121 122 bool CreateCompilerInstance(bool &IsAST); 123 124 //------------------------------------------------------------------ 125 // For ClangExpression only 126 //------------------------------------------------------------------ 127 ClangExpression(const ClangExpression&); 128 const ClangExpression& operator=(const ClangExpression&); 129}; 130 131} // namespace lldb_private 132 133#endif // liblldb_ClangExpression_h_ 134