diff options
author | Chris Lattner <sabre@nondot.org> | 2010-02-02 23:37:42 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-02-02 23:37:42 +0000 |
commit | 56591ab218639d8a6e4c756ca37adaf20215c3b6 (patch) | |
tree | e5b0843d0c8a5259a3b6b640c6a43ff8e7ddc440 /lib/CodeGen | |
parent | 9f34dd305b7d9d54904a28774e93ac8d81b211fc (diff) |
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
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 13 | ||||
-rw-r--r-- | lib/CodeGen/LLVMTargetMachine.cpp | 23 |
2 files changed, 24 insertions, 12 deletions
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 49db51ea0b..fea06badca 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -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() { diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index a4f313938d..f4065924b1 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -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; } |