blob: c4370d9e84211ba938d37800e3e799835c61441f [file] [log] [blame]
Vikram S. Adve2d94a342001-07-21 12:42:29 +00001// $Id$
2//***************************************************************************
3// File:
4// llc.cpp
5//
6// Purpose:
7// Driver for llc compiler.
8//
9// History:
10// 7/15/01 - Vikram Adve - Created
11//
12//**************************************************************************/
13
Vikram S. Adve2d94a342001-07-21 12:42:29 +000014#include "llvm/Module.h"
15#include "llvm/Method.h"
16#include "llvm/Bytecode/Reader.h"
17#include "llvm/Bytecode/Writer.h"
Chris Lattnerdd511762001-07-21 20:58:30 +000018#include "llvm/CodeGen/InstrSelection.h"
Chris Lattner9c0f8f22001-07-22 04:40:02 +000019#include "llvm/CodeGen/Sparc.h"
Chris Lattnere2472bb2001-07-23 17:46:59 +000020#include "llvm/Support/CommandLine.h"
Chris Lattner0af24642001-07-23 02:35:57 +000021
22cl::String InputFilename ("", "Input filename", cl::NoFlags, "");
23cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
24
Chris Lattnerd8f1cc92001-07-23 03:09:03 +000025static bool CompileModule(Module *module, TargetMachine &Target) {
Chris Lattner9c0f8f22001-07-22 04:40:02 +000026 bool failed = false;
27
28 for (Module::MethodListType::const_iterator
29 methodIter = module->getMethodList().begin();
30 methodIter != module->getMethodList().end();
31 ++methodIter)
32 {
33 Method* method = *methodIter;
34
Chris Lattnerd8f1cc92001-07-23 03:09:03 +000035 if (SelectInstructionsForMethod(method, Target))
Chris Lattner9c0f8f22001-07-22 04:40:02 +000036 {
37 failed = true;
38 cerr << "Instruction selection failed for method "
39 << method->getName() << "\n\n";
40 }
41 }
42
43 return failed;
44}
Vikram S. Adve2d94a342001-07-21 12:42:29 +000045
46
47//---------------------------------------------------------------------------
48// Function main()
49//
50// Entry point for the driver.
51//---------------------------------------------------------------------------
52
Chris Lattner0af24642001-07-23 02:35:57 +000053int main(int argc, char** argv) {
54 cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
Chris Lattnerd8f1cc92001-07-23 03:09:03 +000055 UltraSparc Target;
Chris Lattner0af24642001-07-23 02:35:57 +000056
57 Module *module = ParseBytecodeFile(InputFilename.getValue());
Vikram S. Adve2d94a342001-07-21 12:42:29 +000058 if (module == 0) {
59 cerr << "bytecode didn't read correctly.\n";
60 return 1;
61 }
62
Chris Lattnerd8f1cc92001-07-23 03:09:03 +000063 bool failure = CompileModule(module, Target);
Vikram S. Adve2d94a342001-07-21 12:42:29 +000064
Chris Lattner9c0f8f22001-07-22 04:40:02 +000065 if (failure) {
Vikram S. Adve2d94a342001-07-21 12:42:29 +000066 cerr << "Error compiling "
Chris Lattner0af24642001-07-23 02:35:57 +000067 << InputFilename.getValue() << "!\n";
Vikram S. Adve2d94a342001-07-21 12:42:29 +000068 delete module;
69 return 1;
70 }
71
72 // Okay, we're done now... write out result...
73 // WriteBytecodeToFile(module,
Chris Lattner0af24642001-07-23 02:35:57 +000074 // OutputFilename.getValue());
Vikram S. Adve2d94a342001-07-21 12:42:29 +000075
76 // Clean up and exit
77 delete module;
78 return 0;
79}