IRToDWARF.h revision f285ebcfa3ce0fd200b6a566eb1196927e618fc6
1//===-- IRToDWARF.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_IRToDWARF_h_ 11#define liblldb_IRToDWARF_h_ 12 13#include "llvm/Pass.h" 14#include "llvm/PassManager.h" 15 16namespace llvm { 17 class BasicBlock; 18 class Module; 19} 20 21namespace lldb_private { 22 class ClangExpressionVariableList; 23 class ClangExpressionDeclMap; 24 class StreamString; 25} 26 27class Relocator; 28 29//---------------------------------------------------------------------- 30/// @class IRToDWARF IRToDWARF.h "lldb/Expression/IRToDWARF.h" 31/// @brief Transforms the IR for a function into a DWARF location expression 32/// 33/// Once an expression has been parsed and converted to IR, it can run 34/// in two contexts: interpreted by LLDB as a DWARF location expression, 35/// or compiled by the JIT and inserted into the target process for 36/// execution. 37/// 38/// IRToDWARF makes the first possible, by traversing the control flow 39/// graph and writing the code for each basic block out as location 40/// expression bytecode. To ensure that the links between the basic blocks 41/// remain intact, it uses a relocator that records the location of every 42/// location expression instruction that has a relocatable operand, the 43/// target of that operand (as a basic block), and the mapping of each basic 44/// block to an actual location. After all code has been written out, the 45/// relocator post-processes it and performs all necessary relocations. 46//---------------------------------------------------------------------- 47class IRToDWARF : public llvm::ModulePass 48{ 49public: 50 //------------------------------------------------------------------ 51 /// Constructor 52 /// 53 /// @param[in] pid 54 /// A unique identifier for this pass. I'm not sure what this does; 55 /// it just gets passed down to ModulePass's constructor. 56 /// 57 /// @param[in] variable_list 58 /// A list of variables to populate with the local variables this 59 /// expression uses. 60 /// 61 /// @param[in] decl_map 62 /// The list of externally-referenced variables for the expression, 63 /// for use in looking up globals. 64 /// 65 /// @param[in] stream 66 /// The stream to dump DWARF bytecode onto. 67 //------------------------------------------------------------------ 68 IRToDWARF(const void *pid, 69 lldb_private::ClangExpressionVariableList &variable_list, 70 lldb_private::ClangExpressionDeclMap *decl_map, 71 lldb_private::StreamString &strm); 72 73 //------------------------------------------------------------------ 74 /// Destructor 75 //------------------------------------------------------------------ 76 ~IRToDWARF(); 77 78 //------------------------------------------------------------------ 79 /// Run this IR transformer on a single module 80 /// 81 /// @param[in] M 82 /// The module to run on. This module is searched for the function 83 /// ___clang_expr, and that function is converted to a location 84 /// expression. 85 /// 86 /// @return 87 /// True on success; false otherwise 88 //------------------------------------------------------------------ 89 bool runOnModule(llvm::Module &M); 90 91 //------------------------------------------------------------------ 92 /// Interface stub 93 //------------------------------------------------------------------ 94 void assignPassManager(llvm::PMStack &PMS, 95 llvm::PassManagerType T = llvm::PMT_ModulePassManager); 96 97 //------------------------------------------------------------------ 98 /// Returns PMT_ModulePassManager 99 //------------------------------------------------------------------ 100 llvm::PassManagerType getPotentialPassManagerType() const; 101private: 102 //------------------------------------------------------------------ 103 /// Run this IR transformer on a single basic block 104 /// 105 /// @param[in] BB 106 /// The basic block to transform. 107 /// 108 /// @param[in] Relocator 109 /// The relocator to use when registering branches. 110 /// 111 /// @return 112 /// True on success; false otherwise 113 //------------------------------------------------------------------ 114 bool runOnBasicBlock(llvm::BasicBlock &BB, Relocator &Relocator); 115 116 lldb_private::ClangExpressionVariableList &m_variable_list; ///< The list of local variables to populate while transforming 117 lldb_private::ClangExpressionDeclMap *m_decl_map; ///< The list of external variables 118 lldb_private::StreamString &m_strm; ///< The stream to write bytecode to 119}; 120 121#endif