From f3ce009fcb0a04a245c437d86657e9bd61ecc18f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 17 Aug 2009 04:23:44 +0000 Subject: [PATCH] give MCAsmStreamer a TargetAsmInfo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79222 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCStreamer.h | 3 ++- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 +- lib/MC/MCAsmStreamer.cpp | 11 +++++++---- tools/llvm-mc/llvm-mc.cpp | 18 +++++++++--------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h index 434288eb188..b8399d0115a 100644 --- a/include/llvm/MC/MCStreamer.h +++ b/include/llvm/MC/MCStreamer.h @@ -25,6 +25,7 @@ namespace llvm { class MCSymbol; class StringRef; class raw_ostream; + class TargetAsmInfo; /// MCStreamer - Streaming machine code generation interface. This interface /// is intended to provide a programatic interface that is very similar to the @@ -232,7 +233,7 @@ namespace llvm { /// /// \arg AP - If given, an AsmPrinter to use for printing instructions. MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS, - AsmPrinter *AP = 0); + const TargetAsmInfo &TAI, AsmPrinter *AP = 0); // FIXME: These two may end up getting rolled into a single // createObjectStreamer interface, which implements the assembler backend, and diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 02ff2f0b50a..d46043b29cd 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -59,7 +59,7 @@ AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm, TM(tm), TAI(T), TRI(tm.getRegisterInfo()), OutContext(*new MCContext()), - OutStreamer(*createAsmStreamer(OutContext, O)), + OutStreamer(*createAsmStreamer(OutContext, O, *T, this)), LastMI(0), LastFn(0), Counter(~0U), PrevDLT(0, ~0U, ~0U) { diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index 0eed1206aa1..db39fb8b1cb 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -22,11 +22,14 @@ namespace { class MCAsmStreamer : public MCStreamer { raw_ostream &OS; + const TargetAsmInfo &TAI; AsmPrinter *Printer; MCSection *CurSection; public: - MCAsmStreamer(MCContext &Context, raw_ostream &_OS, AsmPrinter *_AsmPrinter) - : MCStreamer(Context), OS(_OS), Printer(_AsmPrinter), CurSection(0) {} + MCAsmStreamer(MCContext &Context, raw_ostream &_OS, const TargetAsmInfo &tai, + AsmPrinter *_AsmPrinter) + : MCStreamer(Context), OS(_OS), TAI(tai), Printer(_AsmPrinter), + CurSection(0) {} ~MCAsmStreamer() {} /// @name MCStreamer Interface @@ -293,6 +296,6 @@ void MCAsmStreamer::Finish() { } MCStreamer *llvm::createAsmStreamer(MCContext &Context, raw_ostream &OS, - AsmPrinter *AP) { - return new MCAsmStreamer(Context, OS, AP); + const TargetAsmInfo &TAI, AsmPrinter *AP) { + return new MCAsmStreamer(Context, OS, TAI, AP); } diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 7c57f356998..a9ba8bd73a3 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -211,21 +211,21 @@ static int AssembleInput(const char *ProgName) { if (!Out) return 1; - // See if we can get an asm printer. - OwningPtr AP(0); // FIXME: We shouldn't need to do this (and link in codegen). OwningPtr TM(TheTarget->createTargetMachine(TripleName, "")); - const TargetAsmInfo *TAI = 0; - if (TM) { - TAI = TheTarget->createAsmInfo(TripleName); - assert(TAI && "Unable to create target asm info!"); - - AP.reset(TheTarget->createAsmPrinter(*Out, *TM, TAI, true)); + if (!TM) { + errs() << ProgName << ": error: could not create target for triple '" + << TripleName << "'.\n"; + return 1; } - OwningPtr Str(createAsmStreamer(Ctx, *Out, AP.get())); + const TargetAsmInfo *TAI = TheTarget->createAsmInfo(TripleName); + assert(TAI && "Unable to create target asm info!"); + + OwningPtr AP(TheTarget->createAsmPrinter(*Out, *TM, TAI, true)); + OwningPtr Str(createAsmStreamer(Ctx, *Out, *TAI, AP.get())); // FIXME: Target hook & command line option for initial section. Str.get()->SwitchSection(MCSectionMachO::Create("__TEXT","__text", -- 2.34.1