blob: a4803071523e08b23b008d5f16541b2945766b90 [file] [log] [blame]
Anton Korobeynikov425a9382009-10-21 00:10:30 +00001//===-- MSP430InstPrinter.cpp - Convert MSP430 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 MSP430 MCInst to a .s file.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "asm-printer"
Anton Korobeynikova791a042009-10-21 19:16:49 +000015#include "MSP430.h"
Anton Korobeynikov7199ce52009-10-21 00:13:05 +000016#include "MSP430InstrInfo.h"
Anton Korobeynikov425a9382009-10-21 00:10:30 +000017#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"
Anton Korobeynikov425a9382009-10-21 00:10:30 +000023using namespace llvm;
24
25
26// Include the auto-generated portion of the assembly writer.
27#define MachineInstr MCInst
Anton Korobeynikov425a9382009-10-21 00:10:30 +000028#define NO_ASM_WRITER_BOILERPLATE
29#include "MSP430GenAsmWriter.inc"
30#undef MachineInstr
Anton Korobeynikov425a9382009-10-21 00:10:30 +000031
32void MSP430InstPrinter::printInst(const MCInst *MI) {
33 printInstruction(MI);
34}
Anton Korobeynikov0f66de42009-10-21 00:11:27 +000035
Anton Korobeynikovc9a90ae2009-10-21 00:13:25 +000036void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo) {
37 const MCOperand &Op = MI->getOperand(OpNo);
38 if (Op.isImm())
39 O << Op.getImm();
40 else {
41 assert(Op.isExpr() && "unknown pcrel immediate operand");
Chris Lattner1e9a11b2010-01-18 00:37:40 +000042 O << *Op.getExpr();
Anton Korobeynikovc9a90ae2009-10-21 00:13:25 +000043 }
44}
45
Anton Korobeynikov0f66de42009-10-21 00:11:27 +000046void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
47 const char *Modifier) {
Anton Korobeynikovdd5e1eb2009-10-21 00:13:58 +000048 assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
Anton Korobeynikov0f66de42009-10-21 00:11:27 +000049 const MCOperand &Op = MI->getOperand(OpNo);
50 if (Op.isReg()) {
51 O << getRegisterName(Op.getReg());
52 } else if (Op.isImm()) {
53 O << '#' << Op.getImm();
54 } else {
55 assert(Op.isExpr() && "unknown operand kind in printOperand");
Chris Lattner1e9a11b2010-01-18 00:37:40 +000056 O << '#' << *Op.getExpr();
Anton Korobeynikov0f66de42009-10-21 00:11:27 +000057 }
58}
Anton Korobeynikovbaffc352009-10-21 00:12:08 +000059
60void 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);
64
Anton Korobeynikov1c7e1662009-11-07 17:13:35 +000065 // Print displacement first
66 if (Disp.isExpr()) {
Chris Lattner1e9a11b2010-01-18 00:37:40 +000067 O << '&' << *Disp.getExpr();
Anton Korobeynikovbaffc352009-10-21 00:12:08 +000068 } else {
Anton Korobeynikov1c7e1662009-11-07 17:13:35 +000069 assert(Disp.isImm() && "Expected immediate in displacement field");
70 if (!Base.getReg())
71 O << '&';
72
73 O << Disp.getImm();
74 }
75
76
77 // Print register base field
78 if (Base.getReg()) {
79 O << '(' << getRegisterName(Base.getReg()) << ')';
Anton Korobeynikovbaffc352009-10-21 00:12:08 +000080 }
Anton Korobeynikovbaffc352009-10-21 00:12:08 +000081}
Anton Korobeynikovc9a90ae2009-10-21 00:13:25 +000082
Anton Korobeynikov7199ce52009-10-21 00:13:05 +000083void MSP430InstPrinter::printCCOperand(const MCInst *MI, unsigned OpNo) {
84 unsigned CC = MI->getOperand(OpNo).getImm();
85
86 switch (CC) {
87 default:
88 llvm_unreachable("Unsupported CC code");
89 break;
Anton Korobeynikova791a042009-10-21 19:16:49 +000090 case MSP430CC::COND_E:
Anton Korobeynikov7199ce52009-10-21 00:13:05 +000091 O << "eq";
92 break;
Anton Korobeynikova791a042009-10-21 19:16:49 +000093 case MSP430CC::COND_NE:
Anton Korobeynikov7199ce52009-10-21 00:13:05 +000094 O << "ne";
95 break;
Anton Korobeynikova791a042009-10-21 19:16:49 +000096 case MSP430CC::COND_HS:
Anton Korobeynikov7199ce52009-10-21 00:13:05 +000097 O << "hs";
98 break;
Anton Korobeynikova791a042009-10-21 19:16:49 +000099 case MSP430CC::COND_LO:
Anton Korobeynikov7199ce52009-10-21 00:13:05 +0000100 O << "lo";
101 break;
Anton Korobeynikova791a042009-10-21 19:16:49 +0000102 case MSP430CC::COND_GE:
Anton Korobeynikov7199ce52009-10-21 00:13:05 +0000103 O << "ge";
104 break;
Anton Korobeynikova791a042009-10-21 19:16:49 +0000105 case MSP430CC::COND_L:
Anton Korobeynikov7199ce52009-10-21 00:13:05 +0000106 O << 'l';
107 break;
108 }
109}