mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-18 13:34:04 +00:00
refactor code so that LLVMTargetMachine creates the asmstreamer and
mccontext instead of having AsmPrinter do it. This allows other types of MCStreamer's to be passed in. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95155 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9f34dd305b
commit
56591ab218
@ -149,7 +149,8 @@ namespace llvm {
|
||||
|
||||
protected:
|
||||
explicit AsmPrinter(formatted_raw_ostream &o, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V);
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T);
|
||||
|
||||
public:
|
||||
virtual ~AsmPrinter();
|
||||
|
@ -60,6 +60,10 @@ namespace llvm {
|
||||
|
||||
/// @name Assembly File Formatting.
|
||||
/// @{
|
||||
|
||||
/// isVerboseAsm - Return true if this streamer supports verbose assembly at
|
||||
/// all.
|
||||
virtual bool isVerboseAsm() const { return false; }
|
||||
|
||||
/// AddComment - Add a comment that can be emitted to the generated .s
|
||||
/// file if applicable as a QoI issue to make the output of the compiler
|
||||
|
@ -25,12 +25,14 @@
|
||||
|
||||
namespace llvm {
|
||||
class AsmPrinter;
|
||||
class MCAsmParser;
|
||||
class MCCodeEmitter;
|
||||
class Module;
|
||||
class MCAsmInfo;
|
||||
class MCAsmParser;
|
||||
class MCCodeEmitter;
|
||||
class MCContext;
|
||||
class MCDisassembler;
|
||||
class MCInstPrinter;
|
||||
class MCStreamer;
|
||||
class TargetAsmLexer;
|
||||
class TargetAsmParser;
|
||||
class TargetMachine;
|
||||
@ -58,8 +60,9 @@ namespace llvm {
|
||||
const std::string &Features);
|
||||
typedef AsmPrinter *(*AsmPrinterCtorTy)(formatted_raw_ostream &OS,
|
||||
TargetMachine &TM,
|
||||
const MCAsmInfo *MAI,
|
||||
bool VerboseAsm);
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Streamer,
|
||||
const MCAsmInfo *MAI);
|
||||
typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
|
||||
const MCAsmInfo &MAI);
|
||||
typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P);
|
||||
@ -189,12 +192,14 @@ namespace llvm {
|
||||
return TargetMachineCtorFn(*this, Triple, Features);
|
||||
}
|
||||
|
||||
/// createAsmPrinter - Create a target specific assembly printer pass.
|
||||
/// createAsmPrinter - Create a target specific assembly printer pass. This
|
||||
/// takes ownership of the MCContext and MCStreamer objects but not the MAI.
|
||||
AsmPrinter *createAsmPrinter(formatted_raw_ostream &OS, TargetMachine &TM,
|
||||
const MCAsmInfo *MAI, bool Verbose) const {
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *MAI) const {
|
||||
if (!AsmPrinterCtorFn)
|
||||
return 0;
|
||||
return AsmPrinterCtorFn(OS, TM, MAI, Verbose);
|
||||
return AsmPrinterCtorFn(OS, TM, Ctx, Streamer, MAI);
|
||||
}
|
||||
|
||||
/// createAsmLexer - Create a target specific assembly lexer.
|
||||
@ -547,8 +552,9 @@ namespace llvm {
|
||||
|
||||
private:
|
||||
static AsmPrinter *Allocator(formatted_raw_ostream &OS, TargetMachine &TM,
|
||||
const MCAsmInfo *MAI, bool Verbose) {
|
||||
return new AsmPrinterImpl(OS, TM, MAI, Verbose);
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *MAI) {
|
||||
return new AsmPrinterImpl(OS, TM, Ctx, Streamer, MAI);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -55,19 +55,14 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed");
|
||||
|
||||
char AsmPrinter::ID = 0;
|
||||
AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
|
||||
const MCAsmInfo *T, bool VerboseAsm)
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: MachineFunctionPass(&ID), O(o),
|
||||
TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
|
||||
|
||||
OutContext(*new MCContext()),
|
||||
// FIXME: Pass instprinter to streamer.
|
||||
OutStreamer(*createAsmStreamer(OutContext, O, *T,
|
||||
TM.getTargetData()->isLittleEndian(),
|
||||
VerboseAsm, 0)),
|
||||
|
||||
OutContext(Ctx), OutStreamer(Streamer),
|
||||
LastMI(0), LastFn(0), Counter(~0U), PrevDLT(NULL) {
|
||||
DW = 0; MMI = 0;
|
||||
this->VerboseAsm = VerboseAsm;
|
||||
VerboseAsm = Streamer.isVerboseAsm();
|
||||
}
|
||||
|
||||
AsmPrinter::~AsmPrinter() {
|
||||
|
@ -21,6 +21,9 @@
|
||||
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/Target/TargetData.h"
|
||||
#include "llvm/Target/TargetRegistry.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
@ -121,10 +124,24 @@ LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
|
||||
case CGFT_ObjectFile:
|
||||
return CGFT_ErrorOccurred;
|
||||
case CGFT_AssemblyFile: {
|
||||
MCContext *Context = new MCContext();
|
||||
MCStreamer *AsmStreamer =
|
||||
createAsmStreamer(*Context, Out, *getMCAsmInfo(),
|
||||
getTargetData()->isLittleEndian(),
|
||||
getVerboseAsm(),
|
||||
/*instprinter*/0,
|
||||
/*codeemitter*/0);
|
||||
|
||||
// Create the AsmPrinter, which takes ownership of Context and AsmStreamer
|
||||
// if successful.
|
||||
FunctionPass *Printer =
|
||||
getTarget().createAsmPrinter(Out, *this, getMCAsmInfo(),
|
||||
getVerboseAsm());
|
||||
if (Printer == 0) return CGFT_ErrorOccurred;
|
||||
getTarget().createAsmPrinter(Out, *this, *Context, *AsmStreamer,
|
||||
getMCAsmInfo());
|
||||
if (Printer == 0) {
|
||||
delete AsmStreamer;
|
||||
delete Context;
|
||||
return CGFT_ErrorOccurred;
|
||||
}
|
||||
PM.add(Printer);
|
||||
break;
|
||||
}
|
||||
|
@ -47,7 +47,6 @@ public:
|
||||
|
||||
bool isLittleEndian() const { return IsLittleEndian; }
|
||||
|
||||
|
||||
inline void EmitEOL() {
|
||||
// If we don't have any comments, just emit a \n.
|
||||
if (!IsVerboseAsm) {
|
||||
@ -57,6 +56,10 @@ public:
|
||||
EmitCommentsAndEOL();
|
||||
}
|
||||
void EmitCommentsAndEOL();
|
||||
|
||||
/// isVerboseAsm - Return true if this streamer supports verbose assembly at
|
||||
/// all.
|
||||
virtual bool isVerboseAsm() const { return IsVerboseAsm; }
|
||||
|
||||
/// AddComment - Add a comment that can be emitted to the generated .s
|
||||
/// file if applicable as a QoI issue to make the output of the compiler
|
||||
|
@ -73,8 +73,9 @@ namespace {
|
||||
|
||||
public:
|
||||
explicit ARMAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V)
|
||||
: AsmPrinter(O, TM, T, V), AFI(NULL), MCP(NULL) {
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: AsmPrinter(O, TM, Ctx, Streamer, T), AFI(NULL), MCP(NULL) {
|
||||
Subtarget = &TM.getSubtarget<ARMSubtarget>();
|
||||
}
|
||||
|
||||
|
@ -37,8 +37,9 @@ namespace {
|
||||
///
|
||||
|
||||
explicit AlphaAsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
|
||||
const MCAsmInfo *T, bool V)
|
||||
: AsmPrinter(o, tm, T, V) {}
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: AsmPrinter(o, tm, Ctx, Streamer, T) {}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
return "Alpha Assembly Printer";
|
||||
|
@ -39,8 +39,9 @@ namespace {
|
||||
class BlackfinAsmPrinter : public AsmPrinter {
|
||||
public:
|
||||
BlackfinAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *MAI, bool V)
|
||||
: AsmPrinter(O, TM, MAI, V) {}
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *MAI)
|
||||
: AsmPrinter(O, TM, Ctx, Streamer, MAI) {}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
return "Blackfin Assembly Printer";
|
||||
|
@ -38,8 +38,9 @@ namespace {
|
||||
class SPUAsmPrinter : public AsmPrinter {
|
||||
public:
|
||||
explicit SPUAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V) :
|
||||
AsmPrinter(O, TM, T, V) {}
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T) :
|
||||
AsmPrinter(O, TM, Ctx, Streamer, T) {}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
return "STI CBEA SPU Assembly Printer";
|
||||
|
@ -42,8 +42,9 @@ namespace {
|
||||
class MSP430AsmPrinter : public AsmPrinter {
|
||||
public:
|
||||
MSP430AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *MAI, bool V)
|
||||
: AsmPrinter(O, TM, MAI, V) {}
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *MAI)
|
||||
: AsmPrinter(O, TM, Ctx, Streamer, MAI) {}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
return "MSP430 Assembly Printer";
|
||||
|
@ -50,8 +50,9 @@ namespace {
|
||||
const MipsSubtarget *Subtarget;
|
||||
public:
|
||||
explicit MipsAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V)
|
||||
: AsmPrinter(O, TM, T, V) {
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: AsmPrinter(O, TM, Ctx, Streamer, T) {
|
||||
Subtarget = &TM.getSubtarget<MipsSubtarget>();
|
||||
}
|
||||
|
||||
|
@ -35,8 +35,9 @@ using namespace llvm;
|
||||
#include "PIC16GenAsmWriter.inc"
|
||||
|
||||
PIC16AsmPrinter::PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V)
|
||||
: AsmPrinter(O, TM, T, V), DbgInfo(O, T) {
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: AsmPrinter(O, TM, Ctx, Streamer, T), DbgInfo(O, T) {
|
||||
PTLI = static_cast<PIC16TargetLowering*>(TM.getTargetLowering());
|
||||
PMAI = static_cast<const PIC16MCAsmInfo*>(T);
|
||||
PTOF = (PIC16TargetObjectFile *)&PTLI->getObjFileLowering();
|
||||
|
@ -31,7 +31,8 @@ namespace llvm {
|
||||
class VISIBILITY_HIDDEN PIC16AsmPrinter : public AsmPrinter {
|
||||
public:
|
||||
explicit PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V);
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T);
|
||||
private:
|
||||
virtual const char *getPassName() const {
|
||||
return "PIC16 Assembly Printer";
|
||||
|
@ -60,8 +60,9 @@ namespace {
|
||||
uint64_t LabelID;
|
||||
public:
|
||||
explicit PPCAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V)
|
||||
: AsmPrinter(O, TM, T, V),
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: AsmPrinter(O, TM, Ctx, Streamer, T),
|
||||
Subtarget(TM.getSubtarget<PPCSubtarget>()), LabelID(0) {}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
@ -322,8 +323,9 @@ namespace {
|
||||
class PPCLinuxAsmPrinter : public PPCAsmPrinter {
|
||||
public:
|
||||
explicit PPCLinuxAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V)
|
||||
: PPCAsmPrinter(O, TM, T, V){}
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: PPCAsmPrinter(O, TM, Ctx, Streamer, T) {}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
return "Linux PPC Assembly Printer";
|
||||
@ -347,8 +349,9 @@ namespace {
|
||||
formatted_raw_ostream &OS;
|
||||
public:
|
||||
explicit PPCDarwinAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V)
|
||||
: PPCAsmPrinter(O, TM, T, V), OS(O) {}
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: PPCAsmPrinter(O, TM, Ctx, Streamer, T), OS(O) {}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
return "Darwin PPC Assembly Printer";
|
||||
@ -826,13 +829,13 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
|
||||
///
|
||||
static AsmPrinter *createPPCAsmPrinterPass(formatted_raw_ostream &o,
|
||||
TargetMachine &tm,
|
||||
const MCAsmInfo *tai,
|
||||
bool verbose) {
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *tai) {
|
||||
const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>();
|
||||
|
||||
if (Subtarget->isDarwin())
|
||||
return new PPCDarwinAsmPrinter(o, tm, tai, verbose);
|
||||
return new PPCLinuxAsmPrinter(o, tm, tai, verbose);
|
||||
return new PPCDarwinAsmPrinter(o, tm, Ctx, Streamer, tai);
|
||||
return new PPCLinuxAsmPrinter(o, tm, Ctx, Streamer, tai);
|
||||
}
|
||||
|
||||
// Force static initialization.
|
||||
|
@ -29,8 +29,9 @@ namespace {
|
||||
class SparcAsmPrinter : public AsmPrinter {
|
||||
public:
|
||||
explicit SparcAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V)
|
||||
: AsmPrinter(O, TM, T, V) {}
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: AsmPrinter(O, TM, Ctx, Streamer, T) {}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
return "Sparc Assembly Printer";
|
||||
|
@ -40,8 +40,9 @@ namespace {
|
||||
class SystemZAsmPrinter : public AsmPrinter {
|
||||
public:
|
||||
SystemZAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *MAI, bool V)
|
||||
: AsmPrinter(O, TM, MAI, V) {}
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *MAI)
|
||||
: AsmPrinter(O, TM, Ctx, Streamer, MAI) {}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
return "SystemZ Assembly Printer";
|
||||
|
@ -36,8 +36,9 @@ class VISIBILITY_HIDDEN X86AsmPrinter : public AsmPrinter {
|
||||
const X86Subtarget *Subtarget;
|
||||
public:
|
||||
explicit X86AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V)
|
||||
: AsmPrinter(O, TM, T, V) {
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: AsmPrinter(O, TM, Ctx, Streamer, T) {
|
||||
Subtarget = &TM.getSubtarget<X86Subtarget>();
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,9 @@ namespace {
|
||||
const XCoreSubtarget &Subtarget;
|
||||
public:
|
||||
explicit XCoreAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||
const MCAsmInfo *T, bool V)
|
||||
: AsmPrinter(O, TM, T, V),
|
||||
MCContext &Ctx, MCStreamer &Streamer,
|
||||
const MCAsmInfo *T)
|
||||
: AsmPrinter(O, TM, Ctx, Streamer, T),
|
||||
Subtarget(TM.getSubtarget<XCoreSubtarget>()) {}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
|
Loading…
x
Reference in New Issue
Block a user