aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/MachOWriter.h
blob: 2e7e67d2db7298273c034409e4b51a8d40a343d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//=== MachOWriter.h - Target-independent Mach-O writer support --*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the MachOWriter class.
//
//===----------------------------------------------------------------------===//

#ifndef MACHOWRITER_H
#define MACHOWRITER_H

#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/Target/TargetMachine.h"

namespace llvm {
  class GlobalVariable;
  class Mangler;
  class MCCodeEmitter;
  class MCContext;
  class MCStreamer;
  
  /// MachOWriter - This class implements the common target-independent code for
  /// writing Mach-O files.  Targets should derive a class from this to
  /// parameterize the output format.
  ///
  class MachOWriter : public MachineFunctionPass {
    static char ID;

  protected:
    /// Output stream to send the resultant object file to.
    ///
    formatted_raw_ostream &O;

    /// Target machine description.
    ///
    TargetMachine &TM;

    /// Target Asm Printer information.
    ///
    const MCAsmInfo *MAI;
    
    /// MCCE - The MCCodeEmitter object that we are exposing to emit machine
    /// code for functions to the .o file.
    MCCodeEmitter *MCCE;
    
    /// OutContext - This is the context for the output file that we are
    /// streaming.  This owns all of the global MC-related objects for the
    /// generated translation unit.
    MCContext &OutContext;
    
    /// OutStreamer - This is the MCStreamer object for the file we are
    /// generating.  This contains the transient state for the current
    /// translation unit that we are generating (such as the current section
    /// etc).
    MCStreamer &OutStreamer;
    
    /// Name-mangler for global names.
    ///
    Mangler *Mang;
    
    /// doInitialization - Emit the file header and all of the global variables
    /// for the module to the Mach-O file.
    bool doInitialization(Module &M);

    /// doFinalization - Now that the module has been completely processed, emit
    /// the Mach-O file to 'O'.
    bool doFinalization(Module &M);

    bool runOnMachineFunction(MachineFunction &MF);
    
  public:
    explicit MachOWriter(formatted_raw_ostream &O, TargetMachine &TM,
                         const MCAsmInfo *T, MCCodeEmitter *MCE);
    
    virtual ~MachOWriter();
    
    virtual const char *getPassName() const {
      return "Mach-O Writer";
    }
  };
}

#endif