start defining codes for instructions
[oota-llvm.git] / include / llvm / Target / TargetMachine.h
index 2a41d5ec3d0dccc3c0ca4fd563ce08224b977b72..e5fceba522be8fee3fcd1ecdab265b91880c1238 100644 (file)
@@ -20,6 +20,7 @@
 
 namespace llvm {
 
+class TargetAsmInfo;
 class TargetData;
 class TargetSubtarget;
 class TargetInstrInfo;
@@ -33,6 +34,8 @@ class Module;
 class FunctionPassManager;
 class PassManager;
 class Pass;
+class TargetMachOWriterInfo;
+class TargetELFWriterInfo;
 
 // Relocation model types.
 namespace Reloc {
@@ -55,6 +58,16 @@ namespace CodeModel {
   };
 }
 
+namespace FileModel {
+  enum Model {
+    Error,
+    None,
+    AsmFile,
+    MachOFile,
+    ElfFile
+  };
+}
+
 //===----------------------------------------------------------------------===//
 ///
 /// TargetMachine - Primary interface to the complete machine description for
@@ -65,11 +78,20 @@ class TargetMachine {
   TargetMachine(const TargetMachine &);   // DO NOT IMPLEMENT
   void operator=(const TargetMachine &);  // DO NOT IMPLEMENT
 protected: // Can only create subclasses.
-  TargetMachine() { }
+  TargetMachine() : AsmInfo(NULL) { }
 
   /// getSubtargetImpl - virtual method implemented by subclasses that returns
   /// a reference to that target's TargetSubtarget-derived member variable.
   virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
+  
+  /// AsmInfo - Contains target specific asm information.
+  ///
+  mutable const TargetAsmInfo *AsmInfo;
+  
+  /// createTargetAsmInfo - Create a new instance of target specific asm
+  /// information.
+  virtual const TargetAsmInfo *createTargetAsmInfo() const { return NULL; }
+
 public:
   virtual ~TargetMachine();
 
@@ -96,7 +118,15 @@ public:
   virtual const TargetFrameInfo        *getFrameInfo() const { return 0; }
   virtual       TargetLowering    *getTargetLowering() const { return 0; }
   virtual const TargetData            *getTargetData() const { return 0; }
-
+  
+  
+  /// getTargetAsmInfo - Return target specific asm information.
+  ///
+  const TargetAsmInfo *getTargetAsmInfo() const {
+    if (!AsmInfo) AsmInfo = createTargetAsmInfo();
+    return AsmInfo;
+  }
+  
   /// getSubtarget - This method returns a pointer to the specified type of
   /// TargetSubtarget.  In debug builds, it verifies that the object being
   /// returned is of the correct type.
@@ -125,6 +155,16 @@ public:
     return InstrItineraryData();
   }
 
+  /// getMachOWriterInfo - If this target supports a Mach-O writer, return
+  /// information for it, otherwise return null.
+  /// 
+  virtual const TargetMachOWriterInfo *getMachOWriterInfo() const { return 0; }
+
+  /// getELFWriterInfo - If this target supports an ELF writer, return
+  /// information for it, otherwise return null.
+  /// 
+  virtual const TargetELFWriterInfo *getELFWriterInfo() const { return 0; }
+
   /// getRelocationModel - Returns the code generation relocation model. The
   /// choices are static, PIC, and dynamic-no-pic, and target default.
   static Reloc::Model getRelocationModel();
@@ -145,14 +185,25 @@ public:
     AssemblyFile, ObjectFile, DynamicLibrary
   };
 
-  /// addPassesToEmitFile - Add passes to the specified pass manager to get
-  /// the specified file emitted.  Typically this will involve several steps of
-  /// code generation.  If Fast is set to true, the code generator should emit
-  /// code as fast as possible, without regard for compile time.  This method
-  /// should return true if emission of this file type is not supported.
+  /// addPassesToEmitFile - Add passes to the specified pass manager to get the
+  /// specified file emitted.  Typically this will involve several steps of code
+  /// generation.  If Fast is set to true, the code generator should emit code
+  /// as fast as possible, without regard for compile time.  This method should
+  /// return FileModel::Error if emission of this file type is not supported.
+  ///
+  virtual FileModel::Model addPassesToEmitFile(FunctionPassManager &PM,
+                                               std::ostream &Out,
+                                               CodeGenFileType FileType,
+                                               bool Fast) {
+    return FileModel::None;
+  }
+
+  /// addPassesToEmitFileFinish - If the passes to emit the specified file had
+  /// to be split up (e.g., to add an object writer pass), this method can be
+  /// used to finish up adding passes to emit the file, if necessary.
   ///
-  virtual bool addPassesToEmitFile(FunctionPassManager &PM, std::ostream &Out,
-                                   CodeGenFileType FileType, bool Fast) {
+  virtual bool addPassesToEmitFileFinish(FunctionPassManager &PM,
+                                         MachineCodeEmitter *MCE, bool Fast) {
     return true;
   }
  
@@ -166,7 +217,6 @@ public:
                                           MachineCodeEmitter &MCE, bool Fast) {
     return true;
   }
-  
 
   /// addPassesToEmitWholeFile - This method can be implemented by targets that 
   /// require having the entire module at once.  This is not recommended, do not
@@ -186,19 +236,28 @@ protected: // Can only create subclasses.
     LLVMTargetMachine() { }
 public:
   
-  /// addPassesToEmitFile - Add passes to the specified pass manager to get
-  /// the specified file emitted.  Typically this will involve several steps of
-  /// code generation.  If Fast is set to true, the code generator should emit
-  /// code as fast as possible, without regard for compile time.  This method
-  /// should return true if emission of this file type is not supported.
+  /// addPassesToEmitFile - Add passes to the specified pass manager to get the
+  /// specified file emitted.  Typically this will involve several steps of code
+  /// generation.  If Fast is set to true, the code generator should emit code
+  /// as fast as possible, without regard for compile time.  This method should
+  /// return FileModel::Error if emission of this file type is not supported.
   ///
   /// The default implementation of this method adds components from the
   /// LLVM retargetable code generator, invoking the methods below to get
   /// target-specific passes in standard locations.
   ///
-  virtual bool addPassesToEmitFile(FunctionPassManager &PM, std::ostream &Out,
-                                   CodeGenFileType FileType, bool Fast);
+  virtual FileModel::Model addPassesToEmitFile(FunctionPassManager &PM,
+                                               std::ostream &Out,
+                                               CodeGenFileType FileType,
+                                               bool Fast);
   
+  /// addPassesToEmitFileFinish - If the passes to emit the specified file had
+  /// to be split up (e.g., to add an object writer pass), this method can be
+  /// used to finish up adding passes to emit the file, if necessary.
+  ///
+  virtual bool addPassesToEmitFileFinish(FunctionPassManager &PM,
+                                         MachineCodeEmitter *MCE, bool Fast);
   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
   /// actually outputting the machine code and resolving things like the address
@@ -241,14 +300,6 @@ public:
     return true;
   }
   
-  /// addObjectWriter - This pass should be overridden by the target to add
-  /// the object-file writer, if supported.  If this is not supported,
-  /// 'true' should be returned.
-  virtual bool addObjectWriter(FunctionPassManager &PM, bool Fast,
-                               std::ostream &Out) {
-    return true;
-  }
-  
   /// addCodeEmitter - This pass should be overridden by the target to add a
   /// code emitter, if supported.  If this is not supported, 'true' should be
   /// returned.
@@ -256,6 +307,14 @@ public:
                               MachineCodeEmitter &MCE) {
     return true;
   }
+
+  /// addSimpleCodeEmitter - This pass should be overridden by the target to add
+  /// a code emitter (without setting flags), if supported.  If this is not
+  /// supported, 'true' should be returned.
+  virtual bool addSimpleCodeEmitter(FunctionPassManager &PM, bool Fast, 
+                                    MachineCodeEmitter &MCE) {
+    return true;
+  }
 };
 
 } // End llvm namespace