OLD | NEW |
1 //===-- llvm-dis.cpp - The low-level LLVM disassembler --------------------===// | 1 //===-- llvm-dis.cpp - The low-level LLVM disassembler --------------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This utility may be invoked in the following manner: | 10 // This utility may be invoked in the following manner: |
11 // llvm-dis [options] - Read LLVM bitcode from stdin, write asm to stdout | 11 // llvm-dis [options] - Read LLVM bitcode from stdin, write asm to stdout |
12 // llvm-dis [options] x.bc - Read LLVM bitcode from the x.bc file, write asm | 12 // llvm-dis [options] x.bc - Read LLVM bitcode from the x.bc file, write asm |
13 // to the x.ll file. | 13 // to the x.ll file. |
14 // Options: | 14 // Options: |
15 // --help - Output information about command line switches | 15 // --help - Output information about command line switches |
16 // | 16 // |
17 //===----------------------------------------------------------------------===// | 17 //===----------------------------------------------------------------------===// |
18 | 18 |
19 #include "llvm/IR/LLVMContext.h" | 19 #include "llvm/IR/LLVMContext.h" |
20 #include "llvm/Bitcode/ReaderWriter.h" | 20 #include "llvm/Bitcode/ReaderWriter.h" |
| 21 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" // @LOCALMOD |
21 #include "llvm/IR/AssemblyAnnotationWriter.h" | 22 #include "llvm/IR/AssemblyAnnotationWriter.h" |
22 #include "llvm/IR/DebugInfo.h" | 23 #include "llvm/IR/DebugInfo.h" |
23 #include "llvm/IR/IntrinsicInst.h" | 24 #include "llvm/IR/IntrinsicInst.h" |
24 #include "llvm/IR/Module.h" | 25 #include "llvm/IR/Module.h" |
25 #include "llvm/IR/Type.h" | 26 #include "llvm/IR/Type.h" |
| 27 #include "llvm/IRReader/IRReader.h" // @LOCALMOD |
26 #include "llvm/Support/CommandLine.h" | 28 #include "llvm/Support/CommandLine.h" |
27 #include "llvm/Support/DataStream.h" | 29 #include "llvm/Support/DataStream.h" |
28 #include "llvm/Support/FileSystem.h" | 30 #include "llvm/Support/FileSystem.h" |
29 #include "llvm/Support/FormattedStream.h" | 31 #include "llvm/Support/FormattedStream.h" |
30 #include "llvm/Support/ManagedStatic.h" | 32 #include "llvm/Support/ManagedStatic.h" |
31 #include "llvm/Support/MemoryBuffer.h" | 33 #include "llvm/Support/MemoryBuffer.h" |
32 #include "llvm/Support/PrettyStackTrace.h" | 34 #include "llvm/Support/PrettyStackTrace.h" |
33 #include "llvm/Support/Signals.h" | 35 #include "llvm/Support/Signals.h" |
| 36 #include "llvm/Support/StreamingMemoryObject.h" // @LOCALMOD |
34 #include "llvm/Support/ToolOutputFile.h" | 37 #include "llvm/Support/ToolOutputFile.h" |
35 #include <system_error> | 38 #include <system_error> |
36 using namespace llvm; | 39 using namespace llvm; |
37 | 40 |
38 static cl::opt<std::string> | 41 static cl::opt<std::string> |
39 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); | 42 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); |
40 | 43 |
41 static cl::opt<std::string> | 44 static cl::opt<std::string> |
42 OutputFilename("o", cl::desc("Override output filename"), | 45 OutputFilename("o", cl::desc("Override output filename"), |
43 cl::value_desc("filename")); | 46 cl::value_desc("filename")); |
44 | 47 |
45 static cl::opt<bool> | 48 static cl::opt<bool> |
46 Force("f", cl::desc("Enable binary output on terminals")); | 49 Force("f", cl::desc("Enable binary output on terminals")); |
47 | 50 |
48 static cl::opt<bool> | 51 static cl::opt<bool> |
49 DontPrint("disable-output", cl::desc("Don't output the .ll file"), cl::Hidden); | 52 DontPrint("disable-output", cl::desc("Don't output the .ll file"), cl::Hidden); |
50 | 53 |
51 static cl::opt<bool> | 54 static cl::opt<bool> |
52 ShowAnnotations("show-annotations", | 55 ShowAnnotations("show-annotations", |
53 cl::desc("Add informational comments to the .ll file")); | 56 cl::desc("Add informational comments to the .ll file")); |
54 | 57 |
| 58 // @LOCALMOD-BEGIN |
| 59 static cl::opt<NaClFileFormat> |
| 60 InputFileFormat( |
| 61 "bitcode-format", |
| 62 cl::desc("Define format of input bitcode file:"), |
| 63 cl::values( |
| 64 clEnumValN(LLVMFormat, "llvm", "LLVM bitcode file (default)"), |
| 65 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"), |
| 66 clEnumValEnd), |
| 67 cl::init(LLVMFormat)); |
| 68 // @LOCALMOD-END |
| 69 |
55 namespace { | 70 namespace { |
56 | 71 |
57 static void printDebugLoc(const DebugLoc &DL, formatted_raw_ostream &OS) { | 72 static void printDebugLoc(const DebugLoc &DL, formatted_raw_ostream &OS) { |
58 OS << DL.getLine() << ":" << DL.getCol(); | 73 OS << DL.getLine() << ":" << DL.getCol(); |
59 if (MDNode *N = DL.getInlinedAt(getGlobalContext())) { | 74 if (MDNode *N = DL.getInlinedAt(getGlobalContext())) { |
60 DebugLoc IDL = DebugLoc::getFromDILocation(N); | 75 DebugLoc IDL = DebugLoc::getFromDILocation(N); |
61 if (!IDL.isUnknown()) { | 76 if (!IDL.isUnknown()) { |
62 OS << "@"; | 77 OS << "@"; |
63 printDebugLoc(IDL,OS); | 78 printDebugLoc(IDL,OS); |
64 } | 79 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 LLVMContext &Context = getGlobalContext(); | 135 LLVMContext &Context = getGlobalContext(); |
121 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. | 136 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
122 | 137 |
123 | 138 |
124 cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n"); | 139 cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n"); |
125 | 140 |
126 std::string ErrorMessage; | 141 std::string ErrorMessage; |
127 std::unique_ptr<Module> M; | 142 std::unique_ptr<Module> M; |
128 | 143 |
129 // Use the bitcode streaming interface | 144 // Use the bitcode streaming interface |
130 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage); | 145 DataStreamer *streamer(getDataFileStreamer(InputFilename, &ErrorMessage)); |
131 if (streamer) { | 146 if (streamer) { |
| 147 std::unique_ptr<StreamingMemoryObject> Buffer( |
| 148 new StreamingMemoryObjectImpl(streamer)); // @LOCALMOD |
132 std::string DisplayFilename; | 149 std::string DisplayFilename; |
133 if (InputFilename == "-") | 150 if (InputFilename == "-") |
134 DisplayFilename = "<stdin>"; | 151 DisplayFilename = "<stdin>"; |
135 else | 152 else |
136 DisplayFilename = InputFilename; | 153 DisplayFilename = InputFilename; |
137 M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, | 154 |
138 &ErrorMessage)); | 155 // @LOCALMOD-BEGIN |
| 156 switch (InputFileFormat) { |
| 157 case LLVMFormat: |
| 158 // The Module's BitcodeReader's BitstreamReader takes ownership |
| 159 // of the StreamingMemoryObject. |
| 160 M.reset(getStreamedBitcodeModule( |
| 161 DisplayFilename, Buffer.release(), Context, &ErrorMessage)); |
| 162 break; |
| 163 case PNaClFormat: { |
| 164 M.reset(getNaClStreamedBitcodeModule( |
| 165 DisplayFilename, Buffer.release(), Context, nullptr, |
| 166 &ErrorMessage)); |
| 167 break; |
| 168 case AutodetectFileFormat: |
| 169 report_fatal_error("Command can't autodetect file format!"); |
| 170 } |
| 171 } |
| 172 // @LOCALMOD-END |
| 173 |
139 if(M.get()) { | 174 if(M.get()) { |
140 if (std::error_code EC = M->materializeAllPermanently()) { | 175 if (std::error_code EC = M->materializeAllPermanently()) { |
141 ErrorMessage = EC.message(); | 176 ErrorMessage = EC.message(); |
142 M.reset(); | 177 M.reset(); |
143 } | 178 } |
144 } | 179 } |
145 } | 180 } |
146 | 181 |
147 if (!M.get()) { | 182 if (!M.get()) { |
148 errs() << argv[0] << ": "; | 183 errs() << argv[0] << ": "; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 220 |
186 // All that llvm-dis does is write the assembly to a file. | 221 // All that llvm-dis does is write the assembly to a file. |
187 if (!DontPrint) | 222 if (!DontPrint) |
188 M->print(Out->os(), Annotator.get()); | 223 M->print(Out->os(), Annotator.get()); |
189 | 224 |
190 // Declare success. | 225 // Declare success. |
191 Out->keep(); | 226 Out->keep(); |
192 | 227 |
193 return 0; | 228 return 0; |
194 } | 229 } |
OLD | NEW |