[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Jan 23 15:03:47 PST 2006



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.185 -> 1.186
---
Log message:

Print out inline asm strings


---
Diffs of the changes:  (+23 -22)

 AsmWriter.cpp |   45 +++++++++++++++++++++++----------------------
 1 files changed, 23 insertions(+), 22 deletions(-)


Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.185 llvm/lib/VMCore/AsmWriter.cpp:1.186
--- llvm/lib/VMCore/AsmWriter.cpp:1.185	Fri Nov 11 18:10:19 2005
+++ llvm/lib/VMCore/AsmWriter.cpp	Mon Jan 23 17:03:36 2006
@@ -398,6 +398,21 @@
   }
 }
 
+// PrintEscapedString - Print each character of the specified string, escaping
+// it if it is not printable or if it is an escape char.
+static void PrintEscapedString(const std::string &Str, std::ostream &Out) {
+  for (unsigned i = 0, e = Str.size(); i != e; ++i) {
+    unsigned char C = Str[i];
+    if (isprint(C) && C != '"' && C != '\\') {
+      Out << C;
+    } else {
+      Out << '\\'
+          << (char) ((C/16  < 10) ? ( C/16 +'0') : ( C/16 -10+'A'))
+          << (char)(((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A'));
+    }
+  }
+}
+
 /// @brief Internal constant writer.
 static void WriteConstantInt(std::ostream &Out, const Constant *CV,
                              bool PrintName,
@@ -443,29 +458,9 @@
     // ubytes or an array of sbytes with positive values.
     //
     const Type *ETy = CA->getType()->getElementType();
-    bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
-
-    if (ETy == Type::SByteTy)
-      for (unsigned i = 0; i < CA->getNumOperands(); ++i)
-        if (cast<ConstantSInt>(CA->getOperand(i))->getValue() < 0) {
-          isString = false;
-          break;
-        }
-
-    if (isString) {
+    if (CA->isString()) {
       Out << "c\"";
-      for (unsigned i = 0; i < CA->getNumOperands(); ++i) {
-        unsigned char C =
-          (unsigned char)cast<ConstantInt>(CA->getOperand(i))->getRawValue();
-
-        if (isprint(C) && C != '"' && C != '\\') {
-          Out << C;
-        } else {
-          Out << '\\'
-              << (char) ((C/16  < 10) ? ( C/16 +'0') : ( C/16 -10+'A'))
-              << (char)(((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A'));
-        }
-      }
+      PrintEscapedString(CA->getAsString(), Out);
       Out << "\"";
 
     } else {                // Cannot output in string format...
@@ -780,6 +775,12 @@
   if (!M->getTargetTriple().empty())
     Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
 
+  if (!M->getInlineAsm().empty()) {
+    Out << "asm \"";
+    PrintEscapedString(M->getInlineAsm(), Out);
+    Out << "\"\n";
+  }
+  
   // Loop over the dependent libraries and emit them.
   Module::lib_iterator LI = M->lib_begin();
   Module::lib_iterator LE = M->lib_end();






More information about the llvm-commits mailing list