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 #include "MSP430InstPrinter.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/FormattedStream.h"
23 #define DEBUG_TYPE "asm-printer"
26 // Include the auto-generated portion of the assembly writer.
27 #include "MSP430GenAsmWriter.inc"
29 void MSP430InstPrinter::printInst(const MCInst *MI, raw_ostream &O,
30 StringRef Annot, const MCSubtargetInfo &STI) {
31 printInstruction(MI, O);
32 printAnnotation(O, Annot);
35 void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo,
37 const MCOperand &Op = MI->getOperand(OpNo);
41 assert(Op.isExpr() && "unknown pcrel immediate operand");
42 Op.getExpr()->print(O, &MAI);
46 void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
47 raw_ostream &O, const char *Modifier) {
48 assert((Modifier == nullptr || 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");
57 Op.getExpr()->print(O, &MAI);
61 void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
63 const char *Modifier) {
64 const MCOperand &Base = MI->getOperand(OpNo);
65 const MCOperand &Disp = MI->getOperand(OpNo+1);
67 // Print displacement first
69 // If the global address expression is a part of displacement field with a
70 // register base, we should not emit any prefix symbol here, e.g.
74 // Otherwise (!) msp430-as will silently miscompile the output :(
79 Disp.getExpr()->print(O, &MAI);
81 assert(Disp.isImm() && "Expected immediate in displacement field");
85 // Print register base field
87 O << '(' << getRegisterName(Base.getReg()) << ')';
90 void MSP430InstPrinter::printCCOperand(const MCInst *MI, unsigned OpNo,
92 unsigned CC = MI->getOperand(OpNo).getImm();
96 llvm_unreachable("Unsupported CC code");
97 case MSP430CC::COND_E:
100 case MSP430CC::COND_NE:
103 case MSP430CC::COND_HS:
106 case MSP430CC::COND_LO:
109 case MSP430CC::COND_GE:
112 case MSP430CC::COND_L: