mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-16 12:24:03 +00:00
Change raw_fd_ostream to take flags as an optional bitmask
instead of as two bools. Use this to add a F_Append flag which has the obvious behavior. Other unrelated changes conflated into this patch: 1. REmove EH stuff from llvm-dis and llvm-as, the try blocks are dead. 2. Simplify the filename inference code in llvm-as/llvm-dis, because raw_fd_ostream does the right thing with '-'. 3. Switch machine verifier to use raw_ostream instead of ostream (Which is the thing that needed append in the first place). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79807 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -50,90 +50,70 @@ int main(int argc, char **argv) {
|
||||
|
||||
LLVMContext &Context = getGlobalContext();
|
||||
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
||||
try {
|
||||
cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
|
||||
|
||||
|
||||
cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
|
||||
|
||||
raw_ostream *Out = &outs(); // Default to printing to stdout.
|
||||
std::string ErrorMessage;
|
||||
|
||||
std::auto_ptr<Module> M;
|
||||
|
||||
if (MemoryBuffer *Buffer
|
||||
= MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
|
||||
M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage));
|
||||
delete Buffer;
|
||||
}
|
||||
|
||||
if (M.get() == 0) {
|
||||
errs() << argv[0] << ": ";
|
||||
if (ErrorMessage.size())
|
||||
errs() << ErrorMessage << "\n";
|
||||
else
|
||||
errs() << "bitcode didn't read correctly.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (DontPrint) {
|
||||
// Just use stdout. We won't actually print anything on it.
|
||||
} else if (OutputFilename != "") { // Specified an output filename?
|
||||
if (OutputFilename != "-") { // Not stdout?
|
||||
std::string ErrorInfo;
|
||||
Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false,
|
||||
Force, ErrorInfo);
|
||||
if (!ErrorInfo.empty()) {
|
||||
errs() << ErrorInfo << '\n';
|
||||
if (!Force)
|
||||
errs() << "Use -f command line argument to force output\n";
|
||||
delete Out;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (InputFilename == "-") {
|
||||
OutputFilename = "-";
|
||||
} else {
|
||||
std::string IFN = InputFilename;
|
||||
int Len = IFN.length();
|
||||
if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
|
||||
// Source ends in .bc
|
||||
OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".ll";
|
||||
} else {
|
||||
OutputFilename = IFN+".ll";
|
||||
}
|
||||
|
||||
std::string ErrorInfo;
|
||||
Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false,
|
||||
Force, ErrorInfo);
|
||||
if (!ErrorInfo.empty()) {
|
||||
errs() << ErrorInfo << '\n';
|
||||
if (!Force)
|
||||
errs() << "Use -f command line argument to force output\n";
|
||||
delete Out;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Make sure that the Out file gets unlinked from the disk if we get a
|
||||
// SIGINT
|
||||
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
|
||||
}
|
||||
}
|
||||
|
||||
// All that llvm-dis does is write the assembly to a file.
|
||||
if (!DontPrint) {
|
||||
PassManager Passes;
|
||||
Passes.add(createPrintModulePass(Out));
|
||||
Passes.run(*M.get());
|
||||
}
|
||||
|
||||
if (Out != &outs())
|
||||
delete Out;
|
||||
return 0;
|
||||
} catch (const std::string& msg) {
|
||||
errs() << argv[0] << ": " << msg << "\n";
|
||||
} catch (...) {
|
||||
errs() << argv[0] << ": Unexpected unknown exception occurred.\n";
|
||||
std::string ErrorMessage;
|
||||
std::auto_ptr<Module> M;
|
||||
|
||||
if (MemoryBuffer *Buffer
|
||||
= MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
|
||||
M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage));
|
||||
delete Buffer;
|
||||
}
|
||||
|
||||
return 1;
|
||||
if (M.get() == 0) {
|
||||
errs() << argv[0] << ": ";
|
||||
if (ErrorMessage.size())
|
||||
errs() << ErrorMessage << "\n";
|
||||
else
|
||||
errs() << "bitcode didn't read correctly.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Just use stdout. We won't actually print anything on it.
|
||||
if (DontPrint)
|
||||
OutputFilename = "-";
|
||||
|
||||
if (OutputFilename.empty()) { // Unspecified output, infer it.
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
std::string ErrorInfo;
|
||||
std::auto_ptr<raw_fd_ostream>
|
||||
Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
|
||||
(Force?raw_fd_ostream::F_Force : 0) |
|
||||
raw_fd_ostream::F_Binary));
|
||||
if (!ErrorInfo.empty()) {
|
||||
errs() << ErrorInfo << '\n';
|
||||
if (!Force)
|
||||
errs() << "Use -f command line argument to force output\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Make sure that the Out file gets unlinked from the disk if we get a
|
||||
// SIGINT.
|
||||
if (OutputFilename != "-")
|
||||
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
|
||||
|
||||
// All that llvm-dis does is write the assembly to a file.
|
||||
if (!DontPrint) {
|
||||
PassManager Passes;
|
||||
Passes.add(createPrintModulePass(Out.get()));
|
||||
Passes.run(*M.get());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user