]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/lib/Target/MBlaze/InstPrinter/MBlazeInstPrinter.cpp
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / lib / Target / MBlaze / InstPrinter / MBlazeInstPrinter.cpp
1 //===-- MBlazeInstPrinter.cpp - Convert MBlaze MCInst to assembly syntax --===//
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 class prints an MBlaze MCInst to a .s file.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #define DEBUG_TYPE "asm-printer"
15 #include "MBlaze.h"
16 #include "MBlazeInstPrinter.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/FormattedStream.h"
22 using namespace llvm;
23
24
25 // Include the auto-generated portion of the assembly writer.
26 #include "MBlazeGenAsmWriter.inc"
27
28 void MBlazeInstPrinter::printInst(const MCInst *MI, raw_ostream &O) {
29   printInstruction(MI, O);
30 }
31
32 void MBlazeInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
33                                      raw_ostream &O, const char *Modifier) {
34   assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
35   const MCOperand &Op = MI->getOperand(OpNo);
36   if (Op.isReg()) {
37     O << getRegisterName(Op.getReg());
38   } else if (Op.isImm()) {
39     O << (int32_t)Op.getImm();
40   } else {
41     assert(Op.isExpr() && "unknown operand kind in printOperand");
42     O << *Op.getExpr();
43   }
44 }
45
46 void MBlazeInstPrinter::printFSLImm(const MCInst *MI, int OpNo,
47                                     raw_ostream &O) {
48   const MCOperand &MO = MI->getOperand(OpNo);
49   if (MO.isImm())
50     O << "rfsl" << MO.getImm();
51   else
52     printOperand(MI, OpNo, O, NULL);
53 }
54
55 void MBlazeInstPrinter::printUnsignedImm(const MCInst *MI, int OpNo,
56                                         raw_ostream &O) {
57   const MCOperand &MO = MI->getOperand(OpNo);
58   if (MO.isImm())
59     O << (uint32_t)MO.getImm();
60   else
61     printOperand(MI, OpNo, O, NULL);
62 }
63
64 void MBlazeInstPrinter::printMemOperand(const MCInst *MI, int OpNo,
65                                         raw_ostream &O, const char *Modifier) {
66   printOperand(MI, OpNo, O, NULL);
67   O << ", ";
68   printOperand(MI, OpNo+1, O, NULL);
69 }