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