]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/lldb/include/lldb/Expression/IRToDWARF.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / lldb / include / lldb / Expression / IRToDWARF.h
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
16 #include "lldb/lldb-public.h"
17
18 class Relocator;
19 //----------------------------------------------------------------------
20 /// @class IRToDWARF IRToDWARF.h "lldb/Expression/IRToDWARF.h"
21 /// @brief Transforms the IR for a function into a DWARF location expression
22 ///
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
26 /// execution.
27 ///
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
38 {
39 public:
40     //------------------------------------------------------------------
41     /// Constructor
42     ///
43     /// @param[in] local_vars
44     ///     A list of variables to populate with the local variables this
45     ///     expression uses.
46     ///
47     /// @param[in] decl_map
48     ///     The list of externally-referenced variables for the expression,
49     ///     for use in looking up globals.
50     ///
51     /// @param[in] stream
52     ///     The stream to dump DWARF bytecode onto.
53     ///
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");
61     
62     //------------------------------------------------------------------
63     /// Destructor
64     //------------------------------------------------------------------
65     virtual ~IRToDWARF();
66     
67     //------------------------------------------------------------------
68     /// Run this IR transformer on a single module
69     ///
70     /// @param[in] M
71     ///     The module to run on.  This module is searched for the function
72     ///     $__lldb_expr, and that function is converted to a location
73     ///     expression.
74     ///
75     /// @return
76     ///     True on success; false otherwise
77     //------------------------------------------------------------------
78     bool runOnModule(llvm::Module &M);
79     
80     //------------------------------------------------------------------
81     /// Interface stub
82     //------------------------------------------------------------------
83     void assignPassManager(llvm::PMStack &PMS,
84                            llvm::PassManagerType T = llvm::PMT_ModulePassManager);
85     
86     //------------------------------------------------------------------
87     /// Returns PMT_ModulePassManager
88     //------------------------------------------------------------------
89     llvm::PassManagerType getPotentialPassManagerType() const;
90 private:
91     //------------------------------------------------------------------
92     /// Run this IR transformer on a single basic block
93     ///
94     /// @param[in] BB
95     ///     The basic block to transform.
96     ///
97     /// @param[in] Relocator
98     ///     The relocator to use when registering branches.
99     ///
100     /// @return
101     ///     True on success; false otherwise
102     //------------------------------------------------------------------
103     bool runOnBasicBlock(llvm::BasicBlock &BB, Relocator &Relocator);
104     
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
109 };
110
111 #endif