1 //===-- IRToDWARF.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_IRToDWARF_h_
11 #define liblldb_IRToDWARF_h_
13 #include "llvm/Pass.h"
14 #include "llvm/PassManager.h"
16 #include "lldb/lldb-public.h"
19 //----------------------------------------------------------------------
20 /// @class IRToDWARF IRToDWARF.h "lldb/Expression/IRToDWARF.h"
21 /// @brief Transforms the IR for a function into a DWARF location expression
23 /// Once an expression has been parsed and converted to IR, it can run
24 /// in two contexts: interpreted by LLDB as a DWARF location expression,
25 /// or compiled by the JIT and inserted into the target process for
28 /// IRToDWARF makes the first possible, by traversing the control flow
29 /// graph and writing the code for each basic block out as location
30 /// expression bytecode. To ensure that the links between the basic blocks
31 /// remain intact, it uses a relocator that records the location of every
32 /// location expression instruction that has a relocatable operand, the
33 /// target of that operand (as a basic block), and the mapping of each basic
34 /// block to an actual location. After all code has been written out, the
35 /// relocator post-processes it and performs all necessary relocations.
36 //----------------------------------------------------------------------
37 class IRToDWARF : public llvm::ModulePass
40 //------------------------------------------------------------------
43 /// @param[in] local_vars
44 /// A list of variables to populate with the local variables this
47 /// @param[in] decl_map
48 /// The list of externally-referenced variables for the expression,
49 /// for use in looking up globals.
52 /// The stream to dump DWARF bytecode onto.
54 /// @param[in] func_name
55 /// The name of the function to translate to DWARF.
56 //------------------------------------------------------------------
57 IRToDWARF(lldb_private::ClangExpressionVariableList &local_vars,
58 lldb_private::ClangExpressionDeclMap *decl_map,
59 lldb_private::StreamString &strm,
60 const char* func_name = "$__lldb_expr");
62 //------------------------------------------------------------------
64 //------------------------------------------------------------------
67 //------------------------------------------------------------------
68 /// Run this IR transformer on a single module
71 /// The module to run on. This module is searched for the function
72 /// $__lldb_expr, and that function is converted to a location
76 /// True on success; false otherwise
77 //------------------------------------------------------------------
78 bool runOnModule(llvm::Module &M);
80 //------------------------------------------------------------------
82 //------------------------------------------------------------------
83 void assignPassManager(llvm::PMStack &PMS,
84 llvm::PassManagerType T = llvm::PMT_ModulePassManager);
86 //------------------------------------------------------------------
87 /// Returns PMT_ModulePassManager
88 //------------------------------------------------------------------
89 llvm::PassManagerType getPotentialPassManagerType() const;
91 //------------------------------------------------------------------
92 /// Run this IR transformer on a single basic block
95 /// The basic block to transform.
97 /// @param[in] Relocator
98 /// The relocator to use when registering branches.
101 /// True on success; false otherwise
102 //------------------------------------------------------------------
103 bool runOnBasicBlock(llvm::BasicBlock &BB, Relocator &Relocator);
105 std::string m_func_name; ///< The name of the function to translate
106 lldb_private::ClangExpressionVariableList &m_local_vars; ///< The list of local variables to populate while transforming
107 lldb_private::ClangExpressionDeclMap *m_decl_map; ///< The list of external variables
108 lldb_private::StreamString &m_strm; ///< The stream to write bytecode to