mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
split MCInst printing out of the X86ATTInstPrinter
class into its own X86ATTInstPrinter class. The inst printer now has just one dependence on the code generator (TRI). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81703 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
73d28f4aee
commit
cae05cb324
@ -15,6 +15,7 @@
|
||||
|
||||
#define DEBUG_TYPE "asm-printer"
|
||||
#include "X86ATTAsmPrinter.h"
|
||||
#include "X86ATTInstPrinter.h"
|
||||
#include "X86MCInstLower.h"
|
||||
#include "X86.h"
|
||||
#include "X86COFF.h"
|
||||
@ -46,6 +47,10 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed");
|
||||
// Primitive Helper Functions.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void X86ATTAsmPrinter::printMCInst(const MCInst *MI) {
|
||||
X86ATTInstPrinter(O, MAI, TRI).printInstruction(MI);
|
||||
}
|
||||
|
||||
void X86ATTAsmPrinter::PrintPICBaseSymbol() const {
|
||||
// FIXME: Gross const cast hack.
|
||||
X86ATTAsmPrinter *AP = const_cast<X86ATTAsmPrinter*>(this);
|
||||
|
@ -29,7 +29,6 @@ namespace llvm {
|
||||
class MachineJumpTableInfo;
|
||||
class MCContext;
|
||||
class MCInst;
|
||||
class MCOperand;
|
||||
class MCStreamer;
|
||||
class MCSymbol;
|
||||
|
||||
@ -63,62 +62,11 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
|
||||
|
||||
void printInstructionThroughMCStreamer(const MachineInstr *MI);
|
||||
|
||||
|
||||
// New MCInst printing stuff.
|
||||
void printInstruction(const MCInst *MI);
|
||||
|
||||
|
||||
virtual void printMCInst(const MCInst *MI) { printInstruction(MI); }
|
||||
// FIXME: REMOVE.
|
||||
virtual void printMCInst(const MCInst *MI);
|
||||
|
||||
void printSymbolOperand(const MachineOperand &MO);
|
||||
void printOperand(const MCInst *MI, unsigned OpNo,
|
||||
const char *Modifier = 0);
|
||||
void printMemReference(const MCInst *MI, unsigned Op);
|
||||
void printLeaMemReference(const MCInst *MI, unsigned Op);
|
||||
void printSSECC(const MCInst *MI, unsigned Op);
|
||||
void printPICLabel(const MCInst *MI, unsigned Op);
|
||||
void print_pcrel_imm(const MCInst *MI, unsigned OpNo);
|
||||
|
||||
void printopaquemem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
|
||||
void printi8mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printi16mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printi32mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printi64mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printi128mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printf32mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printf64mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printf80mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printf128mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printlea32mem(const MCInst *MI, unsigned OpNo) {
|
||||
printLeaMemReference(MI, OpNo);
|
||||
}
|
||||
void printlea64mem(const MCInst *MI, unsigned OpNo) {
|
||||
printLeaMemReference(MI, OpNo);
|
||||
}
|
||||
void printlea64_32mem(const MCInst *MI, unsigned OpNo) {
|
||||
printLeaMemReference(MI, OpNo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -13,12 +13,13 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define DEBUG_TYPE "asm-printer"
|
||||
#include "X86ATTInstPrinter.h"
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "X86ATTAsmPrinter.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Target/TargetRegisterInfo.h" // FIXME: REMOVE.
|
||||
using namespace llvm;
|
||||
|
||||
// Include the auto-generated portion of the assembly writer.
|
||||
@ -27,7 +28,7 @@ using namespace llvm;
|
||||
#include "X86GenAsmWriter.inc"
|
||||
#undef MachineInstr
|
||||
|
||||
void X86ATTAsmPrinter::printSSECC(const MCInst *MI, unsigned Op) {
|
||||
void X86ATTInstPrinter::printSSECC(const MCInst *MI, unsigned Op) {
|
||||
switch (MI->getOperand(Op).getImm()) {
|
||||
default: llvm_unreachable("Invalid ssecc argument!");
|
||||
case 0: O << "eq"; break;
|
||||
@ -42,16 +43,16 @@ void X86ATTAsmPrinter::printSSECC(const MCInst *MI, unsigned Op) {
|
||||
}
|
||||
|
||||
|
||||
void X86ATTAsmPrinter::printPICLabel(const MCInst *MI, unsigned Op) {
|
||||
void X86ATTInstPrinter::printPICLabel(const MCInst *MI, unsigned Op) {
|
||||
llvm_unreachable("This is only used for MOVPC32r,"
|
||||
"should lower before asm printing!");
|
||||
"should lower before instruction printing!");
|
||||
}
|
||||
|
||||
|
||||
/// print_pcrel_imm - This is used to print an immediate value that ends up
|
||||
/// being encoded as a pc-relative value. These print slightly differently, for
|
||||
/// example, a $ is not emitted.
|
||||
void X86ATTAsmPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo) {
|
||||
void X86ATTInstPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo) {
|
||||
const MCOperand &Op = MI->getOperand(OpNo);
|
||||
|
||||
if (Op.isImm())
|
||||
@ -63,7 +64,7 @@ void X86ATTAsmPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo) {
|
||||
}
|
||||
|
||||
|
||||
void X86ATTAsmPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
||||
void X86ATTInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
||||
const char *Modifier) {
|
||||
assert(Modifier == 0 && "Modifiers should not be used");
|
||||
|
||||
@ -85,7 +86,7 @@ void X86ATTAsmPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
||||
O << "<<UNKNOWN OPERAND KIND>>";
|
||||
}
|
||||
|
||||
void X86ATTAsmPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) {
|
||||
void X86ATTInstPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) {
|
||||
const MCOperand &BaseReg = MI->getOperand(Op);
|
||||
const MCOperand &IndexReg = MI->getOperand(Op+2);
|
||||
const MCOperand &DispSpec = MI->getOperand(Op+3);
|
||||
@ -100,8 +101,6 @@ void X86ATTAsmPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) {
|
||||
}
|
||||
|
||||
if (IndexReg.getReg() || BaseReg.getReg()) {
|
||||
assert(IndexReg.getReg() != X86::ESP && IndexReg.getReg() != X86::RSP);
|
||||
|
||||
O << '(';
|
||||
if (BaseReg.getReg())
|
||||
printOperand(MI, Op);
|
||||
@ -117,7 +116,7 @@ void X86ATTAsmPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) {
|
||||
}
|
||||
}
|
||||
|
||||
void X86ATTAsmPrinter::printMemReference(const MCInst *MI, unsigned Op) {
|
||||
void X86ATTInstPrinter::printMemReference(const MCInst *MI, unsigned Op) {
|
||||
const MCOperand &Segment = MI->getOperand(Op+4);
|
||||
if (Segment.getReg()) {
|
||||
printOperand(MI, Op+4);
|
||||
|
86
lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h
Normal file
86
lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h
Normal file
@ -0,0 +1,86 @@
|
||||
//===-- X86ATTInstPrinter.h - Convert X86 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 X86 MCInst to AT&T style .s file syntax.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef X86_ATT_INST_PRINTER_H
|
||||
#define X86_ATT_INST_PRINTER_H
|
||||
|
||||
namespace llvm {
|
||||
class MCAsmInfo;
|
||||
class MCInst;
|
||||
class MCOperand;
|
||||
class raw_ostream;
|
||||
class TargetRegisterInfo; // FIXME: ELIM
|
||||
|
||||
class X86ATTInstPrinter {
|
||||
raw_ostream &O;
|
||||
const MCAsmInfo *MAI;
|
||||
const TargetRegisterInfo *TRI; // FIXME: Elim.
|
||||
public:
|
||||
X86ATTInstPrinter(raw_ostream &o, const MCAsmInfo *mai,
|
||||
const TargetRegisterInfo *tri) : O(o), MAI(mai), TRI(tri) {}
|
||||
|
||||
void printInstruction(const MCInst *MI);
|
||||
|
||||
void printOperand(const MCInst *MI, unsigned OpNo,
|
||||
const char *Modifier = 0);
|
||||
void printMemReference(const MCInst *MI, unsigned Op);
|
||||
void printLeaMemReference(const MCInst *MI, unsigned Op);
|
||||
void printSSECC(const MCInst *MI, unsigned Op);
|
||||
void printPICLabel(const MCInst *MI, unsigned Op);
|
||||
void print_pcrel_imm(const MCInst *MI, unsigned OpNo);
|
||||
|
||||
void printopaquemem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
|
||||
void printi8mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printi16mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printi32mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printi64mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printi128mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printf32mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printf64mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printf80mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printf128mem(const MCInst *MI, unsigned OpNo) {
|
||||
printMemReference(MI, OpNo);
|
||||
}
|
||||
void printlea32mem(const MCInst *MI, unsigned OpNo) {
|
||||
printLeaMemReference(MI, OpNo);
|
||||
}
|
||||
void printlea64mem(const MCInst *MI, unsigned OpNo) {
|
||||
printLeaMemReference(MI, OpNo);
|
||||
}
|
||||
void printlea64_32mem(const MCInst *MI, unsigned OpNo) {
|
||||
printLeaMemReference(MI, OpNo);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -411,7 +411,7 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) {
|
||||
// lot of extra uniquing.
|
||||
TmpInst.addOperand(MCOperand::CreateExpr(MCSymbolRefExpr::Create(PICBase,
|
||||
OutContext)));
|
||||
printInstruction(&TmpInst);
|
||||
printMCInst(&TmpInst);
|
||||
O << '\n';
|
||||
|
||||
// Emit the label.
|
||||
@ -420,7 +420,7 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) {
|
||||
// popl $reg
|
||||
TmpInst.setOpcode(X86::POP32r);
|
||||
TmpInst.getOperand(0) = MCOperand::CreateReg(MI->getOperand(0).getReg());
|
||||
printInstruction(&TmpInst);
|
||||
printMCInst(&TmpInst);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -458,7 +458,7 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) {
|
||||
TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
|
||||
TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg()));
|
||||
TmpInst.addOperand(MCOperand::CreateExpr(DotExpr));
|
||||
printInstruction(&TmpInst);
|
||||
printMCInst(&TmpInst);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -467,5 +467,6 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) {
|
||||
MCInstLowering.Lower(MI, TmpInst);
|
||||
|
||||
|
||||
printInstruction(&TmpInst);
|
||||
printMCInst(&TmpInst);
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ def ATTAsmParser : AsmParser {
|
||||
// The X86 target supports two different syntaxes for emitting machine code.
|
||||
// This is controlled by the -x86-asm-syntax={att|intel}
|
||||
def ATTAsmWriter : AsmWriter {
|
||||
string AsmWriterClassName = "ATTAsmPrinter";
|
||||
string AsmWriterClassName = "ATTInstPrinter";
|
||||
int Variant = 0;
|
||||
}
|
||||
def IntelAsmWriter : AsmWriter {
|
||||
|
Loading…
Reference in New Issue
Block a user