blob: cfebe97dfe1bbf2b58f4cc77eed84334664585d2 [file] [log] [blame]
Jim Grosbach568eeed2010-09-17 18:46:17 +00001//===-- ARM/ARMMCCodeEmitter.cpp - Convert ARM 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 ARMMCCodeEmitter class.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "arm-emitter"
15#include "ARM.h"
Jim Grosbachae93ed12010-10-07 20:41:30 +000016#include "ARMBaseInfo.h"
Jim Grosbach568eeed2010-09-17 18:46:17 +000017#include "llvm/MC/MCCodeEmitter.h"
18#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCInst.h"
20#include "llvm/Support/raw_ostream.h"
21using namespace llvm;
22
23namespace {
24class ARMMCCodeEmitter : public MCCodeEmitter {
25 ARMMCCodeEmitter(const ARMMCCodeEmitter &); // DO NOT IMPLEMENT
26 void operator=(const ARMMCCodeEmitter &); // DO NOT IMPLEMENT
27 const TargetMachine &TM;
28 const TargetInstrInfo &TII;
29 MCContext &Ctx;
30
31public:
32 ARMMCCodeEmitter(TargetMachine &tm, MCContext &ctx)
33 : TM(tm), TII(*TM.getInstrInfo()), Ctx(ctx) {
34 assert(0 && "ARMMCCodeEmitter::ARMMCCodeEmitter() not yet implemented.");
35 }
36
37 ~ARMMCCodeEmitter() {}
38
Jim Grosbach9af82ba2010-10-07 21:57:55 +000039 // getBinaryCodeForInstr - TableGen'erated function for getting the
40 // binary encoding for an instruction.
41 unsigned getBinaryCodeForInstr(const MCInst &MI);
42
43 /// getMachineOpValue - Return binary encoding of operand. If the machine
44 /// operand requires relocation, record the relocation and return zero.
45 unsigned getMachineOpValue(const MCInst &MI,const MCOperand &MO);
46 unsigned getMachineOpValue(const MCInst &MI, unsigned OpIdx) {
47 return getMachineOpValue(MI, MI.getOperand(OpIdx));
48 }
49
Jim Grosbach568eeed2010-09-17 18:46:17 +000050 unsigned getNumFixupKinds() const {
51 assert(0 && "ARMMCCodeEmitter::getNumFixupKinds() not yet implemented.");
Michael J. Spencer895dda62010-09-18 17:54:37 +000052 return 0;
Jim Grosbach568eeed2010-09-17 18:46:17 +000053 }
54
55 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
56 static MCFixupKindInfo rtn;
57 assert(0 && "ARMMCCodeEmitter::getFixupKindInfo() not yet implemented.");
58 return rtn;
59 }
60
61 static unsigned GetARMRegNum(const MCOperand &MO) {
62 // FIXME: getARMRegisterNumbering() is sufficient?
63 assert(0 && "ARMMCCodeEmitter::GetARMRegNum() not yet implemented.");
64 return 0;
65 }
66
67 void EmitByte(unsigned char C, unsigned &CurByte, raw_ostream &OS) const {
68 OS << (char)C;
69 ++CurByte;
70 }
71
72 void EmitConstant(uint64_t Val, unsigned Size, unsigned &CurByte,
73 raw_ostream &OS) const {
74 // Output the constant in little endian byte order.
75 for (unsigned i = 0; i != Size; ++i) {
76 EmitByte(Val & 255, CurByte, OS);
77 Val >>= 8;
78 }
79 }
80
81 void EmitImmediate(const MCOperand &Disp,
82 unsigned ImmSize, MCFixupKind FixupKind,
83 unsigned &CurByte, raw_ostream &OS,
84 SmallVectorImpl<MCFixup> &Fixups,
85 int ImmOffset = 0) const;
86
87 void EncodeInstruction(const MCInst &MI, raw_ostream &OS,
88 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach568eeed2010-09-17 18:46:17 +000089};
90
91} // end anonymous namespace
92
93
94MCCodeEmitter *llvm::createARMMCCodeEmitter(const Target &,
95 TargetMachine &TM,
96 MCContext &Ctx) {
97 return new ARMMCCodeEmitter(TM, Ctx);
98}
99
100void ARMMCCodeEmitter::
101EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind,
102 unsigned &CurByte, raw_ostream &OS,
103 SmallVectorImpl<MCFixup> &Fixups, int ImmOffset) const {
104 assert(0 && "ARMMCCodeEmitter::EmitImmediate() not yet implemented.");
105}
106
Jim Grosbach568eeed2010-09-17 18:46:17 +0000107void ARMMCCodeEmitter::
108EncodeInstruction(const MCInst &MI, raw_ostream &OS,
109 SmallVectorImpl<MCFixup> &Fixups) const {
110 assert(0 && "ARMMCCodeEmitter::EncodeInstruction() not yet implemented.");
111}
Jim Grosbach9af82ba2010-10-07 21:57:55 +0000112
113// FIXME: These #defines shouldn't be necessary. Instead, tblgen should
114// be able to generate code emitter helpers for either variant, like it
115// does for the AsmWriter.
116#define ARMCodeEmitter ARMMCCodeEmitter
117#define MachineInstr MCInst
118#include "ARMGenCodeEmitter.inc"
119#undef ARMCodeEmitter
120#undef MachineInstr