summaryrefslogtreecommitdiff
path: root/tools/llvm-dis
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
commit009505452b713ed2e3a8e99c5545a6e721c65495 (patch)
tree136a71c5b87bdf534d1f20a67558b49226b5a4d6 /tools/llvm-dis
parent8d0afd3d32d1d67f9aa5df250a1d6955aa8f1ac9 (diff)
downloadllvm-009505452b713ed2e3a8e99c5545a6e721c65495.tar.gz
llvm-009505452b713ed2e3a8e99c5545a6e721c65495.tar.bz2
llvm-009505452b713ed2e3a8e99c5545a6e721c65495.tar.xz
Initial revision
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-dis')
-rw-r--r--tools/llvm-dis/Makefile10
-rw-r--r--tools/llvm-dis/dis.cpp64
-rw-r--r--tools/llvm-dis/llvm-dis.cpp64
3 files changed, 138 insertions, 0 deletions
diff --git a/tools/llvm-dis/Makefile b/tools/llvm-dis/Makefile
new file mode 100644
index 0000000000..fc77cdd140
--- /dev/null
+++ b/tools/llvm-dis/Makefile
@@ -0,0 +1,10 @@
+LEVEL = ../..
+include $(LEVEL)/Makefile.common
+
+all:: dis
+clean ::
+ rm -f dis
+
+dis : $(ObjectsG)
+ $(LinkG) -o $@ $(ObjectsG) -lvmcore -lasmwriter -lanalysis \
+ -lbcreader
diff --git a/tools/llvm-dis/dis.cpp b/tools/llvm-dis/dis.cpp
new file mode 100644
index 0000000000..3f45ee3c0d
--- /dev/null
+++ b/tools/llvm-dis/dis.cpp
@@ -0,0 +1,64 @@
+//===------------------------------------------------------------------------===
+// LLVM 'DIS' UTILITY
+//
+// This utility may be invoked in the following manner:
+// dis --help - Output information about command line switches
+// dis [options] - Read LLVM bytecode from stdin, write assembly to stdout
+// dis [options] x.bc - Read LLVM bytecode from the x.bc file, write assembly
+// to the x.ll file.
+//
+//===------------------------------------------------------------------------===
+
+#include <iostream.h>
+#include <fstream.h>
+#include "llvm/Module.h"
+#include "llvm/Assembly/Writer.h"
+#include "llvm/Bytecode/Reader.h"
+#include "llvm/Tools/CommandLine.h"
+
+int main(int argc, char **argv) {
+ ToolCommandLine Opts(argc, argv, false);
+
+ // We only support the options that the system parser does... if it left any
+ // then we don't know what to do.
+ //
+ if (argc > 1) {
+ for (int i = 1; i < argc; i++) {
+ if (string(argv[i]) != string("--help"))
+ cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
+ }
+
+ cerr << argv[0] << " usage:\n"
+ << " " << argv[0] << " --help - Print this usage information\n"
+ << " " << argv[0] << " x.bc - Parse <x.bc> file and output "
+ << "assembly to x.ll\n"
+ << " " << argv[0] << " - Parse stdin and write to stdout.\n";
+ return 1;
+ }
+
+ ostream *Out = &cout; // Default to printing to stdout...
+
+ Module *C = ParseBytecodeFile(Opts.getInputFilename());
+ if (C == 0) {
+ cerr << "bytecode didn't read correctly.\n";
+ return 1;
+ }
+
+ 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()
+ << ": sending to stdout instead!\n";
+ Out = &cout;
+ }
+ }
+
+ // All that dis does is write the assembly out to a file... which is exactly
+ // what the writer library is supposed to do...
+ (*Out) << C;
+ delete C;
+
+ if (Out != &cout) delete Out;
+ return 0;
+}
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
new file mode 100644
index 0000000000..3f45ee3c0d
--- /dev/null
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -0,0 +1,64 @@
+//===------------------------------------------------------------------------===
+// LLVM 'DIS' UTILITY
+//
+// This utility may be invoked in the following manner:
+// dis --help - Output information about command line switches
+// dis [options] - Read LLVM bytecode from stdin, write assembly to stdout
+// dis [options] x.bc - Read LLVM bytecode from the x.bc file, write assembly
+// to the x.ll file.
+//
+//===------------------------------------------------------------------------===
+
+#include <iostream.h>
+#include <fstream.h>
+#include "llvm/Module.h"
+#include "llvm/Assembly/Writer.h"
+#include "llvm/Bytecode/Reader.h"
+#include "llvm/Tools/CommandLine.h"
+
+int main(int argc, char **argv) {
+ ToolCommandLine Opts(argc, argv, false);
+
+ // We only support the options that the system parser does... if it left any
+ // then we don't know what to do.
+ //
+ if (argc > 1) {
+ for (int i = 1; i < argc; i++) {
+ if (string(argv[i]) != string("--help"))
+ cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
+ }
+
+ cerr << argv[0] << " usage:\n"
+ << " " << argv[0] << " --help - Print this usage information\n"
+ << " " << argv[0] << " x.bc - Parse <x.bc> file and output "
+ << "assembly to x.ll\n"
+ << " " << argv[0] << " - Parse stdin and write to stdout.\n";
+ return 1;
+ }
+
+ ostream *Out = &cout; // Default to printing to stdout...
+
+ Module *C = ParseBytecodeFile(Opts.getInputFilename());
+ if (C == 0) {
+ cerr << "bytecode didn't read correctly.\n";
+ return 1;
+ }
+
+ 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()
+ << ": sending to stdout instead!\n";
+ Out = &cout;
+ }
+ }
+
+ // All that dis does is write the assembly out to a file... which is exactly
+ // what the writer library is supposed to do...
+ (*Out) << C;
+ delete C;
+
+ if (Out != &cout) delete Out;
+ return 0;
+}