1 //===-- MSP430InstPrinter.cpp - Convert MSP430 MCInst to assembly syntax --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class prints an MSP430 MCInst to a .s file.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "asm-printer"
15 #include "MSP430InstrInfo.h"
16 #include "MSP430InstPrinter.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 #include "MSP430GenInstrNames.inc"
26 // Include the auto-generated portion of the assembly writer.
27 #define MachineInstr MCInst
28 #define MSP430AsmPrinter MSP430InstPrinter // FIXME: REMOVE.
29 #define NO_ASM_WRITER_BOILERPLATE
30 #include "MSP430GenAsmWriter.inc"
32 #undef MSP430AsmPrinter
34 void MSP430InstPrinter::printInst(const MCInst *MI) {
38 void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo) {
39 const MCOperand &Op = MI->getOperand(OpNo);
43 assert(Op.isExpr() && "unknown pcrel immediate operand");
44 Op.getExpr()->print(O, &MAI);
48 void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
49 const char *Modifier) {
50 assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
51 const MCOperand &Op = MI->getOperand(OpNo);
53 O << getRegisterName(Op.getReg());
54 } else if (Op.isImm()) {
55 O << '#' << Op.getImm();
57 assert(Op.isExpr() && "unknown operand kind in printOperand");
59 Op.getExpr()->print(O, &MAI);
63 void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
64 const char *Modifier) {
65 const MCOperand &Base = MI->getOperand(OpNo);
66 const MCOperand &Disp = MI->getOperand(OpNo+1);
68 // FIXME: move global to displacement field!
71 Base.getExpr()->print(O, &MAI);
72 } else if (Disp.isImm() && !Base.isReg())
73 printOperand(MI, OpNo);
74 else if (Base.isReg()) {
76 O << Disp.getImm() << '(';
77 printOperand(MI, OpNo);
81 printOperand(MI, OpNo);
86 llvm_unreachable("Unsupported memory operand");
90 void MSP430InstPrinter::printCCOperand(const MCInst *MI, unsigned OpNo) {
91 unsigned CC = MI->getOperand(OpNo).getImm();
95 llvm_unreachable("Unsupported CC code");
100 case MSP430::COND_NE:
103 case MSP430::COND_HS:
106 case MSP430::COND_LO:
109 case MSP430::COND_GE: