summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-as/llvm-as.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-06-06 20:29:01 +0000
committerChris Lattner <sabre@nondot.org>2001-06-06 20:29:01 +0000
commit2f7c963559dbc6dbda43df77a090a93f94c6625e (patch)
tree095d7b8910fd91af079a547362923a3ed877ded1 /llvm/tools/llvm-as/llvm-as.cpp
parent97724f18c79c7cc81ced24239eb5e883bf1398ef (diff)
downloadbcm5719-llvm-2f7c963559dbc6dbda43df77a090a93f94c6625e.tar.gz
bcm5719-llvm-2f7c963559dbc6dbda43df77a090a93f94c6625e.zip
Initial revision
llvm-svn: 2
Diffstat (limited to 'llvm/tools/llvm-as/llvm-as.cpp')
-rw-r--r--llvm/tools/llvm-as/llvm-as.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/llvm/tools/llvm-as/llvm-as.cpp b/llvm/tools/llvm-as/llvm-as.cpp
new file mode 100644
index 00000000000..2c319a08491
--- /dev/null
+++ b/llvm/tools/llvm-as/llvm-as.cpp
@@ -0,0 +1,85 @@
+//===------------------------------------------------------------------------===
+// LLVM 'AS' UTILITY
+//
+// This utility may be invoked in the following manner:
+// as --help - Output information about command line switches
+// as [options] - Read LLVM assembly from stdin, write bytecode to stdout
+// as [options] x.ll - Read LLVM assembly from the x.ll file, write bytecode
+// to the x.bc file.
+//
+//===------------------------------------------------------------------------===
+
+#include <iostream.h>
+#include <fstream.h>
+#include <string>
+#include "llvm/Module.h"
+#include "llvm/Assembly/Parser.h"
+#include "llvm/Assembly/Writer.h"
+#include "llvm/Bytecode/Writer.h"
+#include "llvm/Tools/CommandLine.h"
+
+
+int main(int argc, char **argv) {
+ ToolCommandLine Opts(argc, argv);
+ bool DumpAsm = false;
+
+ 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...
+ try {
+ // Parse the file now...
+ Module *C = ParseAssemblyFile(Opts);
+ if (C == 0) {
+ cerr << "assembly didn't read correctly.\n";
+ return 1;
+ }
+
+ if (DumpAsm)
+ cerr << "Here's the assembly:\n" << C;
+
+ 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";
+ delete C;
+ return 1;
+ }
+ }
+
+ WriteBytecodeToFile(C, *Out);
+
+ delete C;
+ } catch (const ParseException &E) {
+ cerr << E.getMessage() << endl;
+ return 1;
+ }
+
+ if (Out != &cout) delete Out;
+ return 0;
+}
+
OpenPOWER on IntegriCloud