llvm.org GIT mirror llvm / 4d5aad2
add bitcode reading support to llvm-nm git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36847 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
2 changed file(s) with 32 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
88 LEVEL = ../..
99
1010 TOOLNAME = llvm-nm
11 LINK_COMPONENTS = archive bcreader
12 REQUIRES_EH := 1
11 LINK_COMPONENTS = archive bcreader bitreader
1312
1413 include $(LEVEL)/Makefile.common
1616 //===----------------------------------------------------------------------===//
1717
1818 #include "llvm/Module.h"
19 #include "llvm/Bitcode/ReaderWriter.h"
1920 #include "llvm/Bytecode/Reader.h"
2021 #include "llvm/Bytecode/Archive.h"
2122 #include "llvm/Support/CommandLine.h"
2223 #include "llvm/Support/ManagedStatic.h"
24 #include "llvm/Support/MemoryBuffer.h"
2325 #include "llvm/System/Signals.h"
2426 #include
2527 #include
2628 #include
2729 #include
2830 #include
31 using namespace llvm;
2932
30 using namespace llvm;
33 cl::opt Bitcode("bitcode");
3134
3235 namespace {
3336 enum OutputFormatTy { bsd, sysv, posix };
131134 std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
132135 return;
133136 }
137 } else if (aPath.isBitcodeFile()) {
138 std::auto_ptr Buffer(
139 MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size()));
140 Module *Result = 0;
141 if (Buffer.get())
142 Result = ParseBitcodeFile(Buffer.get(), &ErrorMessage);
143
144 if (Result)
145 DumpSymbolNamesFromModule(Result);
146 else {
147 std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
148 return;
149 }
150
134151 } else if (aPath.isArchive()) {
135152 std::string ErrMsg;
136153 Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), &ErrorMessage);
152169
153170 int main(int argc, char **argv) {
154171 llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
155 try {
156 cl::ParseCommandLineOptions(argc, argv, " llvm symbol table dumper\n");
157 sys::PrintStackTraceOnErrorSignal();
172 cl::ParseCommandLineOptions(argc, argv, " llvm symbol table dumper\n");
173 sys::PrintStackTraceOnErrorSignal();
158174
159 ToolName = argv[0];
160 if (BSDFormat) OutputFormat = bsd;
161 if (POSIXFormat) OutputFormat = posix;
175 ToolName = argv[0];
176 if (BSDFormat) OutputFormat = bsd;
177 if (POSIXFormat) OutputFormat = posix;
162178
163 switch (InputFilenames.size()) {
164 case 0: InputFilenames.push_back("-");
165 case 1: break;
166 default: MultipleFiles = true;
167 }
179 switch (InputFilenames.size()) {
180 case 0: InputFilenames.push_back("-");
181 case 1: break;
182 default: MultipleFiles = true;
183 }
168184
169 std::for_each (InputFilenames.begin (), InputFilenames.end (),
170 DumpSymbolNamesFromFile);
171 return 0;
172 } catch (const std::string& msg) {
173 std::cerr << argv[0] << ": " << msg << "\n";
174 } catch (...) {
175 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
176 }
177 return 1;
185 std::for_each(InputFilenames.begin(), InputFilenames.end(),
186 DumpSymbolNamesFromFile);
187 return 0;
178188 }