llvm.org GIT mirror llvm / 92b1dfe
set up some infrastructure, some minor cleanups. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95260 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
1 changed file(s) with 39 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
1212
1313 #define DEBUG_TYPE "x86-emitter"
1414 #include "X86.h"
15 #include "X86TargetMachine.h"
15 #include "X86InstrInfo.h"
1616 #include "llvm/MC/MCCodeEmitter.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/Support/raw_ostream.h"
1719 using namespace llvm;
1820
1921 namespace {
2022 class X86MCCodeEmitter : public MCCodeEmitter {
2123 X86MCCodeEmitter(const X86MCCodeEmitter &); // DO NOT IMPLEMENT
2224 void operator=(const X86MCCodeEmitter &); // DO NOT IMPLEMENT
23 X86TargetMachine &TM;
25 const TargetMachine &TM;
26 const TargetInstrInfo &TII;
2427 public:
25 X86MCCodeEmitter(X86TargetMachine &tm) : TM(tm) {
28 X86MCCodeEmitter(TargetMachine &tm)
29 : TM(tm), TII(*TM.getInstrInfo()) {
2630 }
2731
2832 ~X86MCCodeEmitter() {}
2933
30 void EncodeInstruction(const MCInst &MI, raw_ostream &OS) const {
34 void EmitByte(unsigned char C, raw_ostream &OS) const {
35 OS << (char)C;
3136 }
37
38 void EncodeInstruction(const MCInst &MI, raw_ostream &OS) const;
39
3240 };
3341
3442 } // end anonymous namespace
3644
3745 MCCodeEmitter *llvm::createX86MCCodeEmitter(const Target &,
3846 TargetMachine &TM) {
39 return new X86MCCodeEmitter(static_cast(TM));
47 return new X86MCCodeEmitter(TM);
4048 }
49
50
51
52 void X86MCCodeEmitter::
53 EncodeInstruction(const MCInst &MI, raw_ostream &OS) const {
54 unsigned Opcode = MI.getOpcode();
55 const TargetInstrDesc &Desc = TII.get(Opcode);
56
57 // Emit the lock opcode prefix as needed.
58 if (Desc.TSFlags & X86II::LOCK)
59 EmitByte(0xF0, OS);
60
61 // Emit segment override opcode prefix as needed.
62 switch (Desc.TSFlags & X86II::SegOvrMask) {
63 default: assert(0 && "Invalid segment!");
64 case 0: break; // No segment override!
65 case X86II::FS:
66 EmitByte(0x64, OS);
67 break;
68 case X86II::GS:
69 EmitByte(0x65, OS);
70 break;
71 }
72
73
74 }