[ORC] Fail materialization in tasks that are destroyed before running.
[llvm-project.git] / llvm / lib / Target / MSP430 / MCTargetDesc / MSP430InstPrinter.cpp
blob57e23d24720423bb964c1d5f925a6d9981e4d8fb
1 //===-- MSP430InstPrinter.cpp - Convert MSP430 MCInst to assembly syntax --===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This class prints an MSP430 MCInst to a .s file.
11 //===----------------------------------------------------------------------===//
13 #include "MSP430InstPrinter.h"
14 #include "MSP430.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCExpr.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/Support/ErrorHandling.h"
20 using namespace llvm;
22 #define DEBUG_TYPE "asm-printer"
24 // Include the auto-generated portion of the assembly writer.
25 #define PRINT_ALIAS_INSTR
26 #include "MSP430GenAsmWriter.inc"
28 void MSP430InstPrinter::printRegName(raw_ostream &O, MCRegister Reg) {
29 O << getRegisterName(Reg);
32 void MSP430InstPrinter::printInst(const MCInst *MI, uint64_t Address,
33 StringRef Annot, const MCSubtargetInfo &STI,
34 raw_ostream &O) {
35 if (!printAliasInstr(MI, Address, O))
36 printInstruction(MI, Address, O);
37 printAnnotation(O, Annot);
40 void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo,
41 raw_ostream &O) {
42 const MCOperand &Op = MI->getOperand(OpNo);
43 if (Op.isImm()) {
44 int64_t Imm = Op.getImm() * 2 + 2;
45 O << "$";
46 if (Imm >= 0)
47 O << '+';
48 O << Imm;
49 } else {
50 assert(Op.isExpr() && "unknown pcrel immediate operand");
51 Op.getExpr()->print(O, &MAI);
55 void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
56 raw_ostream &O, const char *Modifier) {
57 assert((Modifier == nullptr || Modifier[0] == 0) && "No modifiers supported");
58 const MCOperand &Op = MI->getOperand(OpNo);
59 if (Op.isReg()) {
60 O << getRegisterName(Op.getReg());
61 } else if (Op.isImm()) {
62 O << '#' << Op.getImm();
63 } else {
64 assert(Op.isExpr() && "unknown operand kind in printOperand");
65 O << '#';
66 Op.getExpr()->print(O, &MAI);
70 void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
71 raw_ostream &O,
72 const char *Modifier) {
73 const MCOperand &Base = MI->getOperand(OpNo);
74 const MCOperand &Disp = MI->getOperand(OpNo+1);
76 // Print displacement first
78 // If the global address expression is a part of displacement field with a
79 // register base, we should not emit any prefix symbol here, e.g.
80 // mov.w &foo, r1
81 // vs
82 // mov.w glb(r1), r2
83 // Otherwise (!) msp430-as will silently miscompile the output :(
84 if (Base.getReg() == MSP430::SR)
85 O << '&';
87 if (Disp.isExpr())
88 Disp.getExpr()->print(O, &MAI);
89 else {
90 assert(Disp.isImm() && "Expected immediate in displacement field");
91 O << Disp.getImm();
94 // Print register base field
95 if ((Base.getReg() != MSP430::SR) &&
96 (Base.getReg() != MSP430::PC))
97 O << '(' << getRegisterName(Base.getReg()) << ')';
100 void MSP430InstPrinter::printIndRegOperand(const MCInst *MI, unsigned OpNo,
101 raw_ostream &O) {
102 const MCOperand &Base = MI->getOperand(OpNo);
103 O << "@" << getRegisterName(Base.getReg());
106 void MSP430InstPrinter::printPostIndRegOperand(const MCInst *MI, unsigned OpNo,
107 raw_ostream &O) {
108 const MCOperand &Base = MI->getOperand(OpNo);
109 O << "@" << getRegisterName(Base.getReg()) << "+";
112 void MSP430InstPrinter::printCCOperand(const MCInst *MI, unsigned OpNo,
113 raw_ostream &O) {
114 unsigned CC = MI->getOperand(OpNo).getImm();
116 switch (CC) {
117 default:
118 llvm_unreachable("Unsupported CC code");
119 case MSP430CC::COND_E:
120 O << "eq";
121 break;
122 case MSP430CC::COND_NE:
123 O << "ne";
124 break;
125 case MSP430CC::COND_HS:
126 O << "hs";
127 break;
128 case MSP430CC::COND_LO:
129 O << "lo";
130 break;
131 case MSP430CC::COND_GE:
132 O << "ge";
133 break;
134 case MSP430CC::COND_L:
135 O << 'l';
136 break;
137 case MSP430CC::COND_N:
138 O << 'n';
139 break;