diff options
Diffstat (limited to 'tools/llvm-dis/llvm-dis.cpp')
| -rw-r--r-- | tools/llvm-dis/llvm-dis.cpp | 54 | 
1 files changed, 30 insertions, 24 deletions
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index 1349ecc85a4cd..26f14b9b1a287 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -54,16 +54,18 @@ static cl::opt<bool>  ShowAnnotations("show-annotations",                  cl::desc("Add informational comments to the .ll file")); +static cl::opt<bool> PreserveAssemblyUseListOrder( +    "preserve-ll-uselistorder", +    cl::desc("Preserve use-list order when writing LLVM assembly."), +    cl::init(false), cl::Hidden); +  namespace {  static void printDebugLoc(const DebugLoc &DL, formatted_raw_ostream &OS) {    OS << DL.getLine() << ":" << DL.getCol(); -  if (MDNode *N = DL.getInlinedAt(getGlobalContext())) { -    DebugLoc IDL = DebugLoc::getFromDILocation(N); -    if (!IDL.isUnknown()) { -      OS << "@"; -      printDebugLoc(IDL,OS); -    } +  if (DILocation *IDL = DL.getInlinedAt()) { +    OS << "@"; +    printDebugLoc(IDL, OS);    }  }  class CommentWriter : public AssemblyAnnotationWriter { @@ -78,11 +80,11 @@ public:      if (!V.getType()->isVoidTy()) {        OS.PadToColumn(50);        Padded = true; -      OS << "; [#uses=" << V.getNumUses() << " type=" << *V.getType() << "]";  // Output # uses and type +      // Output # uses and type +      OS << "; [#uses=" << V.getNumUses() << " type=" << *V.getType() << "]";      }      if (const Instruction *I = dyn_cast<Instruction>(&V)) { -      const DebugLoc &DL = I->getDebugLoc(); -      if (!DL.isUnknown()) { +      if (const DebugLoc &DL = I->getDebugLoc()) {          if (!Padded) {            OS.PadToColumn(50);            Padded = true; @@ -93,20 +95,18 @@ public:          OS << "]";        }        if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I)) { -        DIVariable Var(DDI->getVariable());          if (!Padded) {            OS.PadToColumn(50);            OS << ";";          } -        OS << " [debug variable = " << Var.getName() << "]"; +        OS << " [debug variable = " << DDI->getVariable()->getName() << "]";        }        else if (const DbgValueInst *DVI = dyn_cast<DbgValueInst>(I)) { -        DIVariable Var(DVI->getVariable());          if (!Padded) {            OS.PadToColumn(50);            OS << ";";          } -        OS << " [debug variable = " << Var.getName() << "]"; +        OS << " [debug variable = " << DVI->getVariable()->getName() << "]";        }      }    } @@ -115,14 +115,21 @@ public:  } // end anon namespace  static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) { -  assert(DI.getSeverity() == DS_Error && "Only expecting errors"); -    raw_ostream &OS = errs();    OS << (char *)Context << ": "; +  switch (DI.getSeverity()) { +  case DS_Error: OS << "error: "; break; +  case DS_Warning: OS << "warning: "; break; +  case DS_Remark: OS << "remark: "; break; +  case DS_Note: OS << "note: "; break; +  } +    DiagnosticPrinterRawOStream DP(OS);    DI.print(DP);    OS << '\n'; -  exit(1); + +  if (DI.getSeverity() == DS_Error) +    exit(1);  }  int main(int argc, char **argv) { @@ -152,6 +159,9 @@ int main(int argc, char **argv) {          getStreamedBitcodeModule(DisplayFilename, Streamer, Context);      M = std::move(*MOrErr);      M->materializeAllPermanently(); +  } else { +    errs() << argv[0] << ": " << ErrorMessage << '\n'; +    return 1;    }    // Just use stdout.  We won't actually print anything on it. @@ -162,13 +172,9 @@ int main(int argc, char **argv) {      if (InputFilename == "-") {        OutputFilename = "-";      } else { -      const std::string &IFN = InputFilename; -      int Len = IFN.length(); -      // If the source ends in .bc, strip it off. -      if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') -        OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".ll"; -      else -        OutputFilename = IFN+".ll"; +      StringRef IFN = InputFilename; +      OutputFilename = (IFN.endswith(".bc") ? IFN.drop_back(3) : IFN).str(); +      OutputFilename += ".ll";      }    } @@ -186,7 +192,7 @@ int main(int argc, char **argv) {    // All that llvm-dis does is write the assembly to a file.    if (!DontPrint) -    M->print(Out->os(), Annotator.get()); +    M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder);    // Declare success.    Out->keep();  | 
