blob: ecff0e8b2b38449e86cd45bfeb5bbc8a8997e68d [file] [log] [blame]
Chris Lattner5ffe38e2010-11-15 04:16:32 +00001//===-- 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"
21using namespace llvm;
22
23STATISTIC(MCNumEmitted, "Number of MC instructions emitted");
24
25namespace {
26class 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
32public:
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
86MCCodeEmitter *llvm::createPPCMCCodeEmitter(const Target &, TargetMachine &TM,
87 MCContext &Ctx) {
88 return new PPCMCCodeEmitter(TM, Ctx);
89}
90
91unsigned PPCMCCodeEmitter::
92getMachineOpValue(const MCInst &MI, const MCOperand &MO,
93 SmallVectorImpl<MCFixup> &Fixups) const {
94 // FIXME.
95 return 0;
96}
97
98
99#include "PPCGenMCCodeEmitter.inc"