2e94030dbdeebb7cb34ee47e1558214ae31d96db
[oota-llvm.git] / lib / Target / PowerPC / PPCMCInstLower.cpp
1 //===-- PPCMCInstLower.cpp - Convert PPC MachineInstr to an MCInst --------===//
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 contains code to lower PPC MachineInstrs to their corresponding
11 // MCInst records.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "PPC.h"
16 #include "llvm/CodeGen/AsmPrinter.h"
17 #include "llvm/CodeGen/MachineBasicBlock.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCInst.h"
20 using namespace llvm;
21
22 void llvm::LowerPPCMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,
23                                         AsmPrinter &Printer) {
24   OutMI.setOpcode(MI->getOpcode());
25   
26   for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
27     const MachineOperand &MO = MI->getOperand(i);
28     
29     MCOperand MCOp;
30     switch (MO.getType()) {
31     default:
32       MI->dump();
33       assert(0 && "unknown operand type");
34     case MachineOperand::MO_Register:
35       assert(!MO.getSubReg() && "Subregs should be eliminated!");
36       MCOp = MCOperand::CreateReg(MO.getReg());
37       break;
38     case MachineOperand::MO_Immediate:
39       MCOp = MCOperand::CreateImm(MO.getImm());
40       break;
41     }
42     
43     OutMI.addOperand(MCOp);
44   }
45 }