blob: 2e7e67d2db7298273c034409e4b51a8d40a343d7 [file] [log] [blame]
Nate Begemaneb883af2006-08-23 21:08:52 +00001//=== MachOWriter.h - Target-independent Mach-O writer support --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Nate Begemaneb883af2006-08-23 21:08:52 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the MachOWriter class.
11//
12//===----------------------------------------------------------------------===//
13
Bill Wendling4b2ca1a2007-02-08 01:30:50 +000014#ifndef MACHOWRITER_H
15#define MACHOWRITER_H
Nate Begemaneb883af2006-08-23 21:08:52 +000016
Nate Begemaneb883af2006-08-23 21:08:52 +000017#include "llvm/CodeGen/MachineFunctionPass.h"
Nate Begeman3fe980b2010-01-15 18:51:18 +000018#include "llvm/Target/TargetMachine.h"
Nate Begemaneb883af2006-08-23 21:08:52 +000019
20namespace llvm {
21 class GlobalVariable;
22 class Mangler;
Nate Begeman3fe980b2010-01-15 18:51:18 +000023 class MCCodeEmitter;
24 class MCContext;
25 class MCStreamer;
26
Nate Begemaneb883af2006-08-23 21:08:52 +000027 /// 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 {
Devang Patel19974732007-05-03 01:11:54 +000032 static char ID;
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +000033
Nate Begemaneb883af2006-08-23 21:08:52 +000034 protected:
Nate Begemaneb883af2006-08-23 21:08:52 +000035 /// Output stream to send the resultant object file to.
36 ///
Nate Begeman3fe980b2010-01-15 18:51:18 +000037 formatted_raw_ostream &O;
Nate Begemaneb883af2006-08-23 21:08:52 +000038
39 /// Target machine description.
40 ///
41 TargetMachine &TM;
42
Nate Begeman3fe980b2010-01-15 18:51:18 +000043 /// 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.
Nate Begemaneb883af2006-08-23 21:08:52 +000063 ///
64 Mangler *Mang;
Nate Begeman3fe980b2010-01-15 18:51:18 +000065
Nate Begemaneb883af2006-08-23 21:08:52 +000066 /// 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
Nate Begemaneb883af2006-08-23 21:08:52 +000070 /// doFinalization - Now that the module has been completely processed, emit
71 /// the Mach-O file to 'O'.
72 bool doFinalization(Module &M);
73
Nate Begeman3fe980b2010-01-15 18:51:18 +000074 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";
Nate Begemanf8f2c5a2006-08-25 06:36:58 +000084 }
Nate Begemaneb883af2006-08-23 21:08:52 +000085 };
86}
87
88#endif