From 91bead790518fcf5cb26019fb1ebf2372e8a5b3f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 3 Apr 2010 21:35:55 +0000 Subject: add a new EmitInlineAsm function to asmprinter to handle inline asm. If we have an MCAsmStreamer, we continue to emit asm textually, otherwise we (currently) emit an error to errs and ignore it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100289 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'lib/CodeGen') diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 2cb4d01574..0d6a2e2999 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -125,14 +125,12 @@ bool AsmPrinter::doInitialization(Module &M) { for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I) if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I)) MP->beginAssembly(O, *this, *MAI); - + + // Emit module-level inline asm if it exists. if (!M.getModuleInlineAsm().empty()) { OutStreamer.AddComment("Start of file scope inline assembly"); OutStreamer.AddBlankLine(); - O << M.getModuleInlineAsm(); - - if (*M.getModuleInlineAsm().rbegin() != '\n') - OutStreamer.AddBlankLine(); + EmitInlineAsm(M.getModuleInlineAsm()); OutStreamer.AddComment("End of file scope inline assembly"); OutStreamer.AddBlankLine(); } @@ -879,6 +877,22 @@ void AsmPrinter::EmitXXStructorList(Constant *List) { } } +/// EmitInlineAsm - Emit a blob of inline asm to the output streamer. +void AsmPrinter::EmitInlineAsm(StringRef Str) { + assert(!Str.empty() && "Can't emit empty inline asm block"); + + // If the output streamer is actually a .s file, just emit the blob textually. + // This is useful in case the asm parser doesn't handle something but the + // system assembler does. + if (OutStreamer.hasRawTextSupport()) { + OutStreamer.EmitRawText(Str); + return; + } + + errs() << "Inline asm not supported by this streamer!\n"; +} + + //===--------------------------------------------------------------------===// // Emission and print routines // -- cgit v1.2.3-70-g09d2