blob: 84a2e023c4ee2f03eaa06d0b84c989879b6d66d4 [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"
15#include "MSP430InstPrinter.h"
16#include "llvm/MC/MCInst.h"
17#include "llvm/MC/MCAsmInfo.h"
18#include "llvm/MC/MCExpr.h"
19#include "llvm/Support/ErrorHandling.h"
20#include "llvm/Support/FormattedStream.h"
21#include "MSP430GenInstrNames.inc"
22using namespace llvm;
23
24
25// Include the auto-generated portion of the assembly writer.
26#define MachineInstr MCInst
27#define MSP430AsmPrinter MSP430InstPrinter // FIXME: REMOVE.
28#define NO_ASM_WRITER_BOILERPLATE
29#include "MSP430GenAsmWriter.inc"
30#undef MachineInstr
31#undef MSP430AsmPrinter
32
33void MSP430InstPrinter::printInst(const MCInst *MI) {
34 printInstruction(MI);
35}
Anton Korobeynikov0f66de42009-10-21 00:11:27 +000036
37void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
38 const char *Modifier) {
39 assert((Modifier == 0 || Modifier[0] == 0) && "Cannot print modifiers");
40
41 const MCOperand &Op = MI->getOperand(OpNo);
42 if (Op.isReg()) {
43 O << getRegisterName(Op.getReg());
44 } else if (Op.isImm()) {
45 O << '#' << Op.getImm();
46 } else {
47 assert(Op.isExpr() && "unknown operand kind in printOperand");
Anton Korobeynikovbaffc352009-10-21 00:12:08 +000048 Op.getExpr()->print(O, &MAI);
Anton Korobeynikov0f66de42009-10-21 00:11:27 +000049 }
50}
Anton Korobeynikovbaffc352009-10-21 00:12:08 +000051
52void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
53 const char *Modifier) {
54 const MCOperand &Base = MI->getOperand(OpNo);
55 const MCOperand &Disp = MI->getOperand(OpNo+1);
56
57 if (Disp.isImm() && !Base.isReg())
58 printOperand(MI, OpNo);
59 else if (Base.isReg()) {
60 if (Disp.getImm()) {
61 O << Disp.getImm() << '(';
62 printOperand(MI, OpNo);
63 O << ')';
64 } else {
65 O << '@';
66 printOperand(MI, OpNo);
67 }
68 } else {
69 Base.dump();
70 Disp.dump();
71 llvm_unreachable("Unsupported memory operand");
72 }
73
74}