diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-19 22:03:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-19 22:03:38 +0000 |
commit | dc50e5d128f98081e3fda1bb42a6e49150ba5ffc (patch) | |
tree | 849c6684a834b58fee1f51d4566237af4740cf96 | |
parent | 92244b00c7d151934e58e826d73337e594cf663e (diff) | |
download | bcm5719-llvm-dc50e5d128f98081e3fda1bb42a6e49150ba5ffc.tar.gz bcm5719-llvm-dc50e5d128f98081e3fda1bb42a6e49150ba5ffc.zip |
add a new EmitIntValue method that MCStreamer impls can optionally define
and that clients can use.
llvm-svn: 93923
-rw-r--r-- | llvm/include/llvm/MC/MCStreamer.h | 4 | ||||
-rw-r--r-- | llvm/lib/MC/MCAsmStreamer.cpp | 35 | ||||
-rw-r--r-- | llvm/lib/MC/MCStreamer.cpp | 7 |
3 files changed, 40 insertions, 6 deletions
diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index be66a624073..f1680a94e36 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -169,6 +169,10 @@ namespace llvm { virtual void EmitValue(const MCExpr *Value, unsigned Size, unsigned AddrSpace) = 0; + /// EmitIntValue - Special case of EmitValue that avoids the client having + /// to pass in a MCExpr for constant integers. + virtual void EmitIntValue(uint64_t Value, unsigned Size,unsigned AddrSpace); + /// EmitFill - Emit NumBytes bytes worth of the value specified by /// FillValue. This implements directives such as '.space'. virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue, diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index f3346006436..a126b527863 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -61,6 +61,8 @@ public: virtual void EmitBytes(StringRef Data, unsigned AddrSpace); virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace); + virtual void EmitIntValue(uint64_t Value, unsigned Size, unsigned AddrSpace); + virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue, unsigned AddrSpace); @@ -187,19 +189,40 @@ void MCAsmStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) { OS << Directive << (unsigned)(unsigned char)Data[i] << '\n'; } +/// EmitIntValue - Special case of EmitValue that avoids the client having +/// to pass in a MCExpr for constant integers. +void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size, + unsigned AddrSpace) { + assert(CurSection && "Cannot emit contents before setting section!"); + // Need target hooks to know how to print this. + const char *Directive = 0; + switch (Size) { + default: break; + case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break; + case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break; + case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break; + case 8: Directive = MAI.getData64bitsDirective(AddrSpace); break; + } + + assert(Directive && "Invalid size for machine code value!"); + OS << Directive << truncateToSize(Value, Size) << '\n'; +} + void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size, unsigned AddrSpace) { assert(CurSection && "Cannot emit contents before setting section!"); // Need target hooks to know how to print this. + const char *Directive = 0; switch (Size) { - default: assert(0 && "Invalid size for machine code value!"); - case 1: OS << MAI.getData8bitsDirective(AddrSpace); break; - case 2: OS << MAI.getData16bitsDirective(AddrSpace); break; - case 4: OS << MAI.getData32bitsDirective(AddrSpace); break; - case 8: OS << MAI.getData64bitsDirective(AddrSpace); break; + default: break; + case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break; + case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break; + case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break; + case 8: Directive = MAI.getData64bitsDirective(AddrSpace); break; } - OS << *truncateToSize(Value, Size) << '\n'; + assert(Directive && "Invalid size for machine code value!"); + OS << Directive << *truncateToSize(Value, Size) << '\n'; } /// EmitFill - Emit NumBytes bytes worth of the value specified by diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 20767de3bee..4e9d094550a 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -18,6 +18,13 @@ MCStreamer::MCStreamer(MCContext &_Context) : Context(_Context), CurSection(0) { MCStreamer::~MCStreamer() { } +/// EmitIntValue - Special case of EmitValue that avoids the client having to +/// pass in a MCExpr for constant integers. +void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size, + unsigned AddrSpace) { + EmitValue(MCConstantExpr::Create(Value, getContext()), Size, AddrSpace); +} + /// EmitFill - Emit NumBytes bytes worth of the value specified by /// FillValue. This implements directives such as '.space'. void MCStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue, |