mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-26 10:29:36 +00:00
per-function subtarget. Currently, code-gen passes the default or generic subtarget to the constructors of MCInstPrinter subclasses (see LLVMTargetMachine::addPassesToEmitFile), which enables some targets (AArch64, ARM, and X86) to change their instprinter's behavior based on the subtarget feature bits. Since the backend can now use different subtargets for each function, instprinter has to be changed to use the per-function subtarget rather than the default subtarget. This patch takes the first step towards enabling instprinter to change its behavior based on the per-function subtarget. It adds a bit "PassSubtarget" to AsmWriter which tells table-gen to pass a reference to MCSubtargetInfo to the various print methods table-gen auto-generates. I will follow up with changes to instprinters of AArch64, ARM, and X86. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233411 91177308-0d34-0410-b5e6-96231b3b80d8
116 lines
3.3 KiB
C++
116 lines
3.3 KiB
C++
//===-- 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.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "MSP430InstPrinter.h"
|
|
#include "MSP430.h"
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
#include "llvm/MC/MCExpr.h"
|
|
#include "llvm/MC/MCInst.h"
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
#include "llvm/Support/FormattedStream.h"
|
|
using namespace llvm;
|
|
|
|
#define DEBUG_TYPE "asm-printer"
|
|
|
|
|
|
// Include the auto-generated portion of the assembly writer.
|
|
#include "MSP430GenAsmWriter.inc"
|
|
|
|
void MSP430InstPrinter::printInst(const MCInst *MI, raw_ostream &O,
|
|
StringRef Annot, const MCSubtargetInfo &STI) {
|
|
printInstruction(MI, O);
|
|
printAnnotation(O, Annot);
|
|
}
|
|
|
|
void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo,
|
|
raw_ostream &O) {
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
if (Op.isImm())
|
|
O << Op.getImm();
|
|
else {
|
|
assert(Op.isExpr() && "unknown pcrel immediate operand");
|
|
O << *Op.getExpr();
|
|
}
|
|
}
|
|
|
|
void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
|
raw_ostream &O, const char *Modifier) {
|
|
assert((Modifier == nullptr || Modifier[0] == 0) && "No modifiers supported");
|
|
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");
|
|
O << '#' << *Op.getExpr();
|
|
}
|
|
}
|
|
|
|
void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
|
|
raw_ostream &O,
|
|
const char *Modifier) {
|
|
const MCOperand &Base = MI->getOperand(OpNo);
|
|
const MCOperand &Disp = MI->getOperand(OpNo+1);
|
|
|
|
// Print displacement first
|
|
|
|
// If the global address expression is a part of displacement field with a
|
|
// register base, we should not emit any prefix symbol here, e.g.
|
|
// mov.w &foo, r1
|
|
// vs
|
|
// mov.w glb(r1), r2
|
|
// Otherwise (!) msp430-as will silently miscompile the output :(
|
|
if (!Base.getReg())
|
|
O << '&';
|
|
|
|
if (Disp.isExpr())
|
|
O << *Disp.getExpr();
|
|
else {
|
|
assert(Disp.isImm() && "Expected immediate in displacement field");
|
|
O << Disp.getImm();
|
|
}
|
|
|
|
// Print register base field
|
|
if (Base.getReg())
|
|
O << '(' << getRegisterName(Base.getReg()) << ')';
|
|
}
|
|
|
|
void MSP430InstPrinter::printCCOperand(const MCInst *MI, unsigned OpNo,
|
|
raw_ostream &O) {
|
|
unsigned CC = MI->getOperand(OpNo).getImm();
|
|
|
|
switch (CC) {
|
|
default:
|
|
llvm_unreachable("Unsupported CC code");
|
|
case MSP430CC::COND_E:
|
|
O << "eq";
|
|
break;
|
|
case MSP430CC::COND_NE:
|
|
O << "ne";
|
|
break;
|
|
case MSP430CC::COND_HS:
|
|
O << "hs";
|
|
break;
|
|
case MSP430CC::COND_LO:
|
|
O << "lo";
|
|
break;
|
|
case MSP430CC::COND_GE:
|
|
O << "ge";
|
|
break;
|
|
case MSP430CC::COND_L:
|
|
O << 'l';
|
|
break;
|
|
}
|
|
}
|