Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 1 | //===-- PowerPCCodeEmitter.cpp - JIT Code Emitter for PowerPC -----*- 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 "PowerPCTargetMachine.h" |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame^] | 14 | #include "llvm/CodeGen/MachineCodeEmitter.h" |
| 15 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 16 | #include "llvm/CodeGen/Passes.h" |
| 17 | #include "Support/Debug.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
| 20 | |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame^] | 21 | namespace { |
| 22 | class PowerPCCodeEmitter : public MachineFunctionPass { |
| 23 | TargetMachine &TM; |
| 24 | MachineCodeEmitter &MCE; |
| 25 | |
| 26 | public: |
| 27 | PowerPCCodeEmitter(TargetMachine &T, MachineCodeEmitter &M) |
| 28 | : TM(T), MCE(M) {} |
| 29 | |
| 30 | const char *getPassName() const { return "PowerPC Machine Code Emitter"; } |
| 31 | |
| 32 | /// runOnMachineFunction - emits the given MachineFunction to memory |
| 33 | /// |
| 34 | bool runOnMachineFunction(MachineFunction &MF); |
| 35 | |
| 36 | /// emitBasicBlock - emits the given MachineBasicBlock to memory |
| 37 | /// |
| 38 | void emitBasicBlock(MachineBasicBlock &MBB); |
| 39 | |
| 40 | /// emitWord - write a 32-bit word to memory at the current PC |
| 41 | /// |
| 42 | void emitWord(unsigned w) { MCE.emitWord(w); } |
| 43 | |
| 44 | unsigned getValueBit(int64_t Val, unsigned bit); |
| 45 | |
| 46 | /// getBinaryCodeForInstr - returns the assembled code for an instruction |
| 47 | /// |
| 48 | unsigned getBinaryCodeForInstr(MachineInstr &MI) { return 0; } |
| 49 | }; |
| 50 | } |
| 51 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 52 | /// addPassesToEmitMachineCode - Add passes to the specified pass manager to get |
| 53 | /// machine code emitted. This uses a MachineCodeEmitter object to handle |
| 54 | /// actually outputting the machine code and resolving things like the address |
| 55 | /// of functions. This method should returns true if machine code emission is |
| 56 | /// not supported. |
| 57 | /// |
| 58 | bool PowerPCTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM, |
| 59 | MachineCodeEmitter &MCE) { |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame^] | 60 | // Machine code emitter pass for PowerPC |
| 61 | PM.add(new PowerPCCodeEmitter(*this, MCE)); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 62 | // Delete machine code for this function after emitting it: |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame^] | 63 | PM.add(createMachineCodeDeleter()); |
| 64 | // We don't yet support machine code emission |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | bool PowerPCCodeEmitter::runOnMachineFunction(MachineFunction &MF) { |
| 69 | MCE.startFunction(MF); |
| 70 | MCE.emitConstantPool(MF.getConstantPool()); |
| 71 | for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) |
| 72 | emitBasicBlock(*I); |
| 73 | MCE.finishFunction(MF); |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | void PowerPCCodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) { |
| 78 | for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I) |
| 79 | emitWord(getBinaryCodeForInstr(*I)); |
| 80 | } |
| 81 | |
| 82 | unsigned PowerPCCodeEmitter::getValueBit(int64_t Val, unsigned bit) { |
| 83 | Val >>= bit; |
| 84 | return (Val & 1); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void *PowerPCJITInfo::getJITStubForFunction(Function *F, |
| 88 | MachineCodeEmitter &MCE) { |
| 89 | assert (0 && "PowerPCJITInfo::getJITStubForFunction not implemented"); |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | void PowerPCJITInfo::replaceMachineCodeForFunction (void *Old, void *New) { |
| 94 | assert (0 && "PowerPCJITInfo::replaceMachineCodeForFunction not implemented"); |
| 95 | } |
| 96 | |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame^] | 97 | //#include "PowerPCGenCodeEmitter.inc" |
| 98 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 99 | } // end llvm namespace |
| 100 | |