blob: a3312967d64942c85e79c5410aba57d9c646d737 [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"
Chris Lattnerdd511762001-07-21 20:58:30 +000017#include "llvm/CodeGen/InstrSelection.h"
Chris Lattner9c0f8f22001-07-22 04:40:02 +000018#include "llvm/CodeGen/Sparc.h"
Chris Lattnere2472bb2001-07-23 17:46:59 +000019#include "llvm/Support/CommandLine.h"
Chris Lattner0af24642001-07-23 02:35:57 +000020
Chris Lattnerab0cc402001-07-23 19:27:24 +000021cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
Chris Lattner0af24642001-07-23 02:35:57 +000022cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
23
Chris Lattnerab0cc402001-07-23 19:27:24 +000024static bool CompileModule(Module *M, TargetMachine &Target) {
Chris Lattner9c0f8f22001-07-22 04:40:02 +000025 bool failed = false;
26
Chris Lattnerab0cc402001-07-23 19:27:24 +000027 for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
28 Method * method = *MI;
Chris Lattner9c0f8f22001-07-22 04:40:02 +000029
Chris Lattnerab0cc402001-07-23 19:27:24 +000030 if (SelectInstructionsForMethod(method, Target)) {
31 failed = true;
32 cerr << "Instruction selection failed for method "
33 << method->getName() << "\n\n";
Chris Lattner9c0f8f22001-07-22 04:40:02 +000034 }
Chris Lattnerab0cc402001-07-23 19:27:24 +000035 }
Chris Lattner9c0f8f22001-07-22 04:40:02 +000036
37 return failed;
38}
Vikram S. Adve2d94a342001-07-21 12:42:29 +000039
40
41//---------------------------------------------------------------------------
42// Function main()
43//
44// Entry point for the driver.
45//---------------------------------------------------------------------------
46
Chris Lattner0af24642001-07-23 02:35:57 +000047int main(int argc, char** argv) {
48 cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
Chris Lattnerd8f1cc92001-07-23 03:09:03 +000049 UltraSparc Target;
Chris Lattner0af24642001-07-23 02:35:57 +000050
Chris Lattnerab0cc402001-07-23 19:27:24 +000051 Module *module = ParseBytecodeFile(InputFilename);
Vikram S. Adve2d94a342001-07-21 12:42:29 +000052 if (module == 0) {
53 cerr << "bytecode didn't read correctly.\n";
54 return 1;
55 }
56
Chris Lattnerab0cc402001-07-23 19:27:24 +000057 if (CompileModule(module, Target)) {
58 cerr << "Error compiling " << InputFilename << "!\n";
59 delete module;
60 return 1;
61 }
Vikram S. Adve2d94a342001-07-21 12:42:29 +000062
63 // Clean up and exit
64 delete module;
65 return 0;
66}