Misha Brukman | 3de36f5 | 2003-05-27 20:07:58 +0000 | [diff] [blame] | 1 | #include "llvm/PassManager.h" |
| 2 | #include "llvm/CodeGen/MachineCodeEmitter.h" |
| 3 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 4 | #include "llvm/CodeGen/MachineInstr.h" |
| 5 | #include "SparcInternals.h" |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame^] | 6 | #include "SparcV9CodeEmitter.h" |
Misha Brukman | 3de36f5 | 2003-05-27 20:07:58 +0000 | [diff] [blame] | 7 | |
| 8 | bool UltraSparc::addPassesToEmitMachineCode(PassManager &PM, |
| 9 | MachineCodeEmitter &MCE) { |
| 10 | //PM.add(new SparcV9CodeEmitter(MCE)); |
| 11 | //MachineCodeEmitter *M = MachineCodeEmitter::createDebugMachineCodeEmitter(); |
| 12 | MachineCodeEmitter *M = |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame^] | 13 | MachineCodeEmitter::createFilePrinterMachineCodeEmitter(MCE); |
Misha Brukman | 3de36f5 | 2003-05-27 20:07:58 +0000 | [diff] [blame] | 14 | PM.add(new SparcV9CodeEmitter(*M)); |
| 15 | return false; |
| 16 | } |
| 17 | |
| 18 | void SparcV9CodeEmitter::emitConstant(unsigned Val, unsigned Size) { |
| 19 | // Output the constant in big endian byte order... |
| 20 | unsigned byteVal; |
| 21 | for (int i = Size-1; i >= 0; --i) { |
| 22 | byteVal = Val >> 8*i; |
| 23 | MCE.emitByte(byteVal & 255); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | int64_t SparcV9CodeEmitter::getMachineOpValue(MachineOperand &MO) { |
| 28 | if (MO.isPhysicalRegister()) { |
| 29 | return MO.getReg(); |
| 30 | } else if (MO.isImmediate()) { |
| 31 | return MO.getImmedValue(); |
| 32 | } else if (MO.isPCRelativeDisp()) { |
| 33 | // FIXME!!! |
| 34 | //return MO.getPCRelativeDisp(); |
| 35 | return 0; |
| 36 | } else { |
| 37 | assert(0 && "Unknown type of MachineOperand"); |
| 38 | return 0; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | unsigned SparcV9CodeEmitter::getValueBit(int64_t Val, unsigned bit) { |
| 43 | Val >>= bit; |
| 44 | return (Val & 1); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | bool SparcV9CodeEmitter::runOnMachineFunction(MachineFunction &MF) { |
| 49 | MCE.startFunction(MF); |
| 50 | MCE.emitConstantPool(MF.getConstantPool()); |
| 51 | for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) |
| 52 | emitBasicBlock(*I); |
| 53 | MCE.finishFunction(MF); |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | void SparcV9CodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) { |
| 58 | MCE.startBasicBlock(MBB); |
| 59 | for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I) |
| 60 | emitInstruction(**I); |
| 61 | } |
| 62 | |
| 63 | void SparcV9CodeEmitter::emitInstruction(MachineInstr &MI) { |
| 64 | emitConstant(getBinaryCodeForInstr(MI), 4); |
| 65 | } |
| 66 | |
| 67 | #include "SparcV9CodeEmitter.inc" |