Changes For Bug 352
[oota-llvm.git] / lib / Target / PowerPC / PPCCodeEmitter.cpp
1 //===-- PPC32CodeEmitter.cpp - JIT Code Emitter for PowerPC32 -----*- C++ -*-=//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 // 
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "PPC32JITInfo.h"
14 #include "PPC32TargetMachine.h"
15 #include "llvm/CodeGen/MachineCodeEmitter.h"
16 #include "llvm/CodeGen/MachineFunctionPass.h"
17 #include "llvm/CodeGen/Passes.h"
18 #include "llvm/Support/Debug.h"
19
20 namespace llvm {
21
22 namespace {
23   class PPC32CodeEmitter : public MachineFunctionPass {
24     TargetMachine &TM;
25     MachineCodeEmitter &MCE;
26
27   public:
28     PPC32CodeEmitter(TargetMachine &T, MachineCodeEmitter &M) 
29       : TM(T), MCE(M) {}
30
31     const char *getPassName() const { return "PowerPC Machine Code Emitter"; }
32
33     /// runOnMachineFunction - emits the given MachineFunction to memory
34     ///
35     bool runOnMachineFunction(MachineFunction &MF);
36
37     /// emitBasicBlock - emits the given MachineBasicBlock to memory
38     ///
39     void emitBasicBlock(MachineBasicBlock &MBB);
40
41     /// emitWord - write a 32-bit word to memory at the current PC
42     ///
43     void emitWord(unsigned w) { MCE.emitWord(w); }
44
45     unsigned getValueBit(int64_t Val, unsigned bit);
46
47     /// getBinaryCodeForInstr - returns the assembled code for an instruction
48     ///
49     unsigned getBinaryCodeForInstr(MachineInstr &MI) { return 0; }
50   };
51 }
52
53 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to get
54 /// machine code emitted.  This uses a MachineCodeEmitter object to handle
55 /// actually outputting the machine code and resolving things like the address
56 /// of functions.  This method should returns true if machine code emission is
57 /// not supported.
58 ///
59 bool PPC32TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
60                                                     MachineCodeEmitter &MCE) {
61   // Machine code emitter pass for PowerPC
62   PM.add(new PPC32CodeEmitter(*this, MCE)); 
63   // Delete machine code for this function after emitting it:
64   PM.add(createMachineCodeDeleter());
65   // We don't yet support machine code emission
66   return true;
67 }
68
69 bool PPC32CodeEmitter::runOnMachineFunction(MachineFunction &MF) {
70   MCE.startFunction(MF);
71   MCE.emitConstantPool(MF.getConstantPool());
72   for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
73     emitBasicBlock(*I);
74   MCE.finishFunction(MF);
75   return false;
76 }
77
78 void PPC32CodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
79   for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I)
80     emitWord(getBinaryCodeForInstr(*I));
81 }
82
83 unsigned PPC32CodeEmitter::getValueBit(int64_t Val, unsigned bit) {
84   Val >>= bit;
85   return (Val & 1);
86 }
87
88 void *PPC32JITInfo::getJITStubForFunction(Function *F,
89                                           MachineCodeEmitter &MCE) {
90   assert (0 && "PPC32JITInfo::getJITStubForFunction not implemented");
91   return 0;
92 }
93
94 void PPC32JITInfo::replaceMachineCodeForFunction (void *Old, void *New) {
95   assert (0 && "PPC32JITInfo::replaceMachineCodeForFunction not implemented");
96 }
97
98 //#include "PowerPCGenCodeEmitter.inc"
99
100 } // end llvm namespace
101