add a new EmitIntValue method that MCStreamer impls can optionally define
authorChris Lattner <sabre@nondot.org>
Tue, 19 Jan 2010 22:03:38 +0000 (22:03 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 19 Jan 2010 22:03:38 +0000 (22:03 +0000)
and that clients can use.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93923 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCStreamer.h
lib/MC/MCAsmStreamer.cpp
lib/MC/MCStreamer.cpp

index be66a624073ad07606281b69de3cbb446e39e444..f1680a94e3643584692bb0fb8bbd8b55cb3857b5 100644 (file)
@@ -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,
index f334600643642170066577b336535081e00bdea1..a126b52786315cf4b96a4f5694fad9ac9cb4c922 100644 (file)
@@ -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
index 20767de3bee335ec9146f152d5501af69ab365f1..4e9d094550a6e042822c6e1b726433712d656499 100644 (file)
@@ -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,