[llvm-commits] CVS: llvm/lib/Target/X86/X86ELFWriter.cpp X86.h X86TargetMachine.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Jun 27 01:30:24 CDT 2005



Changes in directory llvm/lib/Target/X86:

X86ELFWriter.cpp added (r1.1)
X86.h updated: 1.31 -> 1.32
X86TargetMachine.cpp updated: 1.79 -> 1.80
---
Log message:

Add support to the X86 backend for emitting ELF files.  To use this, we
currently use: llc t.bc --filetype=obj

This will produce a t.o file which is dumpable with readelf.  Currently
the file produced is empty, but the scaffolding to do more is now in place.


---
Diffs of the changes:  (+55 -2)

 X86.h                |    6 ++++++
 X86ELFWriter.cpp     |   34 ++++++++++++++++++++++++++++++++++
 X86TargetMachine.cpp |   17 +++++++++++++++--
 3 files changed, 55 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/X86/X86ELFWriter.cpp
diff -c /dev/null llvm/lib/Target/X86/X86ELFWriter.cpp:1.1
*** /dev/null	Mon Jun 27 01:30:23 2005
--- llvm/lib/Target/X86/X86ELFWriter.cpp	Mon Jun 27 01:30:12 2005
***************
*** 0 ****
--- 1,34 ----
+ //===-- X86ELFWriter.cpp - Emit an ELF file for the X86 backend -----------===//
+ //
+ //                     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 an ELF writer for the X86 backend.  The public interface
+ // to this file is the createX86ELFObjectWriterPass function.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #include "X86.h"
+ #include "llvm/CodeGen/ELFWriter.h"
+ using namespace llvm;
+ 
+ namespace {
+   class X86ELFWriter : public ELFWriter {
+   public:
+     X86ELFWriter(std::ostream &O, TargetMachine &TM) : ELFWriter(O, TM) {
+       e_machine = 3;   // EM_386
+     }
+   };
+ }
+ 
+ /// createX86ELFObjectWriterPass - Returns a pass that outputs the generated
+ /// code as an ELF object file.
+ ///
+ FunctionPass *llvm::createX86ELFObjectWriterPass(std::ostream &O,
+                                                  TargetMachine &TM) {
+   return new X86ELFWriter(O, TM);
+ }


Index: llvm/lib/Target/X86/X86.h
diff -u llvm/lib/Target/X86/X86.h:1.31 llvm/lib/Target/X86/X86.h:1.32
--- llvm/lib/Target/X86/X86.h:1.31	Thu Apr 21 18:38:14 2005
+++ llvm/lib/Target/X86/X86.h	Mon Jun 27 01:30:12 2005
@@ -69,6 +69,12 @@
 ///
 FunctionPass *createX86CodePrinterPass(std::ostream &o,TargetMachine &tm);
 
+/// createX86ELFObjectWriterPass - Returns a pass that outputs the generated
+/// code as an ELF object file.
+///
+FunctionPass *createX86ELFObjectWriterPass(std::ostream &o, TargetMachine &tm);
+
+
 /// createX86EmitCodeToMemory - Returns a pass that converts a register
 /// allocated function into raw machine code in a dynamically
 /// allocated chunk of memory.


Index: llvm/lib/Target/X86/X86TargetMachine.cpp
diff -u llvm/lib/Target/X86/X86TargetMachine.cpp:1.79 llvm/lib/Target/X86/X86TargetMachine.cpp:1.80
--- llvm/lib/Target/X86/X86TargetMachine.cpp:1.79	Fri Jun 24 21:48:37 2005
+++ llvm/lib/Target/X86/X86TargetMachine.cpp	Mon Jun 27 01:30:12 2005
@@ -98,7 +98,8 @@
 // does to emit statically compiled machine code.
 bool X86TargetMachine::addPassesToEmitFile(PassManager &PM, std::ostream &Out,
                                            CodeGenFileType FileType) {
-  if (FileType != TargetMachine::AssemblyFile) return true;
+  if (FileType != TargetMachine::AssemblyFile && 
+      FileType != TargetMachine::ObjectFile) return true;
 
   // FIXME: Implement efficient support for garbage collection intrinsics.
   PM.add(createLowerGCPass());
@@ -146,7 +147,19 @@
     PM.add(createX86CodePrinterPass(std::cerr, *this));
 
   if (!DisableOutput)
-    PM.add(createX86CodePrinterPass(Out, *this));
+    switch (FileType) {
+    default:
+      assert(0 && "Unexpected filetype here!");
+    case TargetMachine::AssemblyFile:
+      PM.add(createX86CodePrinterPass(Out, *this));
+      break;
+    case TargetMachine::ObjectFile:
+      // FIXME: We only support emission of ELF files for now, this should check
+      // the target triple and decide on the format to write (e.g. COFF on
+      // win32).
+      PM.add(createX86ELFObjectWriterPass(Out, *this));
+      break;
+    }
 
   // Delete machine code for this function
   PM.add(createMachineCodeDeleter());






More information about the llvm-commits mailing list