summaryrefslogtreecommitdiff
path: root/tools/llvm-as
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-23 02:35:57 +0000
committerChris Lattner <sabre@nondot.org>2001-07-23 02:35:57 +0000
commit8f367bd3c0f56b7b318c46cee04f77735f617777 (patch)
treeef00b00e2465f9168bbbd83fd2ebef8fa857146f /tools/llvm-as
parenta28504313d4c3fe87173a71b511dd4c8e25c3312 (diff)
downloadllvm-8f367bd3c0f56b7b318c46cee04f77735f617777.tar.gz
llvm-8f367bd3c0f56b7b318c46cee04f77735f617777.tar.bz2
llvm-8f367bd3c0f56b7b318c46cee04f77735f617777.tar.xz
Large scale changes to implement new command line argument facility
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-as')
-rw-r--r--tools/llvm-as/Makefile2
-rw-r--r--tools/llvm-as/as.cpp65
-rw-r--r--tools/llvm-as/llvm-as.cpp65
3 files changed, 61 insertions, 71 deletions
diff --git a/tools/llvm-as/Makefile b/tools/llvm-as/Makefile
index 9d36cc1d00..fcb9293572 100644
--- a/tools/llvm-as/Makefile
+++ b/tools/llvm-as/Makefile
@@ -6,4 +6,4 @@ clean::
rm -f as
as : $(ObjectsG)
- $(LinkG) -o as $(ObjectsG) -lasmparser -lbcwriter -lasmwriter -lanalysis -lvmcore
+ $(LinkG) -o as $(ObjectsG) -lasmparser -lbcwriter -lasmwriter -lanalysis -lvmcore -lsupport
diff --git a/tools/llvm-as/as.cpp b/tools/llvm-as/as.cpp
index 2c319a0849..da05a36f7f 100644
--- a/tools/llvm-as/as.cpp
+++ b/tools/llvm-as/as.cpp
@@ -18,54 +18,49 @@
#include "llvm/Bytecode/Writer.h"
#include "llvm/Tools/CommandLine.h"
+cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
+cl::String OutputFilename("o", "Override output filename", 0, "");
+cl::Flag Force ("f", "Overwrite output files", 0, false);
+cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false);
int main(int argc, char **argv) {
- ToolCommandLine Opts(argc, argv);
- bool DumpAsm = false;
+ cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n");
- for (int i = 1; i < argc; i++) {
- if (string(argv[i]) == string("-d")) {
- argv[i] = 0; DumpAsm = true;
- }
- }
-
- bool PrintMessage = false;
- for (int i = 1; i < argc; i++) {
- if (argv[i] == 0) continue;
-
- if (string(argv[i]) == string("--help")) {
- PrintMessage = true;
- } else {
- cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
- }
- }
-
- if (PrintMessage) {
- cerr << argv[0] << " usage:\n"
- << " " << argv[0] << " --help - Print this usage information\n"
- << " " << argv[0] << " x.ll - Parse <x.ll> file and output "
- << "bytecodes to x.bc\n"
- << " " << argv[0] << " - Parse stdin and write to stdout.\n";
- return 1;
- }
-
- ostream *Out = &cout; // Default to output to stdout...
+ ostream *Out = 0;
try {
// Parse the file now...
- Module *C = ParseAssemblyFile(Opts);
+ Module *C = ParseAssemblyFile(InputFilename.getValue());
if (C == 0) {
cerr << "assembly didn't read correctly.\n";
return 1;
}
- if (DumpAsm)
+ if (DumpAsm.getValue())
cerr << "Here's the assembly:\n" << C;
+
+ if (OutputFilename.getValue() != "") { // Specified an output filename?
+ Out = new ofstream(OutputFilename.getValue().c_str(),
+ (Force.getValue() ? 0 : ios::noreplace)|ios::out);
+ } else {
+ if (InputFilename.getValue() == "-") {
+ OutputFilename.setValue("-");
+ Out = &cout;
+ } else {
+ string IFN = InputFilename.getValue();
+ int Len = IFN.length();
+ if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
+ // Source ends in .ll
+ OutputFilename.setValue(string(IFN.begin(), IFN.end()-3));
+ } else {
+ OutputFilename.setValue(IFN); // Append a .bc to it
+ }
+ OutputFilename.setValue(OutputFilename.getValue() + ".bc");
+ Out = new ofstream(OutputFilename.getValue().c_str(),
+ (Force.getValue() ? 0 : ios::noreplace)|ios::out);
+ }
- if (Opts.getOutputFilename() != "-") {
- Out = new ofstream(Opts.getOutputFilename().c_str(),
- (Opts.getForce() ? 0 : ios::noreplace)|ios::out);
if (!Out->good()) {
- cerr << "Error opening " << Opts.getOutputFilename() << "!\n";
+ cerr << "Error opening " << OutputFilename.getValue() << "!\n";
delete C;
return 1;
}
diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp
index 2c319a0849..da05a36f7f 100644
--- a/tools/llvm-as/llvm-as.cpp
+++ b/tools/llvm-as/llvm-as.cpp
@@ -18,54 +18,49 @@
#include "llvm/Bytecode/Writer.h"
#include "llvm/Tools/CommandLine.h"
+cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
+cl::String OutputFilename("o", "Override output filename", 0, "");
+cl::Flag Force ("f", "Overwrite output files", 0, false);
+cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false);
int main(int argc, char **argv) {
- ToolCommandLine Opts(argc, argv);
- bool DumpAsm = false;
+ cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n");
- for (int i = 1; i < argc; i++) {
- if (string(argv[i]) == string("-d")) {
- argv[i] = 0; DumpAsm = true;
- }
- }
-
- bool PrintMessage = false;
- for (int i = 1; i < argc; i++) {
- if (argv[i] == 0) continue;
-
- if (string(argv[i]) == string("--help")) {
- PrintMessage = true;
- } else {
- cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
- }
- }
-
- if (PrintMessage) {
- cerr << argv[0] << " usage:\n"
- << " " << argv[0] << " --help - Print this usage information\n"
- << " " << argv[0] << " x.ll - Parse <x.ll> file and output "
- << "bytecodes to x.bc\n"
- << " " << argv[0] << " - Parse stdin and write to stdout.\n";
- return 1;
- }
-
- ostream *Out = &cout; // Default to output to stdout...
+ ostream *Out = 0;
try {
// Parse the file now...
- Module *C = ParseAssemblyFile(Opts);
+ Module *C = ParseAssemblyFile(InputFilename.getValue());
if (C == 0) {
cerr << "assembly didn't read correctly.\n";
return 1;
}
- if (DumpAsm)
+ if (DumpAsm.getValue())
cerr << "Here's the assembly:\n" << C;
+
+ if (OutputFilename.getValue() != "") { // Specified an output filename?
+ Out = new ofstream(OutputFilename.getValue().c_str(),
+ (Force.getValue() ? 0 : ios::noreplace)|ios::out);
+ } else {
+ if (InputFilename.getValue() == "-") {
+ OutputFilename.setValue("-");
+ Out = &cout;
+ } else {
+ string IFN = InputFilename.getValue();
+ int Len = IFN.length();
+ if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
+ // Source ends in .ll
+ OutputFilename.setValue(string(IFN.begin(), IFN.end()-3));
+ } else {
+ OutputFilename.setValue(IFN); // Append a .bc to it
+ }
+ OutputFilename.setValue(OutputFilename.getValue() + ".bc");
+ Out = new ofstream(OutputFilename.getValue().c_str(),
+ (Force.getValue() ? 0 : ios::noreplace)|ios::out);
+ }
- if (Opts.getOutputFilename() != "-") {
- Out = new ofstream(Opts.getOutputFilename().c_str(),
- (Opts.getForce() ? 0 : ios::noreplace)|ios::out);
if (!Out->good()) {
- cerr << "Error opening " << Opts.getOutputFilename() << "!\n";
+ cerr << "Error opening " << OutputFilename.getValue() << "!\n";
delete C;
return 1;
}