silence a bogus warning
[oota-llvm.git] / lib / CodeGen / MachineCodeEmitter.cpp
index e6f93dcc40f885b04007a847e6810bd54cc00175..1090d762d7ed182c6e06beeeb17aa2e37a0c4826 100644 (file)
@@ -1,5 +1,12 @@
 //===-- MachineCodeEmitter.cpp - Implement the MachineCodeEmitter itf -----===//
 //
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
 // This file implements the MachineCodeEmitter interface.
 //
 //===----------------------------------------------------------------------===//
@@ -8,6 +15,9 @@
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Function.h"
 #include <fstream>
+#include <iostream>
+
+using namespace llvm;
 
 namespace {
   struct DebugMachineCodeEmitter : public MachineCodeEmitter {
@@ -18,69 +28,53 @@ namespace {
     void finishFunction(MachineFunction &F) {
       std::cout << "\n";
     }
-    void startFunctionStub(const Function &F, unsigned StubSize) {
-      std::cout << "\n--- Function stub for function: " << F.getName() << "\n";
+    void startFunctionStub(unsigned StubSize) {
+      std::cout << "\n--- Function stub:\n";
     }
-    void *finishFunctionStub(const Function &F) {
-      std::cout << "\n";
+    void *finishFunctionStub(const Function *F) {
+      std::cout << "\n--- End of stub for Function\n";
       return 0;
     }
-    
+
     void emitByte(unsigned char B) {
       std::cout << "0x" << std::hex << (unsigned int)B << std::dec << " ";
     }
     void emitWord(unsigned W) {
       std::cout << "0x" << std::hex << W << std::dec << " ";
     }
+    void emitWordAt(unsigned W, unsigned *Ptr) {
+      std::cout << "0x" << std::hex << W << std::dec << " (at "
+                << (void*) Ptr << ") ";
+    }
 
-    uint64_t getGlobalValueAddress(GlobalValue *V) { return 0; }
-    uint64_t getGlobalValueAddress(const std::string &Name) { return 0; }
-    uint64_t getConstantPoolEntryAddress(unsigned Num) { return 0; }
-    uint64_t getCurrentPCValue() { return 0; }
-
-    // forceCompilationOf - Force the compilation of the specified function, and
-    // return its address, because we REALLY need the address now.
-    //
-    // FIXME: This is JIT specific!
-    //
-    virtual uint64_t forceCompilationOf(Function *F) {
-      return 0;
+    void addRelocation(const MachineRelocation &MR) {
+      std::cout << "<relocation> ";
     }
-  };
-}
 
+    virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment)
+    { return 0; }
 
-/// createDebugMachineCodeEmitter - Return a dynamically allocated machine
-/// code emitter, which just prints the opcodes and fields out the cout.  This
-/// can be used for debugging users of the MachineCodeEmitter interface.
-///
-MachineCodeEmitter *MachineCodeEmitter::createDebugEmitter() {
-  return new DebugMachineCodeEmitter();
-}
+    uint64_t getConstantPoolEntryAddress(unsigned Num) { return 0; }
+    uint64_t getCurrentPCValue() { return 0; }
+    uint64_t getCurrentPCOffset() { return 0; }
+  };
 
-namespace {
   class FilePrinterEmitter : public MachineCodeEmitter {
-    std::ofstream f, actual;
+    std::ofstream actual;
     std::ostream &o;
     MachineCodeEmitter &MCE;
     unsigned counter;
-    bool mustClose;
     unsigned values[4];
-    
+
   public:
     FilePrinterEmitter(MachineCodeEmitter &M, std::ostream &os)
-      : f("lli.out"), o(os), MCE(M), counter(0), mustClose(false) {
-      if (!f.good()) {
-        std::cerr << "Cannot open 'lli.out' for writing\n";
-        abort();
-      }
+      : o(os), MCE(M), counter(0) {
       openActual();
     }
-    
-    ~FilePrinterEmitter() { 
+
+    ~FilePrinterEmitter() {
       o << "\n";
       actual.close();
-      if (mustClose) f.close();
     }
 
     void openActual() {
@@ -99,14 +93,18 @@ namespace {
       MCE.finishFunction(F);
     }
 
-    void startFunctionStub(const Function &F, unsigned StubSize) {
-      MCE.startFunctionStub(F, StubSize);
+    void emitConstantPool(MachineConstantPool *MCP) {
+      MCE.emitConstantPool(MCP);
     }
 
-    void *finishFunctionStub(const Function &F) {
+    void startFunctionStub(unsigned StubSize) {
+      MCE.startFunctionStub(StubSize);
+    }
+
+    void *finishFunctionStub(const Function *F) {
       return MCE.finishFunctionStub(F);
     }
-    
+
     void emitByte(unsigned char B) {
       MCE.emitByte(B);
       actual << B; actual.flush();
@@ -140,31 +138,38 @@ namespace {
 
     void emitWord(unsigned W) {
       MCE.emitWord(W);
-      assert(0 && "FilePrinterEmitter::emitWord not implemented!");
     }
-    uint64_t getGlobalValueAddress(GlobalValue *V) {
-      return MCE.getGlobalValueAddress(V);
-    }
-    uint64_t getGlobalValueAddress(const std::string &Name) {
-      return MCE.getGlobalValueAddress(Name);
+    void emitWordAt(unsigned W, unsigned *Ptr) {
+      MCE.emitWordAt(W, Ptr);
     }
     uint64_t getConstantPoolEntryAddress(unsigned Num) {
       return MCE.getConstantPoolEntryAddress(Num);
     }
+
+    virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment)
+    { return MCE.allocateGlobal(size, alignment); }
+
     uint64_t getCurrentPCValue() {
       return MCE.getCurrentPCValue();
     }
-    // forceCompilationOf - Force the compilation of the specified function, and
-    // return its address, because we REALLY need the address now.
-    //
-    // FIXME: This is JIT specific!
-    //
-    virtual uint64_t forceCompilationOf(Function *F) {
-      return MCE.forceCompilationOf(F);
+    uint64_t getCurrentPCOffset() {
+      return MCE.getCurrentPCOffset();
+    }
+    void addRelocation(const MachineRelocation &MR) {
+      return MCE.addRelocation(MR);
     }
   };
 }
 
+/// createDebugMachineCodeEmitter - Return a dynamically allocated machine
+/// code emitter, which just prints the opcodes and fields out the cout.  This
+/// can be used for debugging users of the MachineCodeEmitter interface.
+///
+MachineCodeEmitter *
+MachineCodeEmitter::createDebugEmitter() {
+  return new DebugMachineCodeEmitter();
+}
+
 MachineCodeEmitter *
 MachineCodeEmitter::createFilePrinterEmitter(MachineCodeEmitter &MCE) {
   return new FilePrinterEmitter(MCE, std::cerr);