1 //===------------------------------------------------------------------------===
4 // This utility may be invoked in the following manner:
5 // as --help - Output information about command line switches
6 // as [options] - Read LLVM assembly from stdin, write bytecode to stdout
7 // as [options] x.ll - Read LLVM assembly from the x.ll file, write bytecode
10 //===------------------------------------------------------------------------===
15 #include "llvm/Module.h"
16 #include "llvm/Assembly/Parser.h"
17 #include "llvm/Assembly/Writer.h"
18 #include "llvm/Bytecode/Writer.h"
19 #include "llvm/Tools/CommandLine.h"
22 int main(int argc, char **argv) {
23 ToolCommandLine Opts(argc, argv);
26 for (int i = 1; i < argc; i++) {
27 if (string(argv[i]) == string("-d")) {
28 argv[i] = 0; DumpAsm = true;
32 bool PrintMessage = false;
33 for (int i = 1; i < argc; i++) {
34 if (argv[i] == 0) continue;
36 if (string(argv[i]) == string("--help")) {
39 cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
44 cerr << argv[0] << " usage:\n"
45 << " " << argv[0] << " --help - Print this usage information\n"
46 << " " << argv[0] << " x.ll - Parse <x.ll> file and output "
47 << "bytecodes to x.bc\n"
48 << " " << argv[0] << " - Parse stdin and write to stdout.\n";
52 ostream *Out = &cout; // Default to output to stdout...
54 // Parse the file now...
55 Module *C = ParseAssemblyFile(Opts);
57 cerr << "assembly didn't read correctly.\n";
62 cerr << "Here's the assembly:\n" << C;
64 if (Opts.getOutputFilename() != "-") {
65 Out = new ofstream(Opts.getOutputFilename().c_str(),
66 (Opts.getForce() ? 0 : ios::noreplace)|ios::out);
68 cerr << "Error opening " << Opts.getOutputFilename() << "!\n";
74 WriteBytecodeToFile(C, *Out);
77 } catch (const ParseException &E) {
78 cerr << E.getMessage() << endl;
82 if (Out != &cout) delete Out;