Chris Lattner | 5ffe38e | 2010-11-15 04:16:32 +0000 | [diff] [blame^] | 1 | //===-- PPCMCCodeEmitter.cpp - Convert PPC code to machine code -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the PPCMCCodeEmitter class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #define DEBUG_TYPE "mccodeemitter" |
| 15 | #include "PPC.h" |
| 16 | #include "llvm/MC/MCCodeEmitter.h" |
| 17 | #include "llvm/MC/MCInst.h" |
| 18 | #include "llvm/ADT/Statistic.h" |
| 19 | #include "llvm/Support/raw_ostream.h" |
| 20 | #include "llvm/Support/ErrorHandling.h" |
| 21 | using namespace llvm; |
| 22 | |
| 23 | STATISTIC(MCNumEmitted, "Number of MC instructions emitted"); |
| 24 | |
| 25 | namespace { |
| 26 | class PPCMCCodeEmitter : public MCCodeEmitter { |
| 27 | PPCMCCodeEmitter(const PPCMCCodeEmitter &); // DO NOT IMPLEMENT |
| 28 | void operator=(const PPCMCCodeEmitter &); // DO NOT IMPLEMENT |
| 29 | const TargetMachine &TM; |
| 30 | MCContext &Ctx; |
| 31 | |
| 32 | public: |
| 33 | PPCMCCodeEmitter(TargetMachine &tm, MCContext &ctx) |
| 34 | : TM(tm), Ctx(ctx) { |
| 35 | } |
| 36 | |
| 37 | ~PPCMCCodeEmitter() {} |
| 38 | |
| 39 | unsigned getNumFixupKinds() const { return 0 /*PPC::NumTargetFixupKinds*/; } |
| 40 | |
| 41 | const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const { |
| 42 | const static MCFixupKindInfo Infos[] = { |
| 43 | #if 0 |
| 44 | // name offset bits flags |
| 45 | { "fixup_arm_pcrel_12", 2, 12, MCFixupKindInfo::FKF_IsPCRel }, |
| 46 | { "fixup_arm_vfp_pcrel_12", 3, 8, MCFixupKindInfo::FKF_IsPCRel }, |
| 47 | { "fixup_arm_branch", 1, 24, MCFixupKindInfo::FKF_IsPCRel }, |
| 48 | #endif |
| 49 | }; |
| 50 | |
| 51 | if (Kind < FirstTargetFixupKind) |
| 52 | return MCCodeEmitter::getFixupKindInfo(Kind); |
| 53 | |
| 54 | assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() && |
| 55 | "Invalid kind!"); |
| 56 | return Infos[Kind - FirstTargetFixupKind]; |
| 57 | } |
| 58 | |
| 59 | /// getMachineOpValue - Return binary encoding of operand. If the machine |
| 60 | /// operand requires relocation, record the relocation and return zero. |
| 61 | unsigned getMachineOpValue(const MCInst &MI,const MCOperand &MO, |
| 62 | SmallVectorImpl<MCFixup> &Fixups) const; |
| 63 | |
| 64 | |
| 65 | // getBinaryCodeForInstr - TableGen'erated function for getting the |
| 66 | // binary encoding for an instruction. |
| 67 | unsigned getBinaryCodeForInstr(const MCInst &MI, |
| 68 | SmallVectorImpl<MCFixup> &Fixups) const; |
| 69 | void EncodeInstruction(const MCInst &MI, raw_ostream &OS, |
| 70 | SmallVectorImpl<MCFixup> &Fixups) const { |
| 71 | unsigned Bits = getBinaryCodeForInstr(MI, Fixups); |
| 72 | |
| 73 | // Output the constant in big endian byte order. |
| 74 | for (unsigned i = 0; i != 4; ++i) { |
| 75 | OS << (char)(Bits >> 24); |
| 76 | Bits <<= 8; |
| 77 | } |
| 78 | |
| 79 | ++MCNumEmitted; // Keep track of the # of mi's emitted. |
| 80 | } |
| 81 | |
| 82 | }; |
| 83 | |
| 84 | } // end anonymous namespace |
| 85 | |
| 86 | MCCodeEmitter *llvm::createPPCMCCodeEmitter(const Target &, TargetMachine &TM, |
| 87 | MCContext &Ctx) { |
| 88 | return new PPCMCCodeEmitter(TM, Ctx); |
| 89 | } |
| 90 | |
| 91 | unsigned PPCMCCodeEmitter:: |
| 92 | getMachineOpValue(const MCInst &MI, const MCOperand &MO, |
| 93 | SmallVectorImpl<MCFixup> &Fixups) const { |
| 94 | // FIXME. |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | #include "PPCGenMCCodeEmitter.inc" |