[llvm-commits] [llvm] r94166 - in /llvm/trunk: include/llvm/MC/MCStreamer.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/MC/MCAsmStreamer.cpp
Daniel Dunbar
daniel at zuster.org
Fri Jan 22 08:36:42 PST 2010
On Thu, Jan 21, 2010 at 11:29 PM, Chris Lattner <sabre at nondot.org> wrote:
> Author: lattner
> Date: Fri Jan 22 01:29:22 2010
> New Revision: 94166
>
> URL: http://llvm.org/viewvc/llvm-project?rev=94166&view=rev
> Log:
> Add the ability for MCStreamer to emit comments on the same line as directives.
> Switch over the asm-verbose comment for double values to use it. We now get:
>
> _x:
> .long 343597384 ## double 1.231200e+02
> .long 1079953326
>
> For example, note that the comment is on the same line as the .long. Woo.
Great!
> Modified:
> llvm/trunk/include/llvm/MC/MCStreamer.h
> llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
> llvm/trunk/lib/MC/MCAsmStreamer.cpp
>
> Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=94166&r1=94165&r2=94166&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
> +++ llvm/trunk/include/llvm/MC/MCStreamer.h Fri Jan 22 01:29:22 2010
> @@ -26,7 +26,9 @@
> class MCSection;
> class MCSymbol;
> class StringRef;
> + class Twine;
> class raw_ostream;
> + class formatted_raw_ostream;
>
> /// MCStreamer - Streaming machine code generation interface. This interface
> /// is intended to provide a programatic interface that is very similar to the
> @@ -79,6 +81,15 @@
>
> MCContext &getContext() const { return Context; }
>
> + /// 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
> + /// more readable. This only affects the MCAsmStreamer, and only when
> + /// verbose assembly output is enabled.
> + ///
> + /// If the comment includes embedded \n's, they will each get the comment
> + /// prefix as appropriate. The added comment should not end with a \n.
> + virtual void addComment(const Twine &T) {}
Should this be 'AddComment'?
> /// @name Symbol & Section Management
> /// @{
>
> @@ -234,7 +245,7 @@
> /// createAsmStreamer - Create a machine code streamer which will print out
> /// assembly for the native target, suitable for compiling with a native
> /// assembler.
> - MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS,
> + MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
> const MCAsmInfo &MAI, bool isLittleEndian,
> bool isVerboseAsm,
> MCInstPrinter *InstPrint = 0,
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=94166&r1=94165&r2=94166&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Fri Jan 22 01:29:22 2010
> @@ -1126,13 +1126,16 @@
>
> static void EmitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace,
> AsmPrinter &AP) {
> + SmallString<128> TmpBuffer;
> +
> // FP Constants are printed as integer constants to avoid losing
> // precision.
> if (CFP->getType()->isDoubleTy()) {
> if (AP.VerboseAsm) {
> + raw_svector_ostream OS(TmpBuffer);
> double Val = CFP->getValueAPF().convertToDouble(); // for comment only
> - AP.O.PadToColumn(AP.MAI->getCommentColumn());
> - AP.O << AP.MAI->getCommentString() << " double " << Val << '\n';
> + OS << "double " << Val;
> + AP.OutStreamer.addComment(OS.str());
What, we don't auto-word-wrap the comments? :)
- Daniel
> }
>
> uint64_t Val = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
>
> Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=94166&r1=94165&r2=94166&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Fri Jan 22 01:29:22 2010
> @@ -8,7 +8,6 @@
> //===----------------------------------------------------------------------===//
>
> #include "llvm/MC/MCStreamer.h"
> -#include "llvm/ADT/SmallString.h"
> #include "llvm/MC/MCAsmInfo.h"
> #include "llvm/MC/MCCodeEmitter.h"
> #include "llvm/MC/MCContext.h"
> @@ -17,22 +16,27 @@
> #include "llvm/MC/MCInstPrinter.h"
> #include "llvm/MC/MCSectionMachO.h"
> #include "llvm/MC/MCSymbol.h"
> +#include "llvm/ADT/SmallString.h"
> +#include "llvm/ADT/Twine.h"
> #include "llvm/Support/ErrorHandling.h"
> #include "llvm/Support/MathExtras.h"
> #include "llvm/Support/Format.h"
> -#include "llvm/Support/raw_ostream.h"
> +#include "llvm/Support/FormattedStream.h"
> using namespace llvm;
>
> namespace {
>
> class MCAsmStreamer : public MCStreamer {
> - raw_ostream &OS;
> + formatted_raw_ostream &OS;
> const MCAsmInfo &MAI;
> bool IsLittleEndian, IsVerboseAsm;
> MCInstPrinter *InstPrinter;
> MCCodeEmitter *Emitter;
> +
> + SmallString<128> CommentToEmit;
> public:
> - MCAsmStreamer(MCContext &Context, raw_ostream &os, const MCAsmInfo &mai,
> + MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os,
> + const MCAsmInfo &mai,
> bool isLittleEndian, bool isVerboseAsm, MCInstPrinter *printer,
> MCCodeEmitter *emitter)
> : MCStreamer(Context), OS(os), MAI(mai), IsLittleEndian(isLittleEndian),
> @@ -41,6 +45,22 @@
>
> bool isLittleEndian() const { return IsLittleEndian; }
>
> +
> + inline void EmitEOL() {
> + if (CommentToEmit.empty()) {
> + OS << '\n';
> + return;
> + }
> + EmitCommentsAndEOL();
> + }
> + void EmitCommentsAndEOL();
> +
> + /// 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
> + /// more readable. This only affects the MCAsmStreamer, and only when
> + /// verbose assembly output is enabled.
> + virtual void addComment(const Twine &T);
> +
> /// @name MCStreamer Interface
> /// @{
>
> @@ -86,6 +106,34 @@
>
> } // end anonymous namespace.
>
> +/// 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
> +/// more readable. This only affects the MCAsmStreamer, and only when
> +/// verbose assembly output is enabled.
> +void MCAsmStreamer::addComment(const Twine &T) {
> + if (!IsVerboseAsm) return;
> + // Each comment goes on its own line.
> + if (!CommentToEmit.empty())
> + CommentToEmit.push_back('\n');
> + T.toVector(CommentToEmit);
> +}
> +
> +void MCAsmStreamer::EmitCommentsAndEOL() {
> + StringRef Comments = CommentToEmit.str();
> + while (!Comments.empty()) {
> + // Emit a line of comments.
> + OS.PadToColumn(MAI.getCommentColumn());
> + size_t Position = Comments.find('\n');
> + OS << MAI.getCommentString() << ' ' << Comments.substr(0, Position) << '\n';
> +
> + if (Position == StringRef::npos) break;
> + Comments = Comments.substr(Position+1);
> + }
> +
> + CommentToEmit.clear();
> +}
> +
> +
> static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
> assert(Bytes && "Invalid size!");
> return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
> @@ -219,7 +267,8 @@
> }
>
> assert(Directive && "Invalid size for machine code value!");
> - OS << Directive << truncateToSize(Value, Size) << '\n';
> + OS << Directive << truncateToSize(Value, Size);
> + EmitEOL();
> }
>
> void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size,
> @@ -235,7 +284,8 @@
> }
>
> assert(Directive && "Invalid size for machine code value!");
> - OS << Directive << *truncateToSize(Value, Size) << '\n';
> + OS << Directive << *truncateToSize(Value, Size);
> + EmitEOL();
> }
>
> /// EmitFill - Emit NumBytes bytes worth of the value specified by
> @@ -249,7 +299,7 @@
> OS << ZeroDirective << NumBytes;
> if (FillValue != 0)
> OS << ',' << (int)FillValue;
> - OS << '\n';
> + EmitEOL();
> return;
> }
>
> @@ -349,7 +399,8 @@
> OS.flush();
> }
>
> -MCStreamer *llvm::createAsmStreamer(MCContext &Context, raw_ostream &OS,
> +MCStreamer *llvm::createAsmStreamer(MCContext &Context,
> + formatted_raw_ostream &OS,
> const MCAsmInfo &MAI, bool isLittleEndian,
> bool isVerboseAsm, MCInstPrinter *IP,
> MCCodeEmitter *CE) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list