2009-10-21 00:10:30 +00:00
|
|
|
//===-- MSP430InstPrinter.cpp - Convert MSP430 MCInst to assembly syntax --===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class prints an MSP430 MCInst to a .s file.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "asm-printer"
|
2009-10-21 19:16:49 +00:00
|
|
|
#include "MSP430.h"
|
2009-10-21 00:13:05 +00:00
|
|
|
#include "MSP430InstrInfo.h"
|
2009-10-21 00:10:30 +00:00
|
|
|
#include "MSP430InstPrinter.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
|
|
|
|
// Include the auto-generated portion of the assembly writer.
|
|
|
|
#define MachineInstr MCInst
|
|
|
|
#define NO_ASM_WRITER_BOILERPLATE
|
|
|
|
#include "MSP430GenAsmWriter.inc"
|
|
|
|
#undef MachineInstr
|
|
|
|
|
|
|
|
void MSP430InstPrinter::printInst(const MCInst *MI) {
|
|
|
|
printInstruction(MI);
|
|
|
|
}
|
2009-10-21 00:11:27 +00:00
|
|
|
|
2009-10-21 00:13:25 +00:00
|
|
|
void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo) {
|
|
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
|
|
if (Op.isImm())
|
|
|
|
O << Op.getImm();
|
|
|
|
else {
|
|
|
|
assert(Op.isExpr() && "unknown pcrel immediate operand");
|
2010-01-18 00:37:40 +00:00
|
|
|
O << *Op.getExpr();
|
2009-10-21 00:13:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 00:11:27 +00:00
|
|
|
void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
|
|
|
const char *Modifier) {
|
2009-10-21 00:13:58 +00:00
|
|
|
assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
|
2009-10-21 00:11:27 +00:00
|
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
|
|
if (Op.isReg()) {
|
|
|
|
O << getRegisterName(Op.getReg());
|
|
|
|
} else if (Op.isImm()) {
|
|
|
|
O << '#' << Op.getImm();
|
|
|
|
} else {
|
|
|
|
assert(Op.isExpr() && "unknown operand kind in printOperand");
|
2010-01-18 00:37:40 +00:00
|
|
|
O << '#' << *Op.getExpr();
|
2009-10-21 00:11:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-21 00:12:08 +00:00
|
|
|
|
|
|
|
void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
|
|
|
|
const char *Modifier) {
|
|
|
|
const MCOperand &Base = MI->getOperand(OpNo);
|
|
|
|
const MCOperand &Disp = MI->getOperand(OpNo+1);
|
|
|
|
|
2009-11-07 17:13:35 +00:00
|
|
|
// Print displacement first
|
|
|
|
if (Disp.isExpr()) {
|
2010-01-18 00:37:40 +00:00
|
|
|
O << '&' << *Disp.getExpr();
|
2009-10-21 00:12:08 +00:00
|
|
|
} else {
|
2009-11-07 17:13:35 +00:00
|
|
|
assert(Disp.isImm() && "Expected immediate in displacement field");
|
|
|
|
if (!Base.getReg())
|
|
|
|
O << '&';
|
|
|
|
|
|
|
|
O << Disp.getImm();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Print register base field
|
|
|
|
if (Base.getReg()) {
|
|
|
|
O << '(' << getRegisterName(Base.getReg()) << ')';
|
2009-10-21 00:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-21 00:13:25 +00:00
|
|
|
|
2009-10-21 00:13:05 +00:00
|
|
|
void MSP430InstPrinter::printCCOperand(const MCInst *MI, unsigned OpNo) {
|
|
|
|
unsigned CC = MI->getOperand(OpNo).getImm();
|
|
|
|
|
|
|
|
switch (CC) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unsupported CC code");
|
|
|
|
break;
|
2009-10-21 19:16:49 +00:00
|
|
|
case MSP430CC::COND_E:
|
2009-10-21 00:13:05 +00:00
|
|
|
O << "eq";
|
|
|
|
break;
|
2009-10-21 19:16:49 +00:00
|
|
|
case MSP430CC::COND_NE:
|
2009-10-21 00:13:05 +00:00
|
|
|
O << "ne";
|
|
|
|
break;
|
2009-10-21 19:16:49 +00:00
|
|
|
case MSP430CC::COND_HS:
|
2009-10-21 00:13:05 +00:00
|
|
|
O << "hs";
|
|
|
|
break;
|
2009-10-21 19:16:49 +00:00
|
|
|
case MSP430CC::COND_LO:
|
2009-10-21 00:13:05 +00:00
|
|
|
O << "lo";
|
|
|
|
break;
|
2009-10-21 19:16:49 +00:00
|
|
|
case MSP430CC::COND_GE:
|
2009-10-21 00:13:05 +00:00
|
|
|
O << "ge";
|
|
|
|
break;
|
2009-10-21 19:16:49 +00:00
|
|
|
case MSP430CC::COND_L:
|
2009-10-21 00:13:05 +00:00
|
|
|
O << 'l';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|