Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp
- This file was added.
//===- XtensaInstPrinter.cpp - Convert Xtensa MCInst to asm syntax --------===// | |||||
// | |||||
// The LLVM Compiler Infrastructure | |||||
// | |||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||||
// See https://llvm.org/LICENSE.txt for license information. | |||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||||
// | |||||
//===----------------------------------------------------------------------===// | |||||
// | |||||
// This class prints an Xtensa MCInst to a .s file. | |||||
// | |||||
//===----------------------------------------------------------------------===// | |||||
#include "XtensaInstPrinter.h" | |||||
#include "llvm/CodeGen/MachineOperand.h" | |||||
#include "llvm/MC/MCExpr.h" | |||||
#include "llvm/MC/MCInstrInfo.h" | |||||
#include "llvm/MC/MCSymbol.h" | |||||
#include "llvm/Support/raw_ostream.h" | |||||
using namespace llvm; | |||||
#define DEBUG_TYPE "asm-printer" | |||||
#include "XtensaGenAsmWriter.inc" | |||||
static void printExpr(const MCExpr *Expr, raw_ostream &OS) { | |||||
int Offset = 0; | |||||
const MCSymbolRefExpr *SRE; | |||||
if (!(SRE = dyn_cast<MCSymbolRefExpr>(Expr))) | |||||
assert(false && "Unexpected MCExpr type."); | |||||
MCSymbolRefExpr::VariantKind Kind = SRE->getKind(); | |||||
arsenm: Just use cast<> | |||||
Corrected andreisfr: Corrected | |||||
Not Done ReplyInline ActionsAlso means you can get rid of the assert(false) and if arsenm: Also means you can get rid of the assert(false) and if | |||||
switch (Kind) { | |||||
case MCSymbolRefExpr::VK_None: | |||||
break; | |||||
// TODO | |||||
default: | |||||
llvm_unreachable("Invalid kind!"); | |||||
} | |||||
OS << SRE->getSymbol(); | |||||
if (Offset) { | |||||
if (Offset > 0) | |||||
OS << '+'; | |||||
OS << Offset; | |||||
} | |||||
if (Kind != MCSymbolRefExpr::VK_None) | |||||
OS << ')'; | |||||
} | |||||
void XtensaInstPrinter::printOperand(const MCOperand &MC, raw_ostream &O) { | |||||
if (MC.isReg()) | |||||
O << getRegisterName(MC.getReg()); | |||||
else if (MC.isImm()) | |||||
O << MC.getImm(); | |||||
else if (MC.isExpr()) | |||||
printExpr(MC.getExpr(), O); | |||||
else | |||||
llvm_unreachable("Invalid operand"); | |||||
} | |||||
void XtensaInstPrinter::printInst(const MCInst *MI, uint64_t Address, | |||||
StringRef Annot, const MCSubtargetInfo &STI, | |||||
raw_ostream &O) { | |||||
printInstruction(MI, Address, O); | |||||
printAnnotation(O, Annot); | |||||
} | |||||
void XtensaInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const { | |||||
O << getRegisterName(RegNo); | |||||
} | |||||
void XtensaInstPrinter::printOperand(const MCInst *MI, int OpNum, | |||||
raw_ostream &O) { | |||||
printOperand(MI->getOperand(OpNum), O); | |||||
} | |||||
void XtensaInstPrinter::printImm8_AsmOperand(const MCInst *MI, int OpNum, | |||||
raw_ostream &O) { | |||||
if (MI->getOperand(OpNum).isImm()) { | |||||
int64_t Value = MI->getOperand(OpNum).getImm(); | |||||
assert((Value >= -128 && Value <= 127) && | |||||
"Invalid argument, value must be in ranges [-128,127]"); | |||||
O << Value; | |||||
Not Done ReplyInline ActionsisInt<8> from MathExtras.h MaskRay: `isInt<8>` from MathExtras.h | |||||
Corrected andreisfr: Corrected | |||||
} else | |||||
printOperand(MI, OpNum, O); | |||||
} | |||||
Not Done ReplyInline ActionsAdd braces. then uses braces and else should use, too. MaskRay: Add braces. `then` uses braces and `else` should use, too. | |||||
Corrected andreisfr: Corrected | |||||
void XtensaInstPrinter::printImm8_sh8_AsmOperand(const MCInst *MI, int OpNum, | |||||
raw_ostream &O) { | |||||
if (MI->getOperand(OpNum).isImm()) { | |||||
int64_t Value = MI->getOperand(OpNum).getImm(); | |||||
assert((Value >= -32768 && Value <= 32512 && ((Value & 0xFF) == 0)) && | |||||
"Invalid argument, value must be multiples of 256 in range " | |||||
"[-32768,32512]"); | |||||
Not Done ReplyInline ActionsisInt<16> from MathExtras.h MaskRay: isInt<16> from MathExtras.h | |||||
Corrected andreisfr: Corrected | |||||
O << Value; | |||||
} else | |||||
printOperand(MI, OpNum, O); | |||||
} |
Just use cast<>