blob: 8760ed5602bad70476004fd5ed2e3af0dc43db87 [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) {
Anton Korobeynikov0f66de42009-10-21 00:11:27 +000039 const MCOperand &Op = MI->getOperand(OpNo);
40 if (Op.isReg()) {
41 O << getRegisterName(Op.getReg());
42 } else if (Op.isImm()) {
43 O << '#' << Op.getImm();
44 } else {
45 assert(Op.isExpr() && "unknown operand kind in printOperand");
Anton Korobeynikoveb85a3f2009-10-21 00:12:27 +000046 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
47 O << (isMemOp ? '&' : '#');
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
Anton Korobeynikoveb85a3f2009-10-21 00:12:27 +000057 // FIXME: move global to displacement field!
58 if (Base.isExpr())
59 printOperand(MI, OpNo, "mem");
60 else if (Disp.isImm() && !Base.isReg())
Anton Korobeynikovbaffc352009-10-21 00:12:08 +000061 printOperand(MI, OpNo);
62 else if (Base.isReg()) {
63 if (Disp.getImm()) {
64 O << Disp.getImm() << '(';
65 printOperand(MI, OpNo);
66 O << ')';
67 } else {
68 O << '@';
69 printOperand(MI, OpNo);
70 }
71 } else {
72 Base.dump();
73 Disp.dump();
74 llvm_unreachable("Unsupported memory operand");
75 }
76
77}