Fix CodeGen/Generic/2007-04-08-MultipleFrameIndices.ll and PR1308:
[oota-llvm.git] / lib / CodeGen / ELFWriter.cpp
index 4f988070fddf558289da9b9055318998d0d6365e..ffc0a929f318d67ef2ac7dea84a44d2719c918be 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/CodeGen/ELFWriter.h"
+#include "ELFWriter.h"
 #include "llvm/Module.h"
+#include "llvm/PassManager.h"
+#include "llvm/CodeGen/FileWriters.h"
 #include "llvm/CodeGen/MachineCodeEmitter.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetELFWriterInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/Support/OutputBuffer.h"
 #include "llvm/Support/Streams.h"
+#include <list>
 using namespace llvm;
 
+/// AddELFWriter - Concrete function to add the ELF writer to the function pass
+/// manager.
+MachineCodeEmitter *llvm::AddELFWriter(FunctionPassManager &FPM,
+                                       std::ostream &O,
+                                       TargetMachine &TM) {
+  ELFWriter *EW = new ELFWriter(O, TM);
+  FPM.add(EW);
+  return &EW->getMachineCodeEmitter();
+}
+
 //===----------------------------------------------------------------------===//
 //                       ELFCodeEmitter Implementation
 //===----------------------------------------------------------------------===//
@@ -162,7 +177,6 @@ bool ELFCodeEmitter::finishFunction(MachineFunction &F) {
 //===----------------------------------------------------------------------===//
 
 ELFWriter::ELFWriter(std::ostream &o, TargetMachine &tm) : O(o), TM(tm) {
-  e_machine = 0;  // e_machine defaults to 'No Machine'
   e_flags = 0;    // e_flags defaults to 0, no flags.
 
   is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
@@ -197,7 +211,7 @@ bool ELFWriter::doInitialization(Module &M) {
 
   // This should change for shared objects.
   FHOut.outhalf(1);                 // e_type = ET_REL
-  FHOut.outhalf(e_machine);         // e_machine = whatever the target wants
+  FHOut.outword(TM.getELFWriterInfo()->getEMachine()); // target-defined
   FHOut.outword(1);                 // e_version = 1
   FHOut.outaddr(0);                 // e_entry = 0 -> no entry point in .o file
   FHOut.outaddr(0);                 // e_phoff = 0 -> no program header for .o
@@ -241,7 +255,7 @@ void ELFWriter::EmitGlobal(GlobalVariable *GV) {
   }
 
   const Type *GVType = (const Type*)GV->getType();
-  unsigned Align = TM.getTargetData()->getTypeAlignment(GVType);
+  unsigned Align = TM.getTargetData()->getPrefTypeAlignment(GVType);
   unsigned Size  = TM.getTargetData()->getTypeSize(GVType);
 
   // If this global has a zero initializer, it is part of the .bss or common