Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 1 | //===-- PPC32CodeEmitter.cpp - JIT Code Emitter for PowerPC32 -----*- C++ -*-=// |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 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 | |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 13 | #include "PPC32JITInfo.h" |
| 14 | #include "PPC32TargetMachine.h" |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineCodeEmitter.h" |
| 16 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 17 | #include "llvm/CodeGen/Passes.h" |
| 18 | #include "Support/Debug.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 22 | namespace { |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 23 | class PPC32CodeEmitter : public MachineFunctionPass { |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 24 | TargetMachine &TM; |
| 25 | MachineCodeEmitter &MCE; |
| 26 | |
| 27 | public: |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 28 | PPC32CodeEmitter(TargetMachine &T, MachineCodeEmitter &M) |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 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 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 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 | /// |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 59 | bool PPC32TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM, |
| 60 | MachineCodeEmitter &MCE) { |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 61 | // Machine code emitter pass for PowerPC |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 62 | PM.add(new PPC32CodeEmitter(*this, MCE)); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 63 | // Delete machine code for this function after emitting it: |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 64 | PM.add(createMachineCodeDeleter()); |
| 65 | // We don't yet support machine code emission |
| 66 | return true; |
| 67 | } |
| 68 | |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 69 | bool PPC32CodeEmitter::runOnMachineFunction(MachineFunction &MF) { |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 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 | |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 78 | void PPC32CodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) { |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 79 | for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I) |
| 80 | emitWord(getBinaryCodeForInstr(*I)); |
| 81 | } |
| 82 | |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 83 | unsigned PPC32CodeEmitter::getValueBit(int64_t Val, unsigned bit) { |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 84 | Val >>= bit; |
| 85 | return (Val & 1); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 88 | void *PPC32JITInfo::getJITStubForFunction(Function *F, |
| 89 | MachineCodeEmitter &MCE) { |
| 90 | assert (0 && "PPC32JITInfo::getJITStubForFunction not implemented"); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 91 | return 0; |
| 92 | } |
| 93 | |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 94 | void PPC32JITInfo::replaceMachineCodeForFunction (void *Old, void *New) { |
| 95 | assert (0 && "PPC32JITInfo::replaceMachineCodeForFunction not implemented"); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 98 | //#include "PowerPCGenCodeEmitter.inc" |
| 99 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 100 | } // end llvm namespace |
| 101 | |