]>
git.proxmox.com Git - rustc.git/blob - src/llvm/lib/Target/MSP430/InstPrinter/MSP430InstPrinter.cpp
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 "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"
25 // Include the auto-generated portion of the assembly writer.
26 #include "MSP430GenAsmWriter.inc"
28 void MSP430InstPrinter::printInst(const MCInst
*MI
, raw_ostream
&O
,
30 printInstruction(MI
, O
);
31 printAnnotation(O
, Annot
);
34 void MSP430InstPrinter::printPCRelImmOperand(const MCInst
*MI
, unsigned OpNo
,
36 const MCOperand
&Op
= MI
->getOperand(OpNo
);
40 assert(Op
.isExpr() && "unknown pcrel immediate operand");
45 void MSP430InstPrinter::printOperand(const MCInst
*MI
, unsigned OpNo
,
46 raw_ostream
&O
, const char *Modifier
) {
47 assert((Modifier
== 0 || Modifier
[0] == 0) && "No modifiers supported");
48 const MCOperand
&Op
= MI
->getOperand(OpNo
);
50 O
<< getRegisterName(Op
.getReg());
51 } else if (Op
.isImm()) {
52 O
<< '#' << Op
.getImm();
54 assert(Op
.isExpr() && "unknown operand kind in printOperand");
55 O
<< '#' << *Op
.getExpr();
59 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 // If the global address expression is a part of displacement field with a
68 // register base, we should not emit any prefix symbol here, e.g.
72 // Otherwise (!) msp430-as will silently miscompile the output :(
79 assert(Disp
.isImm() && "Expected immediate in displacement field");
83 // Print register base field
85 O
<< '(' << getRegisterName(Base
.getReg()) << ')';
88 void MSP430InstPrinter::printCCOperand(const MCInst
*MI
, unsigned OpNo
,
90 unsigned CC
= MI
->getOperand(OpNo
).getImm();
94 llvm_unreachable("Unsupported CC code");
95 case MSP430CC::COND_E
:
98 case MSP430CC::COND_NE
:
101 case MSP430CC::COND_HS
:
104 case MSP430CC::COND_LO
:
107 case MSP430CC::COND_GE
:
110 case MSP430CC::COND_L
: