AsmWriter should not print LLVM constant in comment. Assembler won't like
[oota-llvm.git] / lib / VMCore / AsmWriter.cpp
index a5ac8f03311d3131fd804772aec28dbbbf242be3..6b644219e13ac306dd98d24e9960ea095deff419 100644 (file)
@@ -26,7 +26,6 @@
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
-#include "llvm/Assembly/Writer.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/STLExtras.h"
@@ -419,6 +418,8 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
                              bool PrintName,
                              std::map<const Type *, std::string> &TypeTable,
                              SlotMachine *Machine) {
+  const int IndentSize = 4;
+  static std::string Indent = "\n";
   if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
     Out << (CB == ConstantBool::True ? "true" : "false");
   } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV)) {
@@ -482,22 +483,30 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
     }
   } else if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) {
     Out << '{';
-    if (CS->getNumOperands()) {
-      Out << ' ';
+    unsigned N = CS->getNumOperands();
+    if (N) {
+      if (N > 2) {
+        Indent += std::string(IndentSize, ' ');
+        Out << Indent;
+      } else {
+        Out << ' ';
+      }
       printTypeInt(Out, CS->getOperand(0)->getType(), TypeTable);
 
       WriteAsOperandInternal(Out, CS->getOperand(0),
                              PrintName, TypeTable, Machine);
 
-      for (unsigned i = 1; i < CS->getNumOperands(); i++) {
+      for (unsigned i = 1; i < N; i++) {
         Out << ", ";
+        if (N > 2) Out << Indent;
         printTypeInt(Out, CS->getOperand(i)->getType(), TypeTable);
 
         WriteAsOperandInternal(Out, CS->getOperand(i),
                                PrintName, TypeTable, Machine);
       }
+      if (N > 2) Indent.resize(Indent.size() - IndentSize);
     }
-
     Out << " }";
   } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(CV)) {
       const Type *ETy = CP->getType()->getElementType();
@@ -556,9 +565,18 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
     Out << getLLVMName(V->getName());
   else {
     const Constant *CV = dyn_cast<Constant>(V);
-    if (CV && !isa<GlobalValue>(CV))
+    if (CV && !isa<GlobalValue>(CV)) {
       WriteConstantInt(Out, CV, PrintName, TypeTable, Machine);
-    else {
+    } else if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
+      Out << "asm ";
+      if (IA->hasSideEffects())
+        Out << "sideeffect ";
+      Out << '"';
+      PrintEscapedString(IA->getAsmString(), Out);
+      Out << "\", \"";
+      PrintEscapedString(IA->getConstraintString(), Out);
+      Out << '"';
+    } else {
       int Slot;
       if (Machine) {
         Slot = Machine->getSlot(V);
@@ -1271,8 +1289,7 @@ void Function::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
 }
 
 void InlineAsm::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
-  assert(0 && "Inline asm printing unimplemented!");
-  //W.write(this);
+  WriteAsOperand(o, this, true, true, 0);
 }
 
 void BasicBlock::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
@@ -1294,9 +1311,6 @@ void Constant::print(std::ostream &o) const {
   if (this == 0) { o << "<null> constant value\n"; return; }
 
   o << ' ' << getType()->getDescription() << ' ';
-
-  std::map<const Type *, std::string> TypeTable;
-  WriteConstantInt(o, this, false, TypeTable, 0);
 }
 
 void Type::print(std::ostream &o) const {