mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00:00
Change MCAsmStreamer to take an MCInstPrinter instead of a
full AsmPrinter, and change TargetRegistry to keep track of registered MCInstPrinters. llvm-mc is still linking in the entire target foo to get the code emitter stuff, but this is an important step in the right direction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81754 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
db5fe936db
commit
90edac0e8b
@ -17,12 +17,12 @@
|
|||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class AsmPrinter;
|
|
||||||
class MCAsmInfo;
|
class MCAsmInfo;
|
||||||
class MCCodeEmitter;
|
class MCCodeEmitter;
|
||||||
class MCContext;
|
class MCContext;
|
||||||
class MCExpr;
|
class MCExpr;
|
||||||
class MCInst;
|
class MCInst;
|
||||||
|
class MCInstPrinter;
|
||||||
class MCSection;
|
class MCSection;
|
||||||
class MCSymbol;
|
class MCSymbol;
|
||||||
class StringRef;
|
class StringRef;
|
||||||
@ -217,10 +217,9 @@ namespace llvm {
|
|||||||
/// createAsmStreamer - Create a machine code streamer which will print out
|
/// createAsmStreamer - Create a machine code streamer which will print out
|
||||||
/// assembly for the native target, suitable for compiling with a native
|
/// assembly for the native target, suitable for compiling with a native
|
||||||
/// assembler.
|
/// assembler.
|
||||||
///
|
|
||||||
/// \arg AP - If given, an AsmPrinter to use for printing instructions.
|
|
||||||
MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS,
|
MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS,
|
||||||
const MCAsmInfo &MAI, AsmPrinter *AP = 0,
|
const MCAsmInfo &MAI,
|
||||||
|
MCInstPrinter *InstPrint = 0,
|
||||||
MCCodeEmitter *CE = 0);
|
MCCodeEmitter *CE = 0);
|
||||||
|
|
||||||
// FIXME: These two may end up getting rolled into a single
|
// FIXME: These two may end up getting rolled into a single
|
||||||
|
@ -30,9 +30,11 @@ namespace llvm {
|
|||||||
class Module;
|
class Module;
|
||||||
class MCAsmInfo;
|
class MCAsmInfo;
|
||||||
class MCDisassembler;
|
class MCDisassembler;
|
||||||
|
class MCInstPrinter;
|
||||||
class TargetAsmParser;
|
class TargetAsmParser;
|
||||||
class TargetMachine;
|
class TargetMachine;
|
||||||
class formatted_raw_ostream;
|
class formatted_raw_ostream;
|
||||||
|
class raw_ostream;
|
||||||
|
|
||||||
/// Target - Wrapper for Target specific information.
|
/// Target - Wrapper for Target specific information.
|
||||||
///
|
///
|
||||||
@ -60,6 +62,10 @@ namespace llvm {
|
|||||||
typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,
|
typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,
|
||||||
MCAsmParser &P);
|
MCAsmParser &P);
|
||||||
typedef const MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
|
typedef const MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
|
||||||
|
typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
|
||||||
|
unsigned SyntaxVariant,
|
||||||
|
const MCAsmInfo &MAI,
|
||||||
|
raw_ostream &O);
|
||||||
typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
|
typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
|
||||||
TargetMachine &TM);
|
TargetMachine &TM);
|
||||||
|
|
||||||
@ -99,6 +105,11 @@ namespace llvm {
|
|||||||
/// MCDisassembler, if registered.
|
/// MCDisassembler, if registered.
|
||||||
MCDisassemblerCtorTy MCDisassemblerCtorFn;
|
MCDisassemblerCtorTy MCDisassemblerCtorFn;
|
||||||
|
|
||||||
|
|
||||||
|
/// MCInstPrinterCtorFn - Construction function for this target's
|
||||||
|
/// MCInstPrinter, if registered.
|
||||||
|
MCInstPrinterCtorTy MCInstPrinterCtorFn;
|
||||||
|
|
||||||
/// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
|
/// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
|
||||||
/// if registered.
|
/// if registered.
|
||||||
CodeEmitterCtorTy CodeEmitterCtorFn;
|
CodeEmitterCtorTy CodeEmitterCtorFn;
|
||||||
@ -135,6 +146,9 @@ namespace llvm {
|
|||||||
/// hasMCDisassembler - Check if this target has a disassembler.
|
/// hasMCDisassembler - Check if this target has a disassembler.
|
||||||
bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
|
bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
|
||||||
|
|
||||||
|
/// hasMCInstPrinter - Check if this target has an instruction printer.
|
||||||
|
bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
|
||||||
|
|
||||||
/// hasCodeEmitter - Check if this target supports instruction encoding.
|
/// hasCodeEmitter - Check if this target supports instruction encoding.
|
||||||
bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
|
bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
|
||||||
|
|
||||||
@ -193,6 +207,15 @@ namespace llvm {
|
|||||||
return MCDisassemblerCtorFn(*this);
|
return MCDisassemblerCtorFn(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
|
||||||
|
const MCAsmInfo &MAI,
|
||||||
|
raw_ostream &O) const {
|
||||||
|
if (!MCInstPrinterCtorFn)
|
||||||
|
return 0;
|
||||||
|
return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, O);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// createCodeEmitter - Create a target specific code emitter.
|
/// createCodeEmitter - Create a target specific code emitter.
|
||||||
MCCodeEmitter *createCodeEmitter(TargetMachine &TM) const {
|
MCCodeEmitter *createCodeEmitter(TargetMachine &TM) const {
|
||||||
if (!CodeEmitterCtorFn)
|
if (!CodeEmitterCtorFn)
|
||||||
@ -364,6 +387,12 @@ namespace llvm {
|
|||||||
T.MCDisassemblerCtorFn = Fn;
|
T.MCDisassemblerCtorFn = Fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void RegisterMCInstPrinter(Target &T,
|
||||||
|
Target::MCInstPrinterCtorTy Fn) {
|
||||||
|
if (!T.MCInstPrinterCtorFn)
|
||||||
|
T.MCInstPrinterCtorFn = Fn;
|
||||||
|
}
|
||||||
|
|
||||||
/// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
|
/// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
|
||||||
/// given target.
|
/// given target.
|
||||||
///
|
///
|
||||||
|
@ -56,7 +56,8 @@ AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
|
|||||||
TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
|
TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
|
||||||
|
|
||||||
OutContext(*new MCContext()),
|
OutContext(*new MCContext()),
|
||||||
OutStreamer(*createAsmStreamer(OutContext, O, *T, this)),
|
// FIXME: Pass instprinter to streamer.
|
||||||
|
OutStreamer(*createAsmStreamer(OutContext, O, *T, 0)),
|
||||||
|
|
||||||
LastMI(0), LastFn(0), Counter(~0U),
|
LastMI(0), LastFn(0), Counter(~0U),
|
||||||
PrevDLT(0, ~0U, ~0U) {
|
PrevDLT(0, ~0U, ~0U) {
|
||||||
|
@ -9,12 +9,12 @@
|
|||||||
|
|
||||||
#include "llvm/MC/MCStreamer.h"
|
#include "llvm/MC/MCStreamer.h"
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/CodeGen/AsmPrinter.h"
|
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/MC/MCCodeEmitter.h"
|
#include "llvm/MC/MCCodeEmitter.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCInst.h"
|
#include "llvm/MC/MCInst.h"
|
||||||
|
#include "llvm/MC/MCInstPrinter.h"
|
||||||
#include "llvm/MC/MCSectionMachO.h"
|
#include "llvm/MC/MCSectionMachO.h"
|
||||||
#include "llvm/MC/MCSymbol.h"
|
#include "llvm/MC/MCSymbol.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
@ -28,12 +28,12 @@ namespace {
|
|||||||
class MCAsmStreamer : public MCStreamer {
|
class MCAsmStreamer : public MCStreamer {
|
||||||
raw_ostream &OS;
|
raw_ostream &OS;
|
||||||
const MCAsmInfo &MAI;
|
const MCAsmInfo &MAI;
|
||||||
AsmPrinter *Printer;
|
MCInstPrinter *InstPrinter;
|
||||||
MCCodeEmitter *Emitter;
|
MCCodeEmitter *Emitter;
|
||||||
public:
|
public:
|
||||||
MCAsmStreamer(MCContext &Context, raw_ostream &_OS, const MCAsmInfo &tai,
|
MCAsmStreamer(MCContext &Context, raw_ostream &_OS, const MCAsmInfo &tai,
|
||||||
AsmPrinter *_Printer, MCCodeEmitter *_Emitter)
|
MCInstPrinter *_Printer, MCCodeEmitter *_Emitter)
|
||||||
: MCStreamer(Context), OS(_OS), MAI(tai), Printer(_Printer),
|
: MCStreamer(Context), OS(_OS), MAI(tai), InstPrinter(_Printer),
|
||||||
Emitter(_Emitter) {}
|
Emitter(_Emitter) {}
|
||||||
~MCAsmStreamer() {}
|
~MCAsmStreamer() {}
|
||||||
|
|
||||||
@ -265,8 +265,8 @@ void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
|
|||||||
assert(CurSection && "Cannot emit contents before setting section!");
|
assert(CurSection && "Cannot emit contents before setting section!");
|
||||||
|
|
||||||
// If we have an AsmPrinter, use that to print.
|
// If we have an AsmPrinter, use that to print.
|
||||||
if (Printer) {
|
if (InstPrinter) {
|
||||||
Printer->printMCInst(&Inst);
|
InstPrinter->printInst(&Inst);
|
||||||
OS << '\n';
|
OS << '\n';
|
||||||
|
|
||||||
// Show the encoding if we have a code emitter.
|
// Show the encoding if we have a code emitter.
|
||||||
@ -300,7 +300,7 @@ void MCAsmStreamer::Finish() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MCStreamer *llvm::createAsmStreamer(MCContext &Context, raw_ostream &OS,
|
MCStreamer *llvm::createAsmStreamer(MCContext &Context, raw_ostream &OS,
|
||||||
const MCAsmInfo &MAI, AsmPrinter *AP,
|
const MCAsmInfo &MAI, MCInstPrinter *IP,
|
||||||
MCCodeEmitter *CE) {
|
MCCodeEmitter *CE) {
|
||||||
return new MCAsmStreamer(Context, OS, MAI, AP, CE);
|
return new MCAsmStreamer(Context, OS, MAI, IP, CE);
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "X86.h"
|
#include "X86.h"
|
||||||
#include "X86ATTAsmPrinter.h"
|
#include "X86ATTAsmPrinter.h"
|
||||||
#include "X86IntelAsmPrinter.h"
|
#include "X86IntelAsmPrinter.h"
|
||||||
|
#include "X86ATTInstPrinter.h"
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -34,8 +35,23 @@ static AsmPrinter *createX86CodePrinterPass(formatted_raw_ostream &o,
|
|||||||
return new X86ATTAsmPrinter(o, tm, tai, verbose);
|
return new X86ATTAsmPrinter(o, tm, tai, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static MCInstPrinter *createX86MCInstPrinter(const Target &T,
|
||||||
|
unsigned SyntaxVariant,
|
||||||
|
const MCAsmInfo &MAI,
|
||||||
|
raw_ostream &O) {
|
||||||
|
if (SyntaxVariant == 0)
|
||||||
|
return new X86ATTInstPrinter(O, MAI);
|
||||||
|
|
||||||
|
// Don't support intel syntax instprinter yet.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Force static initialization.
|
// Force static initialization.
|
||||||
extern "C" void LLVMInitializeX86AsmPrinter() {
|
extern "C" void LLVMInitializeX86AsmPrinter() {
|
||||||
TargetRegistry::RegisterAsmPrinter(TheX86_32Target, createX86CodePrinterPass);
|
TargetRegistry::RegisterAsmPrinter(TheX86_32Target, createX86CodePrinterPass);
|
||||||
TargetRegistry::RegisterAsmPrinter(TheX86_64Target, createX86CodePrinterPass);
|
TargetRegistry::RegisterAsmPrinter(TheX86_64Target, createX86CodePrinterPass);
|
||||||
|
|
||||||
|
TargetRegistry::RegisterMCInstPrinter(TheX86_32Target,createX86MCInstPrinter);
|
||||||
|
TargetRegistry::RegisterMCInstPrinter(TheX86_64Target,createX86MCInstPrinter);
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,13 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/MC/MCAsmLexer.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCCodeEmitter.h"
|
#include "llvm/MC/MCCodeEmitter.h"
|
||||||
|
#include "llvm/MC/MCInstPrinter.h"
|
||||||
#include "llvm/MC/MCSectionMachO.h"
|
#include "llvm/MC/MCSectionMachO.h"
|
||||||
#include "llvm/MC/MCStreamer.h"
|
#include "llvm/MC/MCStreamer.h"
|
||||||
#include "llvm/MC/MCAsmLexer.h"
|
|
||||||
#include "llvm/ADT/OwningPtr.h"
|
#include "llvm/ADT/OwningPtr.h"
|
||||||
#include "llvm/CodeGen/AsmPrinter.h"
|
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/FormattedStream.h"
|
#include "llvm/Support/FormattedStream.h"
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
#include "llvm/Support/ManagedStatic.h"
|
||||||
@ -29,6 +29,7 @@
|
|||||||
#include "llvm/System/Signals.h"
|
#include "llvm/System/Signals.h"
|
||||||
#include "llvm/Target/TargetAsmParser.h"
|
#include "llvm/Target/TargetAsmParser.h"
|
||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
|
#include "llvm/Target/TargetMachine.h" // FIXME.
|
||||||
#include "llvm/Target/TargetSelect.h"
|
#include "llvm/Target/TargetSelect.h"
|
||||||
#include "AsmParser.h"
|
#include "AsmParser.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -243,7 +244,7 @@ static int AssembleInput(const char *ProgName) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
OwningPtr<AsmPrinter> AP;
|
OwningPtr<MCInstPrinter> IP;
|
||||||
OwningPtr<MCCodeEmitter> CE;
|
OwningPtr<MCCodeEmitter> CE;
|
||||||
OwningPtr<MCStreamer> Str;
|
OwningPtr<MCStreamer> Str;
|
||||||
|
|
||||||
@ -251,10 +252,12 @@ static int AssembleInput(const char *ProgName) {
|
|||||||
assert(MAI && "Unable to create target asm info!");
|
assert(MAI && "Unable to create target asm info!");
|
||||||
|
|
||||||
if (FileType == OFT_AssemblyFile) {
|
if (FileType == OFT_AssemblyFile) {
|
||||||
AP.reset(TheTarget->createAsmPrinter(*Out, *TM, MAI, true));
|
// FIXME: Syntax Variant should be selectable somehow?
|
||||||
|
unsigned SyntaxVariant = 0;
|
||||||
|
IP.reset(TheTarget->createMCInstPrinter(SyntaxVariant, *MAI, *Out));
|
||||||
if (ShowEncoding)
|
if (ShowEncoding)
|
||||||
CE.reset(TheTarget->createCodeEmitter(*TM));
|
CE.reset(TheTarget->createCodeEmitter(*TM));
|
||||||
Str.reset(createAsmStreamer(Ctx, *Out, *MAI, AP.get(), CE.get()));
|
Str.reset(createAsmStreamer(Ctx, *Out, *MAI, IP.get(), CE.get()));
|
||||||
} else {
|
} else {
|
||||||
assert(FileType == OFT_ObjectFile && "Invalid file type!");
|
assert(FileType == OFT_ObjectFile && "Invalid file type!");
|
||||||
CE.reset(TheTarget->createCodeEmitter(*TM));
|
CE.reset(TheTarget->createCodeEmitter(*TM));
|
||||||
|
Loading…
Reference in New Issue
Block a user