Use AssertingVH, just to be paranoid.
[oota-llvm.git] / lib / CodeGen / MachOWriter.h
1 //=== MachOWriter.h - Target-independent Mach-O writer support --*- 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 // This file defines the MachOWriter class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef MACHOWRITER_H
15 #define MACHOWRITER_H
16
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/Target/TargetMachine.h"
19
20 namespace llvm {
21   class GlobalVariable;
22   class Mangler;
23   class MCCodeEmitter;
24   class MCContext;
25   class MCStreamer;
26   
27   /// MachOWriter - This class implements the common target-independent code for
28   /// writing Mach-O files.  Targets should derive a class from this to
29   /// parameterize the output format.
30   ///
31   class MachOWriter : public MachineFunctionPass {
32     static char ID;
33
34   protected:
35     /// Output stream to send the resultant object file to.
36     ///
37     formatted_raw_ostream &O;
38
39     /// Target machine description.
40     ///
41     TargetMachine &TM;
42
43     /// Target Asm Printer information.
44     ///
45     const MCAsmInfo *MAI;
46     
47     /// MCCE - The MCCodeEmitter object that we are exposing to emit machine
48     /// code for functions to the .o file.
49     MCCodeEmitter *MCCE;
50     
51     /// OutContext - This is the context for the output file that we are
52     /// streaming.  This owns all of the global MC-related objects for the
53     /// generated translation unit.
54     MCContext &OutContext;
55     
56     /// OutStreamer - This is the MCStreamer object for the file we are
57     /// generating.  This contains the transient state for the current
58     /// translation unit that we are generating (such as the current section
59     /// etc).
60     MCStreamer &OutStreamer;
61     
62     /// Name-mangler for global names.
63     ///
64     Mangler *Mang;
65     
66     /// doInitialization - Emit the file header and all of the global variables
67     /// for the module to the Mach-O file.
68     bool doInitialization(Module &M);
69
70     /// doFinalization - Now that the module has been completely processed, emit
71     /// the Mach-O file to 'O'.
72     bool doFinalization(Module &M);
73
74     bool runOnMachineFunction(MachineFunction &MF);
75     
76   public:
77     explicit MachOWriter(formatted_raw_ostream &O, TargetMachine &TM,
78                          const MCAsmInfo *T, MCCodeEmitter *MCE);
79     
80     virtual ~MachOWriter();
81     
82     virtual const char *getPassName() const {
83       return "Mach-O Writer";
84     }
85   };
86 }
87
88 #endif