Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 1 | //=== MachOWriter.h - Target-independent Mach-O writer support --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the MachOWriter class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Bill Wendling | 4b2ca1a | 2007-02-08 01:30:50 +0000 | [diff] [blame] | 14 | #ifndef MACHOWRITER_H |
| 15 | #define MACHOWRITER_H |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 16 | |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Nate Begeman | 3fe980b | 2010-01-15 18:51:18 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetMachine.h" |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | class GlobalVariable; |
| 22 | class Mangler; |
Nate Begeman | 3fe980b | 2010-01-15 18:51:18 +0000 | [diff] [blame] | 23 | class MCCodeEmitter; |
| 24 | class MCContext; |
| 25 | class MCStreamer; |
| 26 | |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 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 { |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 32 | static char ID; |
Bruno Cardoso Lopes | ac57e6e | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 33 | |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 34 | protected: |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 35 | /// Output stream to send the resultant object file to. |
| 36 | /// |
Nate Begeman | 3fe980b | 2010-01-15 18:51:18 +0000 | [diff] [blame] | 37 | formatted_raw_ostream &O; |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 38 | |
| 39 | /// Target machine description. |
| 40 | /// |
| 41 | TargetMachine &TM; |
| 42 | |
Nate Begeman | 3fe980b | 2010-01-15 18:51:18 +0000 | [diff] [blame] | 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. |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 63 | /// |
| 64 | Mangler *Mang; |
Nate Begeman | 3fe980b | 2010-01-15 18:51:18 +0000 | [diff] [blame] | 65 | |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 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 | |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 70 | /// doFinalization - Now that the module has been completely processed, emit |
| 71 | /// the Mach-O file to 'O'. |
| 72 | bool doFinalization(Module &M); |
| 73 | |
Nate Begeman | 3fe980b | 2010-01-15 18:51:18 +0000 | [diff] [blame] | 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"; |
Nate Begeman | f8f2c5a | 2006-08-25 06:36:58 +0000 | [diff] [blame] | 84 | } |
Nate Begeman | eb883af | 2006-08-23 21:08:52 +0000 | [diff] [blame] | 85 | }; |
| 86 | } |
| 87 | |
| 88 | #endif |