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"
16 #include "MSP430InstrInfo.h"
17 #include "MSP430InstPrinter.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/MC/MCExpr.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/FormattedStream.h"
26 // Include the auto-generated portion of the assembly writer.
27 #define MachineInstr MCInst
28 #define NO_ASM_WRITER_BOILERPLATE
29 #include "MSP430GenAsmWriter.inc"
32 void MSP430InstPrinter::printInst(const MCInst *MI) {
36 void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo) {
37 const MCOperand &Op = MI->getOperand(OpNo);
41 assert(Op.isExpr() && "unknown pcrel immediate operand");
46 void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
47 const char *Modifier) {
48 assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
49 const MCOperand &Op = MI->getOperand(OpNo);
51 O << getRegisterName(Op.getReg());
52 } else if (Op.isImm()) {
53 O << '#' << Op.getImm();
55 assert(Op.isExpr() && "unknown operand kind in printOperand");
56 O << '#' << *Op.getExpr();
60 void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
61 const char *Modifier) {
62 const MCOperand &Base = MI->getOperand(OpNo);
63 const MCOperand &Disp = MI->getOperand(OpNo+1);
65 // Print displacement first
67 O << '&' << *Disp.getExpr();
69 assert(Disp.isImm() && "Expected immediate in displacement field");
77 // Print register base field
79 O << '(' << getRegisterName(Base.getReg()) << ')';
83 void MSP430InstPrinter::printCCOperand(const MCInst *MI, unsigned OpNo) {
84 unsigned CC = MI->getOperand(OpNo).getImm();
88 llvm_unreachable("Unsupported CC code");
90 case MSP430CC::COND_E:
93 case MSP430CC::COND_NE:
96 case MSP430CC::COND_HS:
99 case MSP430CC::COND_LO:
102 case MSP430CC::COND_GE:
105 case MSP430CC::COND_L: