Fix use of LEVEL.
[oota-llvm.git] / lib / VMCore / AsmWriter.cpp
index c6a3845a07f9de32052f9ee41fe28abab869c157..cc8c5a12324fa78dc28f4b6182dad9ef83c3b160 100644 (file)
 #include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/InlineAsm.h"
 #include "llvm/Instruction.h"
 #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"
@@ -418,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)) {
@@ -481,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();
@@ -555,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);
@@ -1270,11 +1289,7 @@ void Function::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
 }
 
 void InlineAsm::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
-  SlotMachine SlotTable(getParent());
-  AssemblyWriter W(o, SlotTable, getParent(), AAW);
-  
-  assert(0 && "Inline asm printing unimplemented!");
-  //W.write(this);
+  WriteAsOperand(o, this, true, true, 0);
 }
 
 void BasicBlock::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {